pub struct Allocation<Prov = AllocId, Extra = ()> {
    bytes: Box<[u8]>,
    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 memory module provides higher-level access.

Fields

bytes: Box<[u8]>

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

provenance: ProvenanceMap<Prov>

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.

init_mask: InitMask

Denotes which part of this allocation is initialized.

align: Align

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

mutability: Mutability

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: Extra

Extra state for the machine.

Implementations

Creates an allocation initialized by the given bytes

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

If panic_on_fail is true, this will never return Err.

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

Raw accessors. Provide access to otherwise private bytes.

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.

Returns the mask indicating which bytes are initialized.

Returns the provenance map.

Byte accessors.

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.

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.

Just calling this already marks everything as defined and removes provenance, so be sure to actually put 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.

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

Reading and writing.

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.

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.

Write “uninit” to the given memory range.

Provenance.

Returns all provenance overlapping with the given pointer-offset pair.

Get the provenance of a single byte.

Returns whether this allocation has progrnance overlapping with the given range.

Note: this function exists to allow range_get_provenance to be private, in order to somewhat limit access to provenance outside of the Allocation abstraction.

Removes all provenance inside the given range. If there is provenance overlapping with the edges, it are removed as well and the bytes they cover are marked as uninitialized. This is a somewhat odd “spooky action at a distance”, but it allows strictly more code to run than if we would just error immediately in that case.

Applies a provenance copy. The affected range, as defined in the parameters to prepare_provenance_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.

Uninitialized bytes.

Checks whether the given range is entirely initialized.

Returns Ok(()) if it’s initialized. Otherwise returns the range of byte indexes of the first contiguous uninitialized access.

Checks that a range of bytes is initialized. If not, returns the InvalidUninitBytes error which will report the first range of bytes which is uninitialized.

Transferring the initialization mask to other allocations.

Creates a run-length encoding of the initialization mask; panics if range is empty.

This is essentially a more space-efficient version of InitMask::range_as_init_chunks(...).collect::<Vec<_>>().

Applies multiple instances of the run-length encoding to the initialization 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.

Trait Implementations

Immutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. 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
This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more
This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if fingerprint_style() is not FingerprintStyle::Opaque. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. 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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.