Enum rustc_middle::mir::interpret::Scalar [−][src]
Expand description
A Scalar
represents an immediate, primitive value existing outside of a
memory::Allocation
. It is in many ways like a small chunk of an Allocation
, up to 16 bytes in
size. Like a range of bytes in an Allocation
, a Scalar
can either represent the raw bytes
of a simple value or a pointer into another Allocation
These variants would be private if there was a convenient way to achieve that in Rust.
Do not match on a Scalar
! Use the various to_*
methods instead.
Variants
Int(ScalarInt)
The raw bytes of a simple value.
Tuple Fields of Int
0: ScalarInt
A pointer into an Allocation
. An Allocation
in the memory
module has a list of
relocations, but a Scalar
is only large enough to contain one, so we just represent the
relocation and its associated offset together as a Pointer
here.
We also store the size of the pointer, such that a Scalar
always knows how big it is.
The size is always the pointer size of the current target, but this is not information
that we always have readily available.
Implementations
Create a Scalar from a pointer with an Option<_>
tag (where None
represents a plain integer).
This is almost certainly not the method you want! You should dispatch on the type
and use to_{u8,u16,...}
/scalar_to_ptr
to perform ptr-to-int / int-to-ptr casts as needed.
This method only exists for the benefit of low-level operations that truly need to treat the scalar in whatever form it is.
Fundamental scalar-to-int (cast) operation. Many convenience wrappers exist below, that you likely want to use instead.
Will perform ptr-to-int casts if needed and possible. If that fails, we know the offset is relative, so we return an “erased” Scalar (which is useful for error messages but not much else).
This throws UB (instead of ICEing) on a size mismatch since size mismatches can arise in
Miri when someone declares a function that we shim (such as malloc
) with a wrong type.
Converts the scalar to produce a u8
. Fails if the scalar is a pointer.
Converts the scalar to produce a u16
. Fails if the scalar is a pointer.
Converts the scalar to produce a u32
. Fails if the scalar is a pointer.
Converts the scalar to produce a u64
. Fails if the scalar is a pointer.
Converts the scalar to produce a u128
. Fails if the scalar is a pointer.
Converts the scalar to produce an i8
. Fails if the scalar is a pointer.
Converts the scalar to produce an i16
. Fails if the scalar is a pointer.
Converts the scalar to produce an i32
. Fails if the scalar is a pointer.
Converts the scalar to produce an i64
. Fails if the scalar is a pointer.
Converts the scalar to produce an i128
. Fails if the scalar is a pointer.
Trait Implementations
impl<'__ctx, Tag> HashStable<StableHashingContext<'__ctx>> for Scalar<Tag> where
Tag: HashStable<StableHashingContext<'__ctx>>,
impl<'__ctx, Tag> HashStable<StableHashingContext<'__ctx>> for Scalar<Tag> where
Tag: HashStable<StableHashingContext<'__ctx>>,
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
Auto Trait Implementations
impl<Tag> RefUnwindSafe for Scalar<Tag> where
Tag: RefUnwindSafe,
impl<Tag> UnwindSafe for Scalar<Tag> where
Tag: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
impl<Ctxt, T> DepNodeParams<Ctxt> for T where
Ctxt: DepContext,
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
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 DepNode
s 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
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.