Skip to content

Conversation

@jkelleyrtp
Copy link
Member

@jkelleyrtp jkelleyrtp commented Nov 25, 2025

Fixes #5016

Rewrite the wbg_cast functions to call the indirect functions from the original module.
This is necessary because wasm-bindgen uses these calls to perform dynamic type casting through
the JS layer. If we don't rewrite these, they end up as calls to breaks_if_inlined functions
which are no-ops and get rewritten by the wbindgen post-processing step.

Here, we find the corresponding wbg_cast function in the old module by name and then rewrite
the patch module's cast function to call the indirect function from the original module.

See the wbg_cast implementation in wasm-bindgen for more details:
https://github.com/wasm-bindgen/wasm-bindgen/blob/f61a588f674304964a2062b2307edb304aed4d16/src/rt/mod.rs#L30


wbg changed their handling of wbg_cast functions to include more type information in the JS <-> Rust shims. This now leads to more functions in the callstack of the descriptor functions, which we weren't handling properly.

Instead of relying on the import map for all information here, we instead look for the wbg_cast functions explicitly and then rebind them to their original calls in the main module. This prevents the breaks_if_inlined function from being retained in the patch module, and thus fixes hot-patching on the newer wasm-bindgen versions.

@jkelleyrtp jkelleyrtp requested a review from a team as a code owner November 25, 2025 02:46
@jkelleyrtp jkelleyrtp merged commit 88bc12c into main Nov 25, 2025
19 checks passed
@jkelleyrtp jkelleyrtp deleted the jk/fix-wbg-cast branch November 25, 2025 21:18
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.

wasm_bindgen Closure breaks hot-patching

2 participants