dotnet / dotnet/runtime

Wasm: more_tailcalls fails with test assembly R2R

Open
#131,890 9 comments 0 reactions 0 assignees View on GitHub
arch-wasm area-CodeGen-coreclr disabled-test
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

Research direction

Start with src/tests/JIT/Directed/tailcall/more_tailcalls.cs and reproduce the failure under wasm R2R, then compare it with the passing interpreter run. Read the R2R tail-call handling and the listed Wasm argument conventions before choosing among the proposed mitigations. Done means the test passes under wasm R2R without incorrectly converting the explicit tail call to a normal call.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, wasm
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.