@@ -838,27 +838,29 @@ impl<'a, 'tcx> Struct {
838
838
-> Result < Option < ( Size , Primitive ) > , LayoutError < ' tcx > > {
839
839
let cx = ( tcx, param_env) ;
840
840
match ( layout. layout , & layout. ty . sty ) {
841
- ( & Scalar { non_zero : true , value , .. } , _ ) => {
842
- Ok ( Some ( ( Size :: from_bytes ( 0 ) , value ) ) )
841
+ ( & Scalar ( Pointer ) , _ ) if !layout . ty . is_unsafe_ptr ( ) => {
842
+ Ok ( Some ( ( Size :: from_bytes ( 0 ) , Pointer ) ) )
843
843
}
844
- ( & CEnum { non_zero : true , discr, .. } , _) => {
845
- Ok ( Some ( ( Size :: from_bytes ( 0 ) , Int ( discr) ) ) )
844
+ ( & CEnum { discr, .. } , & ty:: TyAdt ( def, _) ) => {
845
+ if def. discriminants ( tcx) . all ( |d| d. to_u128_unchecked ( ) != 0 ) {
846
+ Ok ( Some ( ( Size :: from_bytes ( 0 ) , Int ( discr) ) ) )
847
+ } else {
848
+ Ok ( None )
849
+ }
846
850
}
847
851
848
- ( & FatPointer { non_zero : true , .. } , _ ) => {
852
+ ( & FatPointer ( _ ) , _ ) if !layout . ty . is_unsafe_ptr ( ) => {
849
853
Ok ( Some ( ( layout. fields . offset ( FAT_PTR_ADDR ) , Pointer ) ) )
850
854
}
851
855
852
856
// Is this the NonZero lang item wrapping a pointer or integer type?
853
857
( _, & ty:: TyAdt ( def, _) ) if Some ( def. did ) == tcx. lang_items ( ) . non_zero ( ) => {
854
858
let field = layout. field ( cx, 0 ) ?;
855
859
match * field {
856
- // FIXME(eddyb) also allow floating-point types here.
857
- Scalar { value : value @ Int ( _) , non_zero : false } |
858
- Scalar { value : value @ Pointer , non_zero : false } => {
860
+ Scalar ( value) => {
859
861
Ok ( Some ( ( layout. fields . offset ( 0 ) , value) ) )
860
862
}
861
- FatPointer { non_zero : false , .. } => {
863
+ FatPointer ( _ ) => {
862
864
Ok ( Some ( ( layout. fields . offset ( 0 ) +
863
865
field. fields . offset ( FAT_PTR_ADDR ) ,
864
866
Pointer ) ) )
@@ -1070,11 +1072,7 @@ pub enum Abi {
1070
1072
#[ derive( Debug , PartialEq , Eq , Hash ) ]
1071
1073
pub enum Layout {
1072
1074
/// TyBool, TyChar, TyInt, TyUint, TyFloat, TyRawPtr, TyRef or TyFnPtr.
1073
- Scalar {
1074
- value : Primitive ,
1075
- // If true, the value cannot represent a bit pattern of all zeroes.
1076
- non_zero : bool
1077
- } ,
1075
+ Scalar ( Primitive ) ,
1078
1076
1079
1077
/// SIMD vectors, from structs marked with #[repr(simd)].
1080
1078
Vector {
@@ -1092,20 +1090,15 @@ pub enum Layout {
1092
1090
count : u64
1093
1091
} ,
1094
1092
1095
- /// TyRawPtr or TyRef with a !Sized pointee.
1096
- FatPointer {
1097
- metadata : Primitive ,
1098
- /// If true, the pointer cannot be null.
1099
- non_zero : bool
1100
- } ,
1093
+ /// TyRawPtr or TyRef with a !Sized pointee. The primitive is the metadata.
1094
+ FatPointer ( Primitive ) ,
1101
1095
1102
1096
// Remaining variants are all ADTs such as structs, enums or tuples.
1103
1097
1104
1098
/// C-like enums; basically an integer.
1105
1099
CEnum {
1106
1100
discr : Integer ,
1107
1101
signed : bool ,
1108
- non_zero : bool ,
1109
1102
/// Inclusive discriminant range.
1110
1103
/// If min > max, it represents min...u64::MAX followed by 0...max.
1111
1104
// FIXME(eddyb) always use the shortest range, e.g. by finding
@@ -1211,7 +1204,7 @@ impl<'a, 'tcx> Layout {
1211
1204
let success = |layout| {
1212
1205
let layout = tcx. intern_layout ( layout) ;
1213
1206
let fields = match * layout {
1214
- Scalar { .. } |
1207
+ Scalar ( _ ) |
1215
1208
CEnum { .. } => {
1216
1209
FieldPlacement :: union ( 0 )
1217
1210
}
@@ -1258,7 +1251,7 @@ impl<'a, 'tcx> Layout {
1258
1251
}
1259
1252
} ;
1260
1253
let abi = match * layout {
1261
- Scalar { value, .. } => Abi :: Scalar ( value) ,
1254
+ Scalar ( value) => Abi :: Scalar ( value) ,
1262
1255
CEnum { discr, .. } => Abi :: Scalar ( Int ( discr) ) ,
1263
1256
1264
1257
Vector { .. } => Abi :: Vector ,
@@ -1286,43 +1279,36 @@ impl<'a, 'tcx> Layout {
1286
1279
assert ! ( !ty. has_infer_types( ) ) ;
1287
1280
1288
1281
let ptr_layout = |pointee : Ty < ' tcx > | {
1289
- let non_zero = !ty. is_unsafe_ptr ( ) ;
1290
1282
let pointee = tcx. normalize_associated_type_in_env ( & pointee, param_env) ;
1291
1283
if pointee. is_sized ( tcx, param_env, DUMMY_SP ) {
1292
- Ok ( Scalar { value : Pointer , non_zero } )
1284
+ Ok ( Scalar ( Pointer ) )
1293
1285
} else {
1294
1286
let unsized_part = tcx. struct_tail ( pointee) ;
1295
1287
let metadata = match unsized_part. sty {
1296
- ty:: TyForeign ( ..) => return Ok ( Scalar { value : Pointer , non_zero } ) ,
1288
+ ty:: TyForeign ( ..) => return Ok ( Scalar ( Pointer ) ) ,
1297
1289
ty:: TySlice ( _) | ty:: TyStr => {
1298
1290
Int ( dl. ptr_sized_integer ( ) )
1299
1291
}
1300
1292
ty:: TyDynamic ( ..) => Pointer ,
1301
1293
_ => return Err ( LayoutError :: Unknown ( unsized_part) )
1302
1294
} ;
1303
- Ok ( FatPointer { metadata, non_zero } )
1295
+ Ok ( FatPointer ( metadata) )
1304
1296
}
1305
1297
} ;
1306
1298
1307
1299
let layout = match ty. sty {
1308
1300
// Basic scalars.
1309
- ty:: TyBool => Scalar { value : Int ( I1 ) , non_zero : false } ,
1310
- ty:: TyChar => Scalar { value : Int ( I32 ) , non_zero : false } ,
1301
+ ty:: TyBool => Scalar ( Int ( I1 ) ) ,
1302
+ ty:: TyChar => Scalar ( Int ( I32 ) ) ,
1311
1303
ty:: TyInt ( ity) => {
1312
- Scalar {
1313
- value : Int ( Integer :: from_attr ( dl, attr:: SignedInt ( ity) ) ) ,
1314
- non_zero : false
1315
- }
1304
+ Scalar ( Int ( Integer :: from_attr ( dl, attr:: SignedInt ( ity) ) ) )
1316
1305
}
1317
1306
ty:: TyUint ( ity) => {
1318
- Scalar {
1319
- value : Int ( Integer :: from_attr ( dl, attr:: UnsignedInt ( ity) ) ) ,
1320
- non_zero : false
1321
- }
1307
+ Scalar ( Int ( Integer :: from_attr ( dl, attr:: UnsignedInt ( ity) ) ) )
1322
1308
}
1323
- ty:: TyFloat ( FloatTy :: F32 ) => Scalar { value : F32 , non_zero : false } ,
1324
- ty:: TyFloat ( FloatTy :: F64 ) => Scalar { value : F64 , non_zero : false } ,
1325
- ty:: TyFnPtr ( _) => Scalar { value : Pointer , non_zero : true } ,
1309
+ ty:: TyFloat ( FloatTy :: F32 ) => Scalar ( F32 ) ,
1310
+ ty:: TyFloat ( FloatTy :: F64 ) => Scalar ( F64 ) ,
1311
+ ty:: TyFnPtr ( _) => Scalar ( Pointer ) ,
1326
1312
1327
1313
// The never type.
1328
1314
ty:: TyNever => {
@@ -1430,7 +1416,7 @@ impl<'a, 'tcx> Layout {
1430
1416
ty:: TyAdt ( def, ..) if def. repr . simd ( ) => {
1431
1417
let element = ty. simd_type ( tcx) ;
1432
1418
match * cx. layout_of ( element) ? {
1433
- Scalar { value, .. } => {
1419
+ Scalar ( value) => {
1434
1420
return success ( Vector {
1435
1421
element : value,
1436
1422
count : ty. simd_size ( tcx) as u64
@@ -1456,12 +1442,9 @@ impl<'a, 'tcx> Layout {
1456
1442
1457
1443
if def. is_enum ( ) && def. variants . iter ( ) . all ( |v| v. fields . is_empty ( ) ) {
1458
1444
// All bodies empty -> intlike
1459
- let ( mut min, mut max, mut non_zero) = ( i64:: max_value ( ) ,
1460
- i64:: min_value ( ) ,
1461
- true ) ;
1445
+ let ( mut min, mut max) = ( i64:: max_value ( ) , i64:: min_value ( ) ) ;
1462
1446
for discr in def. discriminants ( tcx) {
1463
1447
let x = discr. to_u128_unchecked ( ) as i64 ;
1464
- if x == 0 { non_zero = false ; }
1465
1448
if x < min { min = x; }
1466
1449
if x > max { max = x; }
1467
1450
}
@@ -1472,7 +1455,6 @@ impl<'a, 'tcx> Layout {
1472
1455
return success ( CEnum {
1473
1456
discr,
1474
1457
signed,
1475
- non_zero,
1476
1458
// FIXME: should be u128?
1477
1459
min : min as u64 ,
1478
1460
max : max as u64
@@ -1699,7 +1681,7 @@ impl<'a, 'tcx> Layout {
1699
1681
/// Returns true if the layout corresponds to an unsized type.
1700
1682
pub fn is_unsized ( & self ) -> bool {
1701
1683
match * self {
1702
- Scalar { .. } | Vector { ..} | FatPointer { ..} |
1684
+ Scalar ( _ ) | Vector { ..} | FatPointer { ..} |
1703
1685
CEnum { ..} | UntaggedUnion { ..} | General { ..} |
1704
1686
NullablePointer { ..} => false ,
1705
1687
@@ -1712,7 +1694,7 @@ impl<'a, 'tcx> Layout {
1712
1694
let dl = cx. data_layout ( ) ;
1713
1695
1714
1696
match * self {
1715
- Scalar { value, .. } => {
1697
+ Scalar ( value) => {
1716
1698
value. size ( dl)
1717
1699
}
1718
1700
@@ -1734,7 +1716,7 @@ impl<'a, 'tcx> Layout {
1734
1716
}
1735
1717
}
1736
1718
1737
- FatPointer { metadata, .. } => {
1719
+ FatPointer ( metadata) => {
1738
1720
// Effectively a (ptr, meta) tuple.
1739
1721
( Pointer . size ( dl) . abi_align ( metadata. align ( dl) ) +
1740
1722
metadata. size ( dl) ) . abi_align ( self . align ( dl) )
@@ -1755,7 +1737,7 @@ impl<'a, 'tcx> Layout {
1755
1737
let dl = cx. data_layout ( ) ;
1756
1738
1757
1739
match * self {
1758
- Scalar { value, .. } => {
1740
+ Scalar ( value) => {
1759
1741
value. align ( dl)
1760
1742
}
1761
1743
@@ -1769,7 +1751,7 @@ impl<'a, 'tcx> Layout {
1769
1751
dl. vector_align ( vec_size)
1770
1752
}
1771
1753
1772
- FatPointer { metadata, .. } => {
1754
+ FatPointer ( metadata) => {
1773
1755
// Effectively a (ptr, meta) tuple.
1774
1756
Pointer . align ( dl) . max ( metadata. align ( dl) )
1775
1757
}
@@ -1993,7 +1975,7 @@ impl<'a, 'tcx> Layout {
1993
1975
1994
1976
// other cases provide little interesting (i.e. adjustable
1995
1977
// via representation tweaks) size info beyond total size.
1996
- Layout :: Scalar { .. } |
1978
+ Layout :: Scalar ( _ ) |
1997
1979
Layout :: Vector { .. } |
1998
1980
Layout :: Array { .. } |
1999
1981
Layout :: FatPointer { .. } => {
@@ -2421,9 +2403,8 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Layout
2421
2403
mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
2422
2404
2423
2405
match * self {
2424
- Scalar { value, non_zero } => {
2406
+ Scalar ( ref value) => {
2425
2407
value. hash_stable ( hcx, hasher) ;
2426
- non_zero. hash_stable ( hcx, hasher) ;
2427
2408
}
2428
2409
Vector { element, count } => {
2429
2410
element. hash_stable ( hcx, hasher) ;
@@ -2436,14 +2417,12 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Layout
2436
2417
element_size. hash_stable ( hcx, hasher) ;
2437
2418
count. hash_stable ( hcx, hasher) ;
2438
2419
}
2439
- FatPointer { ref metadata, non_zero } => {
2420
+ FatPointer ( ref metadata) => {
2440
2421
metadata. hash_stable ( hcx, hasher) ;
2441
- non_zero. hash_stable ( hcx, hasher) ;
2442
2422
}
2443
- CEnum { discr, signed, non_zero , min, max } => {
2423
+ CEnum { discr, signed, min, max } => {
2444
2424
discr. hash_stable ( hcx, hasher) ;
2445
2425
signed. hash_stable ( hcx, hasher) ;
2446
- non_zero. hash_stable ( hcx, hasher) ;
2447
2426
min. hash_stable ( hcx, hasher) ;
2448
2427
max. hash_stable ( hcx, hasher) ;
2449
2428
}
0 commit comments