Struct rustc_const_eval::const_eval::machine::CompileTimeInterpreter [−][src]
pub struct CompileTimeInterpreter<'mir, 'tcx> {
pub steps_remaining: usize,
pub(crate) stack: Vec<Frame<'mir, 'tcx, AllocId, ()>>,
}
Expand description
Extra machine state for CTFE, and the Machine instance
Fields
steps_remaining: usize
For now, the number of terminators that can be evaluated before we throw a resource exhaustion error.
Setting this to 0
disables the limit and allows the interpreter to run forever.
stack: Vec<Frame<'mir, 'tcx, AllocId, ()>>
The virtual call stack.
Implementations
Trait Implementations
type PointerTag = AllocId
type PointerTag = AllocId
Pointers are “tagged” with provenance information; typically the AllocId
they belong to.
type ExtraFnVal = !
type ExtraFnVal = !
Machines can define extra (non-instance) things that represent values of function pointers.
For example, Miri uses this to return a function pointer from dlsym
that can later be called to execute the right thing. Read more
type MemoryMap = FxHashMap<AllocId, (MemoryKind<Self::MemoryKind>, Allocation)>
type MemoryMap = FxHashMap<AllocId, (MemoryKind<Self::MemoryKind>, Allocation)>
Memory’s allocation map
The memory kind to use for copied global memory (held in tcx
) –
or None if such memory should not be mutated and thus any such attempt will cause
a ModifiedStatic
error to be raised.
Statics are copied under two circumstances: When they are mutated, and when
tag_allocation
(see below) returns an owned allocation
that is added to the memory so that the work is not done twice. Read more
type AllocExtra = ()
type AllocExtra = ()
Extra data stored in every allocation.
type FrameExtra = ()
type FrameExtra = ()
Extra data stored in every call frame.
Whether memory accesses should be alignment-checked.
Whether, when checking alignment, we should force_int
and thus support
custom alignment logic based on whatever the integer address happens to be. Read more
Whether to enforce the validity invariant
fn call_extra_fn(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
fn_val: !,
_abi: Abi,
_args: &[OpTy<'tcx>],
_ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
_unwind: StackPopUnwind
) -> InterpResult<'tcx>
fn call_extra_fn(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
fn_val: !,
_abi: Abi,
_args: &[OpTy<'tcx>],
_ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
_unwind: StackPopUnwind
) -> InterpResult<'tcx>
Execute fn_val
. It is the hook’s responsibility to advance the instruction
pointer as appropriate. Read more
fn init_allocation_extra<'b>(
_mem: &Memory<'mir, 'tcx, Self>,
_id: AllocId,
alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<Self::MemoryKind>>
) -> Cow<'b, Allocation<Self::PointerTag>>
fn init_allocation_extra<'b>(
_mem: &Memory<'mir, 'tcx, Self>,
_id: AllocId,
alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<Self::MemoryKind>>
) -> Cow<'b, Allocation<Self::PointerTag>>
Called to initialize the “extra” state of an allocation and make the pointers it contains (in relocations) tagged. The way we construct allocations is to always first construct it without extra and then add the extra. This keeps uniform code paths for handling both allocations created by CTFE for globals, and allocations created by Miri during evaluation. Read more
fn extern_static_base_pointer(
mem: &Memory<'mir, 'tcx, Self>,
def_id: DefId
) -> InterpResult<'tcx, Pointer>
fn extern_static_base_pointer(
mem: &Memory<'mir, 'tcx, Self>,
def_id: DefId
) -> InterpResult<'tcx, Pointer>
Return the root pointer for the given extern static
.
Return a “base” pointer for the given allocation: the one that is used for direct accesses to this static/const/fn allocation, or the one returned from the heap allocator. Read more
“Int-to-pointer cast”
Convert a pointer with provenance into an allocation-offset pair.
type MemoryKind = MemoryKind
type MemoryKind = MemoryKind
Additional memory kinds a machine wishes to distinguish from the builtin ones
type MemoryExtra = MemoryExtra
type MemoryExtra = MemoryExtra
Extra data stored in memory. A reference to this is available when AllocExtra
gets initialized, so you can e.g., have an Rc
here if there is global state you
need access to in the AllocExtra
hooks. Read more
Should the machine panic on allocation failures?
fn load_mir(
ecx: &InterpCx<'mir, 'tcx, Self>,
instance: InstanceDef<'tcx>
) -> InterpResult<'tcx, &'tcx Body<'tcx>>
fn load_mir(
ecx: &InterpCx<'mir, 'tcx, Self>,
instance: InstanceDef<'tcx>
) -> InterpResult<'tcx, &'tcx Body<'tcx>>
Entry point for obtaining the MIR of anything that should get evaluated. So not just functions and shims, but also const/static initializers, anonymous constants, … Read more
fn find_mir_or_eval_fn(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: Instance<'tcx>,
_abi: Abi,
args: &[OpTy<'tcx>],
_ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
_unwind: StackPopUnwind
) -> InterpResult<'tcx, Option<&'mir Body<'tcx>>>
fn find_mir_or_eval_fn(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: Instance<'tcx>,
_abi: Abi,
args: &[OpTy<'tcx>],
_ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
_unwind: StackPopUnwind
) -> InterpResult<'tcx, Option<&'mir Body<'tcx>>>
Entry point to all function calls. Read more
fn call_intrinsic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: Instance<'tcx>,
args: &[OpTy<'tcx>],
ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
_unwind: StackPopUnwind
) -> InterpResult<'tcx>
fn call_intrinsic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: Instance<'tcx>,
args: &[OpTy<'tcx>],
ret: Option<(&PlaceTy<'tcx>, BasicBlock)>,
_unwind: StackPopUnwind
) -> InterpResult<'tcx>
Directly process an intrinsic without pushing a stack frame. It is the hook’s responsibility to advance the instruction pointer as appropriate. Read more
fn assert_panic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
msg: &AssertMessage<'tcx>,
_unwind: Option<BasicBlock>
) -> InterpResult<'tcx>
fn assert_panic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
msg: &AssertMessage<'tcx>,
_unwind: Option<BasicBlock>
) -> InterpResult<'tcx>
Called to evaluate Assert
MIR terminators that trigger a panic.
Called to evaluate Abort
MIR terminator.
Called for all binary operations where the LHS has pointer type. Read more
fn box_alloc(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_dest: &PlaceTy<'tcx>
) -> InterpResult<'tcx>
fn box_alloc(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_dest: &PlaceTy<'tcx>
) -> InterpResult<'tcx>
Heap allocations via the box
keyword.
Called before a basic block terminator is executed. You can use this to detect endlessly running programs. Read more
fn init_frame_extra(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
frame: Frame<'mir, 'tcx>
) -> InterpResult<'tcx, Frame<'mir, 'tcx>>
fn init_frame_extra(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
frame: Frame<'mir, 'tcx>
) -> InterpResult<'tcx, Frame<'mir, 'tcx>>
Called immediately before a new stack frame gets pushed.
fn stack<'a>(
ecx: &'a InterpCx<'mir, 'tcx, Self>
) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>]
fn stack<'a>(
ecx: &'a InterpCx<'mir, 'tcx, Self>
) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>]
Borrow the current thread’s stack.
fn stack_mut<'a>(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>>
fn stack_mut<'a>(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>>
Mutably borrow the current thread’s stack.
fn before_access_global(
memory_extra: &MemoryExtra,
alloc_id: AllocId,
allocation: &Allocation,
static_def_id: Option<DefId>,
is_write: bool
) -> InterpResult<'tcx>
fn before_access_global(
memory_extra: &MemoryExtra,
alloc_id: AllocId,
allocation: &Allocation,
static_def_id: Option<DefId>,
is_write: bool
) -> InterpResult<'tcx>
Called before a global allocation is accessed.
def_id
is Some
if this is the “lazy” allocation of a static. Read more
Whether function calls should be ABI-checked.
fn access_local(
_ecx: &InterpCx<'mir, 'tcx, Self>,
frame: &Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
local: Local
) -> InterpResult<'tcx, Operand<Self::PointerTag>>
fn access_local(
_ecx: &InterpCx<'mir, 'tcx, Self>,
frame: &Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
local: Local
) -> InterpResult<'tcx, Operand<Self::PointerTag>>
Called to read the specified local
from the frame
.
Since reading a ZST is not actually accessing memory or locals, this is never invoked
for ZST reads. Read more
fn access_local_mut<'a>(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
frame: usize,
local: Local
) -> InterpResult<'tcx, Result<&'a mut LocalValue<Self::PointerTag>, MemPlace<Self::PointerTag>>> where
'tcx: 'mir,
fn access_local_mut<'a>(
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
frame: usize,
local: Local
) -> InterpResult<'tcx, Result<&'a mut LocalValue<Self::PointerTag>, MemPlace<Self::PointerTag>>> where
'tcx: 'mir,
Called to write the specified local
from the frame
.
Since writing a ZST is not actually accessing memory or locals, this is never invoked
for ZST reads. Read more
fn thread_local_static_base_pointer(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
def_id: DefId
) -> InterpResult<'tcx, Pointer<Self::PointerTag>>
fn thread_local_static_base_pointer(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
def_id: DefId
) -> InterpResult<'tcx, Pointer<Self::PointerTag>>
Return the AllocId
for the given thread-local static in the current thread.
fn memory_read(
_memory_extra: &Self::MemoryExtra,
_alloc_extra: &Self::AllocExtra,
_tag: Self::PointerTag,
_range: AllocRange
) -> InterpResult<'tcx>
fn memory_read(
_memory_extra: &Self::MemoryExtra,
_alloc_extra: &Self::AllocExtra,
_tag: Self::PointerTag,
_range: AllocRange
) -> InterpResult<'tcx>
Hook for performing extra checks on a memory read access. Read more
fn memory_written(
_memory_extra: &mut Self::MemoryExtra,
_alloc_extra: &mut Self::AllocExtra,
_tag: Self::PointerTag,
_range: AllocRange
) -> InterpResult<'tcx>
fn memory_written(
_memory_extra: &mut Self::MemoryExtra,
_alloc_extra: &mut Self::AllocExtra,
_tag: Self::PointerTag,
_range: AllocRange
) -> InterpResult<'tcx>
Hook for performing extra checks on a memory write access.
fn memory_deallocated(
_memory_extra: &mut Self::MemoryExtra,
_alloc_extra: &mut Self::AllocExtra,
_tag: Self::PointerTag,
_range: AllocRange
) -> InterpResult<'tcx>
fn memory_deallocated(
_memory_extra: &mut Self::MemoryExtra,
_alloc_extra: &mut Self::AllocExtra,
_tag: Self::PointerTag,
_range: AllocRange
) -> InterpResult<'tcx>
Hook for performing extra operations on a memory deallocation.
fn retag(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_kind: RetagKind,
_place: &PlaceTy<'tcx, Self::PointerTag>
) -> InterpResult<'tcx>
fn retag(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_kind: RetagKind,
_place: &PlaceTy<'tcx, Self::PointerTag>
) -> InterpResult<'tcx>
Executes a retagging operation.
Called immediately after a stack frame got pushed and its locals got initialized.
fn after_stack_pop(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_frame: Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
_unwinding: bool
) -> InterpResult<'tcx, StackPopJump>
fn after_stack_pop(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_frame: Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
_unwinding: bool
) -> InterpResult<'tcx, StackPopJump>
Called immediately after a stack frame got popped, but before jumping back to the caller.
Auto Trait Implementations
impl<'mir, 'tcx> !RefUnwindSafe for CompileTimeInterpreter<'mir, 'tcx>
impl<'mir, 'tcx> !Send for CompileTimeInterpreter<'mir, 'tcx>
impl<'mir, 'tcx> !Sync for CompileTimeInterpreter<'mir, 'tcx>
impl<'mir, 'tcx> Unpin for CompileTimeInterpreter<'mir, 'tcx> where
'tcx: 'mir,
impl<'mir, 'tcx> !UnwindSafe for CompileTimeInterpreter<'mir, 'tcx>
Blanket Implementations
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes