@@ -1004,7 +1004,7 @@ pub const FAT_PTR_ADDR: usize = 0;
1004
1004
pub const FAT_PTR_EXTRA : usize = 1 ;
1005
1005
1006
1006
/// Describes how the fields of a type are located in memory.
1007
- #[ derive( Copy , Clone , Debug ) ]
1007
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
1008
1008
pub enum FieldPlacement < ' a > {
1009
1009
/// Array-like placement. Can also express
1010
1010
/// unions, by using a stride of zero bytes.
@@ -1058,7 +1058,7 @@ impl<'a> FieldPlacement<'a> {
1058
1058
1059
1059
/// Describes how values of the type are passed by target ABIs,
1060
1060
/// in terms of categories of C types there are ABI rules for.
1061
- #[ derive( Copy , Clone , Debug ) ]
1061
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
1062
1062
pub enum Abi {
1063
1063
Scalar ( Primitive ) ,
1064
1064
Vector {
@@ -1141,8 +1141,8 @@ impl Abi {
1141
1141
/// For ADTs, it also includes field placement and enum optimizations.
1142
1142
/// NOTE: Because Layout is interned, redundant information should be
1143
1143
/// kept to a minimum, e.g. it includes no sub-component Ty or Layout.
1144
- #[ derive( Debug , PartialEq , Eq , Hash ) ]
1145
- pub enum Layout {
1144
+ #[ derive( PartialEq , Eq , Hash , Debug ) ]
1145
+ pub enum Layout < ' a > {
1146
1146
/// TyBool, TyChar, TyInt, TyUint, TyFloat, TyRawPtr, TyRef or TyFnPtr.
1147
1147
Scalar ( Primitive ) ,
1148
1148
@@ -1184,7 +1184,7 @@ pub enum Layout {
1184
1184
// the largest space between two consecutive discriminants and
1185
1185
// taking everything else as the (shortest) discriminant range.
1186
1186
discr_range : RangeInclusive < u64 > ,
1187
- variants : Vec < Struct > ,
1187
+ variants : Vec < CachedLayout < ' a > > ,
1188
1188
size : Size ,
1189
1189
align : Align ,
1190
1190
primitive_align : Align ,
@@ -1202,7 +1202,7 @@ pub enum Layout {
1202
1202
nndiscr : u64 ,
1203
1203
discr : Primitive ,
1204
1204
discr_offset : Size ,
1205
- variants : Vec < Struct > ,
1205
+ variants : Vec < CachedLayout < ' a > > ,
1206
1206
size : Size ,
1207
1207
align : Align ,
1208
1208
primitive_align : Align ,
@@ -1228,9 +1228,9 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
1228
1228
}
1229
1229
}
1230
1230
1231
- #[ derive( Copy , Clone , Debug ) ]
1231
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
1232
1232
pub struct CachedLayout < ' tcx > {
1233
- pub layout : & ' tcx Layout ,
1233
+ pub layout : & ' tcx Layout < ' tcx > ,
1234
1234
pub fields : FieldPlacement < ' tcx > ,
1235
1235
pub abi : Abi ,
1236
1236
}
@@ -1262,7 +1262,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
1262
1262
} ;
1263
1263
}
1264
1264
1265
- impl < ' a , ' tcx > Layout {
1265
+ impl < ' a , ' tcx > Layout < ' tcx > {
1266
1266
fn compute_uncached ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1267
1267
param_env : ty:: ParamEnv < ' tcx > ,
1268
1268
ty : Ty < ' tcx > )
@@ -1624,7 +1624,9 @@ impl<'a, 'tcx> Layout {
1624
1624
size : st[ discr] . stride ( ) ,
1625
1625
align,
1626
1626
primitive_align,
1627
- variants : st,
1627
+ variants : st. into_iter ( ) . map ( |variant| {
1628
+ success ( Univariant ( variant) )
1629
+ } ) . collect :: < Result < Vec < _ > , _ > > ( ) ?,
1628
1630
} ) ;
1629
1631
}
1630
1632
}
@@ -1730,7 +1732,9 @@ impl<'a, 'tcx> Layout {
1730
1732
1731
1733
// FIXME: should be u128?
1732
1734
discr_range : ( min as u64 ) ..=( max as u64 ) ,
1733
- variants,
1735
+ variants : variants. into_iter ( ) . map ( |variant| {
1736
+ success ( Univariant ( variant) )
1737
+ } ) . collect :: < Result < Vec < _ > , _ > > ( ) ?,
1734
1738
size,
1735
1739
align,
1736
1740
primitive_align,
@@ -1897,6 +1901,10 @@ impl<'a, 'tcx> Layout {
1897
1901
. iter ( )
1898
1902
. map ( |f| ( f. name , f. ty ( tcx, substs) ) )
1899
1903
. collect ( ) ;
1904
+ let variant_layout = match * variant_layout. layout {
1905
+ Univariant ( ref variant) => variant,
1906
+ _ => bug ! ( )
1907
+ } ;
1900
1908
build_variant_info ( Some ( variant_def. name ) ,
1901
1909
& fields,
1902
1910
variant_layout)
@@ -2084,7 +2092,7 @@ impl<'a, 'tcx> SizeSkeleton<'tcx> {
2084
2092
pub struct FullLayout < ' tcx > {
2085
2093
pub ty : Ty < ' tcx > ,
2086
2094
pub variant_index : Option < usize > ,
2087
- pub layout : & ' tcx Layout ,
2095
+ pub layout : & ' tcx Layout < ' tcx > ,
2088
2096
pub fields : FieldPlacement < ' tcx > ,
2089
2097
pub abi : Abi ,
2090
2098
}
@@ -2198,27 +2206,22 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2198
2206
variants[ variant_index] . fields . len ( )
2199
2207
} ;
2200
2208
2201
- let ( fields, abi) = match * self . layout {
2202
- Univariant ( _) => ( self . fields , self . abi ) ,
2209
+ let ( layout , fields, abi) = match * self . layout {
2210
+ Univariant ( _) => ( self . layout , self . fields , self . abi ) ,
2203
2211
2204
2212
NullablePointer { ref variants, .. } |
2205
2213
General { ref variants, .. } => {
2206
- let variant = & variants[ variant_index] ;
2207
- ( FieldPlacement :: Arbitrary {
2208
- offsets : & variant. offsets
2209
- } , Abi :: Aggregate {
2210
- sized : true ,
2211
- align : variant. align ,
2212
- primitive_align : variant. primitive_align ,
2213
- size : variant. stride ( ) ,
2214
- } )
2214
+ let variant = variants[ variant_index] ;
2215
+ ( variant. layout , variant. fields , variant. abi )
2215
2216
}
2216
2217
2217
- _ => ( FieldPlacement :: union ( count ) , self . abi )
2218
+ _ => bug ! ( )
2218
2219
} ;
2220
+ assert_eq ! ( fields. count( ) , count) ;
2219
2221
2220
2222
FullLayout {
2221
2223
variant_index : Some ( variant_index) ,
2224
+ layout,
2222
2225
fields,
2223
2226
abi,
2224
2227
..* self
@@ -2348,8 +2351,7 @@ impl<'a, 'tcx> FullLayout<'tcx> {
2348
2351
}
2349
2352
}
2350
2353
2351
- impl < ' gcx > HashStable < StableHashingContext < ' gcx > > for Layout
2352
- {
2354
+ impl < ' gcx > HashStable < StableHashingContext < ' gcx > > for Layout < ' gcx > {
2353
2355
fn hash_stable < W : StableHasherResult > ( & self ,
2354
2356
hcx : & mut StableHashingContext < ' gcx > ,
2355
2357
hasher : & mut StableHasher < W > ) {
0 commit comments