pub struct Allocation<Prov: Provenance = 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§

source§

impl<Prov: Provenance> Allocation<Prov>

source

pub fn from_bytes<'a>(
    slice: impl Into<Cow<'a, [u8]>>,
    align: Align,
    mutability: Mutability
) -> Self

Creates an allocation initialized by the given bytes

source

pub fn from_bytes_byte_aligned_immutable<'a>(
    slice: impl Into<Cow<'a, [u8]>>
) -> Self

source

pub fn uninit<'tcx>(
    size: Size,
    align: Align,
    panic_on_fail: bool
) -> InterpResult<'tcx, Self>

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.

source§

impl Allocation

source

pub fn adjust_from_tcx<Prov: Provenance, Extra, Err>(
    self,
    cx: &impl HasDataLayout,
    extra: Extra,
    adjust_ptr: impl FnMut(Pointer<AllocId>) -> Result<Pointer<Prov>, Err>
) -> Result<Allocation<Prov, Extra>, Err>

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

source§

impl<Prov: Provenance, Extra> Allocation<Prov, Extra>

Raw accessors. Provide access to otherwise private bytes.

source

pub fn len(&self) -> usize

source

pub fn size(&self) -> Size

source

pub fn inspect_with_uninit_and_ptr_outside_interpreter(
    &self,
    range: Range<usize>
) -> &[u8]

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

pub fn init_mask(&self) -> &InitMask

Returns the mask indicating which bytes are initialized.

source

pub fn provenance(&self) -> &ProvenanceMap<Prov>

Returns the provenance map.

source§

impl<Prov: Provenance, Extra> Allocation<Prov, Extra>

Byte accessors.

source

pub fn get_bytes_unchecked(&self, range: AllocRange) -> &[u8]

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

pub fn get_bytes_strip_provenance(
    &self,
    cx: &impl HasDataLayout,
    range: AllocRange
) -> AllocResult<&[u8]>

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

pub fn get_bytes_mut(
    &mut self,
    cx: &impl HasDataLayout,
    range: AllocRange
) -> AllocResult<&mut [u8]>

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.

source

pub fn get_bytes_mut_ptr(
    &mut self,
    cx: &impl HasDataLayout,
    range: AllocRange
) -> AllocResult<*mut [u8]>

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

source§

impl<Prov: Provenance, Extra> Allocation<Prov, Extra>

Reading and writing.

source

fn mark_init(&mut self, range: AllocRange, is_init: bool)

Sets the init bit for the given range.

source

pub fn read_scalar(
    &self,
    cx: &impl HasDataLayout,
    range: AllocRange,
    read_provenance: bool
) -> AllocResult<Scalar<Prov>>

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

pub fn write_scalar(
    &mut self,
    cx: &impl HasDataLayout,
    range: AllocRange,
    val: Scalar<Prov>
) -> AllocResult

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

pub fn write_uninit(
    &mut self,
    cx: &impl HasDataLayout,
    range: AllocRange
) -> AllocResult

Write “uninit” to the given memory range.

source

pub fn provenance_apply_copy(&mut self, copy: ProvenanceCopy<Prov>)

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

pub fn init_mask_apply_copy(
    &mut self,
    copy: InitCopy,
    range: AllocRange,
    repeat: u64
)

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.

Trait Implementations§

source§

impl<'tcx> ArenaAllocatable<'tcx, IsNotCopy> for Allocation

source§

fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self

source§

fn allocate_from_iter<'a>(
    arena: &'a Arena<'tcx>,
    iter: impl IntoIterator<Item = Self>
) -> &'a mut [Self]

source§

impl<'tcx> Borrow<Allocation<AllocId, ()>> for InternedInSet<'tcx, Allocation>

source§

fn borrow<'a>(&'a self) -> &'a Allocation

Immutably borrows from an owned value. Read more
source§

impl<Prov: Clone + Provenance, Extra: Clone> Clone for Allocation<Prov, Extra>

source§

fn clone(&self) -> Allocation<Prov, Extra>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'tcx, Prov, Extra, __D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<__D> for Allocation<Prov, Extra>where
    Prov: Decodable<__D> + Provenance,
    Extra: Decodable<__D>,

source§

fn decode(__decoder: &mut __D) -> Self

source§

impl<'tcx, Prov, Extra, __E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<__E> for Allocation<Prov, Extra>where
    Prov: Encodable<__E> + Provenance,
    Extra: Encodable<__E>,

source§

fn encode(&self, __encoder: &mut __E)

source§

impl Hash for Allocation

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where
    H: Hasher,
    Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'__ctx, Prov, Extra> HashStable<StableHashingContext<'__ctx>> for Allocation<Prov, Extra>where
    Prov: HashStable<StableHashingContext<'__ctx>> + Provenance,
    Extra: HashStable<StableHashingContext<'__ctx>>,

source§

fn hash_stable(
    &self,
    __hcx: &mut StableHashingContext<'__ctx>,
    __hasher: &mut StableHasher
)

source§

impl<Prov: PartialEq + Provenance, Extra: PartialEq> PartialEq<Allocation<Prov, Extra>> for Allocation<Prov, Extra>

source§

fn eq(&self, other: &Allocation<Prov, Extra>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Prov: Eq + Provenance, Extra: Eq> Eq for Allocation<Prov, Extra>

source§

impl<Prov: Provenance, Extra> StructuralEq for Allocation<Prov, Extra>

source§

impl<Prov: Provenance, Extra> StructuralPartialEq for Allocation<Prov, Extra>

Auto Trait Implementations§

§

impl<Prov, Extra> RefUnwindSafe for Allocation<Prov, Extra>where
    Extra: RefUnwindSafe,
    Prov: RefUnwindSafe,

§

impl<Prov, Extra> Send for Allocation<Prov, Extra>where
    Extra: Send,
    Prov: Send,

§

impl<Prov, Extra> Sync for Allocation<Prov, Extra>where
    Extra: Sync,
    Prov: Sync,

§

impl<Prov, Extra> Unpin for Allocation<Prov, Extra>where
    Extra: Unpin,
    Prov: Unpin,

§

impl<Prov, Extra> UnwindSafe for Allocation<Prov, Extra>where
    Extra: UnwindSafe,
    Prov: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, R> InternIteratorElement<T, R> for T

§

type Output = R

source§

fn intern_with<I, F>(iter: I, f: F) -> <T as InternIteratorElement<T, R>>::Outputwhere
    I: Iterator<Item = T>,
    F: FnOnce(&[T]) -> R,

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> MaybeResult<T> for T

§

type Error = !

source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<'tcx, T> ToPredicate<'tcx, T> for T

source§

fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T

source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<Tcx, T, D> Value<Tcx, D> for Twhere
    Tcx: DepContext,
    D: DepKind,

source§

default fn from_cycle_error(tcx: Tcx, _: &[QueryInfo<D>]) -> T

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.