Skip to content

Commit 576ef91

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] new-rti: lower field setters
Replace calls to field setters that don't need a check with HFieldSet. Change-Id: I3408e87fc82686e66cf01d53a4ae10f94279041d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112704 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com>
1 parent 06509e3 commit 576ef91

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

pkg/compiler/lib/src/inferrer/typemasks/masks.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class CommonMasks implements AbstractValueDomain {
305305
} else if (type is FunctionType) {
306306
return finish(
307307
TypeMask.subtype(commonElements.functionClass, _closedWorld), false);
308+
} else if (type is DynamicType) {
309+
return AbstractValueWithPrecision(dynamicType, true);
308310
} else {
309311
return finish(dynamicType, false);
310312
}

pkg/compiler/lib/src/ssa/optimize.dart

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,41 +1335,64 @@ class SsaInstructionSimplifier extends HBaseVisitor
13351335
// Use `node.inputs.last` in case the call follows the interceptor calling
13361336
// convention, but is not a call on an interceptor.
13371337
HInstruction value = node.inputs.last;
1338-
if (_closedWorld.annotationsData.getParameterCheckPolicy(field).isEmitted) {
1339-
if (_options.experimentNewRti) {
1340-
// TODO(sra): Implement inlining of setters with checks for new rti.
1341-
node.needsCheck = true;
1342-
return node;
1343-
}
1344-
DartType type = _closedWorld.elementEnvironment.getFieldType(field);
1345-
if (!type.treatAsRaw ||
1346-
type.isTypeVariable ||
1347-
type.unaliased.isFunctionType ||
1348-
type.unaliased.isFutureOr) {
1349-
// We cannot generate the correct type representation here, so don't
1350-
// inline this access.
1351-
// TODO(sra): If the input is such that we don't need a type check, we
1352-
// can skip the test an generate the HFieldSet.
1353-
node.needsCheck = true;
1354-
return node;
1355-
}
1356-
HInstruction other =
1357-
value.convertType(_closedWorld, type, HTypeConversion.TYPE_CHECK);
1358-
if (other != value) {
1359-
node.block.addBefore(node, other);
1360-
value = other;
1338+
1339+
HInstruction assignField() {
1340+
if (_closedWorld.fieldAnalysis.getFieldData(field).isElided) {
1341+
_log?.registerFieldSet(node);
1342+
return value;
1343+
} else {
1344+
HFieldSet result =
1345+
new HFieldSet(_abstractValueDomain, field, receiver, value)
1346+
..sourceInformation = node.sourceInformation;
1347+
_log?.registerFieldSet(node, result);
1348+
return result;
13611349
}
13621350
}
1363-
if (_closedWorld.fieldAnalysis.getFieldData(field).isElided) {
1364-
_log?.registerFieldSet(node);
1365-
return value;
1366-
} else {
1367-
HFieldSet result =
1368-
new HFieldSet(_abstractValueDomain, field, receiver, value)
1369-
..sourceInformation = node.sourceInformation;
1370-
_log?.registerFieldSet(node, result);
1371-
return result;
1351+
1352+
if (!_closedWorld.annotationsData
1353+
.getParameterCheckPolicy(field)
1354+
.isEmitted) {
1355+
return assignField();
13721356
}
1357+
1358+
DartType fieldType = _closedWorld.elementEnvironment.getFieldType(field);
1359+
1360+
if (_options.experimentNewRti) {
1361+
AbstractValueWithPrecision checkedType =
1362+
_abstractValueDomain.createFromStaticType(fieldType);
1363+
if (checkedType.isPrecise &&
1364+
_abstractValueDomain
1365+
.isIn(value.instructionType, checkedType.abstractValue)
1366+
.isDefinitelyTrue) {
1367+
return assignField();
1368+
}
1369+
// TODO(sra): Implement inlining of setters with checks for new rti. The
1370+
// check and field assignmeny for the setter should inlined if this is the
1371+
// only call to the setter, or the current function already computes the
1372+
// type of the field.
1373+
node.needsCheck = true;
1374+
return node;
1375+
}
1376+
1377+
if (!fieldType.treatAsRaw ||
1378+
fieldType.isTypeVariable ||
1379+
fieldType.unaliased.isFunctionType ||
1380+
fieldType.unaliased.isFutureOr) {
1381+
// We cannot generate the correct type representation here, so don't
1382+
// inline this access.
1383+
// TODO(sra): If the input is such that we don't need a type check, we
1384+
// can skip the test an generate the HFieldSet.
1385+
node.needsCheck = true;
1386+
return node;
1387+
}
1388+
HInstruction other =
1389+
value.convertType(_closedWorld, fieldType, HTypeConversion.TYPE_CHECK);
1390+
if (other != value) {
1391+
node.block.addBefore(node, other);
1392+
value = other;
1393+
}
1394+
1395+
return assignField();
13731396
}
13741397

13751398
@override

0 commit comments

Comments
 (0)