1
Fork 0

Remove BackendRepr::Uninhabited, replaced with an uninhabited: bool field in LayoutData.

Also update comments that refered to BackendRepr::Uninhabited.
This commit is contained in:
Zachary S 2025-01-25 20:15:24 -06:00
parent 28b83ee596
commit 7ba3d7b54e
26 changed files with 93 additions and 113 deletions

View file

@ -472,9 +472,7 @@ fn fn_abi_sanity_check<'tcx>(
// `layout.backend_repr` and ignore everything else. We should just reject
//`Aggregate` entirely here, but some targets need to be fixed first.
match arg.layout.backend_repr {
BackendRepr::Uninhabited
| BackendRepr::Scalar(_)
| BackendRepr::Vector { .. } => {}
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => {}
BackendRepr::ScalarPair(..) => {
panic!("`PassMode::Direct` used for ScalarPair type {}", arg.layout.ty)
}

View file

@ -348,19 +348,17 @@ fn layout_of_uncached<'tcx>(
.checked_mul(count, dl)
.ok_or_else(|| error(cx, LayoutError::SizeOverflow(ty)))?;
let abi = if count != 0 && ty.is_privately_uninhabited(tcx, cx.typing_env) {
BackendRepr::Uninhabited
} else {
BackendRepr::Memory { sized: true }
};
let abi = BackendRepr::Memory { sized: true };
let largest_niche = if count != 0 { element.largest_niche } else { None };
let uninhabited = if count != 0 { element.uninhabited } else { false };
tcx.mk_layout(LayoutData {
variants: Variants::Single { index: FIRST_VARIANT },
fields: FieldsShape::Array { stride: element.size, count },
backend_repr: abi,
largest_niche,
uninhabited,
align: element.align,
size,
max_repr_align: None,
@ -375,6 +373,7 @@ fn layout_of_uncached<'tcx>(
fields: FieldsShape::Array { stride: element.size, count: 0 },
backend_repr: BackendRepr::Memory { sized: false },
largest_niche: None,
uninhabited: false,
align: element.align,
size: Size::ZERO,
max_repr_align: None,
@ -390,6 +389,7 @@ fn layout_of_uncached<'tcx>(
fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 },
backend_repr: BackendRepr::Memory { sized: false },
largest_niche: None,
uninhabited: false,
align: dl.i8_align,
size: Size::ZERO,
max_repr_align: None,
@ -555,6 +555,7 @@ fn layout_of_uncached<'tcx>(
fields,
backend_repr: abi,
largest_niche: e_ly.largest_niche,
uninhabited: false,
size,
align,
max_repr_align: None,
@ -1014,13 +1015,8 @@ fn coroutine_layout<'tcx>(
size = size.align_to(align.abi);
let abi = if prefix.backend_repr.is_uninhabited()
|| variants.iter().all(|v| v.backend_repr.is_uninhabited())
{
BackendRepr::Uninhabited
} else {
BackendRepr::Memory { sized: true }
};
let uninhabited = prefix.uninhabited || variants.iter().all(|v| v.is_uninhabited());
let abi = BackendRepr::Memory { sized: true };
// this is similar to how ReprOptions populates its field_shuffle_seed
let def_hash = tcx.def_path_hash(def_id).0.to_smaller_hash();
@ -1041,6 +1037,7 @@ fn coroutine_layout<'tcx>(
// See <https://github.com/rust-lang/rust/issues/63818>, <https://github.com/rust-lang/miri/issues/3780>.
// FIXME: Remove when <https://github.com/rust-lang/rust/issues/125735> is implemented and aliased coroutine fields are wrapped in `UnsafePinned`.
largest_niche: None,
uninhabited,
size,
align,
max_repr_align: None,

View file

@ -10,7 +10,11 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
// Type-level uninhabitedness should always imply ABI uninhabitedness.
if layout.ty.is_privately_uninhabited(tcx, cx.typing_env) {
assert!(layout.is_uninhabited());
assert!(
layout.is_uninhabited(),
"{:?} is type-level uninhabited but not ABI-uninhabited?",
layout.ty
);
}
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
@ -71,7 +75,7 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
let Some((align, size)) = align.zip(size) else {
assert_matches!(
layout.layout.backend_repr(),
BackendRepr::Uninhabited | BackendRepr::Memory { .. },
BackendRepr::Memory { .. },
"ABI unexpectedly missing alignment and/or size in {layout:#?}"
);
return;
@ -235,7 +239,7 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
assert!(align >= element.align(cx).abi); // just sanity-checking `vector_align`.
// FIXME: Do some kind of check of the inner type, like for Scalar and ScalarPair.
}
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => {} // Nothing to check.
BackendRepr::Memory { .. } => {} // Nothing to check.
}
}
@ -291,8 +295,8 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
|| variant.is_uninhabited()
{
// These are never actually accessed anyway, so we can skip the coherence check
// for them. They also fail that check, since they have
// `Aggregate`/`Uninhabited` ABI even when the main type is
// for them. They also fail that check, since they may have
// a different ABI even when the main type is
// `Scalar`/`ScalarPair`. (Note that sometimes, variants with fields have size
// 0, and sometimes, variants without fields have non-0 size.)
continue;
@ -306,7 +310,6 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
(BackendRepr::ScalarPair(a1, b1), BackendRepr::ScalarPair(a2, b2)) => {
scalar_coherent(a1, a2) && scalar_coherent(b1, b2)
}
(BackendRepr::Uninhabited, _) => true,
(BackendRepr::Memory { .. }, _) => true,
_ => false,
};