Skip to content

Commit

Permalink
[dart2wasm] Fix array.new_fixed calls with too large size
Browse files Browse the repository at this point in the history
Currently `array.new_fixed` has the upper size limit of 10,000.

Larger arrays need to be initialized with `array.new` or
`array.new_default`.

We handle this correctly in constant list and strings, but we didn't
handle it in `WasmArray.literal` consturctor. This CL fixes it.

Fixes dart-lang#55396.
  • Loading branch information
osa1 committed Apr 9, 2024
1 parent 60230e0 commit 931771f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/dart2wasm/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,33 @@ class ConstantCreator extends ConstantVisitor<ConstantInfo?>

List<Constant> elements =
(constant.fieldValues.values.single as ListConstant).entries;
bool lazy = false;
bool lazy = elements.length > maxArrayNewFixedLength;
for (Constant element in elements) {
lazy |= ensureConstant(element)?.isLazy ?? false;
}

return createConstant(constant, w.RefType.def(arrayType, nullable: false),
lazy: lazy, (function, b) {
for (Constant element in elements) {
constants.instantiateConstant(function, b, element, elementType);
if (lazy) {
w.Local arrayLocal =
function!.addLocal(w.RefType.def(arrayType, nullable: false));
constants.instantiateConstant(function, b, elements[0], elementType);
b.i32_const(elements.length);
b.array_new(arrayType);
b.local_set(arrayLocal);
for (int i = 1; i < elements.length; i++) {
b.local_get(arrayLocal);
b.i32_const(i);
constants.instantiateConstant(function, b, elements[i], elementType);
b.array_set(arrayType);
}
b.local_get(arrayLocal);
} else {
for (Constant element in elements) {
constants.instantiateConstant(function, b, element, elementType);
}
b.array_new_fixed(arrayType, elements.length);
}
b.array_new_fixed(arrayType, elements.length);
});
}

Expand Down

0 comments on commit 931771f

Please sign in to comment.