@@ -1133,24 +1133,14 @@ pub enum Layout {
1133
1133
} ,
1134
1134
1135
1135
/// Two cases distinguished by a nullable pointer: the case with discriminant
1136
- /// `nndiscr` must have single field which is known to be nonnull due to its type.
1137
- /// The other case is known to be zero sized. Hence we represent the enum
1138
- /// as simply a nullable pointer: if not null it indicates the `nndiscr` variant,
1139
- /// otherwise it indicates the other case.
1136
+ /// `nndiscr` is represented by the struct `nonnull`, where the field at the
1137
+ /// `discr_offset` offset is known to be nonnull due to its type; if that field is null, then
1138
+ /// it represents the other case, which is known to be zero sized.
1140
1139
///
1141
1140
/// For example, `std::option::Option` instantiated at a safe pointer type
1142
1141
/// is represented such that `None` is a null pointer and `Some` is the
1143
1142
/// identity function.
1144
- RawNullablePointer {
1145
- nndiscr : u64 ,
1146
- discr : Primitive
1147
- } ,
1148
-
1149
- /// Two cases distinguished by a nullable pointer: the case with discriminant
1150
- /// `nndiscr` is represented by the struct `nonnull`, where the field at the
1151
- /// `discr_offset` offset is known to be nonnull due to its type; if that field is null, then
1152
- /// it represents the other case, which is known to be zero sized.
1153
- StructWrappedNullablePointer {
1143
+ NullablePointer {
1154
1144
nndiscr : u64 ,
1155
1145
nonnull : Struct ,
1156
1146
discr : Primitive ,
@@ -1259,18 +1249,16 @@ impl<'a, 'tcx> Layout {
1259
1249
FieldPlacement :: union ( def. struct_variant ( ) . fields . len ( ) )
1260
1250
}
1261
1251
1262
- General { .. } |
1263
- RawNullablePointer { .. } => FieldPlacement :: union ( 1 ) ,
1252
+ General { .. } => FieldPlacement :: union ( 1 ) ,
1264
1253
1265
- StructWrappedNullablePointer { ref discr_offset, .. } => {
1254
+ NullablePointer { ref discr_offset, .. } => {
1266
1255
FieldPlacement :: Arbitrary {
1267
1256
offsets : ref_slice ( discr_offset)
1268
1257
}
1269
1258
}
1270
1259
} ;
1271
1260
let abi = match * layout {
1272
- Scalar { value, .. } |
1273
- RawNullablePointer { discr : value, .. } => Abi :: Scalar ( value) ,
1261
+ Scalar { value, .. } => Abi :: Scalar ( value) ,
1274
1262
CEnum { discr, .. } => Abi :: Scalar ( Int ( discr) ) ,
1275
1263
1276
1264
Vector { .. } => Abi :: Vector ,
@@ -1279,8 +1267,15 @@ impl<'a, 'tcx> Layout {
1279
1267
FatPointer { .. } |
1280
1268
Univariant ( _) |
1281
1269
UntaggedUnion ( _) |
1282
- General { .. } |
1283
- StructWrappedNullablePointer { .. } => Abi :: Aggregate
1270
+ General { .. } => Abi :: Aggregate ,
1271
+
1272
+ NullablePointer { discr, discr_offset, .. } => {
1273
+ if discr_offset. bytes ( ) == 0 && discr. size ( cx) == layout. size ( cx) {
1274
+ Abi :: Scalar ( discr)
1275
+ } else {
1276
+ Abi :: Aggregate
1277
+ }
1278
+ }
1284
1279
} ;
1285
1280
Ok ( CachedLayout {
1286
1281
layout,
@@ -1562,15 +1557,6 @@ impl<'a, 'tcx> Layout {
1562
1557
// out of arrays with just the indexing operator.
1563
1558
let mut st = if discr == 0 { st0 } else { st1 } ;
1564
1559
1565
- // FIXME(eddyb) should take advantage of a newtype.
1566
- if offset. bytes ( ) == 0 && primitive. size ( dl) == st. stride ( ) &&
1567
- variants[ discr] . len ( ) == 1 {
1568
- return success ( RawNullablePointer {
1569
- nndiscr : discr as u64 ,
1570
- discr : primitive,
1571
- } ) ;
1572
- }
1573
-
1574
1560
let mut discr_align = primitive. align ( dl) ;
1575
1561
if offset. abi_align ( discr_align) != offset {
1576
1562
st. packed = true ;
@@ -1579,7 +1565,7 @@ impl<'a, 'tcx> Layout {
1579
1565
st. align = st. align . max ( discr_align) ;
1580
1566
st. primitive_align = st. primitive_align . max ( discr_align) ;
1581
1567
1582
- return success ( StructWrappedNullablePointer {
1568
+ return success ( NullablePointer {
1583
1569
nndiscr : discr as u64 ,
1584
1570
nonnull : st,
1585
1571
discr : primitive,
@@ -1715,8 +1701,7 @@ impl<'a, 'tcx> Layout {
1715
1701
match * self {
1716
1702
Scalar { ..} | Vector { ..} | FatPointer { ..} |
1717
1703
CEnum { ..} | UntaggedUnion { ..} | General { ..} |
1718
- RawNullablePointer { ..} |
1719
- StructWrappedNullablePointer { ..} => false ,
1704
+ NullablePointer { ..} => false ,
1720
1705
1721
1706
Array { sized, .. } |
1722
1707
Univariant ( Struct { sized, .. } ) => !sized
@@ -1727,7 +1712,7 @@ impl<'a, 'tcx> Layout {
1727
1712
let dl = cx. data_layout ( ) ;
1728
1713
1729
1714
match * self {
1730
- Scalar { value, .. } | RawNullablePointer { discr : value , .. } => {
1715
+ Scalar { value, .. } => {
1731
1716
value. size ( dl)
1732
1717
}
1733
1718
@@ -1760,7 +1745,7 @@ impl<'a, 'tcx> Layout {
1760
1745
UntaggedUnion ( ref un) => un. stride ( ) ,
1761
1746
1762
1747
Univariant ( ref variant) |
1763
- StructWrappedNullablePointer { nonnull : ref variant, .. } => {
1748
+ NullablePointer { nonnull : ref variant, .. } => {
1764
1749
variant. stride ( )
1765
1750
}
1766
1751
}
@@ -1770,7 +1755,7 @@ impl<'a, 'tcx> Layout {
1770
1755
let dl = cx. data_layout ( ) ;
1771
1756
1772
1757
match * self {
1773
- Scalar { value, .. } | RawNullablePointer { discr : value , .. } => {
1758
+ Scalar { value, .. } => {
1774
1759
value. align ( dl)
1775
1760
}
1776
1761
@@ -1794,7 +1779,7 @@ impl<'a, 'tcx> Layout {
1794
1779
UntaggedUnion ( ref un) => un. align ,
1795
1780
1796
1781
Univariant ( ref variant) |
1797
- StructWrappedNullablePointer { nonnull : ref variant, .. } => {
1782
+ NullablePointer { nonnull : ref variant, .. } => {
1798
1783
variant. align
1799
1784
}
1800
1785
}
@@ -1809,7 +1794,7 @@ impl<'a, 'tcx> Layout {
1809
1794
match * self {
1810
1795
Array { primitive_align, .. } | General { primitive_align, .. } => primitive_align,
1811
1796
Univariant ( ref variant) |
1812
- StructWrappedNullablePointer { nonnull : ref variant, .. } => {
1797
+ NullablePointer { nonnull : ref variant, .. } => {
1813
1798
variant. primitive_align
1814
1799
} ,
1815
1800
@@ -1924,11 +1909,11 @@ impl<'a, 'tcx> Layout {
1924
1909
} ;
1925
1910
1926
1911
match * layout {
1927
- Layout :: StructWrappedNullablePointer { nonnull : ref variant_layout,
1928
- nndiscr,
1929
- discr : _,
1930
- discr_offset : _ } => {
1931
- debug ! ( "print-type-size t: `{:?}` adt struct-wrapped nullable nndiscr {} is {:?}" ,
1912
+ Layout :: NullablePointer { nonnull : ref variant_layout,
1913
+ nndiscr,
1914
+ discr : _,
1915
+ discr_offset : _ } => {
1916
+ debug ! ( "print-type-size t: `{:?}` adt nullable nndiscr {} is {:?}" ,
1932
1917
ty, nndiscr, variant_layout) ;
1933
1918
let variant_def = & adt_def. variants [ nndiscr as usize ] ;
1934
1919
let fields: Vec < _ > =
@@ -1941,13 +1926,6 @@ impl<'a, 'tcx> Layout {
1941
1926
& fields,
1942
1927
variant_layout) ] ) ;
1943
1928
}
1944
- Layout :: RawNullablePointer { nndiscr, discr } => {
1945
- debug ! ( "print-type-size t: `{:?}` adt raw nullable nndiscr {} is {:?}" ,
1946
- ty, nndiscr, discr) ;
1947
- let variant_def = & adt_def. variants [ nndiscr as usize ] ;
1948
- record ( adt_kind. into ( ) , None ,
1949
- vec ! [ build_primitive_info( variant_def. name, & discr) ] ) ;
1950
- }
1951
1929
Layout :: Univariant ( ref variant_layout) => {
1952
1930
let variant_names = || {
1953
1931
adt_def. variants . iter ( ) . map ( |v|format ! ( "{}" , v. name) ) . collect :: < Vec < _ > > ( )
@@ -2314,7 +2292,7 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2314
2292
}
2315
2293
}
2316
2294
2317
- StructWrappedNullablePointer { nndiscr, ref nonnull, .. }
2295
+ NullablePointer { nndiscr, ref nonnull, .. }
2318
2296
if nndiscr as usize == variant_index => {
2319
2297
FieldPlacement :: Arbitrary {
2320
2298
offsets : & nonnull. offsets
@@ -2402,8 +2380,7 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2402
2380
General { discr, .. } => {
2403
2381
return [ discr. to_ty ( tcx, false ) ] [ i] ;
2404
2382
}
2405
- RawNullablePointer { discr, .. } |
2406
- StructWrappedNullablePointer { discr, .. } => {
2383
+ NullablePointer { discr, .. } => {
2407
2384
return [ discr. to_ty ( tcx) ] [ i] ;
2408
2385
}
2409
2386
_ if def. variants . len ( ) > 1 => return [ ] [ i] ,
@@ -2483,11 +2460,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Layout
2483
2460
align. hash_stable ( hcx, hasher) ;
2484
2461
primitive_align. hash_stable ( hcx, hasher) ;
2485
2462
}
2486
- RawNullablePointer { nndiscr, ref discr } => {
2487
- nndiscr. hash_stable ( hcx, hasher) ;
2488
- discr. hash_stable ( hcx, hasher) ;
2489
- }
2490
- StructWrappedNullablePointer {
2463
+ NullablePointer {
2491
2464
nndiscr,
2492
2465
ref nonnull,
2493
2466
ref discr,
0 commit comments