Skip to content

Support tail calls in mir via TerminatorKind::TailCall#113128

Merged
bors merged 15 commits intorust-lang:masterfrom
WaffleLapkin:become_trully_unuwuable
Jul 8, 2024
Merged

Support tail calls in mir via TerminatorKind::TailCall#113128
bors merged 15 commits intorust-lang:masterfrom
WaffleLapkin:become_trully_unuwuable

Conversation

@WaffleLapkin
Copy link
Member

This is one of the interesting bits in tail call implementation — MIR support.

This adds a new TerminatorKind which represents a tail call:

    TailCall {
        func: Operand<'tcx>,
        args: Vec<Operand<'tcx>>,
        fn_span: Span,
    },

Structurally this is very similar to a normal Call but is missing a few fields:

  • destination — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual return will write to the caller of the function that used tail call)
  • target — similarly to destination tail calls pass the caller's return address to the callee, so there is nothing to do
  • unwind — I think this is applicable too, although it's a bit confusing
  • call_sourcebecome forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now)

It might be helpful to read the interpreter implementation to understand what TailCall means exactly, although I've tried documenting it too.


There are a few FIXME-questions still left, ideally we'd be able to answer them during review ':)


r? @oli-obk
cc @scottmcm @drmeepster @JakobDegen

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

Labels

F-explicit_tail_calls `#![feature(explicit_tail_calls)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.