Type Alias rustc_middle::query::queries::valtree_to_const_val::ProvidedValue
source · pub type ProvidedValue<'tcx> = ConstValue<'tcx>;Expand description
This type alias specifies the type returned from query providers and the type
used for decoding. For regular queries this is the declared returned type V,
but arena_cache will use <V as Deref>::Target instead.
Aliased Type§
enum ProvidedValue<'tcx> {
Scalar(Scalar<AllocId>),
ZeroSized,
Slice {
data: ConstAllocation<'tcx>,
meta: u64,
},
Indirect {
alloc_id: AllocId,
offset: Size,
},
}Variants§
Scalar(Scalar<AllocId>)
Used for types with layout::abi::Scalar ABI.
Not using the enum Value to encode that this must not be Uninit.
ZeroSized
Only for ZSTs.
Slice
Fields
data: ConstAllocation<'tcx>The allocation storing the slice contents. This always points to the beginning of the allocation.
Used for references to unsized types with slice tail.
This is worth an optimized representation since Rust has literals of type &str and
&[u8]. Not having to indirect those through an AllocId (or two, if we used Indirect)
has shown measurable performance improvements on stress tests. We then reuse this
optimization for slice-tail types more generally during valtree-to-constval conversion.
Indirect
Fields
alloc_id: AllocIdThe backing memory of the value. May contain more memory than needed for just the value if this points into some other larger ConstValue.
We use an AllocId here instead of a ConstAllocation<'tcx> to make sure that when a
raw constant (which is basically just an AllocId) is turned into a ConstValue and
back, we can preserve the original AllocId.
A value not representable by the other variants; needs to be stored in-memory.
Must not be used for scalars or ZST, but having &str or other slices in this variant is fine.
Implementations§
source§impl<'tcx> ConstValue<'tcx>
impl<'tcx> ConstValue<'tcx>
pub fn try_to_scalar(&self) -> Option<Scalar<AllocId>>
pub fn try_to_scalar_int(&self) -> Option<ScalarInt>
pub fn try_to_bits(&self, size: Size) -> Option<u128>
pub fn try_to_bool(&self) -> Option<bool>
pub fn try_to_target_usize(&self, tcx: TyCtxt<'tcx>) -> Option<u64>
pub fn try_to_bits_for_ty( &self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx> ) -> Option<u128>
pub fn from_bool(b: bool) -> Self
pub fn from_u64(i: u64) -> Self
pub fn from_u128(i: u128) -> Self
pub fn from_target_usize(i: u64, cx: &impl HasDataLayout) -> Self
sourcepub fn try_get_slice_bytes_for_diagnostics(
&self,
tcx: TyCtxt<'tcx>
) -> Option<&'tcx [u8]>
pub fn try_get_slice_bytes_for_diagnostics( &self, tcx: TyCtxt<'tcx> ) -> Option<&'tcx [u8]>
Must only be called on constants of type &str or &[u8]!
Trait Implementations§
source§impl<'tcx> Clone for ConstValue<'tcx>
impl<'tcx> Clone for ConstValue<'tcx>
source§fn clone(&self) -> ConstValue<'tcx>
fn clone(&self) -> ConstValue<'tcx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'tcx> Debug for ConstValue<'tcx>
impl<'tcx> Debug for ConstValue<'tcx>
source§impl<'tcx> Hash for ConstValue<'tcx>
impl<'tcx> Hash for ConstValue<'tcx>
source§impl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for ConstValue<'tcx>
impl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for ConstValue<'tcx>
fn hash_stable( &self, __hcx: &mut StableHashingContext<'__ctx>, __hasher: &mut StableHasher )
source§impl<'tcx, '__lifted> Lift<'__lifted> for ConstValue<'tcx>
impl<'tcx, '__lifted> Lift<'__lifted> for ConstValue<'tcx>
type Lifted = ConstValue<'__lifted>
fn lift_to_tcx(self, __tcx: TyCtxt<'__lifted>) -> Option<ConstValue<'__lifted>>
source§impl<'tcx> PartialEq<ConstValue<'tcx>> for ConstValue<'tcx>
impl<'tcx> PartialEq<ConstValue<'tcx>> for ConstValue<'tcx>
source§fn eq(&self, other: &ConstValue<'tcx>) -> bool
fn eq(&self, other: &ConstValue<'tcx>) -> bool
self and other values to be equal, and is used
by ==.source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ConstValue<'tcx>
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ConstValue<'tcx>
source§fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
_: &mut F
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _: &mut F ) -> Result<Self, F::Error>
source§impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ConstValue<'tcx>
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ConstValue<'tcx>
source§fn visit_with<F: TypeVisitor<TyCtxt<'tcx>>>(
&self,
_: &mut F
) -> ControlFlow<F::BreakTy>
fn visit_with<F: TypeVisitor<TyCtxt<'tcx>>>( &self, _: &mut F ) -> ControlFlow<F::BreakTy>
impl<'tcx> Copy for ConstValue<'tcx>
impl<'tcx> Eq for ConstValue<'tcx>
impl<'tcx> StructuralEq for ConstValue<'tcx>
impl<'tcx> StructuralPartialEq for ConstValue<'tcx>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes
Size for each variant:
Scalar: 24 bytesZeroSized: 0 bytesSlice: 24 bytesIndirect: 24 bytes