Allocation in rustc_middle::mir::interpret - Rust (original) (raw)

pub struct Allocation<Prov: Provenance = CtfeProvenance, Extra = (), Bytes = Box<[u8]>> {
    bytes: Bytes,
    provenance: ProvenanceMap<Prov>,
    init_mask: InitMask,
    pub align: Align,
    pub mutability: Mutability,
    pub extra: Extra,
}

Expand description

This type represents an Allocation in the Miri/CTFE core engine.

Its public API is rather low-level, working directly with allocation offsets and a custom error type to account for the lack of an AllocId on this level. The Miri/CTFE core engine memorymodule provides higher-level access.

The actual bytes of the allocation. Note that the bytes of a pointer represent the offset of the pointer.

Maps from byte addresses to extra provenance data for each pointer. Only the first byte of a pointer is inserted into the map; i.e., every entry in this map applies to pointer_size consecutive bytes starting at the given offset.

Denotes which part of this allocation is initialized.

The alignment of the allocation to detect unaligned reads. (Align guarantees that this is a power of two.)

true if the allocation is mutable. Also used by codegen to determine if a static should be put into mutable memory, which happens for static mut and static with interior mutability.

Extra state for the machine.

Source§

Source

Creates an allocation initialized by the given bytes

Source

Source

Source

Try to create an Allocation of size bytes, failing if there is not enough memory available to the compiler to do so.

Source

Try to create an Allocation of size bytes, panics if there is not enough memory available to the compiler to do so.

Example use case: To obtain an Allocation filled with specific data, first call this function and then call write_scalar to fill in the right data.

Add the extra.

Source§

Source

Adjust allocation from the ones in tcx to a custom Machine instance with a different Provenance and Byte type.

Source

Source

Source

Looks at a slice which may contain uninitialized bytes or provenance. This differs from get_bytes_with_uninit_and_ptr in that it does no provenance checks (even on the edges) at all. This must not be used for reads affecting the interpreter execution.

Source

Returns the mask indicating which bytes are initialized.

Source

Returns the provenance map.

Source

This is the entirely abstraction-violating way to just grab the raw bytes without caring about provenance or initialization.

This function also guarantees that the resulting pointer will remain stable even when new allocations are pushed to the HashMap. mem_copy_repeatedly relies on that.

Source

Checks that these bytes are initialized, and then strip provenance (if possible) and return them.

It is the caller’s responsibility to check bounds and alignment beforehand. Most likely, you want to use the PlaceTy and OperandTy-based methods on InterpCx instead.

Source

This is the entirely abstraction-violating way to just get mutable access to the raw bytes. Just calling this already marks everything as defined and removes provenance, so be sure to actually overwrite all the data there!

It is the caller’s responsibility to check bounds and alignment beforehand. Most likely, you want to use the PlaceTy and OperandTy-based methods on InterpCx instead.

Source

A raw pointer variant of get_bytes_unchecked_for_overwrite that avoids invalidating existing immutable aliases into this memory.

Source

This gives direct mutable access to the entire buffer, just exposing their internal state without resetting anything. Directly exposes AllocBytes::as_mut_ptr. Only works ifOFFSET_IS_ADDR is true.

Source

This gives direct immutable access to the entire buffer, just exposing their internal state without resetting anything. Directly exposes AllocBytes::as_ptr. Only works ifOFFSET_IS_ADDR is true.

Source

Sets the init bit for the given range.

Source

Reads a non-ZST scalar.

If read_provenance is true, this will also read provenance; otherwise (if the machine supports that) provenance is entirely ignored.

ZSTs can’t be read because in order to obtain a Pointer, we need to check for ZSTness anyway due to integer pointers being valid for ZSTs.

It is the caller’s responsibility to check bounds and alignment beforehand. Most likely, you want to call InterpCx::read_scalar instead of this method.

Source

Writes a non-ZST scalar.

ZSTs can’t be read because in order to obtain a Pointer, we need to check for ZSTness anyway due to integer pointers being valid for ZSTs.

It is the caller’s responsibility to check bounds and alignment beforehand. Most likely, you want to call InterpCx::write_scalar instead of this method.

Source

Write “uninit” to the given memory range.

Source

Initialize all previously uninitialized bytes in the entire allocation, and set provenance of everything to Wildcard. Before calling this, make sure all provenance in this allocation is exposed!

Source

Remove all provenance in the given memory range.

Source

Applies a previously prepared provenance copy. The affected range, as defined in the parameters to provenance().prepare_copy is expected to be clear of provenance.

This is dangerous to use as it can violate internal Allocation invariants! It only exists to support an efficient implementation of mem_copy_repeatedly.

Source

Applies a previously prepared copy of the init mask.

This is dangerous to use as it can violate internal Allocation invariants! It only exists to support an efficient implementation of mem_copy_repeatedly.

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.