@@ -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+ in_memory_order : [ 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 in_memory_order } => {
1012+ assert_eq ! ( in_memory_order . 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+ in_memory_order : [ FieldIdx :: new ( 0 ) ] . into ( ) ,
10651065 } ,
10661066 largest_niche,
10671067 uninhabited,
@@ -1110,10 +1110,10 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
11101110 let pack = repr. pack ;
11111111 let mut align = if pack. is_some ( ) { dl. i8_align } else { dl. aggregate_align } ;
11121112 let mut max_repr_align = repr. align ;
1113- let mut inverse_memory_index : IndexVec < u32 , FieldIdx > = fields. indices ( ) . collect ( ) ;
1113+ let mut in_memory_order : IndexVec < u32 , FieldIdx > = fields. indices ( ) . collect ( ) ;
11141114 let optimize_field_order = !repr. inhibit_struct_field_reordering ( ) ;
11151115 let end = if let StructKind :: MaybeUnsized = kind { fields. len ( ) - 1 } else { fields. len ( ) } ;
1116- let optimizing = & mut inverse_memory_index . raw [ ..end] ;
1116+ let optimizing = & mut in_memory_order . raw [ ..end] ;
11171117 let fields_excluding_tail = & fields. raw [ ..end] ;
11181118 // unsizable tail fields are excluded so that we use the same seed for the sized and unsized layouts.
11191119 let field_seed = fields_excluding_tail
@@ -1248,12 +1248,10 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
12481248 // regardless of the status of `-Z randomize-layout`
12491249 }
12501250 }
1251- // inverse_memory_index holds field indices by increasing memory offset.
1252- // That is, if field 5 has offset 0, the first element of inverse_memory_index is 5.
1251+ // in_memory_order holds field indices by increasing memory offset.
1252+ // That is, if field 5 has offset 0, the first element of in_memory_order 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 ;
@@ -1265,7 +1263,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
12651263 align = align. max ( prefix_align) ;
12661264 offset = prefix_size. align_to ( prefix_align) ;
12671265 }
1268- for & i in & inverse_memory_index {
1266+ for & i in & in_memory_order {
12691267 let field = & fields[ i] ;
12701268 if let Some ( unsized_field) = unsized_field {
12711269 return Err ( LayoutCalculatorError :: UnexpectedUnsized ( * unsized_field) ) ;
@@ -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,11 @@ 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 { ref offsets, ref in_memory_order } => {
1379+ assert_eq ! (
1380+ in_memory_order. raw,
1381+ [ FieldIdx :: new( 0 ) , FieldIdx :: new( 1 ) ]
1382+ ) ;
13941383 offsets
13951384 }
13961385 FieldsShape :: Primitive
@@ -1434,7 +1423,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
14341423
14351424 Ok ( LayoutData {
14361425 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1437- fields : FieldsShape :: Arbitrary { offsets, memory_index } ,
1426+ fields : FieldsShape :: Arbitrary { offsets, in_memory_order } ,
14381427 backend_repr : abi,
14391428 largest_niche,
14401429 uninhabited,
@@ -1530,7 +1519,10 @@ where
15301519
15311520 Ok ( LayoutData {
15321521 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1533- fields : FieldsShape :: Arbitrary { offsets : [ Size :: ZERO ] . into ( ) , memory_index : [ 0 ] . into ( ) } ,
1522+ fields : FieldsShape :: Arbitrary {
1523+ offsets : [ Size :: ZERO ] . into ( ) ,
1524+ in_memory_order : [ FieldIdx :: new ( 0 ) ] . into ( ) ,
1525+ } ,
15341526 backend_repr : repr,
15351527 largest_niche : elt. largest_niche ,
15361528 uninhabited : false ,
0 commit comments