@@ -1438,51 +1438,81 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for AdtDef {
1438
1438
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
1439
1439
pub enum AdtKind { Struct , Union , Enum }
1440
1440
1441
+ bitflags ! {
1442
+ #[ derive( RustcEncodable , RustcDecodable , Default ) ]
1443
+ flags ReprFlags : u8 {
1444
+ const IS_C = 1 << 0 ,
1445
+ const IS_PACKED = 1 << 1 ,
1446
+ const IS_SIMD = 1 << 2 ,
1447
+ // Internal only for now. If true, don't reorder fields.
1448
+ const IS_LINEAR = 1 << 3 ,
1449
+
1450
+ // Any of these flags being set prevent field reordering optimisation.
1451
+ const IS_UNOPTIMISABLE = ReprFlags :: IS_C . bits |
1452
+ ReprFlags :: IS_PACKED . bits |
1453
+ ReprFlags :: IS_SIMD . bits |
1454
+ ReprFlags :: IS_LINEAR . bits,
1455
+ }
1456
+ }
1457
+
1458
+ impl_stable_hash_for ! ( struct ReprFlags {
1459
+ bits
1460
+ } ) ;
1461
+
1462
+
1463
+
1441
1464
/// Represents the repr options provided by the user,
1442
1465
#[ derive( Copy , Clone , Eq , PartialEq , RustcEncodable , RustcDecodable , Default ) ]
1443
1466
pub struct ReprOptions {
1444
- pub c : bool ,
1445
- pub packed : bool ,
1446
- pub simd : bool ,
1447
1467
pub int : Option < attr:: IntType > ,
1448
- // Internal only for now. If true, don't reorder fields.
1449
- pub linear : bool ,
1468
+ pub flags : ReprFlags ,
1450
1469
}
1451
1470
1452
1471
impl_stable_hash_for ! ( struct ReprOptions {
1453
- c,
1454
- packed,
1455
- simd,
1456
1472
int,
1457
- linear
1473
+ flags
1458
1474
} ) ;
1459
1475
1460
1476
impl ReprOptions {
1461
1477
pub fn new ( tcx : TyCtxt , did : DefId ) -> ReprOptions {
1462
- let mut ret = ReprOptions :: default ( ) ;
1478
+ let mut flags = ReprFlags :: empty ( ) ;
1479
+ let mut size = None ;
1463
1480
1464
1481
for attr in tcx. get_attrs ( did) . iter ( ) {
1465
1482
for r in attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) , attr) {
1466
- match r {
1467
- attr:: ReprExtern => ret. c = true ,
1468
- attr:: ReprPacked => ret. packed = true ,
1469
- attr:: ReprSimd => ret. simd = true ,
1470
- attr:: ReprInt ( i) => ret. int = Some ( i) ,
1471
- }
1483
+ flags. insert ( match r {
1484
+ attr:: ReprExtern => ReprFlags :: IS_C ,
1485
+ attr:: ReprPacked => ReprFlags :: IS_PACKED ,
1486
+ attr:: ReprSimd => ReprFlags :: IS_SIMD ,
1487
+ attr:: ReprInt ( i) => {
1488
+ size = Some ( i) ;
1489
+ ReprFlags :: empty ( )
1490
+ } ,
1491
+ } ) ;
1472
1492
}
1473
1493
}
1474
1494
1475
1495
// FIXME(eddyb) This is deprecated and should be removed.
1476
1496
if tcx. has_attr ( did, "simd" ) {
1477
- ret . simd = true ;
1497
+ flags . insert ( ReprFlags :: IS_SIMD ) ;
1478
1498
}
1479
1499
1480
1500
// This is here instead of layout because the choice must make it into metadata.
1481
- ret. linear = !tcx. consider_optimizing ( || format ! ( "Reorder fields of {:?}" ,
1482
- tcx. item_path_str( did) ) ) ;
1483
- ret
1501
+ if !tcx. consider_optimizing ( || format ! ( "Reorder fields of {:?}" , tcx. item_path_str( did) ) ) {
1502
+ flags. insert ( ReprFlags :: IS_LINEAR ) ;
1503
+ }
1504
+ ReprOptions { int : size, flags : flags }
1484
1505
}
1485
1506
1507
+ #[ inline]
1508
+ pub fn simd ( & self ) -> bool { self . flags . contains ( ReprFlags :: IS_SIMD ) }
1509
+ #[ inline]
1510
+ pub fn c ( & self ) -> bool { self . flags . contains ( ReprFlags :: IS_C ) }
1511
+ #[ inline]
1512
+ pub fn packed ( & self ) -> bool { self . flags . contains ( ReprFlags :: IS_PACKED ) }
1513
+ #[ inline]
1514
+ pub fn linear ( & self ) -> bool { self . flags . contains ( ReprFlags :: IS_LINEAR ) }
1515
+
1486
1516
pub fn discr_type ( & self ) -> attr:: IntType {
1487
1517
self . int . unwrap_or ( attr:: SignedInt ( ast:: IntTy :: Is ) )
1488
1518
}
@@ -1491,7 +1521,7 @@ impl ReprOptions {
1491
1521
/// layout" optimizations, such as representing `Foo<&T>` as a
1492
1522
/// single pointer.
1493
1523
pub fn inhibit_enum_layout_opt ( & self ) -> bool {
1494
- self . c || self . int . is_some ( )
1524
+ self . c ( ) || self . int . is_some ( )
1495
1525
}
1496
1526
}
1497
1527
0 commit comments