about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2024-06-17 17:25:14 +0000
committerMaybe Lapkin <waffle.lapkin@gmail.com>2024-07-07 18:16:38 +0200
commit236352024b25c2e834c7a73fc9219ddc84c0bcf9 (patch)
tree3a3d784beff856e41ed999a39dfee8603e824d3a
parentcda6f0c25d6421fd6814bd55a25701205da23585 (diff)
downloadrust-236352024b25c2e834c7a73fc9219ddc84c0bcf9.tar.gz
rust-236352024b25c2e834c7a73fc9219ddc84c0bcf9.zip
make `StackPop` field names less confusing
-rw-r--r--compiler/rustc_const_eval/src/interpret/eval_context.rs38
-rw-r--r--compiler/rustc_const_eval/src/interpret/machine.rs11
-rw-r--r--compiler/rustc_const_eval/src/interpret/mod.rs2
-rw-r--r--compiler/rustc_const_eval/src/interpret/terminator.rs11
-rw-r--r--src/tools/miri/src/machine.rs2
-rw-r--r--src/tools/miri/src/shims/panic.rs6
6 files changed, 39 insertions, 31 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs
index 9517e3d3597..bc15e41343f 100644
--- a/compiler/rustc_const_eval/src/interpret/eval_context.rs
+++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs
@@ -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!(
diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs
index b8a651a744a..7f2e9ce06a5 100644
--- a/compiler/rustc_const_eval/src/interpret/machine.rs
+++ b/compiler/rustc_const_eval/src/interpret/machine.rs
@@ -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
diff --git a/compiler/rustc_const_eval/src/interpret/mod.rs b/compiler/rustc_const_eval/src/interpret/mod.rs
index 7d7b421f869..f703c6fbe3e 100644
--- a/compiler/rustc_const_eval/src/interpret/mod.rs
+++ b/compiler/rustc_const_eval/src/interpret/mod.rs
@@ -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};
diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs
index 589ab6029f9..8886d7d8af5 100644
--- a/compiler/rustc_const_eval/src/interpret/terminator.rs
+++ b/compiler/rustc_const_eval/src/interpret/terminator.rs
@@ -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,
         )
diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs
index 0d91279f9f4..d4d50ebdd14 100644
--- a/src/tools/miri/src/machine.rs
+++ b/src/tools/miri/src/machine.rs
@@ -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.
diff --git a/src/tools/miri/src/shims/panic.rs b/src/tools/miri/src/shims/panic.rs
index ef832f5bbbd..306dce5edcd 100644
--- a/src/tools/miri/src/shims/panic.rs
+++ b/src/tools/miri/src/shims/panic.rs
@@ -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)
         }
     }