Open
Description
import 'dart:typed_data';
void main() {
final buffer1 = Int8List.fromList([1, 2, 3]).buffer;
final buffer2 = Object();
print(buffer1 == buffer2);
}
In this program, when compiling with dart2wasm, TFA infers the concrete type of buffer1
, which has an operator ==
override.
Since the arguments to ==
are not nullable, we should be able to inline the ==
call.
However TFA currently does not add the ==
node to the direct call metadata, so we don't generate a direct call to the ==
member.
Relevant parts of the kernel after TFA:
final typ::ByteBuffer buffer1 = [@vm.direct-call.metadata=dart._typed_data::_WasmI8ArrayBase.buffer] [@vm.inferred-type.metadata=dart._typed_data::_I8ByteBuffer] [@vm.inferred-type.metadata=dart._typed_data::I8List] typ::Int8List::fromList(<core::int>[1, 2, 3]).{typ::TypedData::buffer}{typ::ByteBuffer};
final core::Object buffer2 = new core::Object::•();
core::print([@vm.inferred-type.metadata=dart.core::bool (receiver not int)] buffer1 =={core::Object::==}{(core::Object) → core::bool} buffer2);
Note that the inferred type of buffer1
is _I8ByteBuffer
and buffer2
is not nullable, but the ==
call is to Object.==
, instead of _I8ByteBuffer.==
:
sdk/sdk/lib/_internal/wasm/lib/typed_data.dart
Lines 1113 to 1115 in 0e58775
Compilation command:
dart compile wasm \
-O4 test.dart --no-strip-wasm \
--extra-compiler-option=--dump-kernel-before-tfa=before.kernel \
--extra-compiler-option=--dump-kernel-after-tfa=after.kernel
Tried with the main branch at a5baf4e.
cc @mkustermann