[experiment] ty/layout: compute both niche-filling and tagged layouts for enums.

This commit is contained in:
Eduard-Mihai Burtescu 2020-04-12 00:39:43 +03:00 committed by Erik Desjardins
parent c2dbebd3d4
commit b0a7fbd91f

View file

@ -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.