diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2020-04-12 00:39:43 +0300 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2020-07-26 21:36:04 -0400 |
| commit | 8dc9d4d567dae3481a47ad677e263cb3bd57cdf5 (patch) | |
| tree | 6467a3c2e4a47ff547616b4d676daae5111730e1 | |
| parent | 62392966a3937362146d7228444c8d843d972857 (diff) | |
| download | rust-8dc9d4d567dae3481a47ad677e263cb3bd57cdf5.tar.gz rust-8dc9d4d567dae3481a47ad677e263cb3bd57cdf5.zip | |
[experiment] ty/layout: compute both niche-filling and tagged layouts for enums.
| -rw-r--r-- | src/librustc_middle/ty/layout.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 215f44819b5..010b29a060b 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -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. |
