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

View File

@ -23,10 +23,11 @@ use super::{
MemoryKind, Misalignment, OpTy, PlaceTy, Pointer, Provenance,
};
/// Data returned by Machine::stack_pop,
/// to provide further control over the popping of the stack frame
/// Data returned by [`Machine::after_stack_pop`], and consumed by
/// [`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)]
pub enum StackPopJump {
pub enum ReturnAction {
/// Indicates that no special handling should be
/// done - we'll either return normally or unwind
/// based on the terminator for the function
@ -525,10 +526,10 @@ pub trait Machine<'tcx>: Sized {
_ecx: &mut InterpCx<'tcx, Self>,
_frame: Frame<'tcx, Self::Provenance, Self::FrameExtra>,
unwinding: bool,
) -> InterpResult<'tcx, StackPopJump> {
) -> InterpResult<'tcx, ReturnAction> {
// By default, we do not support unwinding from panics
assert!(!unwinding);
Ok(StackPopJump::Normal)
Ok(ReturnAction::Normal)
}
/// 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,
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::operand::{ImmTy, Immediate, OpTy, Readable};
pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable};

View File

@ -27,7 +27,7 @@ use super::{
};
use crate::{
fluent_generated as fluent,
interpret::{eval_context::StackPop, StackPopJump},
interpret::{eval_context::StackPop, ReturnAction},
};
/// 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.
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");
};
@ -999,7 +1000,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
(caller_abi, caller_fn_abi),
args,
with_caller_location,
&destination,
&return_place,
ret,
unwind,
)

View File

@ -1434,7 +1434,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
ecx: &mut InterpCx<'tcx, Self>,
frame: Frame<'tcx, Provenance, FrameExtra<'tcx>>,
unwinding: bool,
) -> InterpResult<'tcx, StackPopJump> {
) -> InterpResult<'tcx, ReturnAction> {
if frame.extra.is_user_relevant {
// 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.

View File

@ -113,7 +113,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&mut self,
mut extra: FrameExtra<'tcx>,
unwinding: bool,
) -> InterpResult<'tcx, StackPopJump> {
) -> InterpResult<'tcx, ReturnAction> {
let this = self.eval_context_mut();
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!
Ok(StackPopJump::NoJump)
Ok(ReturnAction::NoJump)
} else {
Ok(StackPopJump::Normal)
Ok(ReturnAction::Normal)
}
}