Skip to content

Commit

Permalink
[dart2wasm] Generate direct calls in dynamic invocations
Browse files Browse the repository at this point in the history
Also removes an old TODO about handling null receivers in dynamic
invocations.

Change-Id: I08e14e19084e7186259375b6ac99cde19587dc27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271322
Commit-Queue: Ömer Ağacan <[email protected]>
Reviewed-by: Aske Simon Christensen <[email protected]>
Reviewed-by: Joshua Litt <[email protected]>
  • Loading branch information
osa1 authored and Commit Queue committed Nov 22, 2022
1 parent 8caeaf7 commit a06f10c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pkg/dart2wasm/lib/dynamic_dispatch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class DynamicDispatcher {
// all we care about is code size, we might do best to use constant maps or
// one function per selector. On the other hand, we could also try a hybrid
// IC like approach using globals, rewiring logic, and a state machine.
// TODO(joshualitt): Handle the case of a null receiver.
w.Local cidLocal = addLocal(w.NumType.i32);

// Outer block searches through the methods and invokes the method if it
Expand Down Expand Up @@ -155,28 +154,26 @@ class DynamicDispatcher {
}
translator.functions.activateSelector(selector);
for (int classID in selector.classIds) {
final Reference target = selector.targets[classID]!;
if (target.asMember.isAbstract) {
continue;
}

b.local_get(cidLocal);
b.i32_const(classID);
b.i32_eq();
b.if_();

// TODO(joshualitt): We should be able to make this a direct
// invocation. However, there appear to be corner cases today where we
// still need to do the actual invocation as an indirect call, for
// example if the procedure we are invoking is abstract.
b.comment("Dynamic invocation of '${selector.name}'");
b.local_get(receiverVar);
translator.convertType(function, translator.topInfo.nullableType,
selector.signature.inputs[0]);

pushArguments(selector);
b.local_get(cidLocal);
int offset = selector.offset!;
if (offset != 0) {
b.i32_const(offset);
b.i32_add();
}
b.call_indirect(selector.signature);

final w.BaseFunction targetFunction =
translator.functions.getFunction(target);
b.call(targetFunction);

w.ValueType result =
translator.outputOrVoid(selector.signature.outputs);
Expand Down

0 comments on commit a06f10c

Please sign in to comment.