[experiment] ty/layout: compute both niche-filling and tagged layouts for enums.
This commit is contained in:
parent
c2dbebd3d4
commit
b0a7fbd91f
1 changed files with 8 additions and 4 deletions
|
@ -876,6 +876,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
.iter_enumerated()
|
||||
.all(|(i, v)| v.discr == ty::VariantDiscr::Relative(i.as_u32()));
|
||||
|
||||
let mut niche_filling_layout = None;
|
||||
|
||||
// Niche-filling enum optimization.
|
||||
if !def.repr.inhibit_enum_layout_opt() && no_explicit_discriminants {
|
||||
let mut dataful_variant = None;
|
||||
|
@ -972,7 +974,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
let largest_niche =
|
||||
Niche::from_scalar(dl, offset, niche_scalar.clone());
|
||||
|
||||
return Ok(tcx.intern_layout(Layout {
|
||||
niche_filling_layout = Some(Layout {
|
||||
variants: Variants::Multiple {
|
||||
tag: niche_scalar,
|
||||
tag_encoding: TagEncoding::Niche {
|
||||
|
@ -991,7 +993,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
largest_niche,
|
||||
size,
|
||||
align,
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1214,7 +1216,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
|
||||
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone());
|
||||
|
||||
tcx.intern_layout(Layout {
|
||||
let tagged_layout = Layout {
|
||||
variants: Variants::Multiple {
|
||||
tag,
|
||||
tag_encoding: TagEncoding::Direct,
|
||||
|
@ -1229,7 +1231,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||
abi,
|
||||
align,
|
||||
size,
|
||||
})
|
||||
};
|
||||
|
||||
tcx.intern_layout(niche_filling_layout.unwrap_or(tagged_layout))
|
||||
}
|
||||
|
||||
// Types with no meaningful known layout.
|
||||
|
|
Loading…
Add table
Reference in a new issue