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.05k stars 1.55k forks source link

[dart2wasm] Simplify instantiation closure trampoline generation #50965

Open osa1 opened 1 year ago

osa1 commented 1 year ago

Currently vtable entries (trampolines) for instantiation closures are delayed to make sure we generate Wasm functions for them after collecting imports: https://github.com/dart-lang/sdk/blob/ec5123ada6dcebab4f1fb679c0b06cfc14f9edc4/pkg/dart2wasm/lib/closures.dart#L324-L329

This is no longer necessary as we collect imports and exports as first thing now. The code can be simplified to generate trampolines directly, instead of delaying them using thunks.

osa1 commented 1 year ago

It seems like f4200fed2b5796ef8030222e216c094c2109bfdf probably made this worse.

With that commit, vtable entry generators now use the Constants class (to be able to generate empty const _Type lists), which needs some class infos (with fields) to be initialized.

So ClassInfo generator uses Constants, which needs some ClassInfo to be generated.

Interestingly, the reason why Constants needs ClassInfos on initialization is because it generates an empty List<_Type> constant on initialization, the constant we use in dynamic call entries.