@@ -849,9 +849,6 @@ pub enum Layout {
849
849
/// TyArray, TySlice or TyStr.
850
850
Array ,
851
851
852
- /// TyRawPtr or TyRef with a !Sized pointee. The primitive is the metadata.
853
- FatPointer ,
854
-
855
852
// Remaining variants are all ADTs such as structs, enums or tuples.
856
853
857
854
/// Single-case enums, and structs/tuples.
@@ -1132,7 +1129,7 @@ impl<'a, 'tcx> Layout {
1132
1129
memory_index : vec ! [ 0 , 1 ]
1133
1130
} ;
1134
1131
Ok ( tcx. intern_layout ( CachedLayout {
1135
- layout : Layout :: FatPointer ,
1132
+ layout : Layout :: Univariant ,
1136
1133
fields,
1137
1134
abi : Abi :: Aggregate {
1138
1135
sized : true ,
@@ -1743,8 +1740,7 @@ impl<'a, 'tcx> Layout {
1743
1740
// via representation tweaks) size info beyond total size.
1744
1741
Layout :: Scalar |
1745
1742
Layout :: Vector |
1746
- Layout :: Array |
1747
- Layout :: FatPointer { .. } => {
1743
+ Layout :: Array => {
1748
1744
debug ! ( "print-type-size t: `{:?}` adt other" , ty) ;
1749
1745
record ( adt_kind. into ( ) , None , Vec :: new ( ) )
1750
1746
}
@@ -2047,17 +2043,37 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2047
2043
fn field_type_unnormalized ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > , i : usize ) -> Ty < ' tcx > {
2048
2044
let ptr_field_type = |pointee : Ty < ' tcx > | {
2049
2045
assert ! ( i < 2 ) ;
2046
+ let mk_ptr = |ty : Ty < ' tcx > | {
2047
+ match self . ty . sty {
2048
+ ty:: TyRef ( r, ty:: TypeAndMut { mutbl, .. } ) => {
2049
+ tcx. mk_ref ( r, ty:: TypeAndMut { ty, mutbl } )
2050
+ }
2051
+ ty:: TyRawPtr ( ty:: TypeAndMut { mutbl, .. } ) => {
2052
+ tcx. mk_ptr ( ty:: TypeAndMut { ty, mutbl } )
2053
+ }
2054
+ ty:: TyAdt ( def, _) if def. is_box ( ) => {
2055
+ tcx. mk_box ( ty)
2056
+ }
2057
+ _ => bug ! ( )
2058
+ }
2059
+ } ;
2050
2060
let slice = |element : Ty < ' tcx > | {
2051
2061
if i == 0 {
2052
- tcx . mk_mut_ptr ( element)
2062
+ mk_ptr ( element)
2053
2063
} else {
2054
2064
tcx. types . usize
2055
2065
}
2056
2066
} ;
2057
2067
match tcx. struct_tail ( pointee) . sty {
2058
2068
ty:: TySlice ( element) => slice ( element) ,
2059
2069
ty:: TyStr => slice ( tcx. types . u8 ) ,
2060
- ty:: TyDynamic ( ..) => Pointer . to_ty ( tcx) ,
2070
+ ty:: TyDynamic ( ..) => {
2071
+ if i == 0 {
2072
+ mk_ptr ( tcx. mk_nil ( ) )
2073
+ } else {
2074
+ Pointer . to_ty ( tcx)
2075
+ }
2076
+ }
2061
2077
_ => bug ! ( "FullLayout::field_type({:?}): not applicable" , self )
2062
2078
}
2063
2079
} ;
@@ -2187,9 +2203,16 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2187
2203
{
2188
2204
let tcx = cx. tcx ( ) ;
2189
2205
match ( self . layout , self . abi , & self . ty . sty ) {
2190
- ( & Layout :: Scalar , Abi :: Scalar ( Pointer ) , _) if !self . ty . is_unsafe_ptr ( ) => {
2206
+ // FIXME(eddyb) check this via value ranges on scalars.
2207
+ ( & Layout :: Scalar , Abi :: Scalar ( Pointer ) , & ty:: TyRef ( ..) ) |
2208
+ ( & Layout :: Scalar , Abi :: Scalar ( Pointer ) , & ty:: TyFnPtr ( ..) ) => {
2209
+ Ok ( Some ( ( Size :: from_bytes ( 0 ) , Pointer ) ) )
2210
+ }
2211
+ ( & Layout :: Scalar , Abi :: Scalar ( Pointer ) , & ty:: TyAdt ( def, _) ) if def. is_box ( ) => {
2191
2212
Ok ( Some ( ( Size :: from_bytes ( 0 ) , Pointer ) ) )
2192
2213
}
2214
+
2215
+ // FIXME(eddyb) check this via value ranges on scalars.
2193
2216
( & Layout :: General { discr, .. } , _, & ty:: TyAdt ( def, _) ) => {
2194
2217
if def. discriminants ( tcx) . all ( |d| d. to_u128_unchecked ( ) != 0 ) {
2195
2218
Ok ( Some ( ( self . fields . offset ( 0 ) , discr) ) )
@@ -2198,28 +2221,28 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2198
2221
}
2199
2222
}
2200
2223
2201
- ( & Layout :: FatPointer , _, _) if !self . ty . is_unsafe_ptr ( ) => {
2202
- Ok ( Some ( ( self . fields . offset ( FAT_PTR_ADDR ) , Pointer ) ) )
2203
- }
2204
-
2205
2224
// Is this the NonZero lang item wrapping a pointer or integer type?
2206
2225
( _, _, & ty:: TyAdt ( def, _) ) if Some ( def. did ) == tcx. lang_items ( ) . non_zero ( ) => {
2207
2226
let field = self . field ( cx, 0 ) ?;
2208
- match ( field. layout , field. abi ) {
2209
- ( & Layout :: Scalar , Abi :: Scalar ( value) ) => {
2210
- Ok ( Some ( ( self . fields . offset ( 0 ) , value) ) )
2211
- }
2212
- ( & Layout :: FatPointer , _) => {
2213
- Ok ( Some ( ( self . fields . offset ( 0 ) +
2214
- field. fields . offset ( FAT_PTR_ADDR ) ,
2215
- Pointer ) ) )
2216
- }
2217
- _ => Ok ( None )
2227
+ let offset = self . fields . offset ( 0 ) ;
2228
+ if let Abi :: Scalar ( value) = field. abi {
2229
+ Ok ( Some ( ( offset, value) ) )
2230
+ } else if let ty:: TyRawPtr ( _) = field. ty . sty {
2231
+ // If `NonZero` contains a non-scalar `*T`, it's
2232
+ // a fat pointer, which starts with a thin pointer.
2233
+ Ok ( Some ( ( offset, Pointer ) ) )
2234
+ } else {
2235
+ Ok ( None )
2218
2236
}
2219
2237
}
2220
2238
2221
2239
// Perhaps one of the fields is non-zero, let's recurse and find out.
2222
- ( & Layout :: Univariant , _, _) => {
2240
+ _ => {
2241
+ if let FieldPlacement :: Array { count, .. } = * self . fields {
2242
+ if count > 0 {
2243
+ return self . field ( cx, 0 ) ?. non_zero_field ( cx) ;
2244
+ }
2245
+ }
2223
2246
for i in 0 ..self . fields . count ( ) {
2224
2247
let r = self . field ( cx, i) ?. non_zero_field ( cx) ?;
2225
2248
if let Some ( ( offset, primitive) ) = r {
@@ -2228,23 +2251,6 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2228
2251
}
2229
2252
Ok ( None )
2230
2253
}
2231
-
2232
- // Is this a fixed-size array of something non-zero
2233
- // with at least one element?
2234
- ( _, _, & ty:: TyArray ( ety, _) ) => {
2235
- if self . fields . count ( ) != 0 {
2236
- cx. layout_of ( ety) ?. non_zero_field ( cx)
2237
- } else {
2238
- Ok ( None )
2239
- }
2240
- }
2241
-
2242
- ( _, _, & ty:: TyProjection ( _) ) | ( _, _, & ty:: TyAnon ( ..) ) => {
2243
- bug ! ( "FullLayout::non_zero_field: {:#?} not normalized" , self ) ;
2244
- }
2245
-
2246
- // Anything else is not a non-zero type.
2247
- _ => Ok ( None )
2248
2254
}
2249
2255
}
2250
2256
}
@@ -2260,7 +2266,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Layout {
2260
2266
Scalar => { }
2261
2267
Vector => { }
2262
2268
Array => { }
2263
- FatPointer => { }
2264
2269
Univariant => { }
2265
2270
UntaggedUnion => { }
2266
2271
General {
0 commit comments