Skip to content

Commit 8df4248

Browse files
committed
Some cleanup
1 parent fe3e1c1 commit 8df4248

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::interpret::{self,
2424
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar, Pointer,
2525
RawConst, ConstValue, Machine,
2626
InterpResult, InterpErrorInfo, GlobalId, InterpCx, StackPopCleanup,
27-
Allocation, AllocId, MemoryKind, Memory, StackPopInfo,
27+
Allocation, AllocId, MemoryKind, Memory,
2828
snapshot, RefTracking, intern_const_alloc_recursive,
2929
};
3030

@@ -470,16 +470,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
470470
fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
471471
Ok(())
472472
}
473-
474-
/// Called immediately before a stack frame gets popped.
475-
#[inline(always)]
476-
fn stack_pop(
477-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
478-
_extra: (),
479-
) -> InterpResult<'tcx, StackPopInfo> {
480-
// Const-eval mode does not support unwinding from panics
481-
Ok(StackPopInfo::Normal)
482-
}
483473
}
484474

485475
/// Extracts a field of a (variant of a) const.

src/librustc_mir/interpret/eval_context.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_data_structures::fx::FxHashMap;
2121

2222
use super::{
2323
Immediate, Operand, MemPlace, MPlaceTy, Place, PlaceTy, ScalarMaybeUndef,
24-
Memory, Machine, PointerArithmetic, FnVal, StackPopInfo
24+
Memory, Machine, StackPopInfo
2525
};
2626

2727
pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
@@ -86,7 +86,7 @@ pub struct Frame<'mir, 'tcx, Tag=(), Extra=()> {
8686
/// The block that is currently executed (or will be executed after the above call stacks
8787
/// return).
8888
/// If this is `None`, we are unwinding and this function doesn't need any clean-up.
89-
/// Just continue the same as with
89+
/// Just continue the same as with `Resume`.
9090
pub block: Option<mir::BasicBlock>,
9191

9292
/// The index of the currently evaluated statement.
@@ -563,7 +563,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
563563
/// `cleanup` block for the function, which is responsible for running
564564
/// `Drop` impls for any locals that have been initialized at this point.
565565
/// The cleanup block ends with a special `Resume` terminator, which will
566-
/// cause us to continue unwinding where we left off.
566+
/// cause us to continue unwinding.
567567
pub(super) fn pop_stack_frame(
568568
&mut self,
569569
unwinding: bool
@@ -830,25 +830,4 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
830830
trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
831831
frames
832832
}
833-
834-
/// Resolve the function at the specified slot in the provided
835-
/// vtable. An index of '0' corresponds to the first method
836-
/// declared in the trait of the provided vtable
837-
pub fn get_vtable_slot(
838-
&self,
839-
vtable: Scalar<M::PointerTag>,
840-
idx: usize
841-
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
842-
let ptr_size = self.pointer_size();
843-
// Skip over the 'drop_ptr', 'size', and 'align' fields
844-
let vtable_slot = vtable.ptr_offset(ptr_size * (idx as u64 + 3), self)?;
845-
let vtable_slot = self.memory.check_ptr_access(
846-
vtable_slot,
847-
ptr_size,
848-
self.tcx.data_layout.pointer_align.abi,
849-
)?.expect("cannot be a ZST");
850-
let fn_ptr = self.memory.get(vtable_slot.alloc_id)?
851-
.read_ptr_sized(self, vtable_slot)?.not_undef()?;
852-
Ok(self.memory.get_fn(fn_ptr)?)
853-
}
854833
}

src/librustc_mir/interpret/machine.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,12 @@ pub trait Machine<'mir, 'tcx>: Sized {
268268

269269
/// Called immediately after a stack frame gets popped
270270
fn stack_pop(
271-
ecx: &mut InterpCx<'mir, 'tcx, Self>,
272-
extra: Self::FrameExtra,
273-
) -> InterpResult<'tcx, StackPopInfo>;
271+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
272+
_extra: Self::FrameExtra,
273+
) -> InterpResult<'tcx, StackPopInfo> {
274+
// By default, we do not support unwinding from panics
275+
Ok(StackPopInfo::Normal)
276+
}
274277

275278
fn int_to_ptr(
276279
_mem: &Memory<'mir, 'tcx, Self>,

src/librustc_mir/interpret/traits.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9797
Ok(vtable)
9898
}
9999

100+
/// Resolve the function at the specified slot in the provided
101+
/// vtable. An index of '0' corresponds to the first method
102+
/// declared in the trait of the provided vtable
103+
pub fn get_vtable_slot(
104+
&self,
105+
vtable: Scalar<M::PointerTag>,
106+
idx: usize
107+
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
108+
let ptr_size = self.pointer_size();
109+
// Skip over the 'drop_ptr', 'size', and 'align' fields
110+
let vtable_slot = vtable.ptr_offset(ptr_size * (idx as u64 + 3), self)?;
111+
let vtable_slot = self.memory.check_ptr_access(
112+
vtable_slot,
113+
ptr_size,
114+
self.tcx.data_layout.pointer_align.abi,
115+
)?.expect("cannot be a ZST");
116+
let fn_ptr = self.memory.get(vtable_slot.alloc_id)?
117+
.read_ptr_sized(self, vtable_slot)?.not_undef()?;
118+
Ok(self.memory.get_fn(fn_ptr)?)
119+
}
120+
100121
/// Returns the drop fn instance as well as the actual dynamic type
101122
pub fn read_drop_type_from_vtable(
102123
&self,

0 commit comments

Comments
 (0)