Skip to content

Commit d49cd3c

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Track, rather than compute, isCallOnInterceptor
By tracking `isCallOnInterceptor`, we avoid the need for class context information in the `sourceElement` to compute the value. `sourceElement` is now purely advisory to the choice of local names in codegen, and can't be the wrong kind of element as in issue #60793. Bug: #60793 Change-Id: I8bb68b6bf864a3a6f9f2beb40f68a6254431d49a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432003 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent 74f74d7 commit d49cd3c

File tree

9 files changed

+103
-107
lines changed

9 files changed

+103
-107
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ class SsaCodeGenerator implements HVisitor<void>, HBlockInformationVisitor {
24802480
if (superElement is FieldEntity) {
24812481
// TODO(sra): We can lower these in the simplifier.
24822482
js.Name fieldName = _namer.instanceFieldPropertyName(superElement);
2483-
use(node.getDartReceiver(_closedWorld));
2483+
use(node.getDartReceiver());
24842484
js.PropertyAccess access =
24852485
js.PropertyAccess(
24862486
pop(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SsaInstructionSelection extends HBaseVisitor<HInstruction?>
111111
// The instructionType of [nullCheck] is not nullable (since it is the
112112
// (not) null check!) This means that if we do need to check the type, we
113113
// should test against nullCheck.checkedInput, not the direct input.
114-
if (current!.getDartReceiver(_closedWorld) == nullCheck) {
114+
if (current!.getDartReceiver() == nullCheck) {
115115
if (current is HFieldGet) return current;
116116
if (current is HFieldSet) return current;
117117
if (current is HGetLength) return current;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class SsaFinalizeInterceptors extends HBaseVisitor<void>
6262
}
6363

6464
/// Returns `true` if [element] is an instance method that uses the
65-
/// interceptor calling convention but the instance and interceptor arguments
66-
/// will always be the same value.
65+
/// interceptor calling convention but the interceptor argument will always be
66+
/// the instance.
6767
bool usesSelfInterceptor(MemberEntity element) {
6868
if (!_interceptorData.isInterceptedMethod(element)) return false;
6969
ClassEntity cls = element.enclosingClass!;
@@ -101,6 +101,12 @@ class SsaFinalizeInterceptors extends HBaseVisitor<void>
101101
thisParameter!.instructionType = receiverParameter!.instructionType;
102102
receiverParameter.block!.rewrite(receiverParameter, thisParameter);
103103
receiverParameter.sourceElement = const _RenameToUnderscore();
104+
105+
for (final instruction in thisParameter.usedBy) {
106+
if (instruction is HInvoke) {
107+
instruction.updateIsCallOnInterceptor();
108+
}
109+
}
104110
}
105111

106112
@override
@@ -262,6 +268,7 @@ class SsaFinalizeInterceptors extends HBaseVisitor<void>
262268
}
263269

264270
void _replaceReceiverArgumentWithDummy(HInvoke node, int receiverIndex) {
271+
assert(!node.isCallOnInterceptor, 'node: $node');
265272
ConstantValue constant = DummyInterceptorConstantValue();
266273
HConstant dummy = _graph.addConstant(constant, _closedWorld);
267274
node.replaceInput(receiverIndex, dummy);

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class SsaSimplifyInterceptors extends HBaseVisitor<bool>
266266
// If there is a call that dominates all other uses, we can use just the
267267
// selector of that instruction.
268268
if (dominator is HInvokeDynamic &&
269-
dominator.isCallOnInterceptor(_closedWorld) &&
269+
dominator.isCallOnInterceptor &&
270270
node == dominator.receiver &&
271271
useCount(dominator, node) == 1) {
272272
interceptedClasses = _interceptorData.getInterceptedClassesOn(
@@ -303,7 +303,7 @@ class SsaSimplifyInterceptors extends HBaseVisitor<bool>
303303
interceptedClasses = {};
304304
for (HInstruction user in node.usedBy) {
305305
if (user is HInvokeDynamic &&
306-
user.isCallOnInterceptor(_closedWorld) &&
306+
user.isCallOnInterceptor &&
307307
node == user.receiver &&
308308
useCount(user, node) == 1) {
309309
interceptedClasses.addAll(
@@ -313,7 +313,7 @@ class SsaSimplifyInterceptors extends HBaseVisitor<bool>
313313
),
314314
);
315315
} else if (user is HInvokeSuper &&
316-
user.isCallOnInterceptor(_closedWorld) &&
316+
user.isCallOnInterceptor &&
317317
node == user.receiver &&
318318
useCount(user, node) == 1) {
319319
interceptedClasses.addAll(
@@ -402,7 +402,7 @@ class SsaSimplifyInterceptors extends HBaseVisitor<bool>
402402
// }
403403

404404
void finishInvoke(HInvoke invoke, Selector selector) {
405-
HInstruction callReceiver = invoke.getDartReceiver(_closedWorld)!;
405+
HInstruction callReceiver = invoke.getDartReceiver()!;
406406
if (receiver.nonCheck() == callReceiver.nonCheck()) {
407407
Set<ClassEntity> interceptedClasses = _interceptorData
408408
.getInterceptedClassesOn(selector.name, _closedWorld);
@@ -412,19 +412,20 @@ class SsaSimplifyInterceptors extends HBaseVisitor<bool>
412412
interceptedClasses: interceptedClasses,
413413
)) {
414414
invoke.changeUse(node, callReceiver);
415+
invoke.updateIsCallOnInterceptor();
415416
}
416417
}
417418
}
418419

419420
for (HInstruction user in node.usedBy.toList()) {
420421
if (user is HInvokeDynamic) {
421-
if (user.isCallOnInterceptor(_closedWorld) &&
422+
if (user.isCallOnInterceptor &&
422423
node == user.inputs[0] &&
423424
useCount(user, node) == 1) {
424425
finishInvoke(user, user.selector);
425426
}
426427
} else if (user is HInvokeSuper) {
427-
if (user.isCallOnInterceptor(_closedWorld) &&
428+
if (user.isCallOnInterceptor &&
428429
node == user.inputs[0] &&
429430
useCount(user, node) == 1) {
430431
finishInvoke(user, user.selector);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class IndexSpecializer extends InvokeDynamicSpecializer {
361361
JClosedWorld closedWorld,
362362
OptimizationTestLog? log,
363363
) {
364-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
364+
HInstruction receiver = instruction.getDartReceiver();
365365
var abstractValueDomain = closedWorld.abstractValueDomain;
366366
if (receiver.isIndexablePrimitive(abstractValueDomain).isPotentiallyFalse) {
367367
return null;
@@ -419,7 +419,7 @@ class CodeUnitAtSpecializer extends InvokeDynamicSpecializer {
419419
OptimizationTestLog? log,
420420
) {
421421
final abstractValueDomain = closedWorld.abstractValueDomain;
422-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
422+
HInstruction receiver = instruction.getDartReceiver();
423423
if (receiver.isStringOrNull(abstractValueDomain).isPotentiallyFalse) {
424424
return null;
425425
}
@@ -460,7 +460,7 @@ class RemoveLastSpecializer extends InvokeDynamicSpecializer {
460460
JClosedWorld closedWorld,
461461
OptimizationTestLog? log,
462462
) {
463-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
463+
HInstruction receiver = instruction.getDartReceiver();
464464
final abstractValueDomain = closedWorld.abstractValueDomain;
465465
if (receiver.isGrowableArray(abstractValueDomain).isPotentiallyFalse) {
466466
return null;
@@ -876,7 +876,7 @@ class ModuloSpecializer extends BinaryArithmeticSpecializer {
876876
// track -0.0 precisely, we have to syntactically filter inputs that cannot
877877
// generate -0.0.
878878

879-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
879+
HInstruction receiver = instruction.getDartReceiver();
880880
if (inputsArePositiveIntegers(instruction, closedWorld) &&
881881
!canBeNegativeZero(receiver)) {
882882
return HRemainder(
@@ -1840,7 +1840,7 @@ class CompareToSpecializer extends InvokeDynamicSpecializer {
18401840
JClosedWorld closedWorld,
18411841
OptimizationTestLog? log,
18421842
) {
1843-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
1843+
HInstruction receiver = instruction.getDartReceiver();
18441844
// `compareTo` has no side-effect (other than throwing) and can be GVN'ed
18451845
// for some known types.
18461846
if (receiver
@@ -1890,7 +1890,7 @@ abstract class IdempotentStringOperationSpecializer
18901890
JClosedWorld closedWorld,
18911891
OptimizationTestLog? log,
18921892
) {
1893-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
1893+
HInstruction receiver = instruction.getDartReceiver();
18941894
if (receiver
18951895
.isStringOrNull(closedWorld.abstractValueDomain)
18961896
.isDefinitelyTrue) {
@@ -1937,7 +1937,7 @@ class PatternMatchSpecializer extends InvokeDynamicSpecializer {
19371937
JClosedWorld closedWorld,
19381938
OptimizationTestLog? log,
19391939
) {
1940-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
1940+
HInstruction receiver = instruction.getDartReceiver();
19411941
HInstruction pattern = instruction.inputs[2];
19421942
if (receiver
19431943
.isStringOrNull(closedWorld.abstractValueDomain)
@@ -1969,7 +1969,7 @@ class RoundSpecializer extends InvokeDynamicSpecializer {
19691969
JClosedWorld closedWorld,
19701970
OptimizationTestLog? log,
19711971
) {
1972-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
1972+
HInstruction receiver = instruction.getDartReceiver();
19731973
if (receiver
19741974
.isNumberOrNull(closedWorld.abstractValueDomain)
19751975
.isDefinitelyTrue) {
@@ -1997,7 +1997,7 @@ class ToIntSpecializer extends InvokeDynamicSpecializer {
19971997
JClosedWorld closedWorld,
19981998
OptimizationTestLog? log,
19991999
) {
2000-
HInstruction receiver = instruction.getDartReceiver(closedWorld);
2000+
HInstruction receiver = instruction.getDartReceiver();
20012001

20022002
// We would like to reduce `x.toInt()` to `x`. The web platform considers
20032003
// infinities to be `int` values, but it is too hard to tell if an input is

0 commit comments

Comments
 (0)