Skip to content

Commit 5eb0a65

Browse files
osa1Commit Queue
authored and
Commit Queue
committed
[dart2wasm] Don't add dispatch table entries for _WasmBase methods
Some of the `_WasmBase` subtypes are represented as unboxed Wasm values and cannot be used as virutal method receivers. Previously we added methods for `_WasmBase` subtypes to the dispatch table and considered those types as receivers in dynamic invocations. This causes bad code generation as these types do not represent Dart objects. With this CL we don't add `_WasmBase` subtype methods to dispatch tables, and in dynamic invocations we don't consider `_WasmBase` types as receivers. New passing tests: - language/variable/inference_captured_variable_test - lib/typed_data/typed_data_list_test Change-Id: I4f4145db12652133aa55dcce75acad72bb4ec48b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/268761 Reviewed-by: Aske Simon Christensen <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]>
1 parent 0e88d41 commit 5eb0a65

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

pkg/dart2wasm/lib/dispatch_table.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,14 @@ class DispatchTable {
235235
? 1
236236
: 0;
237237

238-
bool calledDynamically =
238+
// _WasmBase and its subclass methods cannot be called dynamically
239+
final cls = member.enclosingClass;
240+
final isWasmType = cls != null && translator.isWasmType(cls);
241+
242+
final calledDynamically = !isWasmType &&
239243
translator.dynamics.maybeCalledDynamically(member, metadata);
240-
var selector = selectorInfo.putIfAbsent(
244+
245+
final selector = selectorInfo.putIfAbsent(
241246
selectorId,
242247
() => SelectorInfo(
243248
translator,
@@ -277,11 +282,16 @@ class DispatchTable {
277282

278283
void build() {
279284
// Collect class/selector combinations
285+
286+
// Maps class IDs to selector IDs of the class
280287
List<List<int>> selectorsInClass = [];
288+
281289
for (ClassInfo info in translator.classes) {
282290
List<int> selectorIds = [];
283291
ClassInfo? superInfo = info.superInfo;
284-
if (superInfo != null) {
292+
293+
// _WasmBase does not inherit from Object
294+
if (superInfo != null && info.cls != translator.wasmTypesBaseClass) {
285295
int superId = superInfo.classId;
286296
selectorIds = List.of(selectorsInClass[superId]);
287297
for (int selectorId in selectorIds) {

pkg/dart2wasm/lib/translator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ class Translator {
540540
return false;
541541
}
542542

543-
bool isWasmType(Class cls) => _hasSuperclass(cls, wasmTypesBaseClass);
543+
bool isWasmType(Class cls) =>
544+
cls == wasmTypesBaseClass || _hasSuperclass(cls, wasmTypesBaseClass);
544545

545546
bool isFfiCompound(Class cls) => _hasSuperclass(cls, ffiCompoundClass);
546547

sdk/lib/wasm/wasm_types.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library dart.wasm;
1111
// parameter/return of static functions. No other uses of the types are valid.
1212
// - They are not assignable to or from any ordinary Dart types.
1313
// - The integer and float types can't be nullable.
14+
// - Their instance methods cannot be called virtually or dynamically.
1415
//
1516
// TODO(askesc): Give an error message if any of these constraints are violated.
1617

0 commit comments

Comments
 (0)