@@ -594,23 +594,13 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
594594 discr_range_of_repr : impl Fn ( i128 , i128 ) -> ( Integer , bool ) ,
595595 discriminants : impl Iterator < Item = ( VariantIdx , i128 ) > ,
596596 ) -> LayoutCalculatorResult < FieldIdx , VariantIdx , F > {
597- // Until we've decided whether to use the tagged or
598- // niche filling LayoutData, we don't want to intern the
599- // variant layouts, so we can't store them in the
600- // overall LayoutData. Store the overall LayoutData
601- // and the variant LayoutDatas here until then.
602- struct TmpLayout < FieldIdx : Idx , VariantIdx : Idx > {
603- layout : LayoutData < FieldIdx , VariantIdx > ,
604- variants : IndexVec < VariantIdx , LayoutData < FieldIdx , VariantIdx > > ,
605- }
606-
607597 let dl = self . cx . data_layout ( ) ;
608598 // bail if the enum has an incoherent repr that cannot be computed
609599 if repr. packed ( ) {
610600 return Err ( LayoutCalculatorError :: ReprConflict ) ;
611601 }
612602
613- let calculate_niche_filling_layout = || -> Option < TmpLayout < FieldIdx , VariantIdx > > {
603+ let calculate_niche_filling_layout = || -> Option < LayoutData < FieldIdx , VariantIdx > > {
614604 if repr. inhibit_enum_layout_opt ( ) {
615605 return None ;
616606 }
@@ -746,7 +736,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
746736 niche_start,
747737 } ,
748738 tag_field : FieldIdx :: new ( 0 ) ,
749- variants : IndexVec :: new ( ) ,
739+ variants : variant_layouts ,
750740 } ,
751741 fields : FieldsShape :: Arbitrary {
752742 offsets : [ niche_offset] . into ( ) ,
@@ -762,7 +752,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
762752 randomization_seed : combined_seed,
763753 } ;
764754
765- Some ( TmpLayout { layout, variants : variant_layouts } )
755+ Some ( layout)
766756 } ;
767757
768758 let niche_filling_layout = calculate_niche_filling_layout ( ) ;
@@ -1093,7 +1083,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10931083 tag,
10941084 tag_encoding : TagEncoding :: Direct ,
10951085 tag_field : FieldIdx :: new ( 0 ) ,
1096- variants : IndexVec :: new ( ) ,
1086+ variants : layout_variants ,
10971087 } ,
10981088 fields : FieldsShape :: Arbitrary {
10991089 offsets : [ Size :: ZERO ] . into ( ) ,
@@ -1109,18 +1099,16 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
11091099 randomization_seed : combined_seed,
11101100 } ;
11111101
1112- let tagged_layout = TmpLayout { layout : tagged_layout, variants : layout_variants } ;
1113-
1114- let mut best_layout = match ( tagged_layout, niche_filling_layout) {
1102+ let best_layout = match ( tagged_layout, niche_filling_layout) {
11151103 ( tl, Some ( nl) ) => {
11161104 // Pick the smaller layout; otherwise,
11171105 // pick the layout with the larger niche; otherwise,
11181106 // pick tagged as it has simpler codegen.
11191107 use cmp:: Ordering :: * ;
1120- let niche_size = |tmp_l : & TmpLayout < FieldIdx , VariantIdx > | {
1121- tmp_l . layout . largest_niche . map_or ( 0 , |n| n. available ( dl) )
1108+ let niche_size = |l : & LayoutData < FieldIdx , VariantIdx > | {
1109+ l . largest_niche . map_or ( 0 , |n| n. available ( dl) )
11221110 } ;
1123- match ( tl. layout . size . cmp ( & nl. layout . size ) , niche_size ( & tl) . cmp ( & niche_size ( & nl) ) ) {
1111+ match ( tl. size . cmp ( & nl. size ) , niche_size ( & tl) . cmp ( & niche_size ( & nl) ) ) {
11241112 ( Greater , _) => nl,
11251113 ( Equal , Less ) => nl,
11261114 _ => tl,
@@ -1129,16 +1117,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
11291117 ( tl, None ) => tl,
11301118 } ;
11311119
1132- // Now we can intern the variant layouts and store them in the enum layout.
1133- best_layout. layout . variants = match best_layout. layout . variants {
1134- Variants :: Multiple { tag, tag_encoding, tag_field, .. } => {
1135- Variants :: Multiple { tag, tag_encoding, tag_field, variants : best_layout. variants }
1136- }
1137- Variants :: Single { .. } | Variants :: Empty => {
1138- panic ! ( "encountered a single-variant or empty enum during multi-variant layout" )
1139- }
1140- } ;
1141- Ok ( best_layout. layout )
1120+ Ok ( best_layout)
11421121 }
11431122
11441123 fn univariant_biased <
0 commit comments