@@ -6,7 +6,7 @@ use rustc_index::Idx;
6
6
use tracing:: debug;
7
7
8
8
use crate :: {
9
- Abi , AbiAndPrefAlign , Align , FieldsShape , HasDataLayout , IndexSlice , IndexVec , Integer ,
9
+ AbiAndPrefAlign , Align , BackendRepr , FieldsShape , HasDataLayout , IndexSlice , IndexVec , Integer ,
10
10
LayoutData , Niche , NonZeroUsize , Primitive , ReprOptions , Scalar , Size , StructKind , TagEncoding ,
11
11
Variants , WrappingRange ,
12
12
} ;
@@ -125,7 +125,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
125
125
offsets : [ Size :: ZERO , b_offset] . into ( ) ,
126
126
memory_index : [ 0 , 1 ] . into ( ) ,
127
127
} ,
128
- abi : Abi :: ScalarPair ( a, b) ,
128
+ backend_repr : BackendRepr :: ScalarPair ( a, b) ,
129
129
largest_niche,
130
130
align,
131
131
size,
@@ -216,7 +216,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
216
216
LayoutData {
217
217
variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
218
218
fields : FieldsShape :: Primitive ,
219
- abi : Abi :: Uninhabited ,
219
+ backend_repr : BackendRepr :: Uninhabited ,
220
220
largest_niche : None ,
221
221
align : dl. i8_align ,
222
222
size : Size :: ZERO ,
@@ -331,7 +331,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
331
331
332
332
if let Ok ( common) = common_non_zst_abi_and_align {
333
333
// Discard valid range information and allow undef
334
- let field_abi = field. abi . to_union ( ) ;
334
+ let field_abi = field. backend_repr . to_union ( ) ;
335
335
336
336
if let Some ( ( common_abi, common_align) ) = common {
337
337
if common_abi != field_abi {
@@ -340,7 +340,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
340
340
} else {
341
341
// Fields with the same non-Aggregate ABI should also
342
342
// have the same alignment
343
- if !matches ! ( common_abi, Abi :: Aggregate { .. } ) {
343
+ if !matches ! ( common_abi, BackendRepr :: Memory { .. } ) {
344
344
assert_eq ! (
345
345
common_align, field. align. abi,
346
346
"non-Aggregate field with matching ABI but differing alignment"
@@ -369,11 +369,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
369
369
// If all non-ZST fields have the same ABI, we may forward that ABI
370
370
// for the union as a whole, unless otherwise inhibited.
371
371
let abi = match common_non_zst_abi_and_align {
372
- Err ( AbiMismatch ) | Ok ( None ) => Abi :: Aggregate { sized : true } ,
372
+ Err ( AbiMismatch ) | Ok ( None ) => BackendRepr :: Memory { sized : true } ,
373
373
Ok ( Some ( ( abi, _) ) ) => {
374
374
if abi. inherent_align ( dl) . map ( |a| a. abi ) != Some ( align. abi ) {
375
375
// Mismatched alignment (e.g. union is #[repr(packed)]): disable opt
376
- Abi :: Aggregate { sized : true }
376
+ BackendRepr :: Memory { sized : true }
377
377
} else {
378
378
abi
379
379
}
@@ -387,7 +387,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
387
387
Ok ( LayoutData {
388
388
variants : Variants :: Single { index : only_variant_idx } ,
389
389
fields : FieldsShape :: Union ( union_field_count) ,
390
- abi,
390
+ backend_repr : abi,
391
391
largest_niche : None ,
392
392
align,
393
393
size : size. align_to ( align. abi ) ,
@@ -434,23 +434,23 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
434
434
// Already doesn't have any niches
435
435
Scalar :: Union { .. } => { }
436
436
} ;
437
- match & mut st. abi {
438
- Abi :: Uninhabited => { }
439
- Abi :: Scalar ( scalar) => hide_niches ( scalar) ,
440
- Abi :: ScalarPair ( a, b) => {
437
+ match & mut st. backend_repr {
438
+ BackendRepr :: Uninhabited => { }
439
+ BackendRepr :: Scalar ( scalar) => hide_niches ( scalar) ,
440
+ BackendRepr :: ScalarPair ( a, b) => {
441
441
hide_niches ( a) ;
442
442
hide_niches ( b) ;
443
443
}
444
- Abi :: Vector { element, count : _ } => hide_niches ( element) ,
445
- Abi :: Aggregate { sized : _ } => { }
444
+ BackendRepr :: Vector { element, count : _ } => hide_niches ( element) ,
445
+ BackendRepr :: Memory { sized : _ } => { }
446
446
}
447
447
st. largest_niche = None ;
448
448
return Ok ( st) ;
449
449
}
450
450
451
451
let ( start, end) = scalar_valid_range;
452
- match st. abi {
453
- Abi :: Scalar ( ref mut scalar) | Abi :: ScalarPair ( ref mut scalar, _) => {
452
+ match st. backend_repr {
453
+ BackendRepr :: Scalar ( ref mut scalar) | BackendRepr :: ScalarPair ( ref mut scalar, _) => {
454
454
// Enlarging validity ranges would result in missed
455
455
// optimizations, *not* wrongly assuming the inner
456
456
// value is valid. e.g. unions already enlarge validity ranges,
@@ -607,8 +607,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
607
607
}
608
608
609
609
// It can't be a Scalar or ScalarPair because the offset isn't 0.
610
- if !layout. abi . is_uninhabited ( ) {
611
- layout. abi = Abi :: Aggregate { sized : true } ;
610
+ if !layout. is_uninhabited ( ) {
611
+ layout. backend_repr = BackendRepr :: Memory { sized : true } ;
612
612
}
613
613
layout. size += this_offset;
614
614
@@ -627,26 +627,26 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
627
627
let same_size = size == variant_layouts[ largest_variant_index] . size ;
628
628
let same_align = align == variant_layouts[ largest_variant_index] . align ;
629
629
630
- let abi = if variant_layouts. iter ( ) . all ( |v| v. abi . is_uninhabited ( ) ) {
631
- Abi :: Uninhabited
630
+ let abi = if variant_layouts. iter ( ) . all ( |v| v. is_uninhabited ( ) ) {
631
+ BackendRepr :: Uninhabited
632
632
} else if same_size && same_align && others_zst {
633
- match variant_layouts[ largest_variant_index] . abi {
633
+ match variant_layouts[ largest_variant_index] . backend_repr {
634
634
// When the total alignment and size match, we can use the
635
635
// same ABI as the scalar variant with the reserved niche.
636
- Abi :: Scalar ( _) => Abi :: Scalar ( niche_scalar) ,
637
- Abi :: ScalarPair ( first, second) => {
636
+ BackendRepr :: Scalar ( _) => BackendRepr :: Scalar ( niche_scalar) ,
637
+ BackendRepr :: ScalarPair ( first, second) => {
638
638
// Only the niche is guaranteed to be initialised,
639
639
// so use union layouts for the other primitive.
640
640
if niche_offset == Size :: ZERO {
641
- Abi :: ScalarPair ( niche_scalar, second. to_union ( ) )
641
+ BackendRepr :: ScalarPair ( niche_scalar, second. to_union ( ) )
642
642
} else {
643
- Abi :: ScalarPair ( first. to_union ( ) , niche_scalar)
643
+ BackendRepr :: ScalarPair ( first. to_union ( ) , niche_scalar)
644
644
}
645
645
}
646
- _ => Abi :: Aggregate { sized : true } ,
646
+ _ => BackendRepr :: Memory { sized : true } ,
647
647
}
648
648
} else {
649
- Abi :: Aggregate { sized : true }
649
+ BackendRepr :: Memory { sized : true }
650
650
} ;
651
651
652
652
let layout = LayoutData {
@@ -664,7 +664,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
664
664
offsets : [ niche_offset] . into ( ) ,
665
665
memory_index : [ 0 ] . into ( ) ,
666
666
} ,
667
- abi,
667
+ backend_repr : abi,
668
668
largest_niche,
669
669
size,
670
670
align,
@@ -833,14 +833,14 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
833
833
end : ( max as u128 & tag_mask) ,
834
834
} ,
835
835
} ;
836
- let mut abi = Abi :: Aggregate { sized : true } ;
836
+ let mut abi = BackendRepr :: Memory { sized : true } ;
837
837
838
- if layout_variants. iter ( ) . all ( |v| v. abi . is_uninhabited ( ) ) {
839
- abi = Abi :: Uninhabited ;
838
+ if layout_variants. iter ( ) . all ( |v| v. is_uninhabited ( ) ) {
839
+ abi = BackendRepr :: Uninhabited ;
840
840
} else if tag. size ( dl) == size {
841
841
// Make sure we only use scalar layout when the enum is entirely its
842
842
// own tag (i.e. it has no padding nor any non-ZST variant fields).
843
- abi = Abi :: Scalar ( tag) ;
843
+ abi = BackendRepr :: Scalar ( tag) ;
844
844
} else {
845
845
// Try to use a ScalarPair for all tagged enums.
846
846
// That's possible only if we can find a common primitive type for all variants.
@@ -864,8 +864,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
864
864
break ;
865
865
}
866
866
} ;
867
- let prim = match field. abi {
868
- Abi :: Scalar ( scalar) => {
867
+ let prim = match field. backend_repr {
868
+ BackendRepr :: Scalar ( scalar) => {
869
869
common_prim_initialized_in_all_variants &=
870
870
matches ! ( scalar, Scalar :: Initialized { .. } ) ;
871
871
scalar. primitive ( )
@@ -934,20 +934,22 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
934
934
{
935
935
// We can use `ScalarPair` only when it matches our
936
936
// already computed layout (including `#[repr(C)]`).
937
- abi = pair. abi ;
937
+ abi = pair. backend_repr ;
938
938
}
939
939
}
940
940
}
941
941
942
942
// If we pick a "clever" (by-value) ABI, we might have to adjust the ABI of the
943
943
// variants to ensure they are consistent. This is because a downcast is
944
944
// semantically a NOP, and thus should not affect layout.
945
- if matches ! ( abi, Abi :: Scalar ( ..) | Abi :: ScalarPair ( ..) ) {
945
+ if matches ! ( abi, BackendRepr :: Scalar ( ..) | BackendRepr :: ScalarPair ( ..) ) {
946
946
for variant in & mut layout_variants {
947
947
// We only do this for variants with fields; the others are not accessed anyway.
948
948
// Also do not overwrite any already existing "clever" ABIs.
949
- if variant. fields . count ( ) > 0 && matches ! ( variant. abi, Abi :: Aggregate { .. } ) {
950
- variant. abi = abi;
949
+ if variant. fields . count ( ) > 0
950
+ && matches ! ( variant. backend_repr, BackendRepr :: Memory { .. } )
951
+ {
952
+ variant. backend_repr = abi;
951
953
// Also need to bump up the size and alignment, so that the entire value fits
952
954
// in here.
953
955
variant. size = cmp:: max ( variant. size , size) ;
@@ -970,7 +972,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
970
972
memory_index : [ 0 ] . into ( ) ,
971
973
} ,
972
974
largest_niche,
973
- abi,
975
+ backend_repr : abi,
974
976
align,
975
977
size,
976
978
max_repr_align,
@@ -1252,7 +1254,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1252
1254
}
1253
1255
let mut layout_of_single_non_zst_field = None ;
1254
1256
let sized = unsized_field. is_none ( ) ;
1255
- let mut abi = Abi :: Aggregate { sized } ;
1257
+ let mut abi = BackendRepr :: Memory { sized } ;
1256
1258
1257
1259
let optimize_abi = !repr. inhibit_newtype_abi_optimization ( ) ;
1258
1260
@@ -1270,16 +1272,16 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1270
1272
// Field fills the struct and it has a scalar or scalar pair ABI.
1271
1273
if offsets[ i] . bytes ( ) == 0 && align. abi == field. align . abi && size == field. size
1272
1274
{
1273
- match field. abi {
1275
+ match field. backend_repr {
1274
1276
// For plain scalars, or vectors of them, we can't unpack
1275
1277
// newtypes for `#[repr(C)]`, as that affects C ABIs.
1276
- Abi :: Scalar ( _) | Abi :: Vector { .. } if optimize_abi => {
1277
- abi = field. abi ;
1278
+ BackendRepr :: Scalar ( _) | BackendRepr :: Vector { .. } if optimize_abi => {
1279
+ abi = field. backend_repr ;
1278
1280
}
1279
1281
// But scalar pairs are Rust-specific and get
1280
1282
// treated as aggregates by C ABIs anyway.
1281
- Abi :: ScalarPair ( ..) => {
1282
- abi = field. abi ;
1283
+ BackendRepr :: ScalarPair ( ..) => {
1284
+ abi = field. backend_repr ;
1283
1285
}
1284
1286
_ => { }
1285
1287
}
@@ -1288,8 +1290,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1288
1290
1289
1291
// Two non-ZST fields, and they're both scalars.
1290
1292
( Some ( ( i, a) ) , Some ( ( j, b) ) , None ) => {
1291
- match ( a. abi , b. abi ) {
1292
- ( Abi :: Scalar ( a) , Abi :: Scalar ( b) ) => {
1293
+ match ( a. backend_repr , b. backend_repr ) {
1294
+ ( BackendRepr :: Scalar ( a) , BackendRepr :: Scalar ( b) ) => {
1293
1295
// Order by the memory placement, not source order.
1294
1296
let ( ( i, a) , ( j, b) ) = if offsets[ i] < offsets[ j] {
1295
1297
( ( i, a) , ( j, b) )
@@ -1315,7 +1317,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1315
1317
{
1316
1318
// We can use `ScalarPair` only when it matches our
1317
1319
// already computed layout (including `#[repr(C)]`).
1318
- abi = pair. abi ;
1320
+ abi = pair. backend_repr ;
1319
1321
}
1320
1322
}
1321
1323
_ => { }
@@ -1325,8 +1327,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1325
1327
_ => { }
1326
1328
}
1327
1329
}
1328
- if fields. iter ( ) . any ( |f| f. abi . is_uninhabited ( ) ) {
1329
- abi = Abi :: Uninhabited ;
1330
+ if fields. iter ( ) . any ( |f| f. is_uninhabited ( ) ) {
1331
+ abi = BackendRepr :: Uninhabited ;
1330
1332
}
1331
1333
1332
1334
let unadjusted_abi_align = if repr. transparent ( ) {
@@ -1344,7 +1346,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
1344
1346
Ok ( LayoutData {
1345
1347
variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
1346
1348
fields : FieldsShape :: Arbitrary { offsets, memory_index } ,
1347
- abi,
1349
+ backend_repr : abi,
1348
1350
largest_niche,
1349
1351
align,
1350
1352
size,
0 commit comments