@@ -714,7 +714,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
714714 } ,
715715 fields : FieldsShape :: Arbitrary {
716716 offsets : [ niche_offset] . into ( ) ,
717- memory_index : [ 0 ] . into ( ) ,
717+ inverse_memory_index : [ FieldIdx :: new ( 0 ) ] . into ( ) ,
718718 } ,
719719 backend_repr : abi,
720720 largest_niche,
@@ -1008,8 +1008,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10081008 let pair =
10091009 LayoutData :: < FieldIdx , VariantIdx > :: scalar_pair ( & self . cx , tag, prim_scalar) ;
10101010 let pair_offsets = match pair. fields {
1011- FieldsShape :: Arbitrary { ref offsets, ref memory_index } => {
1012- assert_eq ! ( memory_index . raw, [ 0 , 1 ] ) ;
1011+ FieldsShape :: Arbitrary { ref offsets, ref inverse_memory_index } => {
1012+ assert_eq ! ( inverse_memory_index . raw, [ FieldIdx :: new ( 0 ) , FieldIdx :: new ( 1 ) ] ) ;
10131013 offsets
10141014 }
10151015 _ => panic ! ( "encountered a non-arbitrary layout during enum layout" ) ,
@@ -1061,7 +1061,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10611061 } ,
10621062 fields : FieldsShape :: Arbitrary {
10631063 offsets : [ Size :: ZERO ] . into ( ) ,
1064- memory_index : [ 0 ] . into ( ) ,
1064+ inverse_memory_index : [ FieldIdx :: new ( 0 ) ] . into ( ) ,
10651065 } ,
10661066 largest_niche,
10671067 uninhabited,
@@ -1252,8 +1252,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
12521252 // That is, if field 5 has offset 0, the first element of inverse_memory_index is 5.
12531253 // We now write field offsets to the corresponding offset slot;
12541254 // field 5 with offset 0 puts 0 in offsets[5].
1255- // At the bottom of this function, we invert `inverse_memory_index` to
1256- // produce `memory_index` (see `invert_mapping`).
12571255 let mut unsized_field = None :: < & F > ;
12581256 let mut offsets = IndexVec :: from_elem ( Size :: ZERO , fields) ;
12591257 let mut offset = Size :: ZERO ;
@@ -1322,18 +1320,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13221320
13231321 debug ! ( "univariant min_size: {:?}" , offset) ;
13241322 let min_size = offset;
1325- // As stated above, inverse_memory_index holds field indices by increasing offset.
1326- // This makes it an already-sorted view of the offsets vec.
1327- // To invert it, consider:
1328- // If field 5 has offset 0, offsets[0] is 5, and memory_index[5] should be 0.
1329- // Field 5 would be the first element, so memory_index is i:
1330- // Note: if we didn't optimize, it's already right.
1331- let memory_index = if optimize_field_order {
1332- inverse_memory_index. invert_bijective_mapping ( )
1333- } else {
1334- debug_assert ! ( inverse_memory_index. iter( ) . copied( ) . eq( fields. indices( ) ) ) ;
1335- inverse_memory_index. into_iter ( ) . map ( |it| it. index ( ) as u32 ) . collect ( )
1336- } ;
13371323 let size = min_size. align_to ( align) ;
13381324 // FIXME(oli-obk): deduplicate and harden these checks
13391325 if size. bytes ( ) >= dl. obj_size_bound ( ) {
@@ -1389,8 +1375,14 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13891375 let pair =
13901376 LayoutData :: < FieldIdx , VariantIdx > :: scalar_pair ( & self . cx , a, b) ;
13911377 let pair_offsets = match pair. fields {
1392- FieldsShape :: Arbitrary { ref offsets, ref memory_index } => {
1393- assert_eq ! ( memory_index. raw, [ 0 , 1 ] ) ;
1378+ FieldsShape :: Arbitrary {
1379+ ref offsets,
1380+ ref inverse_memory_index,
1381+ } => {
1382+ assert_eq ! (
1383+ inverse_memory_index. raw,
1384+ [ FieldIdx :: new( 0 ) , FieldIdx :: new( 1 ) ]
1385+ ) ;
13941386 offsets
13951387 }
13961388 FieldsShape :: Primitive
@@ -1434,7 +1426,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
14341426
14351427 Ok ( LayoutData {
14361428 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1437- fields : FieldsShape :: Arbitrary { offsets, memory_index } ,
1429+ fields : FieldsShape :: Arbitrary { offsets, inverse_memory_index } ,
14381430 backend_repr : abi,
14391431 largest_niche,
14401432 uninhabited,
@@ -1530,7 +1522,10 @@ where
15301522
15311523 Ok ( LayoutData {
15321524 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1533- fields : FieldsShape :: Arbitrary { offsets : [ Size :: ZERO ] . into ( ) , memory_index : [ 0 ] . into ( ) } ,
1525+ fields : FieldsShape :: Arbitrary {
1526+ offsets : [ Size :: ZERO ] . into ( ) ,
1527+ inverse_memory_index : [ FieldIdx :: new ( 0 ) ] . into ( ) ,
1528+ } ,
15341529 backend_repr : repr,
15351530 largest_niche : elt. largest_niche ,
15361531 uninhabited : false ,
0 commit comments