Skip to content

Commit e525e6a

Browse files
authored
Rollup merge of #92551 - RalfJung:stack-pop-cleanup, r=oli-obk
rename StackPopClean::None to Root With #90102, `StackPopClean::None` is now only used for the "root" frame of the stack, so adjust its name accordingly and add an assertion. r? `@oli-obk`
2 parents 4b743f8 + d60018b commit e525e6a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
6363
cid.instance,
6464
body,
6565
Some(&ret.into()),
66-
StackPopCleanup::None { cleanup: false },
66+
StackPopCleanup::Root { cleanup: false },
6767
)?;
6868

6969
// The main interpreter loop.

compiler/rustc_const_eval/src/interpret/eval_context.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ pub enum StackPopCleanup {
156156
/// `ret` stores the block we jump to on a normal return, while `unwind`
157157
/// stores the block used for cleanup during unwinding.
158158
Goto { ret: Option<mir::BasicBlock>, unwind: StackPopUnwind },
159-
/// Just do nothing: Used by Main and for TLS hooks in miri.
159+
/// The root frame of the stack: nowhere else to jump to.
160160
/// `cleanup` says whether locals are deallocated. Static computation
161161
/// wants them leaked to intern what they need (and just throw away
162162
/// the entire `ecx` when it is done).
163-
None { cleanup: bool },
163+
Root { cleanup: bool },
164164
}
165165

166166
/// State of a local variable including a memoized layout
@@ -849,7 +849,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
849849
// because this is CTFE and the final value will be thoroughly validated anyway.
850850
let cleanup = match return_to_block {
851851
StackPopCleanup::Goto { .. } => true,
852-
StackPopCleanup::None { cleanup, .. } => cleanup,
852+
StackPopCleanup::Root { cleanup, .. } => cleanup,
853853
};
854854

855855
if !cleanup {
@@ -874,16 +874,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
874874
// Follow the unwind edge.
875875
let unwind = match return_to_block {
876876
StackPopCleanup::Goto { unwind, .. } => unwind,
877-
StackPopCleanup::None { .. } => {
878-
panic!("Encountered StackPopCleanup::None when unwinding!")
877+
StackPopCleanup::Root { .. } => {
878+
panic!("encountered StackPopCleanup::Root when unwinding!")
879879
}
880880
};
881881
self.unwind_to_block(unwind)
882882
} else {
883883
// Follow the normal return edge.
884884
match return_to_block {
885885
StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret),
886-
StackPopCleanup::None { .. } => Ok(()),
886+
StackPopCleanup::Root { .. } => {
887+
assert!(
888+
self.stack().is_empty(),
889+
"only the topmost frame can have StackPopCleanup::Root"
890+
);
891+
Ok(())
892+
}
887893
}
888894
}
889895
}

compiler/rustc_mir_transform/src/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
406406
Instance::new(def_id, substs),
407407
dummy_body,
408408
ret.as_ref(),
409-
StackPopCleanup::None { cleanup: false },
409+
StackPopCleanup::Root { cleanup: false },
410410
)
411411
.expect("failed to push initial stack frame");
412412

0 commit comments

Comments
 (0)