Struct rustc_const_eval::interpret::Allocation
source · pub struct Allocation<Prov = CtfeProvenance, Extra = (), Bytes = Box<[u8]>>where
Prov: Provenance,{
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 memory
module provides higher-level access.
Fields§
§bytes: Bytes
§provenance: ProvenanceMap<Prov>
§init_mask: InitMask
§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, Bytes> Allocation<Prov, (), Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
impl<Prov, Bytes> Allocation<Prov, (), Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
sourcepub fn from_raw_bytes(
bytes: Bytes,
align: Align,
mutability: Mutability
) -> Allocation<Prov, (), Bytes>
pub fn from_raw_bytes( bytes: Bytes, align: Align, mutability: Mutability ) -> Allocation<Prov, (), Bytes>
Creates an allocation from an existing Bytes
value - this is needed for miri FFI support
sourcepub fn from_bytes<'a>(
slice: impl Into<Cow<'a, [u8]>>,
align: Align,
mutability: Mutability
) -> Allocation<Prov, (), Bytes>
pub fn from_bytes<'a>( slice: impl Into<Cow<'a, [u8]>>, align: Align, mutability: Mutability ) -> Allocation<Prov, (), Bytes>
Creates an allocation initialized by the given bytes
pub fn from_bytes_byte_aligned_immutable<'a>( slice: impl Into<Cow<'a, [u8]>> ) -> Allocation<Prov, (), Bytes>
sourcepub fn try_uninit<'tcx>(
size: Size,
align: Align
) -> Result<Allocation<Prov, (), Bytes>, InterpErrorInfo<'tcx>>
pub fn try_uninit<'tcx>( size: Size, align: Align ) -> Result<Allocation<Prov, (), Bytes>, InterpErrorInfo<'tcx>>
Try to create an Allocation of size
bytes, failing if there is not enough memory
available to the compiler to do so.
sourcepub fn uninit(size: Size, align: Align) -> Allocation<Prov, (), Bytes>
pub fn uninit(size: Size, align: Align) -> Allocation<Prov, (), Bytes>
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.
source§impl<Bytes> Allocation<CtfeProvenance, (), Bytes>where
Bytes: AllocBytes,
impl<Bytes> Allocation<CtfeProvenance, (), Bytes>where
Bytes: AllocBytes,
sourcepub fn adjust_from_tcx<Prov, Extra, Err>(
self,
cx: &impl HasDataLayout,
extra: Extra,
adjust_ptr: impl FnMut(Pointer) -> Result<Pointer<Prov>, Err>
) -> Result<Allocation<Prov, Extra, Bytes>, Err>where
Prov: Provenance,
pub fn adjust_from_tcx<Prov, Extra, Err>(
self,
cx: &impl HasDataLayout,
extra: Extra,
adjust_ptr: impl FnMut(Pointer) -> Result<Pointer<Prov>, Err>
) -> Result<Allocation<Prov, Extra, Bytes>, Err>where
Prov: Provenance,
Adjust allocation from the ones in tcx
to a custom Machine instance
with a different Provenance
and Extra
type.
source§impl<Prov, Extra, Bytes> Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
impl<Prov, Extra, Bytes> Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
Raw accessors. Provide access to otherwise private bytes.
pub fn len(&self) -> usize
pub fn size(&self) -> Size
sourcepub fn inspect_with_uninit_and_ptr_outside_interpreter(
&self,
range: Range<usize>
) -> &[u8] ⓘ
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.
sourcepub fn provenance(&self) -> &ProvenanceMap<Prov>
pub fn provenance(&self) -> &ProvenanceMap<Prov>
Returns the provenance map.
source§impl<Prov, Extra, Bytes> Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
impl<Prov, Extra, Bytes> Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
Byte accessors.
pub fn base_addr(&self) -> *const u8
sourcepub fn get_bytes_unchecked(&self, range: AllocRange) -> &[u8] ⓘ
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.
sourcepub fn get_bytes_strip_provenance(
&self,
cx: &impl HasDataLayout,
range: AllocRange
) -> Result<&[u8], AllocError>
pub fn get_bytes_strip_provenance( &self, cx: &impl HasDataLayout, range: AllocRange ) -> Result<&[u8], AllocError>
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.
sourcepub fn get_bytes_mut(
&mut self,
cx: &impl HasDataLayout,
range: AllocRange
) -> Result<&mut [u8], AllocError>
pub fn get_bytes_mut( &mut self, cx: &impl HasDataLayout, range: AllocRange ) -> Result<&mut [u8], AllocError>
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.
sourcepub fn get_bytes_mut_ptr(
&mut self,
cx: &impl HasDataLayout,
range: AllocRange
) -> Result<*mut [u8], AllocError>
pub fn get_bytes_mut_ptr( &mut self, cx: &impl HasDataLayout, range: AllocRange ) -> Result<*mut [u8], AllocError>
A raw pointer variant of get_bytes_mut
that avoids invalidating existing aliases into this memory.
source§impl<Prov, Extra, Bytes> Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
impl<Prov, Extra, Bytes> Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Bytes: AllocBytes,
Reading and writing.
sourcepub fn read_scalar(
&self,
cx: &impl HasDataLayout,
range: AllocRange,
read_provenance: bool
) -> Result<Scalar<Prov>, AllocError>
pub fn read_scalar( &self, cx: &impl HasDataLayout, range: AllocRange, read_provenance: bool ) -> Result<Scalar<Prov>, AllocError>
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.
sourcepub fn write_scalar(
&mut self,
cx: &impl HasDataLayout,
range: AllocRange,
val: Scalar<Prov>
) -> Result<(), AllocError>
pub fn write_scalar( &mut self, cx: &impl HasDataLayout, range: AllocRange, val: Scalar<Prov> ) -> Result<(), AllocError>
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.
sourcepub fn write_uninit(
&mut self,
cx: &impl HasDataLayout,
range: AllocRange
) -> Result<(), AllocError>
pub fn write_uninit( &mut self, cx: &impl HasDataLayout, range: AllocRange ) -> Result<(), AllocError>
Write “uninit” to the given memory range.
sourcepub fn provenance_apply_copy(&mut self, copy: ProvenanceCopy<Prov>)
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
.
sourcepub fn init_mask_apply_copy(
&mut self,
copy: InitCopy,
range: AllocRange,
repeat: u64
)
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> for Allocation
impl<'tcx> ArenaAllocatable<'tcx> for Allocation
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Allocation
fn allocate_from_iter<'a>( arena: &'a Arena<'tcx>, iter: impl IntoIterator<Item = Allocation> ) -> &'a mut [Allocation]
source§impl<Prov, Extra, Bytes> Clone for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> Clone for Allocation<Prov, Extra, Bytes>
source§fn clone(&self) -> Allocation<Prov, Extra, Bytes>
fn clone(&self) -> Allocation<Prov, Extra, Bytes>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<Prov, Extra, Bytes, __D> Decodable<__D> for Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
__D: TyDecoder,
Bytes: Decodable<__D>,
ProvenanceMap<Prov>: Decodable<__D>,
Extra: Decodable<__D>,
impl<Prov, Extra, Bytes, __D> Decodable<__D> for Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
__D: TyDecoder,
Bytes: Decodable<__D>,
ProvenanceMap<Prov>: Decodable<__D>,
Extra: Decodable<__D>,
fn decode(__decoder: &mut __D) -> Allocation<Prov, Extra, Bytes>
source§impl<Prov, Extra, Bytes, __E> Encodable<__E> for Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
__E: TyEncoder,
Bytes: Encodable<__E>,
ProvenanceMap<Prov>: Encodable<__E>,
Extra: Encodable<__E>,
impl<Prov, Extra, Bytes, __E> Encodable<__E> for Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
__E: TyEncoder,
Bytes: Encodable<__E>,
ProvenanceMap<Prov>: Encodable<__E>,
Extra: Encodable<__E>,
source§impl Hash for Allocation
impl Hash for Allocation
source§impl<'__ctx, Prov, Extra, Bytes> HashStable<StableHashingContext<'__ctx>> for Allocation<Prov, Extra, Bytes>where
Prov: Provenance + HashStable<StableHashingContext<'__ctx>>,
Bytes: HashStable<StableHashingContext<'__ctx>>,
Extra: HashStable<StableHashingContext<'__ctx>>,
impl<'__ctx, Prov, Extra, Bytes> HashStable<StableHashingContext<'__ctx>> for Allocation<Prov, Extra, Bytes>where
Prov: Provenance + HashStable<StableHashingContext<'__ctx>>,
Bytes: HashStable<StableHashingContext<'__ctx>>,
Extra: HashStable<StableHashingContext<'__ctx>>,
fn hash_stable( &self, __hcx: &mut StableHashingContext<'__ctx>, __hasher: &mut StableHasher )
source§impl<Prov, Extra, Bytes> PartialEq for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> PartialEq for Allocation<Prov, Extra, Bytes>
source§fn eq(&self, other: &Allocation<Prov, Extra, Bytes>) -> bool
fn eq(&self, other: &Allocation<Prov, Extra, Bytes>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<Prov, Extra, Bytes> Eq for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> StructuralPartialEq for Allocation<Prov, Extra, Bytes>where
Prov: Provenance,
Auto Trait Implementations§
impl<Prov, Extra, Bytes> DynSend for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> DynSync for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> Freeze for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> RefUnwindSafe for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> Send for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> Sync for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> Unpin for Allocation<Prov, Extra, Bytes>
impl<Prov, Extra, Bytes> UnwindSafe for Allocation<Prov, Extra, Bytes>
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Filterable for T
impl<T> Filterable for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<'tcx, T> ToPredicate<'tcx, T> for T
impl<'tcx, T> ToPredicate<'tcx, T> for T
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed ) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for 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.