Skip to content

Grand unified tail-calling #129819

Open
Open

Description

@Fidget-Spinner

Feature or enhancement

Proposal:

We have a tail calling interpreter. I now propose to tightly couple that with the JIT, so we can tail call into the JIT and tail call out of it.

This has a few benefits:

  1. No more C stack consumption by the JIT.
  2. Much more efficient entry and exit of jitted code. OSR entry is just a single indirect jump.

We need to align the calling convention of the JIT and the tail calling interpreter. This will need careful benchmarking to make sure we don't regress JIT performance.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. Fidget-Spinner commented on Feb 7, 2025

    @Fidget-Spinner
    MemberAuthor
  2. changed the title [-]Grand unified tail-calling JIT[/-] [+]Grand unified tail-calling[/+] on Feb 8, 2025
  3. brandtbucher commented on Feb 12, 2025

    @brandtbucher
    Member

    The tricky thing here is that it seems like every compiler is going to have their own incompatible ABI for __attribute__((preserve_none)). Meaning, even if GCC and MSVC support it, we're still not able to call directly between them if the JIT is compiled with Clang (which I don't see changing anytime soon).

    At worst, though, we just have a little trampoline that moves the arguments around to the expected registers on the way in (depending on the exact ABI, we may need to do more, and do it on the way out, too). But at least it would get rid of the C stack consumption. It's an open question whether that's worth the effort involved to make it work (and keep it working).

  4. added a commit that references this issue on Feb 12, 2025
  5. picnixz commented on Jul 12, 2025

    @picnixz
    Member

    Anything else to do here?

  6. Fidget-Spinner commented on Jul 21, 2025

    @Fidget-Spinner
    MemberAuthor

    @markshannon you're planning to do this right?

  7. Fidget-Spinner commented on Mar 23, 2026

    @Fidget-Spinner
    MemberAuthor

    I think this might still be worth pursuing. It needs to be opt-in though for platforms that control their entire build system and compiler ABI/preserve_none calling convention. Perhaps --enable-experimental-jit=yes-tailcall would be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions