Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13c200a

Browse files
committedApr 11, 2020
[experiment] ty/layout: compute both niche-filling and tagged layouts for enums.
1 parent 94d3463 commit 13c200a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎src/librustc_middle/ty/layout.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
871871
.iter_enumerated()
872872
.all(|(i, v)| v.discr == ty::VariantDiscr::Relative(i.as_u32()));
873873

874+
let mut niche_filling_layout = None;
875+
874876
// Niche-filling enum optimization.
875877
if !def.repr.inhibit_enum_layout_opt() && no_explicit_discriminants {
876878
let mut dataful_variant = None;
@@ -967,7 +969,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
967969
let largest_niche =
968970
Niche::from_scalar(dl, offset, niche_scalar.clone());
969971

970-
return Ok(tcx.intern_layout(Layout {
972+
niche_filling_layout = Some(Layout {
971973
variants: Variants::Multiple {
972974
discr: niche_scalar,
973975
discr_kind: DiscriminantKind::Niche {
@@ -986,7 +988,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
986988
largest_niche,
987989
size,
988990
align,
989-
}));
991+
});
990992
}
991993
}
992994
}
@@ -1209,7 +1211,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12091211

12101212
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone());
12111213

1212-
tcx.intern_layout(Layout {
1214+
let tagged_layout = Layout {
12131215
variants: Variants::Multiple {
12141216
discr: tag,
12151217
discr_kind: DiscriminantKind::Tag,
@@ -1224,7 +1226,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12241226
abi,
12251227
align,
12261228
size,
1227-
})
1229+
};
1230+
1231+
tcx.intern_layout(niche_filling_layout.unwrap_or(tagged_layout))
12281232
}
12291233

12301234
// Types with no meaningful known layout.

0 commit comments

Comments
 (0)
Please sign in to comment.