Skip to content

Commit 8ef843e

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm,dyn_modules] Support implicit dynamic calls in bytecode
TEST=ci (co19/Language/Expressions/Function_Invocation/Function_Expression_Invocation/call_A04_t01) Change-Id: I49faf7c6f8d8f9353683dd94e9aa9a7ac7d30921 Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443882 Reviewed-by: Tess Strickland <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 9b157b6 commit 8ef843e

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

pkg/dart2bytecode/lib/bytecode_generator.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,10 @@ class BytecodeGenerator extends RecursiveVisitor {
10391039

10401040
late Library? dartFfiLibrary = libraryIndex.tryGetLibrary('dart:ffi');
10411041

1042+
// Selector for implicit dynamic calls 'foo(...)' where
1043+
// variable 'foo' has type 'dynamic'.
1044+
late final implicitCallName = Name('implicit:call');
1045+
10421046
void _recordSourcePosition(int fileOffset) {
10431047
asm.currentSourcePosition = fileOffset;
10441048
maxSourcePosition = math.max(maxSourcePosition, fileOffset);
@@ -3128,12 +3132,13 @@ class BytecodeGenerator extends RecursiveVisitor {
31283132

31293133
@override
31303134
void visitDynamicInvocation(DynamicInvocation node) {
3131-
_genMethodInvocation(node, null);
3135+
final targetName = node.isImplicitCall ? implicitCallName : node.name;
3136+
_genMethodInvocation(node, null, targetName);
31323137
}
31333138

31343139
@override
31353140
void visitInstanceInvocation(InstanceInvocation node) {
3136-
_genMethodInvocation(node, node.interfaceTarget);
3141+
_genMethodInvocation(node, node.interfaceTarget, node.name);
31373142
}
31383143

31393144
@override
@@ -3151,8 +3156,8 @@ class BytecodeGenerator extends RecursiveVisitor {
31513156
asm.emitSpecializedBytecode(Opcode.kEqualsNull);
31523157
}
31533158

3154-
void _genMethodInvocation(
3155-
InstanceInvocationExpression node, Procedure? interfaceTarget) {
3159+
void _genMethodInvocation(InstanceInvocationExpression node,
3160+
Procedure? interfaceTarget, Name targetName) {
31563161
final Opcode? opcode = recognizedMethods.specializedBytecodeFor(node);
31573162
if (opcode != null) {
31583163
_genMethodInvocationUsingSpecializedBytecode(opcode, node);
@@ -3172,7 +3177,7 @@ class BytecodeGenerator extends RecursiveVisitor {
31723177
final argDesc =
31733178
objectTable.getArgDescHandleByArguments(args, hasReceiver: true);
31743179

3175-
_genInstanceCall(node, InvocationKind.method, interfaceTarget, node.name,
3180+
_genInstanceCall(node, InvocationKind.method, interfaceTarget, targetName,
31763181
node.receiver, totalArgCount, argDesc);
31773182
}
31783183

pkg/dart2bytecode/testcases/super_calls.dart.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ ConstantPool {
184184
[1] = DirectCall 'DART_SDK/pkg/dart2bytecode/testcases/super_calls.dart::Base1::get:bar', ArgDesc num-args 1, num-type-args 0, names []
185185
[2] = Reserved
186186
[3] = ObjectRef 'param'
187-
[4] = DynamicCall 'call', ArgDesc num-args 2, num-type-args 1, names []
187+
[4] = DynamicCall 'implicit:call', ArgDesc num-args 2, num-type-args 1, names []
188188
[5] = Reserved
189189
}
190190

@@ -404,7 +404,7 @@ ConstantPool {
404404
[6] = DirectCall 'dart:core::Object::noSuchMethod', ArgDesc num-args 2, num-type-args 0, names []
405405
[7] = Reserved
406406
[8] = ObjectRef 'param'
407-
[9] = DynamicCall 'call', ArgDesc num-args 2, num-type-args 1, names []
407+
[9] = DynamicCall 'implicit:call', ArgDesc num-args 2, num-type-args 1, names []
408408
[10] = Reserved
409409
}
410410

pkg/dart2bytecode/testcases/try_blocks.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ ConstantPool {
762762
[6] = Type dynamic
763763
[7] = ObjectRef 'try 2'
764764
[8] = EndClosureFunctionScope
765-
[9] = DynamicCall 'call', ArgDesc num-args 1, num-type-args 0, names []
765+
[9] = DynamicCall 'implicit:call', ArgDesc num-args 1, num-type-args 0, names []
766766
[10] = Reserved
767767
}
768768
Closure DART_SDK/pkg/dart2bytecode/testcases/try_blocks.dart::testTryFinally3::'<anonymous closure>' () -> dart:core::int

runtime/vm/runtime_entry.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,8 @@ static ObjectPtr InvokeCallThroughGetterOrNoSuchMethod(
31943194
// o.foo(...) failed, invoke noSuchMethod is foo exists but has the wrong
31953195
// number of arguments, or try (o.foo).call(...)
31963196

3197-
if ((target_name.ptr() == Symbols::call().ptr()) && receiver.IsClosure()) {
3197+
if ((demangled_target_name.ptr() == Symbols::call().ptr()) &&
3198+
receiver.IsClosure()) {
31983199
// Special case: closures are implemented with a call getter instead of a
31993200
// call method and with lazy dispatchers the field-invocation-dispatcher
32003201
// would perform the closure call.

0 commit comments

Comments
 (0)