[dart2wasm] Force-inline the List.[] List.[]= operations

Right now the _ListBase.[] looks like this in -O4 mode:

  (func $_ListBase.[] (param $var0 (ref $Object))
                      (param $var1 i64)
                      (result (ref null $#Top))
    local.get $var0
    ref.cast $_ListBase
    struct.get $_ListBase $field4
    local.get $var1
    i32.wrap_i64
    array.get $Array<Object?>
  )

Binaryen doesn't inline this because it thinks its too big. Though we'd
really want reads/writes to fixed length lists to be inlined.

For typed data we already have `@pragma('wasm:prefer-inline')`
annotations so it makes sense to also do this here.

Change-Id: I3e976d98717df6e60e9de133dec37d10cd1b9097
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357140
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann 2024-03-12 13:57:29 +00:00 committed by Commit Queue
parent e38f4fa4ac
commit 4b9dd9d586

View file

@ -21,11 +21,13 @@ abstract class _ListBase<E> extends ListBase<E> {
_ListBase._withData(this._length, this._data);
@pragma('wasm:prefer-inline')
E operator [](int index) {
indexCheckWithName(index, _length, "[]");
return unsafeCast(_data[index]);
}
@pragma('wasm:prefer-inline')
int get length => _length;
List<E> sublist(int start, [int? end]) {
@ -56,6 +58,7 @@ abstract class _ModifiableList<E> extends _ListBase<E> {
_ModifiableList._withData(int length, WasmArray<Object?> data)
: super._withData(length, data);
@pragma('wasm:prefer-inline')
void operator []=(int index, E value) {
indexCheckWithName(index, _length, "[]=");
_data[index] = value;