Module rustc_const_eval::interpret
source · Expand description
An interpreter for MIR used in CTFE and by miri
Re-exports§
pub use rustc_middle::mir::interpret::*;
Modules§
- cast 🔒
- Functions for reading and writing discriminants of multi-variant layouts (enums and coroutines).
- intern 🔒This module specifies the type based interner for constants.
- Intrinsics and other functions that the interpreter executes without looking at their MIR. Intrinsics/functions supported here are shared by CTFE and miri.
- machine 🔒This module contains everything needed to instantiate an interpreter. This separation exists to ensure that no fancy miri features like interpreting common C functions leak into CTFE.
- memory 🔒The memory subsystem.
- operand 🔒Functions concerning immediate values and operands, and reading from operands. All high-level functions to read from memory work on operands as sources.
- operator 🔒
- place 🔒Computations on places – field projections, going from mir::Place, and writing into a place. All high-level functions to write to memory work on places as destinations.
- This file implements “place projections”; basically a symmetric API for 3 types: MPlaceTy, OpTy, PlaceTy.
- step 🔒This module contains the
InterpCxmethods for executing a single step of the interpreter. - traits 🔒
- util 🔒
- validity 🔒Check the validity invariant of a given value, and tell the user where in the value it got violated. In const context, this goes even further and tries to approximate const safety. That’s useful because it means other passes (e.g. promotion) can rely on
consts to be const-safe. - visitor 🔒Visitor for a run-time value with a given layout: Traverse enums, structs and other compound types until we arrive at the leaves, with custom handling for primitive types.
Macros§
- A lot of the flexibility above is just needed for
Miri, but all “compile-time” machines (CTFE and ConstProp) use the same instance. Here, we share that code.
Structs§
- A reference to some allocation that was already bounds-checked for the given region and had the on-access machine hooks run.
- A reference to some allocation that was already bounds-checked for the given region and had the on-access machine hooks run.
- A stack frame.
- What we store about a frame in an interpreter backtrace.
- A MemPlace with its layout. Constructing it is only possible in this module.
- An evaluated place, together with its type.
- State for tracking recursive validation of references
Enums§
- The return value of
get_alloc_infoindicates the “kind” of the allocation. - Extra things to check for during validation of CTFE results.
- An argment passed to a function.
- The value of a function pointer.
- An
Immediaterepresents a single immediate self-contained Rust value. - How a constant value should be interned.
- Information required for the sound usage of a
MemPlace. - Describes the constraints placed on offset-projections.
- Data returned by Machine::stack_pop, to provide further control over the popping of the stack frame
Traits§
- The functionality needed by memory to manage its allocations
- Methods of this trait signifies a point where CTFE evaluation would fail and some use case dependent behaviour can instead be applied.
- Whether this kind of memory is allowed to leak
- A thing that we can project into, and that has a layout.
- The
Readabletrait describes interpreter values that one can read from. - How to traverse a value and what to do when we are at the leaves.
- The
Weiteabletrait describes interpreter values that can be written to.
Functions§
- Turn the given error into a human-readable string. Expects the string to be printed, so if
RUSTC_CTFE_BACKTRACEis set this will show a backtrace of the rustc internals that triggered the error. - Intern
ret. This function assumes thatretreferences no other allocation. - Intern
retand everything it references.