Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a06f10c

Browse files
osa1Commit Queue
authored and
Commit Queue
committed
[dart2wasm] Generate direct calls in dynamic invocations
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]>
1 parent 8caeaf7 commit a06f10c

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

pkg/dart2wasm/lib/dynamic_dispatch.dart

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class DynamicDispatcher {
113113
// all we care about is code size, we might do best to use constant maps or
114114
// one function per selector. On the other hand, we could also try a hybrid
115115
// IC like approach using globals, rewiring logic, and a state machine.
116-
// TODO(joshualitt): Handle the case of a null receiver.
117116
w.Local cidLocal = addLocal(w.NumType.i32);
118117

119118
// Outer block searches through the methods and invokes the method if it
@@ -155,28 +154,26 @@ class DynamicDispatcher {
155154
}
156155
translator.functions.activateSelector(selector);
157156
for (int classID in selector.classIds) {
157+
final Reference target = selector.targets[classID]!;
158+
if (target.asMember.isAbstract) {
159+
continue;
160+
}
161+
158162
b.local_get(cidLocal);
159163
b.i32_const(classID);
160164
b.i32_eq();
161165
b.if_();
162166

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

172172
pushArguments(selector);
173-
b.local_get(cidLocal);
174-
int offset = selector.offset!;
175-
if (offset != 0) {
176-
b.i32_const(offset);
177-
b.i32_add();
178-
}
179-
b.call_indirect(selector.signature);
173+
174+
final w.BaseFunction targetFunction =
175+
translator.functions.getFunction(target);
176+
b.call(targetFunction);
180177

181178
w.ValueType result =
182179
translator.outputOrVoid(selector.signature.outputs);

0 commit comments

Comments
 (0)