Skip to content

Missing direct call opportunity in TFA in equals calls #56691

Open
@osa1

Description

@osa1
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.==:

@override
bool operator ==(Object other) =>
other is _I8ByteBuffer && identical(_data, other._data);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.type-performanceIssue relates to performance or code sizevm-tfa

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions