@@ -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