Repository navigation
gh-129040: Use wasm-gc to handle pointer casts in wasi - #158617
Conversation
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.
freakboy3742
left a comment
There was a problem hiding this comment.
This makes sense to me; I'll leave it to @brettcannon to give the final approval just to make sure I'm not missing any WASI implications that I wasn't aware of.
|
Thanks for the review @freakboy3742! |
|
LGTM, I just had one question that's probably inconsequential. |
|
@hoodmane you ready to have one of us merge this? |
|
Yes, please merge! |
|
Thanks @hoodmane for the PR, and @brettcannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Sorry, @hoodmane and @brettcannon, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
I don't remember adding the "needs backport to 3.15", but regardless I don't think it's appropriate since I don't think this fixes a bug. |
This makes it so that in wasi builds if
-DPY_CALL_TRAMPOLINEis 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