Files
sdk/tests
Martin Kustermann a96ad1b176 [dart2wasm] Add ImmutableWasmArray to dart:_wasm
Dart does not incorporate immutability into it's type system.
Though the WasmGC type system does have such a concept:

  * mutable wasm arrays: they are invariant in the element type
  * immutable wasm arrays: they are covariant in the element type

Currently we use the mutable wasm array types for e.g.

  const foo = const WasmArray<WasmI32>.literal([0]);

which will be compiled to

  (type $Array<WasmI32> () (array (field (mut i32))))
  (global $globalFoo
         (ref $Array<WasmI32>)
         (i32.const 0)
         (array.new_fixed $Array<WasmI32> 1
  )

=> Notice the **mut** in `array (field (mut i32))`

This CL introduces a `ImmutableWasmArray` which is analogous to
`WasmArray`. The array supports only reading methods since the
contents of the array cannot be modified.

Future CLs will make use of this new array type in various places.

=> This will allow binaryen to optimize things better as it knows the
array contents cannot change.
=> So loads from a (final) global with immutable contents can be
folded away at compile time if the index is known at compile-time.

NOTE: The `WasmArray`& `ImmutableArray` classes are not related to
each other. The reason is that in WasmGC a mutable array isn't a
subtype of a immutable array.

Change-Id: I3a764b5aaa3ac47827332f3064035133ab01f1b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392900
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-10-31 19:04:27 +00:00
..

This directory contains tests of the language and core library implementations. For more information, see https://github.com/dart-lang/sdk/tree/main/docs/Testing.md.