Skip to content

Commit 2363520

Browse files
committed
make StackPop field names less confusing
1 parent cda6f0c commit 2363520

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayou
2626
use super::{
2727
err_inval, throw_inval, throw_ub, throw_ub_custom, throw_unsup, GlobalId, Immediate,
2828
InterpErrorInfo, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, MemoryKind,
29-
OpTy, Operand, Place, PlaceTy, Pointer, PointerArithmetic, Projectable, Provenance, Scalar,
30-
StackPopJump,
29+
OpTy, Operand, Place, PlaceTy, Pointer, PointerArithmetic, Projectable, Provenance,
30+
ReturnAction, Scalar,
3131
};
3232
use crate::errors;
3333
use crate::util;
@@ -161,9 +161,15 @@ pub enum StackPopCleanup {
161161

162162
/// Return type of [`InterpCx::pop_stack_frame`].
163163
pub struct StackPop<'tcx, Prov: Provenance> {
164-
pub jump: StackPopJump,
165-
pub target: StackPopCleanup,
166-
pub destination: MPlaceTy<'tcx, Prov>,
164+
/// Additional information about the action to be performed when returning from the popped
165+
/// stack frame.
166+
pub return_action: ReturnAction,
167+
168+
/// [`return_to_block`](Frame::return_to_block) of the popped stack frame.
169+
pub return_to_block: StackPopCleanup,
170+
171+
/// [`return_place`](Frame::return_place) of the popped stack frame.
172+
pub return_place: MPlaceTy<'tcx, Prov>,
167173
}
168174

169175
/// State of a local variable including a memoized layout
@@ -890,16 +896,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
890896
let frame =
891897
self.stack_mut().pop().expect("tried to pop a stack frame, but there were none");
892898

893-
let target = frame.return_to_block;
894-
let destination = frame.return_place.clone();
899+
let return_to_block = frame.return_to_block;
900+
let return_place = frame.return_place.clone();
895901

896-
let jump = if cleanup {
902+
let return_action = if cleanup {
897903
M::after_stack_pop(self, frame, unwinding)?
898904
} else {
899-
StackPopJump::NoCleanup
905+
ReturnAction::NoCleanup
900906
};
901907

902-
Ok(StackPop { jump, target, destination })
908+
Ok(StackPop { return_action, return_to_block, return_place })
903909
}
904910

905911
/// A private helper for [`pop_stack_frame`](InterpCx::pop_stack_frame).
@@ -1042,13 +1048,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10421048
// Report error from return value copy, if any.
10431049
copy_ret_result?;
10441050

1045-
match frame.jump {
1046-
StackPopJump::Normal => {}
1047-
StackPopJump::NoJump => {
1051+
match frame.return_action {
1052+
ReturnAction::Normal => {}
1053+
ReturnAction::NoJump => {
10481054
// The hook already did everything.
10491055
return Ok(());
10501056
}
1051-
StackPopJump::NoCleanup => {
1057+
ReturnAction::NoCleanup => {
10521058
// If we are not doing cleanup, also skip everything else.
10531059
assert!(self.stack().is_empty(), "only the topmost frame should ever be leaked");
10541060
assert!(!unwinding, "tried to skip cleanup during unwinding");
@@ -1060,7 +1066,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10601066
// Normal return, figure out where to jump.
10611067
if unwinding {
10621068
// Follow the unwind edge.
1063-
let unwind = match frame.target {
1069+
let unwind = match frame.return_to_block {
10641070
StackPopCleanup::Goto { unwind, .. } => unwind,
10651071
StackPopCleanup::Root { .. } => {
10661072
panic!("encountered StackPopCleanup::Root when unwinding!")
@@ -1070,7 +1076,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10701076
self.unwind_to_block(unwind)
10711077
} else {
10721078
// Follow the normal return edge.
1073-
match frame.target {
1079+
match frame.return_to_block {
10741080
StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret),
10751081
StackPopCleanup::Root { .. } => {
10761082
assert!(

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ use super::{
2323
MemoryKind, Misalignment, OpTy, PlaceTy, Pointer, Provenance,
2424
};
2525

26-
/// Data returned by Machine::stack_pop,
27-
/// to provide further control over the popping of the stack frame
26+
/// Data returned by [`Machine::after_stack_pop`], and consumed by
27+
/// [`InterpCx::return_from_current_stack_frame`] to determine what actions should be done when
28+
/// returning from a stack frame.
2829
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
29-
pub enum StackPopJump {
30+
pub enum ReturnAction {
3031
/// Indicates that no special handling should be
3132
/// done - we'll either return normally or unwind
3233
/// based on the terminator for the function
@@ -525,10 +526,10 @@ pub trait Machine<'tcx>: Sized {
525526
_ecx: &mut InterpCx<'tcx, Self>,
526527
_frame: Frame<'tcx, Self::Provenance, Self::FrameExtra>,
527528
unwinding: bool,
528-
) -> InterpResult<'tcx, StackPopJump> {
529+
) -> InterpResult<'tcx, ReturnAction> {
529530
// By default, we do not support unwinding from panics
530531
assert!(!unwinding);
531-
Ok(StackPopJump::Normal)
532+
Ok(ReturnAction::Normal)
532533
}
533534

534535
/// Called immediately after actual memory was allocated for a local

compiler/rustc_const_eval/src/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub use self::intern::{
2626
intern_const_alloc_for_constprop, intern_const_alloc_recursive, HasStaticRootDefId, InternKind,
2727
InternResult,
2828
};
29-
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, StackPopJump};
29+
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, ReturnAction};
3030
pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind};
3131
pub use self::operand::{ImmTy, Immediate, OpTy, Readable};
3232
pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable};

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use super::{
2727
};
2828
use crate::{
2929
fluent_generated as fluent,
30-
interpret::{eval_context::StackPop, StackPopJump},
30+
interpret::{eval_context::StackPop, ReturnAction},
3131
};
3232

3333
/// An argment passed to a function.
@@ -982,11 +982,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
982982
// only the tail called function should return to the current return block.
983983
M::before_stack_pop(self, self.frame())?;
984984

985-
let StackPop { jump, target, destination } = self.pop_stack_frame(false)?;
985+
let StackPop { return_action, return_to_block, return_place } =
986+
self.pop_stack_frame(false)?;
986987

987-
assert_eq!(jump, StackPopJump::Normal);
988+
assert_eq!(return_action, ReturnAction::Normal);
988989

989-
let StackPopCleanup::Goto { ret, unwind } = target else {
990+
let StackPopCleanup::Goto { ret, unwind } = return_to_block else {
990991
bug!("can't tailcall as root");
991992
};
992993

@@ -999,7 +1000,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
9991000
(caller_abi, caller_fn_abi),
10001001
args,
10011002
with_caller_location,
1002-
&destination,
1003+
&return_place,
10031004
ret,
10041005
unwind,
10051006
)

src/tools/miri/src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14341434
ecx: &mut InterpCx<'tcx, Self>,
14351435
frame: Frame<'tcx, Provenance, FrameExtra<'tcx>>,
14361436
unwinding: bool,
1437-
) -> InterpResult<'tcx, StackPopJump> {
1437+
) -> InterpResult<'tcx, ReturnAction> {
14381438
if frame.extra.is_user_relevant {
14391439
// All that we store is whether or not the frame we just removed is local, so now we
14401440
// have no idea where the next topmost local frame is. So we recompute it.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
113113
&mut self,
114114
mut extra: FrameExtra<'tcx>,
115115
unwinding: bool,
116-
) -> InterpResult<'tcx, StackPopJump> {
116+
) -> InterpResult<'tcx, ReturnAction> {
117117
let this = self.eval_context_mut();
118118
trace!("handle_stack_pop_unwind(extra = {:?}, unwinding = {})", extra, unwinding);
119119

@@ -150,9 +150,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
150150
)?;
151151

152152
// We pushed a new stack frame, the engine should not do any jumping now!
153-
Ok(StackPopJump::NoJump)
153+
Ok(ReturnAction::NoJump)
154154
} else {
155-
Ok(StackPopJump::Normal)
155+
Ok(ReturnAction::Normal)
156156
}
157157
}
158158

0 commit comments

Comments
 (0)