]> git.lizzy.rs Git - rust.git/commitdiff
Some cleanup
authorAaron Hill <aa1ronham@gmail.com>
Mon, 28 Oct 2019 23:09:54 +0000 (19:09 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Mon, 11 Nov 2019 20:14:33 +0000 (15:14 -0500)
src/librustc_mir/const_eval.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/machine.rs
src/librustc_mir/interpret/traits.rs

index c50fae45490775bfc38e1458c7b4fcd008daaa09..812774fab8de45c51d441944f1ba91c25d2095c9 100644 (file)
@@ -24,7 +24,7 @@
     PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar, Pointer,
     RawConst, ConstValue, Machine,
     InterpResult, InterpErrorInfo, GlobalId, InterpCx, StackPopCleanup,
-    Allocation, AllocId, MemoryKind, Memory, StackPopInfo,
+    Allocation, AllocId, MemoryKind, Memory,
     snapshot, RefTracking, intern_const_alloc_recursive,
 };
 
@@ -470,16 +470,6 @@ fn before_terminator(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>
     fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
         Ok(())
     }
-
-    /// Called immediately before a stack frame gets popped.
-    #[inline(always)]
-    fn stack_pop(
-        _ecx: &mut InterpCx<'mir, 'tcx, Self>,
-        _extra: (),
-    ) -> InterpResult<'tcx, StackPopInfo> {
-        // Const-eval mode does not support unwinding from panics
-        Ok(StackPopInfo::Normal)
-    }
 }
 
 /// Extracts a field of a (variant of a) const.
index 5e505521b72830e0820ade3ccad03fc202ba65e0..6598b0f99f2a99e4e73606ed637672c7fa39ad74 100644 (file)
@@ -21,7 +21,7 @@
 
 use super::{
     Immediate, Operand, MemPlace, MPlaceTy, Place, PlaceTy, ScalarMaybeUndef,
-    Memory, Machine, PointerArithmetic, FnVal, StackPopInfo
+    Memory, Machine, StackPopInfo
 };
 
 pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
@@ -86,7 +86,7 @@ pub struct Frame<'mir, 'tcx, Tag=(), Extra=()> {
     /// The block that is currently executed (or will be executed after the above call stacks
     /// return).
     /// If this is `None`, we are unwinding and this function doesn't need any clean-up.
-    /// Just continue the same as with
+    /// Just continue the same as with `Resume`.
     pub block: Option<mir::BasicBlock>,
 
     /// The index of the currently evaluated statement.
@@ -563,7 +563,7 @@ pub fn push_stack_frame(
     /// `cleanup` block for the function, which is responsible for running
     /// `Drop` impls for any locals that have been initialized at this point.
     /// The cleanup block ends with a special `Resume` terminator, which will
-    /// cause us to continue unwinding where we left off.
+    /// cause us to continue unwinding.
     pub(super) fn pop_stack_frame(
         &mut self,
         unwinding: bool
@@ -830,25 +830,4 @@ pub fn generate_stacktrace(&self, explicit_span: Option<Span>) -> Vec<FrameInfo<
         trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
         frames
     }
-
-    /// Resolve the function at the specified slot in the provided
-    /// vtable. An index of '0' corresponds to the first method
-    /// declared in the trait of the provided vtable
-    pub fn get_vtable_slot(
-        &self,
-        vtable: Scalar<M::PointerTag>,
-        idx: usize
-    ) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
-        let ptr_size = self.pointer_size();
-        // Skip over the 'drop_ptr', 'size', and 'align' fields
-        let vtable_slot = vtable.ptr_offset(ptr_size * (idx as u64 + 3), self)?;
-        let vtable_slot = self.memory.check_ptr_access(
-            vtable_slot,
-            ptr_size,
-            self.tcx.data_layout.pointer_align.abi,
-        )?.expect("cannot be a ZST");
-        let fn_ptr = self.memory.get(vtable_slot.alloc_id)?
-            .read_ptr_sized(self, vtable_slot)?.not_undef()?;
-        Ok(self.memory.get_fn(fn_ptr)?)
-    }
 }
index 995f1199047c35c52414bc07fade179ca1c0480f..18f831f8257bc64ed5c5397b0d06f24475050055 100644 (file)
@@ -268,9 +268,12 @@ fn retag(
 
     /// Called immediately after a stack frame gets popped
     fn stack_pop(
-        ecx: &mut InterpCx<'mir, 'tcx, Self>,
-        extra: Self::FrameExtra,
-    ) -> InterpResult<'tcx, StackPopInfo>;
+        _ecx: &mut InterpCx<'mir, 'tcx, Self>,
+        _extra: Self::FrameExtra,
+    ) -> InterpResult<'tcx, StackPopInfo> {
+        // By default, we do not support unwinding from panics
+        Ok(StackPopInfo::Normal)
+    }
 
     fn int_to_ptr(
         _mem: &Memory<'mir, 'tcx, Self>,
index c15425321ec0123a249ae2be1ce3c4a0ce2d8762..55c127c56f6087f6e52161cbf9ea9fe0c0f92894 100644 (file)
@@ -97,6 +97,27 @@ pub fn get_vtable(
         Ok(vtable)
     }
 
+    /// Resolve the function at the specified slot in the provided
+    /// vtable. An index of '0' corresponds to the first method
+    /// declared in the trait of the provided vtable
+    pub fn get_vtable_slot(
+        &self,
+        vtable: Scalar<M::PointerTag>,
+        idx: usize
+    ) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
+        let ptr_size = self.pointer_size();
+        // Skip over the 'drop_ptr', 'size', and 'align' fields
+        let vtable_slot = vtable.ptr_offset(ptr_size * (idx as u64 + 3), self)?;
+        let vtable_slot = self.memory.check_ptr_access(
+            vtable_slot,
+            ptr_size,
+            self.tcx.data_layout.pointer_align.abi,
+        )?.expect("cannot be a ZST");
+        let fn_ptr = self.memory.get(vtable_slot.alloc_id)?
+            .read_ptr_sized(self, vtable_slot)?.not_undef()?;
+        Ok(self.memory.get_fn(fn_ptr)?)
+    }
+
     /// Returns the drop fn instance as well as the actual dynamic type
     pub fn read_drop_type_from_vtable(
         &self,