pub struct CompileTimeInterpreter<'mir, 'tcx> {
    pub steps_remaining: usize,
    pub(crate) stack: Vec<Frame<'mir, 'tcx, AllocId, ()>>,
    pub(super) can_access_statics: bool,
}
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.

can_access_statics: bool

We need to make sure consts never point to anything mutable, even recursively. That is relied on for pattern matching on consts with references. To achieve this, two pieces have to work together:

  • Interning makes everything outside of statics immutable.
  • Pointers to allocations inside of statics can never leak outside, to a non-static global. This boolean here controls the second part.

Implementations

Trait Implementations

Pointers are “tagged” with provenance information; typically the AllocId they belong to.

When getting the AllocId of a pointer, some extra data is also obtained from the tag that is passed to memory access hooks so they can do things with it. Read more

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

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

Extra data stored in every allocation.

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

Whether to enforce integers and floats being initialized.

Whether to enforce integers and floats not having provenance.

Whether CheckedBinOp MIR statements should actually check for overflow.

Execute fn_val. It is the hook’s responsibility to advance the instruction pointer as appropriate. Read more

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

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

Hook for returning a pointer from a transmute-like operation on an addr. This is only needed to support Miri’s (unsound) “allow-ptr-int-transmute” flag. Read more

“Int-to-pointer cast”

Convert a pointer with provenance into an allocation-offset pair and extra provenance info. Read more

Additional memory kinds a machine wishes to distinguish from the builtin ones

Should the machine panic on allocation failures?

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

Entry point to all function calls. Read more

Directly process an intrinsic without pushing a stack frame. It is the hook’s responsibility to advance the instruction pointer as appropriate. Read more

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

Called before a basic block terminator is executed. You can use this to detect endlessly running programs. Read more

Marks a pointer as exposed, allowing it’s provenance to be recovered. “Pointer-to-int cast” Read more

Called immediately before a new stack frame gets pushed.

Borrow the current thread’s stack.

Mutably borrow the current thread’s stack.

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.

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

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

Return the AllocId for the given thread-local static in the current thread.

Hook for performing extra checks on a memory read access. Read more

Hook for performing extra checks on a memory write access.

Hook for performing extra operations on a memory deallocation.

Executes a retagging operation.

Called immediately after a stack frame got pushed and its locals got initialized.

Called immediately after a stack frame got popped, but before jumping back to the caller. The locals have already been destroyed! Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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: 40 bytes