@@ -1438,51 +1438,81 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for AdtDef {
14381438#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
14391439pub enum AdtKind { Struct , Union , Enum }
14401440
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+
14411464/// Represents the repr options provided by the user,
14421465#[ derive( Copy , Clone , Eq , PartialEq , RustcEncodable , RustcDecodable , Default ) ]
14431466pub struct ReprOptions {
1444- pub c : bool ,
1445- pub packed : bool ,
1446- pub simd : bool ,
14471467 pub int : Option < attr:: IntType > ,
1448- // Internal only for now. If true, don't reorder fields.
1449- pub linear : bool ,
1468+ pub flags : ReprFlags ,
14501469}
14511470
14521471impl_stable_hash_for ! ( struct ReprOptions {
1453- c,
1454- packed,
1455- simd,
14561472 int,
1457- linear
1473+ flags
14581474} ) ;
14591475
14601476impl ReprOptions {
14611477 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 ;
14631480
14641481 for attr in tcx. get_attrs ( did) . iter ( ) {
14651482 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+ } ) ;
14721492 }
14731493 }
14741494
14751495 // FIXME(eddyb) This is deprecated and should be removed.
14761496 if tcx. has_attr ( did, "simd" ) {
1477- ret . simd = true ;
1497+ flags . insert ( ReprFlags :: IS_SIMD ) ;
14781498 }
14791499
14801500 // 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 }
14841505 }
14851506
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+
14861516 pub fn discr_type ( & self ) -> attr:: IntType {
14871517 self . int . unwrap_or ( attr:: SignedInt ( ast:: IntTy :: Is ) )
14881518 }
@@ -1491,7 +1521,7 @@ impl ReprOptions {
14911521 /// layout" optimizations, such as representing `Foo<&T>` as a
14921522 /// single pointer.
14931523 pub fn inhibit_enum_layout_opt ( & self ) -> bool {
1494- self . c || self . int . is_some ( )
1524+ self . c ( ) || self . int . is_some ( )
14951525 }
14961526}
14971527
0 commit comments