rustc_const_eval::interpret

Module intern

Source
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: the outermost allocation generally has a clear mutability, but what about the other allocations it points to that have also been created with this value? We don’t want to do guesswork here. The rules are: static, const, and promoted can only create immutable allocations that way. static mut can be initialized with expressions like &mut 42, so all inner allocations are marked mutable. Some of them could potentially be made immutable, but that would require relying on type information, and given how many ways Rust has to lie about type information, we want to avoid doing that.

Enums§

Traits§

Functions§

Trait Aliases§