Skip to content

gh-128627: Emscripten: Use wasm-gc based call adaptor if available#128628

Merged
freakboy3742 merged 12 commits intopython:mainfrom
hoodmane:wasm-gc-call-adaptor
Jan 12, 2025
Merged

gh-128627: Emscripten: Use wasm-gc based call adaptor if available#128628
freakboy3742 merged 12 commits intopython:mainfrom
hoodmane:wasm-gc-call-adaptor

Conversation

@hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Jan 8, 2025

Part of the ongoing quest to support JSPI. The JSPI spec removed its dependence on JS type reflection, and now the plan is for runtimes to ship JSPI while keeping type reflection in stage 3. So we need an alternative way to count the number of parameters of a function. It is possible to count them by repeatedly trying to instantiate a webassembly module with the function as an import of a different type signature. But this is pretty inefficient.

Since WebAssembly gc is now stage 4, there is a new option. WebAssembly gc added the ref.test instruction which can ask if a funcref has a given type. It's a bit difficult to apply because even our usual assembler the wasm binary toolkit doesn't support this instruction yet. But all JS engines that support JSPI support it. We just have to do some manual work to produce the binary.

This code also has to be written carefully to interact properly with memory snapshots. Importantly, no JS initialization code can be called from the C initialization code. For this reason, we make a C function pointer to fill from JS and fill it in a preRun function.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants