@@ -594,23 +594,13 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
594
594
discr_range_of_repr : impl Fn ( i128 , i128 ) -> ( Integer , bool ) ,
595
595
discriminants : impl Iterator < Item = ( VariantIdx , i128 ) > ,
596
596
) -> 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
-
607
597
let dl = self . cx . data_layout ( ) ;
608
598
// bail if the enum has an incoherent repr that cannot be computed
609
599
if repr. packed ( ) {
610
600
return Err ( LayoutCalculatorError :: ReprConflict ) ;
611
601
}
612
602
613
- let calculate_niche_filling_layout = || -> Option < TmpLayout < FieldIdx , VariantIdx > > {
603
+ let calculate_niche_filling_layout = || -> Option < LayoutData < FieldIdx , VariantIdx > > {
614
604
if repr. inhibit_enum_layout_opt ( ) {
615
605
return None ;
616
606
}
@@ -746,7 +736,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
746
736
niche_start,
747
737
} ,
748
738
tag_field : FieldIdx :: new ( 0 ) ,
749
- variants : IndexVec :: new ( ) ,
739
+ variants : variant_layouts ,
750
740
} ,
751
741
fields : FieldsShape :: Arbitrary {
752
742
offsets : [ niche_offset] . into ( ) ,
@@ -762,7 +752,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
762
752
randomization_seed : combined_seed,
763
753
} ;
764
754
765
- Some ( TmpLayout { layout, variants : variant_layouts } )
755
+ Some ( layout)
766
756
} ;
767
757
768
758
let niche_filling_layout = calculate_niche_filling_layout ( ) ;
@@ -1093,7 +1083,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1093
1083
tag,
1094
1084
tag_encoding : TagEncoding :: Direct ,
1095
1085
tag_field : FieldIdx :: new ( 0 ) ,
1096
- variants : IndexVec :: new ( ) ,
1086
+ variants : layout_variants ,
1097
1087
} ,
1098
1088
fields : FieldsShape :: Arbitrary {
1099
1089
offsets : [ Size :: ZERO ] . into ( ) ,
@@ -1109,18 +1099,16 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1109
1099
randomization_seed : combined_seed,
1110
1100
} ;
1111
1101
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) {
1115
1103
( tl, Some ( nl) ) => {
1116
1104
// Pick the smaller layout; otherwise,
1117
1105
// pick the layout with the larger niche; otherwise,
1118
1106
// pick tagged as it has simpler codegen.
1119
1107
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) )
1122
1110
} ;
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) ) ) {
1124
1112
( Greater , _) => nl,
1125
1113
( Equal , Less ) => nl,
1126
1114
_ => tl,
@@ -1129,16 +1117,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1129
1117
( tl, None ) => tl,
1130
1118
} ;
1131
1119
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)
1142
1121
}
1143
1122
1144
1123
fn univariant_biased <
0 commit comments