Skip to content

Wasm: more_tailcalls fails with test assembly R2R #131890

Open

Description

@AndyAyersMS

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.

Note

This issue was drafted with GitHub Copilot.

Activity

  1. added
    untriaged
    on Aug 5, 2026
  2. added
    area-CodeGen-coreclr
    arch-wasm
    and removed
    untriaged
    on Aug 5, 2026
  3. dotnet-policy-service commented on Aug 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  4. dotnet-policy-service commented on Aug 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  5. AndyAyersMS commented on Aug 5, 2026

    @AndyAyersMS
    MemberAuthor

    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?

  6. added this to the 12.0.0 milestone on Aug 5, 2026
  7. JulieLeeMSFT commented on Aug 5, 2026

    @JulieLeeMSFT
    Member

    Set it to 12. Please feel free to pull in if it can be done in 11.

  8. jakobbotsch commented on Aug 6, 2026

    @jakobbotsch
    Member

    @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.

  9. AndyAyersMS commented on Sep 9, 2026

    @AndyAyersMS
    MemberAuthor

    @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".

  10. AndyAyersMS commented on Sep 9, 2026

    @AndyAyersMS
    MemberAuthor

    We could also for now detect these cases and fail out of R2R.

    @lewing how important is it to fully support F#?

  11. jkotas commented on Sep 9, 2026

    @jkotas
    Member

    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.

  12. AndyAyersMS commented on Sep 9, 2026

    @AndyAyersMS
    MemberAuthor

    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.

  13. added
    disabled-test
    on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmarea-CodeGen-coreclrdisabled-test

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions