You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wasm: more_tailcalls fails with test assembly R2R #131890
arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIdisabled-testThe test is disabled in source code against the issue
src/tests/JIT/Directed/tailcall/more_tailcalls.cs fails under wasm R2R: the
explicit tail call is turned into a normal call.
Primary reason: the callee takes a 32 byte struct arg, which is passed by
reference, and so lives on the caller frame.
Secondary reason: extra non-standard args we report for Wasm (SP and PEP).
Helper assisted tail calls are not available in R2R.
Possible Mitigations
Cleanly fail impacted methods from R2R. Report explicit tail-calling
methods that need to pass byref params as unsupported so the method is
excluded from R2R and runs interpreted — the interpreter already handles
these tail calls correctly (this test passes under interp).
Off-shadow-stack argument buffer + return_call (wasm-specific
hybrid). Spill the frame-aliasing args into an off-stack buffer, then return_call. Smaller than the general helper mechanism since wasm already
has native tailcalls.
Implement the portable helper-based tailcall for wasm. Wire up getTailCallHelpers + StoreArgs/CallTarget/DispatchTailCalls through
the shadow-stack/PEP convention. Likely a lot of work, given that there is
no R2R support at all currently (even on native platforms).
Pass such structs by value on the wasm value stack (return_call
preserves value-stack operands) — an ABI change, so not really viable.
@jakobbotsch any idea how hard it would be to support helper-assisted tail calls in R2R?
Maybe not too hard now that crossgen2 supports generating IL stubs.
However, since wasm has the equivalent of tail., can RyuJIT just emit that for explicit tailcalls? Unsure if all the browsers support it.
If we need to go through our own mechanism then it needs a way to be able to answer the question "would returning directly take me to a particular frame". We control both the caller and callee, so perhaps the SP mechanism can be used. We use return address/code address on other targets.
@jakobbotsch any idea how hard it would be to support helper-assisted tail calls in R2R?
Maybe not too hard now that crossgen2 supports generating IL stubs.
However, since wasm has the equivalent of tail., can RyuJIT just emit that for explicit tailcalls? Unsure if all the browsers support it.
If we need to go through our own mechanism then it needs a way to be able to answer the question "would returning directly take me to a particular frame". We control both the caller and callee, so perhaps the SP mechanism can be used. We use return address/code address on other targets.
We handle most explicit tail calls already, but for cases like this where there's a byref arg we need to move it somehow, or pass it by value (say using many wasm stack slots) to a tail-called thunk that reconstructs it on the stack and then calls the target method. Maybe we can emit this thunk as another kind of "funclet".
We fail out of R2R for complicated "slow" tailcalls on all platforms. It is tracked by #5857 . We should do the same for wasm. wasm is not the best place to start building tailcall support for R2R.
We already handle simple explicit tail calls. I had support for simple implicit calls implemented but backed it out based on feedback here: #129134 (review)
arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIdisabled-testThe test is disabled in source code against the issue
Activity
dotnet-policy-service commentedon Aug 5, 2026
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Aug 5, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
AndyAyersMS commentedon Aug 5, 2026
Not urgent, unless we need to handle a lot of F#. I will probably implement the clean fail-over soonish.
@jakobbotsch any idea how hard it would be to support helper-assisted tail calls in R2R?
JulieLeeMSFT commentedon Aug 5, 2026
Set it to 12. Please feel free to pull in if it can be done in 11.
jakobbotsch commentedon Aug 6, 2026
Maybe not too hard now that crossgen2 supports generating IL stubs.
However, since wasm has the equivalent of
tail., can RyuJIT just emit that for explicit tailcalls? Unsure if all the browsers support it.If we need to go through our own mechanism then it needs a way to be able to answer the question "would returning directly take me to a particular frame". We control both the caller and callee, so perhaps the SP mechanism can be used. We use return address/code address on other targets.
AndyAyersMS commentedon Sep 9, 2026
We handle most explicit tail calls already, but for cases like this where there's a byref arg we need to move it somehow, or pass it by value (say using many wasm stack slots) to a tail-called thunk that reconstructs it on the stack and then calls the target method. Maybe we can emit this thunk as another kind of "funclet".
AndyAyersMS commentedon Sep 9, 2026
We could also for now detect these cases and fail out of R2R.
@lewing how important is it to fully support F#?
jkotas commentedon Sep 9, 2026
We fail out of R2R for complicated "slow" tailcalls on all platforms. It is tracked by #5857 . We should do the same for wasm. wasm is not the best place to start building tailcall support for R2R.
It would be nice if we can handle the simple "fast" tailcalls as a general optimization where possible like we do on other platforms. https://web.dev/blog/wasmgc-wasm-tail-call-optimizations-baseline says that tailcalls are part of the wasm baseline since 2024.
AndyAyersMS commentedon Sep 9, 2026
We already handle simple explicit tail calls. I had support for simple implicit calls implemented but backed it out based on feedback here: #129134 (review)
Would easy enough to revive the implicit part.