From 8df4248c71deba455dab197784708be46da185fc Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 28 Oct 2019 19:09:54 -0400 Subject: [PATCH] Some cleanup --- src/librustc_mir/const_eval.rs | 12 +--------- src/librustc_mir/interpret/eval_context.rs | 27 +++------------------- src/librustc_mir/interpret/machine.rs | 9 +++++--- src/librustc_mir/interpret/traits.rs | 21 +++++++++++++++++ 4 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index c50fae45490..812774fab8d 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -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. diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 5e505521b72..6598b0f99f2 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -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, /// 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) -> Vec, - 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)?) - } } diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 995f1199047..18f831f8257 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -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>, diff --git a/src/librustc_mir/interpret/traits.rs b/src/librustc_mir/interpret/traits.rs index c15425321ec..55c127c56f6 100644 --- a/src/librustc_mir/interpret/traits.rs +++ b/src/librustc_mir/interpret/traits.rs @@ -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, + 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, -- 2.44.0