@@ -226,9 +226,10 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
226
226
tcx. intern_layout ( LayoutDetails :: scalar ( self , scalar_unit ( value) ) )
227
227
} ;
228
228
let scalar_pair = |a : Scalar , b : Scalar | {
229
- let align = a. value . align ( dl) . max ( b. value . align ( dl) ) . max ( dl. aggregate_align ) ;
230
- let b_offset = a. value . size ( dl) . abi_align ( b. value . align ( dl) ) ;
231
- let size = ( b_offset + b. value . size ( dl) ) . abi_align ( align) ;
229
+ let b_align = b. value . align ( dl) ;
230
+ let align = a. value . align ( dl) . max ( b_align) . max ( dl. aggregate_align ) ;
231
+ let b_offset = a. value . size ( dl) . align_to ( b_align. abi ) ;
232
+ let size = ( b_offset + b. value . size ( dl) ) . align_to ( align. abi ) ;
232
233
LayoutDetails {
233
234
variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
234
235
fields : FieldPlacement :: Arbitrary {
@@ -257,10 +258,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
257
258
bug ! ( "struct cannot be packed and aligned" ) ;
258
259
}
259
260
260
- let pack = {
261
- let pack = repr. pack as u64 ;
262
- Align :: from_bytes ( pack, pack) . unwrap ( )
263
- } ;
261
+ let pack = Align :: from_bytes ( repr. pack as u64 ) . unwrap ( ) ;
264
262
265
263
let mut align = if packed {
266
264
dl. i8_align
@@ -274,7 +272,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
274
272
275
273
let mut optimize = !repr. inhibit_struct_field_reordering_opt ( ) ;
276
274
if let StructKind :: Prefixed ( _, align) = kind {
277
- optimize &= align. abi ( ) == 1 ;
275
+ optimize &= align. bytes ( ) == 1 ;
278
276
}
279
277
280
278
if optimize {
@@ -285,7 +283,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
285
283
} ;
286
284
let optimizing = & mut inverse_memory_index[ ..end] ;
287
285
let field_align = |f : & TyLayout < ' _ > | {
288
- if packed { f. align . min ( pack) . abi ( ) } else { f. align . abi ( ) }
286
+ if packed { f. align . abi . min ( pack) } else { f. align . abi }
289
287
} ;
290
288
match kind {
291
289
StructKind :: AlwaysSized |
@@ -312,13 +310,13 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
312
310
let mut offset = Size :: ZERO ;
313
311
314
312
if let StructKind :: Prefixed ( prefix_size, prefix_align) = kind {
315
- if packed {
316
- let prefix_align = prefix_align. min ( pack) ;
317
- align = align. max ( prefix_align) ;
313
+ let prefix_align = if packed {
314
+ prefix_align. min ( pack)
318
315
} else {
319
- align = align. max ( prefix_align) ;
320
- }
321
- offset = prefix_size. abi_align ( prefix_align) ;
316
+ prefix_align
317
+ } ;
318
+ align = align. max ( AbiAndPrefAlign :: new ( prefix_align) ) ;
319
+ offset = prefix_size. align_to ( prefix_align) ;
322
320
}
323
321
324
322
for & i in & inverse_memory_index {
@@ -333,15 +331,13 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
333
331
}
334
332
335
333
// Invariant: offset < dl.obj_size_bound() <= 1<<61
336
- if packed {
337
- let field_pack = field. align . min ( pack) ;
338
- offset = offset. abi_align ( field_pack) ;
339
- align = align. max ( field_pack) ;
340
- }
341
- else {
342
- offset = offset. abi_align ( field. align ) ;
343
- align = align. max ( field. align ) ;
344
- }
334
+ let field_align = if packed {
335
+ field. align . min ( AbiAndPrefAlign :: new ( pack) )
336
+ } else {
337
+ field. align
338
+ } ;
339
+ offset = offset. align_to ( field_align. abi ) ;
340
+ align = align. max ( field_align) ;
345
341
346
342
debug ! ( "univariant offset: {:?} field: {:#?}" , offset, field) ;
347
343
offsets[ i as usize ] = offset;
@@ -352,7 +348,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
352
348
353
349
if repr. align > 0 {
354
350
let repr_align = repr. align as u64 ;
355
- align = align. max ( Align :: from_bytes ( repr_align, repr_align ) . unwrap ( ) ) ;
351
+ align = align. max ( AbiAndPrefAlign :: new ( Align :: from_bytes ( repr_align) . unwrap ( ) ) ) ;
356
352
debug ! ( "univariant repr_align: {:?}" , repr_align) ;
357
353
}
358
354
@@ -377,7 +373,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
377
373
memory_index = inverse_memory_index;
378
374
}
379
375
380
- let size = min_size. abi_align ( align) ;
376
+ let size = min_size. align_to ( align. abi ) ;
381
377
let mut abi = Abi :: Aggregate { sized } ;
382
378
383
379
// Unpack newtype ABIs and find scalar pairs.
@@ -394,7 +390,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
394
390
( Some ( ( i, field) ) , None , None ) => {
395
391
// Field fills the struct and it has a scalar or scalar pair ABI.
396
392
if offsets[ i] . bytes ( ) == 0 &&
397
- align. abi ( ) == field. align . abi ( ) &&
393
+ align. abi == field. align . abi &&
398
394
size == field. size {
399
395
match field. abi {
400
396
// For plain scalars, or vectors of them, we can't unpack
@@ -648,7 +644,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
648
644
let size = element. size . checked_mul ( count, dl)
649
645
. ok_or ( LayoutError :: SizeOverflow ( ty) ) ?;
650
646
let align = dl. vector_align ( size) ;
651
- let size = size. abi_align ( align) ;
647
+ let size = size. align_to ( align. abi ) ;
652
648
653
649
tcx. intern_layout ( LayoutDetails {
654
650
variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
@@ -680,10 +676,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
680
676
bug ! ( "Union cannot be packed and aligned" ) ;
681
677
}
682
678
683
- let pack = {
684
- let pack = def. repr . pack as u64 ;
685
- Align :: from_bytes ( pack, pack) . unwrap ( )
686
- } ;
679
+ let pack = Align :: from_bytes ( def. repr . pack as u64 ) . unwrap ( ) ;
687
680
688
681
let mut align = if packed {
689
682
dl. i8_align
@@ -694,7 +687,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
694
687
if def. repr . align > 0 {
695
688
let repr_align = def. repr . align as u64 ;
696
689
align = align. max (
697
- Align :: from_bytes ( repr_align, repr_align ) . unwrap ( ) ) ;
690
+ AbiAndPrefAlign :: new ( Align :: from_bytes ( repr_align) . unwrap ( ) ) ) ;
698
691
}
699
692
700
693
let optimize = !def. repr . inhibit_union_abi_opt ( ) ;
@@ -704,12 +697,12 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
704
697
for field in & variants[ index] {
705
698
assert ! ( !field. is_unsized( ) ) ;
706
699
707
- if packed {
708
- let field_pack = field. align . min ( pack) ;
709
- align = align. max ( field_pack) ;
700
+ let field_align = if packed {
701
+ field. align . min ( AbiAndPrefAlign :: new ( pack) )
710
702
} else {
711
- align = align. max ( field. align ) ;
712
- }
703
+ field. align
704
+ } ;
705
+ align = align. max ( field_align) ;
713
706
714
707
// If all non-ZST fields have the same ABI, forward this ABI
715
708
if optimize && !field. is_zst ( ) {
@@ -749,7 +742,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
749
742
fields : FieldPlacement :: Union ( variants[ index] . len ( ) ) ,
750
743
abi,
751
744
align,
752
- size : size. abi_align ( align)
745
+ size : size. align_to ( align. abi )
753
746
} ) ) ;
754
747
}
755
748
@@ -964,19 +957,19 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
964
957
let mut size = Size :: ZERO ;
965
958
966
959
// We're interested in the smallest alignment, so start large.
967
- let mut start_align = Align :: from_bytes ( 256 , 256 ) . unwrap ( ) ;
968
- assert_eq ! ( Integer :: for_abi_align ( dl, start_align) , None ) ;
960
+ let mut start_align = Align :: from_bytes ( 256 ) . unwrap ( ) ;
961
+ assert_eq ! ( Integer :: for_align ( dl, start_align) , None ) ;
969
962
970
963
// repr(C) on an enum tells us to make a (tag, union) layout,
971
964
// so we need to grow the prefix alignment to be at least
972
965
// the alignment of the union. (This value is used both for
973
966
// determining the alignment of the overall enum, and the
974
967
// determining the alignment of the payload after the tag.)
975
- let mut prefix_align = min_ity. align ( dl) ;
968
+ let mut prefix_align = min_ity. align ( dl) . abi ;
976
969
if def. repr . c ( ) {
977
970
for fields in & variants {
978
971
for field in fields {
979
- prefix_align = prefix_align. max ( field. align ) ;
972
+ prefix_align = prefix_align. max ( field. align . abi ) ;
980
973
}
981
974
}
982
975
}
@@ -989,8 +982,8 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
989
982
// Find the first field we can't move later
990
983
// to make room for a larger discriminant.
991
984
for field in st. fields . index_by_increasing_offset ( ) . map ( |j| field_layouts[ j] ) {
992
- if !field. is_zst ( ) || field. align . abi ( ) != 1 {
993
- start_align = start_align. min ( field. align ) ;
985
+ if !field. is_zst ( ) || field. align . abi . bytes ( ) != 1 {
986
+ start_align = start_align. min ( field. align . abi ) ;
994
987
break ;
995
988
}
996
989
}
@@ -1000,7 +993,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1000
993
} ) . collect :: < Result < IndexVec < VariantIdx , _ > , _ > > ( ) ?;
1001
994
1002
995
// Align the maximum variant size to the largest alignment.
1003
- size = size. abi_align ( align) ;
996
+ size = size. align_to ( align. abi ) ;
1004
997
1005
998
if size. bytes ( ) >= dl. obj_size_bound ( ) {
1006
999
return Err ( LayoutError :: SizeOverflow ( ty) ) ;
@@ -1036,7 +1029,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1036
1029
let mut ity = if def. repr . c ( ) || def. repr . int . is_some ( ) {
1037
1030
min_ity
1038
1031
} else {
1039
- Integer :: for_abi_align ( dl, start_align) . unwrap_or ( min_ity)
1032
+ Integer :: for_align ( dl, start_align) . unwrap_or ( min_ity)
1040
1033
} ;
1041
1034
1042
1035
// If the alignment is not larger than the chosen discriminant size,
@@ -1204,7 +1197,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1204
1197
let type_desc = format ! ( "{:?}" , layout. ty) ;
1205
1198
self . tcx . sess . code_stats . borrow_mut ( ) . record_type_size ( kind,
1206
1199
type_desc,
1207
- layout. align ,
1200
+ layout. align . abi ,
1208
1201
layout. size ,
1209
1202
packed,
1210
1203
opt_discr_size,
@@ -1251,7 +1244,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1251
1244
name : name. to_string ( ) ,
1252
1245
offset : offset. bytes ( ) ,
1253
1246
size : field_layout. size . bytes ( ) ,
1254
- align : field_layout. align . abi ( ) ,
1247
+ align : field_layout. align . abi . bytes ( ) ,
1255
1248
}
1256
1249
}
1257
1250
}
@@ -1264,7 +1257,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1264
1257
} else {
1265
1258
session:: SizeKind :: Exact
1266
1259
} ,
1267
- align : layout. align . abi ( ) ,
1260
+ align : layout. align . abi . bytes ( ) ,
1268
1261
size : if min_size. bytes ( ) == 0 {
1269
1262
layout. size . bytes ( )
1270
1263
} else {
@@ -1823,7 +1816,9 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
1823
1816
Abi :: ScalarPair ( ref a, ref b) => {
1824
1817
// HACK(nox): We iter on `b` and then `a` because `max_by_key`
1825
1818
// returns the last maximum.
1826
- let niche = iter:: once ( ( b, a. value . size ( self ) . abi_align ( b. value . align ( self ) ) ) )
1819
+ let niche = iter:: once (
1820
+ ( b, a. value . size ( self ) . align_to ( b. value . align ( self ) . abi ) )
1821
+ )
1827
1822
. chain ( iter:: once ( ( a, Size :: ZERO ) ) )
1828
1823
. filter_map ( |( scalar, offset) | scalar_niche ( scalar, offset) )
1829
1824
. max_by_key ( |niche| niche. available ) ;
@@ -1994,12 +1989,16 @@ impl_stable_hash_for!(enum ::ty::layout::Primitive {
1994
1989
Pointer
1995
1990
} ) ;
1996
1991
1992
+ impl_stable_hash_for ! ( struct :: ty:: layout:: AbiAndPrefAlign {
1993
+ abi,
1994
+ pref
1995
+ } ) ;
1996
+
1997
1997
impl < ' gcx > HashStable < StableHashingContext < ' gcx > > for Align {
1998
1998
fn hash_stable < W : StableHasherResult > ( & self ,
1999
1999
hcx : & mut StableHashingContext < ' gcx > ,
2000
2000
hasher : & mut StableHasher < W > ) {
2001
- self . abi ( ) . hash_stable ( hcx, hasher) ;
2002
- self . pref ( ) . hash_stable ( hcx, hasher) ;
2001
+ self . bytes ( ) . hash_stable ( hcx, hasher) ;
2003
2002
}
2004
2003
}
2005
2004
0 commit comments