Module rustc_const_eval::interpret::intern  [−][src]
Expand description
This module specifies the type based interner for constants.
After a const evaluation has computed a value, before we destroy the const evaluator’s session memory, we need to extract all memory allocations to the global memory pool so they stay around.
In principle, this is not very complicated: we recursively walk the final value, follow all the
pointers, and move all reachable allocations to the global tcx memory. The only complication
is picking the right mutability for the allocations in a static initializer: we want to make
as many allocations as possible immutable so LLVM can put them into read-only memory. At the
same time, we need to make memory that could be mutated by the program mutable to avoid
incorrect compilations. To achieve this, we do a type-based traversal of the final value,
tracking mutable and shared references and UnsafeCell to determine the current mutability.
(In principle, we could skip this type-based part for const and promoteds, as they need to be
always immutable. At least for const however we use this opportunity to reject any const
that contains allocations whose mutability we cannot identify.)
Structs
Signalling data structure to ensure we don’t recurse into the memory of other constants or statics
Enums
Functions
Intern ret and everything it references.
Intern an allocation without looking at its children.
mode is the mode of the environment where we found this pointer.
mutablity is the mutability of the place to be interned; even if that says
immutable things might become mutable if ty is not frozen.
ty can be None if there is no potential interior mutability
to account for (e.g. for vtables).