Skip to content

feat: add support for tail calls - #3020

Closed
JairusSW wants to merge 5 commits into
AssemblyScript:mainfrom
JairusSW:tail-call
Closed

JairusSW wants to merge 5 commits into
AssemblyScript:mainfrom
JairusSW:tail-call

Conversation

@JairusSW

@JairusSW JairusSW commented Apr 24, 2026 •

Copy link
Copy Markdown
Member

This PR adds basic support for the Tail Call Proposal behind the --enable tail-calls flag.

Currently, it only detects direct return call() statements. I'll go ahead and support call_indirect along with some other things later.

Roadmap:

  • return call() statements
  • return call_indirect(...) statements
  • Tail positions inside control flow (if/else, switch, ternary) where each terminating branch returns a call
  • Tail positions through expression wrappers that preserve tail semantics (e.g. block-wrapped return values)
  • Indirect forms (const x = call(...); return x;) when no semantic changes can be proven

Oh forgot to say, I used a LLM to scaffold initial tests. Typically I use like foo1, foo2, etc.. so this time you get nice names lol. That being said, it did miss a lot of tests i'd like to add, so I'll be adding them. The current tests are sufficient for now though

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@JairusSW

JairusSW commented Apr 24, 2026 •

Copy link
Copy Markdown
Member Author

oops forgot to fetch upstream

@JairusSW JairusSW changed the title feat: add support feat: add support for tail calls Apr 24, 2026
@KKiiim

KKiiim commented Sep 24, 2026

Copy link
Copy Markdown

Implemented in Binaryen v133.

Merge current main and detect tail calls after conversions and runtime
instrumentation. Cover control flow, wrappers, adjacent temporary returns,
argument order, optional arguments, GC cleanup, and feature gating.

Run the tail-call regression suite in CI, including deep recursion in
debug and release builds.
@JairusSW JairusSW closed this Oct 21, 2026
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.

2 participants