Rollup merge of #69700 - anyska:layout-details-rename, r=oli-obk
Rename LayoutDetails to just Layout.
This commit is contained in:
commit
818da9eb4d
11 changed files with 73 additions and 79 deletions
|
@ -11,7 +11,7 @@
|
||||||
macro_rules! arena_types {
|
macro_rules! arena_types {
|
||||||
($macro:path, $args:tt, $tcx:lifetime) => (
|
($macro:path, $args:tt, $tcx:lifetime) => (
|
||||||
$macro!($args, [
|
$macro!($args, [
|
||||||
[] layouts: rustc::ty::layout::LayoutDetails,
|
[] layouts: rustc::ty::layout::Layout,
|
||||||
[] generics: rustc::ty::Generics,
|
[] generics: rustc::ty::Generics,
|
||||||
[] trait_def: rustc::ty::TraitDef,
|
[] trait_def: rustc::ty::TraitDef,
|
||||||
[] adt_def: rustc::ty::AdtDef,
|
[] adt_def: rustc::ty::AdtDef,
|
||||||
|
|
|
@ -738,7 +738,7 @@ rustc_queries! {
|
||||||
|
|
||||||
query layout_raw(
|
query layout_raw(
|
||||||
env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
|
env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
|
||||||
) -> Result<&'tcx ty::layout::LayoutDetails, ty::layout::LayoutError<'tcx>> {
|
) -> Result<&'tcx ty::layout::Layout, ty::layout::LayoutError<'tcx>> {
|
||||||
desc { "computing layout of `{}`", env.value }
|
desc { "computing layout of `{}`", env.value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::mir::{
|
||||||
};
|
};
|
||||||
use crate::traits;
|
use crate::traits;
|
||||||
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
|
use crate::traits::{Clause, Clauses, Goal, GoalKind, Goals};
|
||||||
use crate::ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
|
use crate::ty::layout::{Layout, TargetDataLayout, VariantIdx};
|
||||||
use crate::ty::query;
|
use crate::ty::query;
|
||||||
use crate::ty::steal::Steal;
|
use crate::ty::steal::Steal;
|
||||||
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
||||||
|
@ -985,7 +985,7 @@ pub struct GlobalCtxt<'tcx> {
|
||||||
/// Stores memory for globals (statics/consts).
|
/// Stores memory for globals (statics/consts).
|
||||||
pub alloc_map: Lock<interpret::AllocMap<'tcx>>,
|
pub alloc_map: Lock<interpret::AllocMap<'tcx>>,
|
||||||
|
|
||||||
layout_interner: ShardedHashMap<&'tcx LayoutDetails, ()>,
|
layout_interner: ShardedHashMap<&'tcx Layout, ()>,
|
||||||
|
|
||||||
output_filenames: Arc<OutputFilenames>,
|
output_filenames: Arc<OutputFilenames>,
|
||||||
}
|
}
|
||||||
|
@ -1040,7 +1040,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.const_stability_interner.intern(stab, |stab| self.arena.alloc(stab))
|
self.const_stability_interner.intern(stab, |stab| self.arena.alloc(stab))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn intern_layout(self, layout: LayoutDetails) -> &'tcx LayoutDetails {
|
pub fn intern_layout(self, layout: Layout) -> &'tcx Layout {
|
||||||
self.layout_interner.intern(layout, |layout| self.arena.alloc(layout))
|
self.layout_interner.intern(layout, |layout| self.arena.alloc(layout))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
|
||||||
fn layout_raw<'tcx>(
|
fn layout_raw<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
|
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
|
||||||
) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
|
) -> Result<&'tcx Layout, LayoutError<'tcx>> {
|
||||||
ty::tls::with_related_context(tcx, move |icx| {
|
ty::tls::with_related_context(tcx, move |icx| {
|
||||||
let rec_limit = *tcx.sess.recursion_limit.get();
|
let rec_limit = *tcx.sess.recursion_limit.get();
|
||||||
let (param_env, ty) = query.into_parts();
|
let (param_env, ty) = query.into_parts();
|
||||||
|
@ -240,7 +240,7 @@ fn invert_mapping(map: &[u32]) -> Vec<u32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
fn scalar_pair(&self, a: Scalar, b: Scalar) -> LayoutDetails {
|
fn scalar_pair(&self, a: Scalar, b: Scalar) -> Layout {
|
||||||
let dl = self.data_layout();
|
let dl = self.data_layout();
|
||||||
let b_align = b.value.align(dl);
|
let b_align = b.value.align(dl);
|
||||||
let align = a.value.align(dl).max(b_align).max(dl.aggregate_align);
|
let align = a.value.align(dl).max(b_align).max(dl.aggregate_align);
|
||||||
|
@ -254,7 +254,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
.chain(Niche::from_scalar(dl, Size::ZERO, a.clone()))
|
.chain(Niche::from_scalar(dl, Size::ZERO, a.clone()))
|
||||||
.max_by_key(|niche| niche.available(dl));
|
.max_by_key(|niche| niche.available(dl));
|
||||||
|
|
||||||
LayoutDetails {
|
Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Arbitrary {
|
fields: FieldPlacement::Arbitrary {
|
||||||
offsets: vec![Size::ZERO, b_offset],
|
offsets: vec![Size::ZERO, b_offset],
|
||||||
|
@ -273,7 +273,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
fields: &[TyLayout<'_>],
|
fields: &[TyLayout<'_>],
|
||||||
repr: &ReprOptions,
|
repr: &ReprOptions,
|
||||||
kind: StructKind,
|
kind: StructKind,
|
||||||
) -> Result<LayoutDetails, LayoutError<'tcx>> {
|
) -> Result<Layout, LayoutError<'tcx>> {
|
||||||
let dl = self.data_layout();
|
let dl = self.data_layout();
|
||||||
let pack = repr.pack;
|
let pack = repr.pack;
|
||||||
if pack.is_some() && repr.align.is_some() {
|
if pack.is_some() && repr.align.is_some() {
|
||||||
|
@ -422,17 +422,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
(
|
(
|
||||||
Some((
|
Some((
|
||||||
i,
|
i,
|
||||||
&TyLayout {
|
&TyLayout { layout: &Layout { abi: Abi::Scalar(ref a), .. }, .. },
|
||||||
details: &LayoutDetails { abi: Abi::Scalar(ref a), .. },
|
|
||||||
..
|
|
||||||
},
|
|
||||||
)),
|
)),
|
||||||
Some((
|
Some((
|
||||||
j,
|
j,
|
||||||
&TyLayout {
|
&TyLayout { layout: &Layout { abi: Abi::Scalar(ref b), .. }, .. },
|
||||||
details: &LayoutDetails { abi: Abi::Scalar(ref b), .. },
|
|
||||||
..
|
|
||||||
},
|
|
||||||
)),
|
)),
|
||||||
None,
|
None,
|
||||||
) => {
|
) => {
|
||||||
|
@ -470,7 +464,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
abi = Abi::Uninhabited;
|
abi = Abi::Uninhabited;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(LayoutDetails {
|
Ok(Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Arbitrary { offsets, memory_index },
|
fields: FieldPlacement::Arbitrary { offsets, memory_index },
|
||||||
abi,
|
abi,
|
||||||
|
@ -480,7 +474,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
|
fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<'tcx>> {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let param_env = self.param_env;
|
let param_env = self.param_env;
|
||||||
let dl = self.data_layout();
|
let dl = self.data_layout();
|
||||||
|
@ -489,8 +483,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
assert!(bits <= 128);
|
assert!(bits <= 128);
|
||||||
Scalar { value, valid_range: 0..=(!0 >> (128 - bits)) }
|
Scalar { value, valid_range: 0..=(!0 >> (128 - bits)) }
|
||||||
};
|
};
|
||||||
let scalar =
|
let scalar = |value: Primitive| tcx.intern_layout(Layout::scalar(self, scalar_unit(value)));
|
||||||
|value: Primitive| tcx.intern_layout(LayoutDetails::scalar(self, scalar_unit(value)));
|
|
||||||
|
|
||||||
let univariant = |fields: &[TyLayout<'_>], repr: &ReprOptions, kind| {
|
let univariant = |fields: &[TyLayout<'_>], repr: &ReprOptions, kind| {
|
||||||
Ok(tcx.intern_layout(self.univariant_uninterned(ty, fields, repr, kind)?))
|
Ok(tcx.intern_layout(self.univariant_uninterned(ty, fields, repr, kind)?))
|
||||||
|
@ -499,11 +492,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
|
|
||||||
Ok(match ty.kind {
|
Ok(match ty.kind {
|
||||||
// Basic scalars.
|
// Basic scalars.
|
||||||
ty::Bool => tcx.intern_layout(LayoutDetails::scalar(
|
ty::Bool => tcx.intern_layout(Layout::scalar(
|
||||||
self,
|
self,
|
||||||
Scalar { value: Int(I8, false), valid_range: 0..=1 },
|
Scalar { value: Int(I8, false), valid_range: 0..=1 },
|
||||||
)),
|
)),
|
||||||
ty::Char => tcx.intern_layout(LayoutDetails::scalar(
|
ty::Char => tcx.intern_layout(Layout::scalar(
|
||||||
self,
|
self,
|
||||||
Scalar { value: Int(I32, false), valid_range: 0..=0x10FFFF },
|
Scalar { value: Int(I32, false), valid_range: 0..=0x10FFFF },
|
||||||
)),
|
)),
|
||||||
|
@ -516,11 +509,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
ty::FnPtr(_) => {
|
ty::FnPtr(_) => {
|
||||||
let mut ptr = scalar_unit(Pointer);
|
let mut ptr = scalar_unit(Pointer);
|
||||||
ptr.valid_range = 1..=*ptr.valid_range.end();
|
ptr.valid_range = 1..=*ptr.valid_range.end();
|
||||||
tcx.intern_layout(LayoutDetails::scalar(self, ptr))
|
tcx.intern_layout(Layout::scalar(self, ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// The never type.
|
// The never type.
|
||||||
ty::Never => tcx.intern_layout(LayoutDetails {
|
ty::Never => tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Union(0),
|
fields: FieldPlacement::Union(0),
|
||||||
abi: Abi::Uninhabited,
|
abi: Abi::Uninhabited,
|
||||||
|
@ -538,13 +531,13 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
|
|
||||||
let pointee = tcx.normalize_erasing_regions(param_env, pointee);
|
let pointee = tcx.normalize_erasing_regions(param_env, pointee);
|
||||||
if pointee.is_sized(tcx.at(DUMMY_SP), param_env) {
|
if pointee.is_sized(tcx.at(DUMMY_SP), param_env) {
|
||||||
return Ok(tcx.intern_layout(LayoutDetails::scalar(self, data_ptr)));
|
return Ok(tcx.intern_layout(Layout::scalar(self, data_ptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
|
let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
|
||||||
let metadata = match unsized_part.kind {
|
let metadata = match unsized_part.kind {
|
||||||
ty::Foreign(..) => {
|
ty::Foreign(..) => {
|
||||||
return Ok(tcx.intern_layout(LayoutDetails::scalar(self, data_ptr)));
|
return Ok(tcx.intern_layout(Layout::scalar(self, data_ptr)));
|
||||||
}
|
}
|
||||||
ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)),
|
ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)),
|
||||||
ty::Dynamic(..) => {
|
ty::Dynamic(..) => {
|
||||||
|
@ -581,7 +574,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
|
|
||||||
let largest_niche = if count != 0 { element.largest_niche.clone() } else { None };
|
let largest_niche = if count != 0 { element.largest_niche.clone() } else { None };
|
||||||
|
|
||||||
tcx.intern_layout(LayoutDetails {
|
tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Array { stride: element.size, count },
|
fields: FieldPlacement::Array { stride: element.size, count },
|
||||||
abi,
|
abi,
|
||||||
|
@ -592,7 +585,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
}
|
}
|
||||||
ty::Slice(element) => {
|
ty::Slice(element) => {
|
||||||
let element = self.layout_of(element)?;
|
let element = self.layout_of(element)?;
|
||||||
tcx.intern_layout(LayoutDetails {
|
tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Array { stride: element.size, count: 0 },
|
fields: FieldPlacement::Array { stride: element.size, count: 0 },
|
||||||
abi: Abi::Aggregate { sized: false },
|
abi: Abi::Aggregate { sized: false },
|
||||||
|
@ -601,7 +594,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
size: Size::ZERO,
|
size: Size::ZERO,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ty::Str => tcx.intern_layout(LayoutDetails {
|
ty::Str => tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Array { stride: Size::from_bytes(1), count: 0 },
|
fields: FieldPlacement::Array { stride: Size::from_bytes(1), count: 0 },
|
||||||
abi: Abi::Aggregate { sized: false },
|
abi: Abi::Aggregate { sized: false },
|
||||||
|
@ -670,7 +663,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
let align = dl.vector_align(size);
|
let align = dl.vector_align(size);
|
||||||
let size = size.align_to(align.abi);
|
let size = size.align_to(align.abi);
|
||||||
|
|
||||||
tcx.intern_layout(LayoutDetails {
|
tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Array { stride: element.size, count },
|
fields: FieldPlacement::Array { stride: element.size, count },
|
||||||
abi: Abi::Vector { element: scalar, count },
|
abi: Abi::Vector { element: scalar, count },
|
||||||
|
@ -746,7 +739,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
align = align.min(AbiAndPrefAlign::new(pack));
|
align = align.min(AbiAndPrefAlign::new(pack));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(tcx.intern_layout(LayoutDetails {
|
return Ok(tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index },
|
variants: Variants::Single { index },
|
||||||
fields: FieldPlacement::Union(variants[index].len()),
|
fields: FieldPlacement::Union(variants[index].len()),
|
||||||
abi,
|
abi,
|
||||||
|
@ -970,7 +963,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
let largest_niche =
|
let largest_niche =
|
||||||
Niche::from_scalar(dl, offset, niche_scalar.clone());
|
Niche::from_scalar(dl, offset, niche_scalar.clone());
|
||||||
|
|
||||||
return Ok(tcx.intern_layout(LayoutDetails {
|
return Ok(tcx.intern_layout(Layout {
|
||||||
variants: Variants::Multiple {
|
variants: Variants::Multiple {
|
||||||
discr: niche_scalar,
|
discr: niche_scalar,
|
||||||
discr_kind: DiscriminantKind::Niche {
|
discr_kind: DiscriminantKind::Niche {
|
||||||
|
@ -1165,7 +1158,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let prim = match field.details.abi {
|
let prim = match field.abi {
|
||||||
Abi::Scalar(ref scalar) => scalar.value,
|
Abi::Scalar(ref scalar) => scalar.value,
|
||||||
_ => {
|
_ => {
|
||||||
common_prim = None;
|
common_prim = None;
|
||||||
|
@ -1212,7 +1205,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
|
|
||||||
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone());
|
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone());
|
||||||
|
|
||||||
tcx.intern_layout(LayoutDetails {
|
tcx.intern_layout(Layout {
|
||||||
variants: Variants::Multiple {
|
variants: Variants::Multiple {
|
||||||
discr: tag,
|
discr: tag,
|
||||||
discr_kind: DiscriminantKind::Tag,
|
discr_kind: DiscriminantKind::Tag,
|
||||||
|
@ -1243,7 +1236,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
| ty::Placeholder(..)
|
| ty::Placeholder(..)
|
||||||
| ty::UnnormalizedProjection(..)
|
| ty::UnnormalizedProjection(..)
|
||||||
| ty::GeneratorWitness(..)
|
| ty::GeneratorWitness(..)
|
||||||
| ty::Infer(_) => bug!("LayoutDetails::compute: unexpected type `{}`", ty),
|
| ty::Infer(_) => bug!("Layout::compute: unexpected type `{}`", ty),
|
||||||
|
|
||||||
ty::Param(_) | ty::Error => {
|
ty::Param(_) | ty::Error => {
|
||||||
return Err(LayoutError::Unknown(ty));
|
return Err(LayoutError::Unknown(ty));
|
||||||
|
@ -1390,7 +1383,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
def_id: hir::def_id::DefId,
|
def_id: hir::def_id::DefId,
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
|
) -> Result<&'tcx Layout, LayoutError<'tcx>> {
|
||||||
use SavedLocalEligibility::*;
|
use SavedLocalEligibility::*;
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
|
@ -1409,8 +1402,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
let discr_int = Integer::fit_unsigned(max_discr);
|
let discr_int = Integer::fit_unsigned(max_discr);
|
||||||
let discr_int_ty = discr_int.to_ty(tcx, false);
|
let discr_int_ty = discr_int.to_ty(tcx, false);
|
||||||
let discr = Scalar { value: Primitive::Int(discr_int, false), valid_range: 0..=max_discr };
|
let discr = Scalar { value: Primitive::Int(discr_int, false), valid_range: 0..=max_discr };
|
||||||
let discr_layout = self.tcx.intern_layout(LayoutDetails::scalar(self, discr.clone()));
|
let discr_layout = self.tcx.intern_layout(Layout::scalar(self, discr.clone()));
|
||||||
let discr_layout = TyLayout { ty: discr_int_ty, details: discr_layout };
|
let discr_layout = TyLayout { ty: discr_int_ty, layout: discr_layout };
|
||||||
|
|
||||||
let promoted_layouts = ineligible_locals
|
let promoted_layouts = ineligible_locals
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1559,7 +1552,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
Abi::Aggregate { sized: true }
|
Abi::Aggregate { sized: true }
|
||||||
};
|
};
|
||||||
|
|
||||||
let layout = tcx.intern_layout(LayoutDetails {
|
let layout = tcx.intern_layout(Layout {
|
||||||
variants: Variants::Multiple {
|
variants: Variants::Multiple {
|
||||||
discr,
|
discr,
|
||||||
discr_kind: DiscriminantKind::Tag,
|
discr_kind: DiscriminantKind::Tag,
|
||||||
|
@ -1908,8 +1901,8 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
|
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
|
||||||
let param_env = self.param_env.with_reveal_all();
|
let param_env = self.param_env.with_reveal_all();
|
||||||
let ty = self.tcx.normalize_erasing_regions(param_env, ty);
|
let ty = self.tcx.normalize_erasing_regions(param_env, ty);
|
||||||
let details = self.tcx.layout_raw(param_env.and(ty))?;
|
let layout = self.tcx.layout_raw(param_env.and(ty))?;
|
||||||
let layout = TyLayout { ty, details };
|
let layout = TyLayout { ty, layout };
|
||||||
|
|
||||||
// N.B., this recording is normally disabled; when enabled, it
|
// N.B., this recording is normally disabled; when enabled, it
|
||||||
// can however trigger recursive invocations of `layout_of`.
|
// can however trigger recursive invocations of `layout_of`.
|
||||||
|
@ -1932,8 +1925,8 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {
|
||||||
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
|
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
|
||||||
let param_env = self.param_env.with_reveal_all();
|
let param_env = self.param_env.with_reveal_all();
|
||||||
let ty = self.tcx.normalize_erasing_regions(param_env, ty);
|
let ty = self.tcx.normalize_erasing_regions(param_env, ty);
|
||||||
let details = self.tcx.layout_raw(param_env.and(ty))?;
|
let layout = self.tcx.layout_raw(param_env.and(ty))?;
|
||||||
let layout = TyLayout { ty, details };
|
let layout = TyLayout { ty, layout };
|
||||||
|
|
||||||
// N.B., this recording is normally disabled; when enabled, it
|
// N.B., this recording is normally disabled; when enabled, it
|
||||||
// can however trigger recursive invocations of `layout_of`.
|
// can however trigger recursive invocations of `layout_of`.
|
||||||
|
@ -1982,7 +1975,7 @@ where
|
||||||
+ HasParamEnv<'tcx>,
|
+ HasParamEnv<'tcx>,
|
||||||
{
|
{
|
||||||
fn for_variant(this: TyLayout<'tcx>, cx: &C, variant_index: VariantIdx) -> TyLayout<'tcx> {
|
fn for_variant(this: TyLayout<'tcx>, cx: &C, variant_index: VariantIdx) -> TyLayout<'tcx> {
|
||||||
let details = match this.variants {
|
let layout = match this.variants {
|
||||||
Variants::Single { index }
|
Variants::Single { index }
|
||||||
// If all variants but one are uninhabited, the variant layout is the enum layout.
|
// If all variants but one are uninhabited, the variant layout is the enum layout.
|
||||||
if index == variant_index &&
|
if index == variant_index &&
|
||||||
|
@ -1990,13 +1983,13 @@ where
|
||||||
// For more details see https://github.com/rust-lang/rust/issues/69763.
|
// For more details see https://github.com/rust-lang/rust/issues/69763.
|
||||||
this.fields != FieldPlacement::Union(0) =>
|
this.fields != FieldPlacement::Union(0) =>
|
||||||
{
|
{
|
||||||
this.details
|
this.layout
|
||||||
}
|
}
|
||||||
|
|
||||||
Variants::Single { index } => {
|
Variants::Single { index } => {
|
||||||
// Deny calling for_variant more than once for non-Single enums.
|
// Deny calling for_variant more than once for non-Single enums.
|
||||||
if let Ok(layout) = cx.layout_of(this.ty).to_result() {
|
if let Ok(original_layout) = cx.layout_of(this.ty).to_result() {
|
||||||
assert_eq!(layout.variants, Variants::Single { index });
|
assert_eq!(original_layout.variants, Variants::Single { index });
|
||||||
}
|
}
|
||||||
|
|
||||||
let fields = match this.ty.kind {
|
let fields = match this.ty.kind {
|
||||||
|
@ -2004,7 +1997,7 @@ where
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
};
|
};
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
tcx.intern_layout(LayoutDetails {
|
tcx.intern_layout(Layout {
|
||||||
variants: Variants::Single { index: variant_index },
|
variants: Variants::Single { index: variant_index },
|
||||||
fields: FieldPlacement::Union(fields),
|
fields: FieldPlacement::Union(fields),
|
||||||
abi: Abi::Uninhabited,
|
abi: Abi::Uninhabited,
|
||||||
|
@ -2017,17 +2010,17 @@ where
|
||||||
Variants::Multiple { ref variants, .. } => &variants[variant_index],
|
Variants::Multiple { ref variants, .. } => &variants[variant_index],
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(details.variants, Variants::Single { index: variant_index });
|
assert_eq!(layout.variants, Variants::Single { index: variant_index });
|
||||||
|
|
||||||
TyLayout { ty: this.ty, details }
|
TyLayout { ty: this.ty, layout }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn field(this: TyLayout<'tcx>, cx: &C, i: usize) -> C::TyLayout {
|
fn field(this: TyLayout<'tcx>, cx: &C, i: usize) -> C::TyLayout {
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
let discr_layout = |discr: &Scalar| -> C::TyLayout {
|
let discr_layout = |discr: &Scalar| -> C::TyLayout {
|
||||||
let layout = LayoutDetails::scalar(cx, discr.clone());
|
let layout = Layout::scalar(cx, discr.clone());
|
||||||
MaybeResult::from(Ok(TyLayout {
|
MaybeResult::from(Ok(TyLayout {
|
||||||
details: tcx.intern_layout(layout),
|
layout: tcx.intern_layout(layout),
|
||||||
ty: discr.value.to_ty(tcx),
|
ty: discr.value.to_ty(tcx),
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
|
|
@ -219,7 +219,7 @@ pub(super) fn from_known_layout<'tcx>(
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
let layout2 = compute()?;
|
let layout2 = compute()?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
layout.details, layout2.details,
|
layout.layout, layout2.layout,
|
||||||
"mismatch in layout of supposedly equal-layout types {:?} and {:?}",
|
"mismatch in layout of supposedly equal-layout types {:?} and {:?}",
|
||||||
layout.ty, layout2.ty
|
layout.ty, layout2.ty
|
||||||
);
|
);
|
||||||
|
|
|
@ -869,7 +869,7 @@ where
|
||||||
// We do NOT compare the types for equality, because well-typed code can
|
// We do NOT compare the types for equality, because well-typed code can
|
||||||
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
|
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
|
||||||
assert!(
|
assert!(
|
||||||
src.layout.details == dest.layout.details,
|
src.layout.layout == dest.layout.layout,
|
||||||
"Layout mismatch when copying!\nsrc: {:#?}\ndest: {:#?}",
|
"Layout mismatch when copying!\nsrc: {:#?}\ndest: {:#?}",
|
||||||
src,
|
src,
|
||||||
dest
|
dest
|
||||||
|
@ -923,7 +923,7 @@ where
|
||||||
src: OpTy<'tcx, M::PointerTag>,
|
src: OpTy<'tcx, M::PointerTag>,
|
||||||
dest: PlaceTy<'tcx, M::PointerTag>,
|
dest: PlaceTy<'tcx, M::PointerTag>,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
if src.layout.details == dest.layout.details {
|
if src.layout.layout == dest.layout.layout {
|
||||||
// Fast path: Just use normal `copy_op`
|
// Fast path: Just use normal `copy_op`
|
||||||
return self.copy_op(src, dest);
|
return self.copy_op(src, dest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -688,7 +688,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
let ty1 = substs[0].expect_ty();
|
let ty1 = substs[0].expect_ty();
|
||||||
let ty2 = substs[1].expect_ty();
|
let ty2 = substs[1].expect_ty();
|
||||||
let ty_is_scalar = |ty| {
|
let ty_is_scalar = |ty| {
|
||||||
this.ecx.layout_of(ty).ok().map(|ty| ty.details.abi.is_scalar())
|
this.ecx.layout_of(ty).ok().map(|layout| layout.abi.is_scalar())
|
||||||
== Some(true)
|
== Some(true)
|
||||||
};
|
};
|
||||||
if ty_is_scalar(ty1) && ty_is_scalar(ty2) {
|
if ty_is_scalar(ty1) && ty_is_scalar(ty2) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn variant_discriminants<'tcx>(
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> Vec<u128> {
|
) -> Vec<u128> {
|
||||||
match &layout.details.variants {
|
match &layout.variants {
|
||||||
Variants::Single { index } => vec![index.as_u32() as u128],
|
Variants::Single { index } => vec![index.as_u32() as u128],
|
||||||
Variants::Multiple { variants, .. } => variants
|
Variants::Multiple { variants, .. } => variants
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
|
|
|
@ -802,7 +802,7 @@ pub enum Variants {
|
||||||
discr: Scalar,
|
discr: Scalar,
|
||||||
discr_kind: DiscriminantKind,
|
discr_kind: DiscriminantKind,
|
||||||
discr_index: usize,
|
discr_index: usize,
|
||||||
variants: IndexVec<VariantIdx, LayoutDetails>,
|
variants: IndexVec<VariantIdx, Layout>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ impl Niche {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||||
pub struct LayoutDetails {
|
pub struct Layout {
|
||||||
/// Says where the fields are located within the layout.
|
/// Says where the fields are located within the layout.
|
||||||
/// Primitives and uninhabited enums appear as unions without fields.
|
/// Primitives and uninhabited enums appear as unions without fields.
|
||||||
pub fields: FieldPlacement,
|
pub fields: FieldPlacement,
|
||||||
|
@ -916,12 +916,12 @@ pub struct LayoutDetails {
|
||||||
pub size: Size,
|
pub size: Size,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutDetails {
|
impl Layout {
|
||||||
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
|
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
|
||||||
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar.clone());
|
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar.clone());
|
||||||
let size = scalar.value.size(cx);
|
let size = scalar.value.size(cx);
|
||||||
let align = scalar.value.align(cx);
|
let align = scalar.value.align(cx);
|
||||||
LayoutDetails {
|
Layout {
|
||||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||||
fields: FieldPlacement::Union(0),
|
fields: FieldPlacement::Union(0),
|
||||||
abi: Abi::Scalar(scalar),
|
abi: Abi::Scalar(scalar),
|
||||||
|
@ -932,23 +932,24 @@ impl LayoutDetails {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The details of the layout of a type, alongside the type itself.
|
/// The layout of a type, alongside the type itself.
|
||||||
/// Provides various type traversal APIs (e.g., recursing into fields).
|
/// Provides various type traversal APIs (e.g., recursing into fields).
|
||||||
///
|
///
|
||||||
/// Note that the details are NOT guaranteed to always be identical
|
/// Note that the layout is NOT guaranteed to always be identical
|
||||||
/// to those obtained from `layout_of(ty)`, as we need to produce
|
/// to that obtained from `layout_of(ty)`, as we need to produce
|
||||||
/// layouts for which Rust types do not exist, such as enum variants
|
/// layouts for which Rust types do not exist, such as enum variants
|
||||||
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
|
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
|
||||||
|
// FIXME: rename to TyAndLayout.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct TyLayout<'a, Ty> {
|
pub struct TyLayout<'a, Ty> {
|
||||||
pub ty: Ty,
|
pub ty: Ty,
|
||||||
pub details: &'a LayoutDetails,
|
pub layout: &'a Layout,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ty> Deref for TyLayout<'a, Ty> {
|
impl<'a, Ty> Deref for TyLayout<'a, Ty> {
|
||||||
type Target = &'a LayoutDetails;
|
type Target = &'a Layout;
|
||||||
fn deref(&self) -> &&'a LayoutDetails {
|
fn deref(&self) -> &&'a Layout {
|
||||||
&self.details
|
&self.layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1109,7 +1110,7 @@ impl<'a, Ty> TyLayout<'a, Ty> {
|
||||||
};
|
};
|
||||||
if !valid {
|
if !valid {
|
||||||
// This is definitely not okay.
|
// This is definitely not okay.
|
||||||
trace!("might_permit_raw_init({:?}, zero={}): not valid", self.details, zero);
|
trace!("might_permit_raw_init({:?}, zero={}): not valid", self.layout, zero);
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: DefId) {
|
||||||
let ty_b = field.ty(tcx, substs_b);
|
let ty_b = field.ty(tcx, substs_b);
|
||||||
|
|
||||||
if let Ok(layout) = tcx.layout_of(param_env.and(ty_a)) {
|
if let Ok(layout) = tcx.layout_of(param_env.and(ty_a)) {
|
||||||
if layout.is_zst() && layout.details.align.abi.bytes() == 1 {
|
if layout.is_zst() && layout.align.abi.bytes() == 1 {
|
||||||
// ignore ZST fields with alignment of 1 byte
|
// ignore ZST fields with alignment of 1 byte
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: layout debugging: LayoutDetails {
|
error: layout debugging: Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [
|
offsets: [
|
||||||
Size {
|
Size {
|
||||||
|
@ -20,7 +20,7 @@ error: layout debugging: LayoutDetails {
|
||||||
discr_kind: Tag,
|
discr_kind: Tag,
|
||||||
discr_index: 0,
|
discr_index: 0,
|
||||||
variants: [
|
variants: [
|
||||||
LayoutDetails {
|
Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [],
|
offsets: [],
|
||||||
memory_index: [],
|
memory_index: [],
|
||||||
|
@ -42,7 +42,7 @@ error: layout debugging: LayoutDetails {
|
||||||
raw: 4,
|
raw: 4,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
LayoutDetails {
|
Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [
|
offsets: [
|
||||||
Size {
|
Size {
|
||||||
|
@ -110,7 +110,7 @@ error: layout debugging: LayoutDetails {
|
||||||
LL | enum E { Foo, Bar(!, i32, i32) }
|
LL | enum E { Foo, Bar(!, i32, i32) }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: layout debugging: LayoutDetails {
|
error: layout debugging: Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [
|
offsets: [
|
||||||
Size {
|
Size {
|
||||||
|
@ -164,7 +164,7 @@ error: layout debugging: LayoutDetails {
|
||||||
LL | struct S { f1: i32, f2: (), f3: i32 }
|
LL | struct S { f1: i32, f2: (), f3: i32 }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: layout debugging: LayoutDetails {
|
error: layout debugging: Layout {
|
||||||
fields: Union(
|
fields: Union(
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
|
@ -190,7 +190,7 @@ error: layout debugging: LayoutDetails {
|
||||||
LL | union U { f1: (i32, i32), f3: i32 }
|
LL | union U { f1: (i32, i32), f3: i32 }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: layout debugging: LayoutDetails {
|
error: layout debugging: Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [
|
offsets: [
|
||||||
Size {
|
Size {
|
||||||
|
@ -212,7 +212,7 @@ error: layout debugging: LayoutDetails {
|
||||||
discr_kind: Tag,
|
discr_kind: Tag,
|
||||||
discr_index: 0,
|
discr_index: 0,
|
||||||
variants: [
|
variants: [
|
||||||
LayoutDetails {
|
Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [
|
offsets: [
|
||||||
Size {
|
Size {
|
||||||
|
@ -240,7 +240,7 @@ error: layout debugging: LayoutDetails {
|
||||||
raw: 8,
|
raw: 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
LayoutDetails {
|
Layout {
|
||||||
fields: Arbitrary {
|
fields: Arbitrary {
|
||||||
offsets: [
|
offsets: [
|
||||||
Size {
|
Size {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue