Skip to content

Commit 96fbc26

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2wasm] Add indirection for dispatch table calls.
In a future change we will add logic to `callDispatchTable` that performs a modified lookup if the provided selector is marked as "overrideable" by the dynamic_interface.yaml passed by a user. Change-Id: Ie8991ca3ebf5d3ff1287cbfc4af58e1b1509826d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401202 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent d261ded commit 96fbc26

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

pkg/dart2wasm/lib/code_generator.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,8 @@ abstract class AstCodeGenerator
18771877
pushReceiver(selector.signature);
18781878

18791879
if (selector.targetRanges.length == 1) {
1880+
// TODO(natebiggs): Ensure dynamic modules exclude this.
1881+
18801882
assert(selector.staticDispatchRanges.length == 1);
18811883
final target = selector.targetRanges[0].target;
18821884
final signature = translator.signatureForDirectCall(target);
@@ -1887,6 +1889,8 @@ abstract class AstCodeGenerator
18871889
}
18881890

18891891
if (selector.targetRanges.isEmpty) {
1892+
// TODO(natebiggs): Ensure dynamic modules exclude this.
1893+
18901894
// Unreachable call
18911895
b.comment("Virtual call of ${selector.name} with no targets"
18921896
" at ${node.location}");
@@ -1907,22 +1911,15 @@ abstract class AstCodeGenerator
19071911
pushArguments(selector.signature, selector.paramInfo);
19081912

19091913
if (selector.staticDispatchRanges.isNotEmpty) {
1914+
// TODO(natebiggs): Ensure dynamic modules exclude this.
1915+
19101916
b.invoke(translator
19111917
.getPolymorphicDispatchersForModule(b.module)
19121918
.getPolymorphicDispatcher(selector));
19131919
} else {
1914-
final offset = selector.offset!;
19151920
b.comment("Instance $kind of '${selector.name}'");
19161921
b.local_get(receiverVar);
1917-
b.struct_get(translator.topInfo.struct, FieldIndex.classId);
1918-
if (offset != 0) {
1919-
b.i32_const(offset);
1920-
b.i32_add();
1921-
}
1922-
b.call_indirect(
1923-
selector.signature, translator.dispatchTable.getWasmTable(b.module));
1924-
1925-
translator.functions.recordSelectorUse(selector);
1922+
translator.callDispatchTable(b, selector);
19261923
}
19271924

19281925
return translator.outputOrVoid(selector.signature.outputs);

pkg/dart2wasm/lib/dynamic_forwarders.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -773,16 +773,7 @@ void generateNoSuchMethodCall(
773773

774774
// Get class id for virtual call
775775
pushReceiver();
776-
b.struct_get(translator.topInfo.struct, FieldIndex.classId);
777-
778-
// Virtual call to noSuchMethod
779-
int selectorOffset = noSuchMethodSelector.offset!;
780-
if (selectorOffset != 0) {
781-
b.i32_const(selectorOffset);
782-
b.i32_add();
783-
}
784-
785-
b.call_indirect(noSuchMethodWasmFunctionType);
776+
translator.callDispatchTable(b, noSuchMethodSelector);
786777
}
787778

788779
class ClassIdRange {

pkg/dart2wasm/lib/translator.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,17 @@ class Translator with KernelNodes {
485485
return function.type.outputs;
486486
}
487487

488+
void callDispatchTable(w.InstructionsBuilder b, SelectorInfo selector) {
489+
// TODO(natebiggs): Handle dispatch to dynamic module overrideable members.
490+
b.struct_get(topInfo.struct, FieldIndex.classId);
491+
if (selector.offset! != 0) {
492+
b.i32_const(selector.offset!);
493+
b.i32_add();
494+
}
495+
b.call_indirect(selector.signature, dispatchTable.getWasmTable(b.module));
496+
functions.recordSelectorUse(selector);
497+
}
498+
488499
Class classForType(DartType type) {
489500
return type is InterfaceType
490501
? type.classNode
@@ -2000,12 +2011,7 @@ class PolymorphicDispatcherCodeGenerator implements CodeGenerator {
20002011
b.local_get(paramLocals[i]);
20012012
}
20022013
b.local_get(paramLocals[0]);
2003-
b.struct_get(translator.topInfo.struct, FieldIndex.classId);
2004-
b.i32_const(selector.offset!);
2005-
b.i32_add();
2006-
b.call_indirect(
2007-
signature, translator.dispatchTable.getWasmTable(b.module));
2008-
translator.functions.recordSelectorUse(selector);
2014+
translator.callDispatchTable(b, selector);
20092015
}
20102016

20112017
b.local_get(paramLocals[0]);

0 commit comments

Comments
 (0)