Skip to content

Support Tail Call extension #2397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alexbiehl opened this issue Apr 21, 2025 · 4 comments
Open

Support Tail Call extension #2397

alexbiehl opened this issue Apr 21, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@alexbiehl
Copy link

alexbiehl commented Apr 21, 2025

Is your feature request related to a problem? Please describe.

I am trying to run a WASM workload that makes use of the return_call instruction (see https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/call).

Currently execution fails with

loadBytes: compile module: invalid function[2]: invalid instruction 0x12

Describe the solution you'd like

Ideally wazero supports that instruction. Some research revealed it’s part of https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md. After all it would be nice if wazero supported the tail call extension.

Describe alternatives you've considered

Additional context

@alexbiehl alexbiehl added the enhancement New feature or request label Apr 21, 2025
@alexbiehl alexbiehl changed the title Support return_call and return_call_indirect instructions Support Tail Call extension Apr 21, 2025
@evacchi
Copy link
Contributor

evacchi commented Apr 22, 2025

interesting, it might be the first time I find this used in the wild. What kind of workload is that? Not ruling out eventually supporting that proposal, but in many cases you are just a compiler flag away from removing that instruction from the output binary

@alexbiehl
Copy link
Author

@evacchi Check out the WASM file attached in this release https://github.com/alexbiehl/sqlc-hs/releases/tag/0.1.0.0. It was produced by the WASM backend of GHC and unfortunately it seems like I can't make it stop emitting that instruction.

@anuraaga
Copy link
Contributor

anuraaga commented May 16, 2025

Hi @alexbiehl - I happened to build a GHC binary recently and found the workaround of using an older ghc-wasm-meta to work fine for now in case it helps.

https://github.com/wasilibs/go-hadolint/blob/main/buildtools/wasm/Dockerfile#L6

@evacchi I think one issue with this in particular is haskell seems to compile wasi-libc themselves, and do enable tail call for it, so even if I try disabling it in my downstream build it ends up in the binary.

@evacchi
Copy link
Contributor

evacchi commented May 16, 2025

@anuraaga FYI I inteded working on tail calls for a while, and in the meantime I implemented them, but it needs a little more testing

I have a working branch on my own fork: evacchi#61
I haven't opened a proper PR here yet because I wanted to make sure everything is in order :)
I confirm that @alexbiehl sqlc-hs works, and all the spec tests pass, but @ncruces found an issue when running a build of sqlite with tail-calls enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants