Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9af6fee

Browse files
committedJul 8, 2024
Auto merge of rust-lang#113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJung
Support tail calls in mir via `TerminatorKind::TailCall` This is one of the interesting bits in tail call implementation — MIR support. This adds a new `TerminatorKind` which represents a tail call: ```rust 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_source` — `become` 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`
2 parents b1de36f + 14e5d5f commit 9af6fee

File tree

75 files changed

+2386
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2386
-174
lines changed
 

‎compiler/rustc_borrowck/src/lib.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,12 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
727727
}
728728
self.mutate_place(loc, (*destination, span), Deep, flow_state);
729729
}
730+
TerminatorKind::TailCall { func, args, fn_span: _ } => {
731+
self.consume_operand(loc, (func, span), flow_state);
732+
for arg in args {
733+
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
734+
}
735+
}
730736
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
731737
self.consume_operand(loc, (cond, span), flow_state);
732738
if let AssertKind::BoundsCheck { len, index } = &**msg {
@@ -813,9 +819,8 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
813819

814820
TerminatorKind::UnwindResume
815821
| TerminatorKind::Return
822+
| TerminatorKind::TailCall { .. }
816823
| TerminatorKind::CoroutineDrop => {
817-
// Returning from the function implicitly kills storage for all locals and statics.
818-
// Often, the storage will already have been killed by an explicit
819824
// StorageDead, but we don't always emit those (notably on unwind paths),
820825
// so this "extra check" serves as a kind of backup.
821826
let borrow_set = self.borrow_set.clone();

‎compiler/rustc_borrowck/src/polonius/loan_invalidations.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
125125
}
126126
self.mutate_place(location, *destination, Deep);
127127
}
128+
TerminatorKind::TailCall { func, args, .. } => {
129+
self.consume_operand(location, func);
130+
for arg in args {
131+
self.consume_operand(location, &arg.node);
132+
}
133+
}
128134
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
129135
self.consume_operand(location, cond);
130136
use rustc_middle::mir::AssertKind;

0 commit comments

Comments
 (0)
This repository has been archived.