Skip to content

Commit 7775166

Browse files
committed
interpret: rename StackPopCleanup
1 parent c83e217 commit 7775166

File tree

10 files changed

+56
-56
lines changed

10 files changed

+56
-56
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine};
1919
use crate::const_eval::CheckAlignment;
2020
use crate::interpret::{
2121
CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpErrorKind,
22-
InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, StackPopCleanup, create_static_alloc,
22+
InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, ReturnContinuation, create_static_alloc,
2323
intern_const_alloc_recursive, interp_ok, throw_exhaust,
2424
};
2525
use crate::{CTRL_C_RECEIVED, errors};
@@ -76,7 +76,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
7676
cid.instance,
7777
body,
7878
&ret.clone().into(),
79-
StackPopCleanup::Root { cleanup: false },
79+
ReturnContinuation::Stop { cleanup: false },
8080
)?;
8181
ecx.storage_live_for_always_live_locals()?;
8282

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tracing::{info, instrument, trace};
1515

1616
use super::{
1717
CtfeProvenance, FnVal, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, PlaceTy,
18-
Projectable, Provenance, ReturnAction, Scalar, StackPopCleanup, StackPopInfo, interp_ok,
18+
Projectable, Provenance, ReturnAction, ReturnContinuation, Scalar, StackPopInfo, interp_ok,
1919
throw_ub, throw_ub_custom, throw_unsup_format,
2020
};
2121
use crate::fluent_generated as fluent;
@@ -340,7 +340,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
340340
args: &[FnArg<'tcx, M::Provenance>],
341341
with_caller_location: bool,
342342
destination: &PlaceTy<'tcx, M::Provenance>,
343-
mut stack_pop: StackPopCleanup,
343+
mut cont: ReturnContinuation,
344344
) -> InterpResult<'tcx> {
345345
// Compute callee information.
346346
// FIXME: for variadic support, do we have to somehow determine callee's extra_args?
@@ -365,15 +365,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
365365

366366
if !callee_fn_abi.can_unwind {
367367
// The callee cannot unwind, so force the `Unreachable` unwind handling.
368-
match &mut stack_pop {
369-
StackPopCleanup::Root { .. } => {}
370-
StackPopCleanup::Goto { unwind, .. } => {
368+
match &mut cont {
369+
ReturnContinuation::Stop { .. } => {}
370+
ReturnContinuation::Goto { unwind, .. } => {
371371
*unwind = mir::UnwindAction::Unreachable;
372372
}
373373
}
374374
}
375375

376-
self.push_stack_frame_raw(instance, body, destination, stack_pop)?;
376+
self.push_stack_frame_raw(instance, body, destination, cont)?;
377377

378378
// If an error is raised here, pop the frame again to get an accurate backtrace.
379379
// To this end, we wrap it all in a `try` block.
@@ -617,7 +617,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
617617
&args,
618618
with_caller_location,
619619
destination,
620-
StackPopCleanup::Goto { ret: target, unwind },
620+
ReturnContinuation::Goto { ret: target, unwind },
621621
)
622622
}
623623
// `InstanceKind::Virtual` does not have callable MIR. Calls to `Virtual` instances must be
@@ -755,16 +755,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
755755
// Note that we are using `pop_stack_frame_raw` and not `return_from_current_stack_frame`,
756756
// as the latter "executes" the goto to the return block, but we don't want to,
757757
// only the tail called function should return to the current return block.
758-
let StackPopInfo { return_action, return_to_block, return_place } = self
759-
.pop_stack_frame_raw(false, |_this, _return_place| {
758+
let StackPopInfo { return_action, return_cont, return_place } =
759+
self.pop_stack_frame_raw(false, |_this, _return_place| {
760760
// This function's return value is just discarded, the tail-callee will fill in the return place instead.
761761
interp_ok(())
762762
})?;
763763

764764
assert_eq!(return_action, ReturnAction::Normal);
765765

766766
// Take the "stack pop cleanup" info, and use that to initiate the next call.
767-
let StackPopCleanup::Goto { ret, unwind } = return_to_block else {
767+
let ReturnContinuation::Goto { ret, unwind } = return_cont else {
768768
bug!("can't tailcall as root");
769769
};
770770

@@ -896,23 +896,23 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
896896
// Normal return, figure out where to jump.
897897
if unwinding {
898898
// Follow the unwind edge.
899-
match stack_pop_info.return_to_block {
900-
StackPopCleanup::Goto { unwind, .. } => {
899+
match stack_pop_info.return_cont {
900+
ReturnContinuation::Goto { unwind, .. } => {
901901
// This must be the very last thing that happens, since it can in fact push a new stack frame.
902902
self.unwind_to_block(unwind)
903903
}
904-
StackPopCleanup::Root { .. } => {
905-
panic!("encountered StackPopCleanup::Root when unwinding!")
904+
ReturnContinuation::Stop { .. } => {
905+
panic!("encountered ReturnContinuation::Stop when unwinding!")
906906
}
907907
}
908908
} else {
909909
// Follow the normal return edge.
910-
match stack_pop_info.return_to_block {
911-
StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret),
912-
StackPopCleanup::Root { .. } => {
910+
match stack_pop_info.return_cont {
911+
ReturnContinuation::Goto { ret, .. } => self.return_to_block(ret),
912+
ReturnContinuation::Stop { .. } => {
913913
assert!(
914914
self.stack().is_empty(),
915-
"only the bottommost frame can have StackPopCleanup::Root"
915+
"only the bottommost frame can have ReturnContinuation::Stop"
916916
);
917917
interp_ok(())
918918
}

compiler/rustc_const_eval/src/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use self::operand::{ImmTy, Immediate, OpTy};
3636
pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable};
3737
use self::place::{MemPlace, Place};
3838
pub use self::projection::{OffsetMode, Projectable};
39-
pub use self::stack::{Frame, FrameInfo, LocalState, StackPopCleanup, StackPopInfo};
39+
pub use self::stack::{Frame, FrameInfo, LocalState, ReturnContinuation, StackPopInfo};
4040
pub(crate) use self::util::create_static_alloc;
4141
pub use self::validity::{CtfeValidationMode, RangeSet, RefTracking};
4242
pub use self::visitor::ValueVisitor;

compiler/rustc_const_eval/src/interpret/stack.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
7272
////////////////////////////////////////////////////////////////////////////////
7373
// Return place and locals
7474
////////////////////////////////////////////////////////////////////////////////
75-
/// Work to perform when returning from this function.
76-
return_to_block: StackPopCleanup,
75+
/// Where to continue when returning from this function.
76+
return_cont: ReturnContinuation,
7777

7878
/// The location where the result of the current stack frame should be written to,
7979
/// and its layout in the caller. This place is to be interpreted relative to the
@@ -106,19 +106,19 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
106106
pub(super) loc: Either<mir::Location, Span>,
107107
}
108108

109+
/// Where and how to continue when returning/unwinding from the current function.
109110
#[derive(Clone, Copy, Eq, PartialEq, Debug)] // Miri debug-prints these
110-
pub enum StackPopCleanup {
111+
pub enum ReturnContinuation {
111112
/// Jump to the next block in the caller, or cause UB if None (that's a function
112-
/// that may never return). Also store layout of return place so
113-
/// we can validate it at that layout.
113+
/// that may never return).
114114
/// `ret` stores the block we jump to on a normal return, while `unwind`
115115
/// stores the block used for cleanup during unwinding.
116116
Goto { ret: Option<mir::BasicBlock>, unwind: mir::UnwindAction },
117-
/// The root frame of the stack: nowhere else to jump to.
117+
/// The root frame of the stack: nowhere else to jump to, so we stop.
118118
/// `cleanup` says whether locals are deallocated. Static computation
119119
/// wants them leaked to intern what they need (and just throw away
120120
/// the entire `ecx` when it is done).
121-
Root { cleanup: bool },
121+
Stop { cleanup: bool },
122122
}
123123

124124
/// Return type of [`InterpCx::pop_stack_frame_raw`].
@@ -127,8 +127,8 @@ pub struct StackPopInfo<'tcx, Prov: Provenance> {
127127
/// stack frame.
128128
pub return_action: ReturnAction,
129129

130-
/// [`return_to_block`](Frame::return_to_block) of the popped stack frame.
131-
pub return_to_block: StackPopCleanup,
130+
/// [`return_cont`](Frame::return_cont) of the popped stack frame.
131+
pub return_cont: ReturnContinuation,
132132

133133
/// [`return_place`](Frame::return_place) of the popped stack frame.
134134
pub return_place: PlaceTy<'tcx, Prov>,
@@ -255,7 +255,7 @@ impl<'tcx, Prov: Provenance> Frame<'tcx, Prov> {
255255
Frame {
256256
body: self.body,
257257
instance: self.instance,
258-
return_to_block: self.return_to_block,
258+
return_cont: self.return_cont,
259259
return_place: self.return_place,
260260
locals: self.locals,
261261
loc: self.loc,
@@ -350,20 +350,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
350350
/// the arguments or local variables.
351351
///
352352
/// The high-level version of this is `init_stack_frame`.
353-
#[instrument(skip(self, body, return_place, return_to_block), level = "debug")]
353+
#[instrument(skip(self, body, return_place, return_cont), level = "debug")]
354354
pub(crate) fn push_stack_frame_raw(
355355
&mut self,
356356
instance: ty::Instance<'tcx>,
357357
body: &'tcx mir::Body<'tcx>,
358358
return_place: &PlaceTy<'tcx, M::Provenance>,
359-
return_to_block: StackPopCleanup,
359+
return_cont: ReturnContinuation,
360360
) -> InterpResult<'tcx> {
361361
trace!("body: {:#?}", body);
362362

363363
// We can push a `Root` frame if and only if the stack is empty.
364364
debug_assert_eq!(
365365
self.stack().is_empty(),
366-
matches!(return_to_block, StackPopCleanup::Root { .. })
366+
matches!(return_cont, ReturnContinuation::Stop { .. })
367367
);
368368

369369
// First push a stack frame so we have access to `instantiate_from_current_frame` and other
@@ -373,7 +373,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
373373
let pre_frame = Frame {
374374
body,
375375
loc: Right(body.span), // Span used for errors caused during preamble.
376-
return_to_block,
376+
return_cont,
377377
return_place: return_place.clone(),
378378
locals,
379379
instance,
@@ -429,15 +429,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
429429
copy_ret_val(self, &frame.return_place)?;
430430
}
431431

432-
let return_to_block = frame.return_to_block;
432+
let return_cont = frame.return_cont;
433433
let return_place = frame.return_place.clone();
434434

435435
// Cleanup: deallocate locals.
436436
// Usually we want to clean up (deallocate locals), but in a few rare cases we don't.
437437
// We do this while the frame is still on the stack, so errors point to the callee.
438-
let cleanup = match return_to_block {
439-
StackPopCleanup::Goto { .. } => true,
440-
StackPopCleanup::Root { cleanup, .. } => cleanup,
438+
let cleanup = match return_cont {
439+
ReturnContinuation::Goto { .. } => true,
440+
ReturnContinuation::Stop { cleanup, .. } => cleanup,
441441
};
442442

443443
let return_action = if cleanup {
@@ -455,7 +455,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
455455
ReturnAction::NoCleanup
456456
};
457457

458-
interp_ok(StackPopInfo { return_action, return_to_block, return_place })
458+
interp_ok(StackPopInfo { return_action, return_cont, return_place })
459459
}
460460

461461
/// In the current stack frame, mark all locals as live that are not arguments and don't have

src/tools/miri/src/concurrency/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
894894
start_abi,
895895
&[func_arg],
896896
Some(&ret_place),
897-
StackPopCleanup::Root { cleanup: true },
897+
ReturnContinuation::Stop { cleanup: true },
898898
)?;
899899

900900
// Restore the old active thread frame.

src/tools/miri/src/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ pub fn create_ecx<'tcx>(
436436
ImmTy::from_uint(sigpipe, ecx.machine.layouts.u8),
437437
],
438438
Some(&ret_place),
439-
StackPopCleanup::Root { cleanup: true },
439+
ReturnContinuation::Stop { cleanup: true },
440440
)?;
441441
}
442442
MiriEntryFnType::MiriStart => {
@@ -445,7 +445,7 @@ pub fn create_ecx<'tcx>(
445445
ExternAbi::Rust,
446446
&[argc, argv],
447447
Some(&ret_place),
448-
StackPopCleanup::Root { cleanup: true },
448+
ReturnContinuation::Stop { cleanup: true },
449449
)?;
450450
}
451451
}

src/tools/miri/src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
444444
caller_abi: ExternAbi,
445445
args: &[ImmTy<'tcx>],
446446
dest: Option<&MPlaceTy<'tcx>>,
447-
stack_pop: StackPopCleanup,
447+
cont: ReturnContinuation,
448448
) -> InterpResult<'tcx> {
449449
let this = self.eval_context_mut();
450450

@@ -472,7 +472,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
472472
&args.iter().map(|a| FnArg::Copy(a.clone().into())).collect::<Vec<_>>(),
473473
/*with_caller_location*/ false,
474474
&dest.into(),
475-
stack_pop,
475+
cont,
476476
)
477477
}
478478

src/tools/miri/src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11991199
ExternAbi::Rust,
12001200
&[],
12011201
None,
1202-
StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
1202+
ReturnContinuation::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
12031203
)?;
12041204
interp_ok(())
12051205
}

src/tools/miri/src/shims/panic.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
9292
&[data.clone()],
9393
None,
9494
// Directly return to caller.
95-
StackPopCleanup::Goto { ret, unwind: mir::UnwindAction::Continue },
95+
ReturnContinuation::Goto { ret, unwind: mir::UnwindAction::Continue },
9696
)?;
9797

9898
// We ourselves will return `0`, eventually (will be overwritten if we catch a panic).
@@ -143,7 +143,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
143143
&[catch_unwind.data, payload],
144144
None,
145145
// Directly return to caller of `catch_unwind`.
146-
StackPopCleanup::Goto {
146+
ReturnContinuation::Goto {
147147
ret: catch_unwind.ret,
148148
// `catch_fn` must not unwind.
149149
unwind: mir::UnwindAction::Unreachable,
@@ -172,7 +172,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
172172
ExternAbi::Rust,
173173
&[this.mplace_to_ref(&msg)?],
174174
None,
175-
StackPopCleanup::Goto { ret: None, unwind },
175+
ReturnContinuation::Goto { ret: None, unwind },
176176
)
177177
}
178178

@@ -191,7 +191,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
191191
ExternAbi::Rust,
192192
&[this.mplace_to_ref(&msg)?],
193193
None,
194-
StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
194+
ReturnContinuation::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
195195
)
196196
}
197197

@@ -220,7 +220,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
220220
ExternAbi::Rust,
221221
&[index, len],
222222
None,
223-
StackPopCleanup::Goto { ret: None, unwind },
223+
ReturnContinuation::Goto { ret: None, unwind },
224224
)?;
225225
}
226226
MisalignedPointerDereference { required, found } => {
@@ -241,7 +241,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
241241
ExternAbi::Rust,
242242
&[required, found],
243243
None,
244-
StackPopCleanup::Goto { ret: None, unwind },
244+
ReturnContinuation::Goto { ret: None, unwind },
245245
)?;
246246
}
247247

@@ -254,7 +254,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
254254
ExternAbi::Rust,
255255
&[],
256256
None,
257-
StackPopCleanup::Goto { ret: None, unwind },
257+
ReturnContinuation::Goto { ret: None, unwind },
258258
)?;
259259
}
260260
}

src/tools/miri/src/shims/tls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
325325
ExternAbi::System { unwind: false },
326326
&[null_ptr.clone(), ImmTy::from_scalar(reason, this.machine.layouts.u32), null_ptr],
327327
None,
328-
StackPopCleanup::Root { cleanup: true },
328+
ReturnContinuation::Stop { cleanup: true },
329329
)?;
330330
interp_ok(())
331331
}
@@ -346,7 +346,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
346346
ExternAbi::C { unwind: false },
347347
&[ImmTy::from_scalar(data, this.machine.layouts.mut_raw_ptr)],
348348
None,
349-
StackPopCleanup::Root { cleanup: true },
349+
ReturnContinuation::Stop { cleanup: true },
350350
)?;
351351

352352
return interp_ok(Poll::Pending);
@@ -383,7 +383,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
383383
ExternAbi::C { unwind: false },
384384
&[ImmTy::from_scalar(ptr, this.machine.layouts.mut_raw_ptr)],
385385
None,
386-
StackPopCleanup::Root { cleanup: true },
386+
ReturnContinuation::Stop { cleanup: true },
387387
)?;
388388

389389
return interp_ok(Poll::Pending);

0 commit comments

Comments
 (0)