dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

[dart2js] Parametric type test weakening optimization #53504

Open rakudrama opened 1 year ago

rakudrama commented 1 year ago

Some type tests have a type argument that is needed for type promotion but unnecessary for operational correctness.

https://github.com/dart-lang/sdk/blob/252bfcb27aa14042ee07e081f25abf60cf6222b3/sdk/lib/internal/cast.dart#L70-L73

Here we could use the test (source is EfficientLengthIterable) except for the lack of type promotion. Testing an interface type with type variables instantiated to bounds is more efficient since the type arguments do not need to be tested.

dart2js should compile a test like this as a test against the generic type instantiated to bounds rather than the type dependent on a type variable.

@johnniwinther Is there enough information about the related types to do this reliably in the front-end? It would also be beneficial to DDC.

@alexmarkov Does VM-JIT or AOT do this optimization or something similar?

johnniwinther commented 1 year ago

We should be able to marks such is-tests in the CFE.