emscripten-core / emscripten-core/emscripten
Stop using re-assignment thunks when WASM_ASYNC_COMPILATION is enabled.
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
In release mode, when WASM_ASYNC_COMPILATION is used (i.e the default) we generate little thunks for all wasm exports. They looks like this:
```
var _foo = Module['_foo'] = () => (_foo = Module['_cfoo'] = wasmExports['foo'])();
```
The idea here is that these would then get re-assigned on first use. However, there are several problem with this:
1. If somebody takes a reference early they will get a reference to wrapper that will *not* get re-assigned and will cause perpetual re-assignment:
```
// This runs early on
var myfunc = Module['foo'];
// Now my func will forever point to the wrapper:
myfunc(); // always goes via wrapper and always re-assigns.. strange
Module['foo'](); // now goes direct
```
2. The identity of these function changes which can be observable (since we don't this re-assignment thing in debug builds):
```
var myfunc = Module['foo'];
// later after instantiation and usage
if (myfunc == Module['foo']) // would always be true in debug builds, but can be false in release builds
```
See #23337
Contributor guide
Assessment
This issue has not been assessed yet.