Skip to content

gh-129040: Use wasm-gc to handle pointer casts in wasi - #158617

Open
hoodmane wants to merge 6 commits into
python:mainfrom
hoodmane:wasi-call-trampolines
Open

hoodmane wants to merge 6 commits into
python:mainfrom
hoodmane:wasi-call-trampolines

Conversation

@hoodmane

@hoodmane hoodmane commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This makes it so that in wasi builds if -DPY_CALL_TRAMPOLINE is passed, a call trampoline adaptor is used to prevent traps when there is a call signature mismatch between a C slot handler and the signature that the interpreter uses to call it.

This requires Clang >= 22. PEP 11 specifies that builds of Python 3.15 use WASI SDK version 33 which includes clang 23.1.0, so this could be used with Python 3.15 WASI builds but not earlier ones.

It requires a WebAssembly runtime that supports wasm-gc. Wasmtime has supported wasm-gc since version 27.0 released November 25, 2024. Some other runtimes still don't support it, but for those runtimes people can use builds with the trampoline disabled.

I also removed the Emscripten trampoline support for JS runtimes with no wasm-gc support. This removes a lot of implementation complexity and allows WASI and Emscripten to share code. The main concern is that it drops support for some very old iPhones, but every iPhone model released since 2018 is compatible with versions of Safari that support wasm-gc.

I also added tests that define handlers with various wrong numbers of arguments. The tests also run on non-webassembly platforms since they should work there as well.

cc @brettcannon

This makes it so that in wasi builds if `-DPY_CALL_TRAMPOLINE` is passed, a call
trampoline adaptor is used to prevent traps when there is a call signature
mismatch between a C slot handler and the signature that the interpreter uses to
call it.

This requires Clang >= 22. PEP 11 specifies that builds of Python 3.15 use WASI
SDK version 33 which includes clang 23.1.0, so this could be used with Python
3.15 WASI builds but not earlier ones.

It requires a WebAssembly runtime that supports wasm-gc. Wasmtime has supported
wasm-gc since version 27.0 released November 25, 2024. Some other runtimes still
don't support it, but for those runtimes people can use builds with the
trampoline disabled.

I also removed the Emscripten trampoline support for JS runtimes with no wasm-gc
support. This removes a lot of implementation complexity and allows WASI and
Emscripten to share code. The main concern is that it drops support for some
very old iPhones, but every iPhone model released since 2018 is compatible with
versions of Safari that support wasm-gc.

I also added tests that define handlers with various wrong numbers of arguments.
The tests also run on non-webassembly platforms since they should work there as
well.
@hoodmane hoodmane added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 2, 2026
@hoodmane
hoodmane requested a review from corona10 as a code owner October 2, 2026 19:23
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 2, 2026
@hoodmane
hoodmane requested a review from freakboy3742 as a code owner October 2, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.15 pre-release feature fixes, bugs and security fixes OS-emscripten OS-wasi type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant