1
Fork 0

make StackPop field names less confusing

This commit is contained in:
Maybe Waffle 2024-06-17 17:25:14 +00:00 committed by Maybe Lapkin
parent cda6f0c25d
commit 236352024b
6 changed files with 39 additions and 31 deletions

View file

@ -26,8 +26,8 @@ use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayou
use super::{ use super::{
err_inval, throw_inval, throw_ub, throw_ub_custom, throw_unsup, GlobalId, Immediate, err_inval, throw_inval, throw_ub, throw_ub_custom, throw_unsup, GlobalId, Immediate,
InterpErrorInfo, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, MemoryKind, InterpErrorInfo, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, MemoryKind,
OpTy, Operand, Place, PlaceTy, Pointer, PointerArithmetic, Projectable, Provenance, Scalar, OpTy, Operand, Place, PlaceTy, Pointer, PointerArithmetic, Projectable, Provenance,
StackPopJump, ReturnAction, Scalar,
}; };
use crate::errors; use crate::errors;
use crate::util; use crate::util;
@ -161,9 +161,15 @@ pub enum StackPopCleanup {
/// Return type of [`InterpCx::pop_stack_frame`]. /// Return type of [`InterpCx::pop_stack_frame`].
pub struct StackPop<'tcx, Prov: Provenance> { pub struct StackPop<'tcx, Prov: Provenance> {
pub jump: StackPopJump, /// Additional information about the action to be performed when returning from the popped
pub target: StackPopCleanup, /// stack frame.
pub destination: MPlaceTy<'tcx, Prov>, pub return_action: ReturnAction,
/// [`return_to_block`](Frame::return_to_block) of the popped stack frame.
pub return_to_block: StackPopCleanup,
/// [`return_place`](Frame::return_place) of the popped stack frame.
pub return_place: MPlaceTy<'tcx, Prov>,
} }
/// State of a local variable including a memoized layout /// State of a local variable including a memoized layout
@ -890,16 +896,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let frame = let frame =
self.stack_mut().pop().expect("tried to pop a stack frame, but there were none"); self.stack_mut().pop().expect("tried to pop a stack frame, but there were none");
let target = frame.return_to_block; let return_to_block = frame.return_to_block;
let destination = frame.return_place.clone(); let return_place = frame.return_place.clone();
let jump = if cleanup { let return_action = if cleanup {
M::after_stack_pop(self, frame, unwinding)? M::after_stack_pop(self, frame, unwinding)?
} else { } else {
StackPopJump::NoCleanup ReturnAction::NoCleanup
}; };
Ok(StackPop { jump, target, destination }) Ok(StackPop { return_action, return_to_block, return_place })
} }
/// A private helper for [`pop_stack_frame`](InterpCx::pop_stack_frame). /// A private helper for [`pop_stack_frame`](InterpCx::pop_stack_frame).
@ -1042,13 +1048,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// Report error from return value copy, if any. // Report error from return value copy, if any.
copy_ret_result?; copy_ret_result?;
match frame.jump { match frame.return_action {
StackPopJump::Normal => {} ReturnAction::Normal => {}
StackPopJump::NoJump => { ReturnAction::NoJump => {
// The hook already did everything. // The hook already did everything.
return Ok(()); return Ok(());
} }
StackPopJump::NoCleanup => { ReturnAction::NoCleanup => {
// If we are not doing cleanup, also skip everything else. // If we are not doing cleanup, also skip everything else.
assert!(self.stack().is_empty(), "only the topmost frame should ever be leaked"); assert!(self.stack().is_empty(), "only the topmost frame should ever be leaked");
assert!(!unwinding, "tried to skip cleanup during unwinding"); assert!(!unwinding, "tried to skip cleanup during unwinding");
@ -1060,7 +1066,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// Normal return, figure out where to jump. // Normal return, figure out where to jump.
if unwinding { if unwinding {
// Follow the unwind edge. // Follow the unwind edge.
let unwind = match frame.target { let unwind = match frame.return_to_block {
StackPopCleanup::Goto { unwind, .. } => unwind, StackPopCleanup::Goto { unwind, .. } => unwind,
StackPopCleanup::Root { .. } => { StackPopCleanup::Root { .. } => {
panic!("encountered StackPopCleanup::Root when unwinding!") panic!("encountered StackPopCleanup::Root when unwinding!")
@ -1070,7 +1076,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
self.unwind_to_block(unwind) self.unwind_to_block(unwind)
} else { } else {
// Follow the normal return edge. // Follow the normal return edge.
match frame.target { match frame.return_to_block {
StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret), StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret),
StackPopCleanup::Root { .. } => { StackPopCleanup::Root { .. } => {
assert!( assert!(

View file

@ -23,10 +23,11 @@ use super::{
MemoryKind, Misalignment, OpTy, PlaceTy, Pointer, Provenance, MemoryKind, Misalignment, OpTy, PlaceTy, Pointer, Provenance,
}; };
/// Data returned by Machine::stack_pop, /// Data returned by [`Machine::after_stack_pop`], and consumed by
/// to provide further control over the popping of the stack frame /// [`InterpCx::return_from_current_stack_frame`] to determine what actions should be done when
/// returning from a stack frame.
#[derive(Eq, PartialEq, Debug, Copy, Clone)] #[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum StackPopJump { pub enum ReturnAction {
/// Indicates that no special handling should be /// Indicates that no special handling should be
/// done - we'll either return normally or unwind /// done - we'll either return normally or unwind
/// based on the terminator for the function /// based on the terminator for the function
@ -525,10 +526,10 @@ pub trait Machine<'tcx>: Sized {
_ecx: &mut InterpCx<'tcx, Self>, _ecx: &mut InterpCx<'tcx, Self>,
_frame: Frame<'tcx, Self::Provenance, Self::FrameExtra>, _frame: Frame<'tcx, Self::Provenance, Self::FrameExtra>,
unwinding: bool, unwinding: bool,
) -> InterpResult<'tcx, StackPopJump> { ) -> InterpResult<'tcx, ReturnAction> {
// By default, we do not support unwinding from panics // By default, we do not support unwinding from panics
assert!(!unwinding); assert!(!unwinding);
Ok(StackPopJump::Normal) Ok(ReturnAction::Normal)
} }
/// Called immediately after actual memory was allocated for a local /// Called immediately after actual memory was allocated for a local

View file

@ -26,7 +26,7 @@ pub use self::intern::{
intern_const_alloc_for_constprop, intern_const_alloc_recursive, HasStaticRootDefId, InternKind, intern_const_alloc_for_constprop, intern_const_alloc_recursive, HasStaticRootDefId, InternKind,
InternResult, InternResult,
}; };
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, StackPopJump}; pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, ReturnAction};
pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind}; pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind};
pub use self::operand::{ImmTy, Immediate, OpTy, Readable}; pub use self::operand::{ImmTy, Immediate, OpTy, Readable};
pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable}; pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable};

View file

@ -27,7 +27,7 @@ use super::{
}; };
use crate::{ use crate::{
fluent_generated as fluent, fluent_generated as fluent,
interpret::{eval_context::StackPop, StackPopJump}, interpret::{eval_context::StackPop, ReturnAction},
}; };
/// An argment passed to a function. /// An argment passed to a function.
@ -982,11 +982,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// only the tail called function should return to the current return block. // only the tail called function should return to the current return block.
M::before_stack_pop(self, self.frame())?; M::before_stack_pop(self, self.frame())?;
let StackPop { jump, target, destination } = self.pop_stack_frame(false)?; let StackPop { return_action, return_to_block, return_place } =
self.pop_stack_frame(false)?;
assert_eq!(jump, StackPopJump::Normal); assert_eq!(return_action, ReturnAction::Normal);
let StackPopCleanup::Goto { ret, unwind } = target else { let StackPopCleanup::Goto { ret, unwind } = return_to_block else {
bug!("can't tailcall as root"); bug!("can't tailcall as root");
}; };
@ -999,7 +1000,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
(caller_abi, caller_fn_abi), (caller_abi, caller_fn_abi),
args, args,
with_caller_location, with_caller_location,
&destination, &return_place,
ret, ret,
unwind, unwind,
) )

View file

@ -1434,7 +1434,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
ecx: &mut InterpCx<'tcx, Self>, ecx: &mut InterpCx<'tcx, Self>,
frame: Frame<'tcx, Provenance, FrameExtra<'tcx>>, frame: Frame<'tcx, Provenance, FrameExtra<'tcx>>,
unwinding: bool, unwinding: bool,
) -> InterpResult<'tcx, StackPopJump> { ) -> InterpResult<'tcx, ReturnAction> {
if frame.extra.is_user_relevant { if frame.extra.is_user_relevant {
// All that we store is whether or not the frame we just removed is local, so now we // All that we store is whether or not the frame we just removed is local, so now we
// have no idea where the next topmost local frame is. So we recompute it. // have no idea where the next topmost local frame is. So we recompute it.

View file

@ -113,7 +113,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&mut self, &mut self,
mut extra: FrameExtra<'tcx>, mut extra: FrameExtra<'tcx>,
unwinding: bool, unwinding: bool,
) -> InterpResult<'tcx, StackPopJump> { ) -> InterpResult<'tcx, ReturnAction> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
trace!("handle_stack_pop_unwind(extra = {:?}, unwinding = {})", extra, unwinding); trace!("handle_stack_pop_unwind(extra = {:?}, unwinding = {})", extra, unwinding);
@ -150,9 +150,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
)?; )?;
// We pushed a new stack frame, the engine should not do any jumping now! // We pushed a new stack frame, the engine should not do any jumping now!
Ok(StackPopJump::NoJump) Ok(ReturnAction::NoJump)
} else { } else {
Ok(StackPopJump::Normal) Ok(ReturnAction::Normal)
} }
} }