@@ -1020,6 +1020,54 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
1020
1020
}
1021
1021
}
1022
1022
1023
+ fn should_encode_type ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , def_kind : DefKind ) -> bool {
1024
+ match def_kind {
1025
+ DefKind :: Struct
1026
+ | DefKind :: Union
1027
+ | DefKind :: Enum
1028
+ | DefKind :: Variant
1029
+ | DefKind :: Ctor ( ..)
1030
+ | DefKind :: Field
1031
+ | DefKind :: Fn
1032
+ | DefKind :: Const
1033
+ | DefKind :: Static ( ..)
1034
+ | DefKind :: TyAlias
1035
+ | DefKind :: OpaqueTy
1036
+ | DefKind :: ForeignTy
1037
+ | DefKind :: Impl
1038
+ | DefKind :: AssocFn
1039
+ | DefKind :: AssocConst
1040
+ | DefKind :: Closure
1041
+ | DefKind :: Generator
1042
+ | DefKind :: ConstParam
1043
+ | DefKind :: AnonConst
1044
+ | DefKind :: InlineConst => true ,
1045
+
1046
+ DefKind :: AssocTy => {
1047
+ let assoc_item = tcx. associated_item ( def_id) ;
1048
+ match assoc_item. container {
1049
+ ty:: AssocItemContainer :: ImplContainer => true ,
1050
+ ty:: AssocItemContainer :: TraitContainer => assoc_item. defaultness ( tcx) . has_value ( ) ,
1051
+ }
1052
+ }
1053
+ DefKind :: TyParam => {
1054
+ let hir:: Node :: GenericParam ( param) = tcx. hir ( ) . get_by_def_id ( def_id) else { bug ! ( ) } ;
1055
+ let hir:: GenericParamKind :: Type { default, .. } = param. kind else { bug ! ( ) } ;
1056
+ default. is_some ( )
1057
+ }
1058
+
1059
+ DefKind :: Trait
1060
+ | DefKind :: TraitAlias
1061
+ | DefKind :: Mod
1062
+ | DefKind :: ForeignMod
1063
+ | DefKind :: Macro ( ..)
1064
+ | DefKind :: Use
1065
+ | DefKind :: LifetimeParam
1066
+ | DefKind :: GlobalAsm
1067
+ | DefKind :: ExternCrate => false ,
1068
+ }
1069
+ }
1070
+
1023
1071
impl < ' a , ' tcx > EncodeContext < ' a , ' tcx > {
1024
1072
fn encode_attrs ( & mut self , def_id : LocalDefId ) {
1025
1073
let mut attrs = self
@@ -1076,6 +1124,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1076
1124
record_array ! ( self . tables. inferred_outlives_of[ def_id] <- inferred_outlives) ;
1077
1125
}
1078
1126
}
1127
+ if should_encode_type ( tcx, local_id, def_kind) {
1128
+ record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1129
+ }
1079
1130
if let DefKind :: TyParam | DefKind :: ConstParam = def_kind {
1080
1131
if let Some ( default) = self . tcx . object_lifetime_default ( def_id) {
1081
1132
record ! ( self . tables. object_lifetime_default[ def_id] <- default ) ;
@@ -1097,11 +1148,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1097
1148
}
1098
1149
}
1099
1150
1100
- fn encode_item_type ( & mut self , def_id : DefId ) {
1101
- debug ! ( "EncodeContext::encode_item_type({:?})" , def_id) ;
1102
- record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1103
- }
1104
-
1105
1151
fn encode_enum_variant_info ( & mut self , def : ty:: AdtDef < ' tcx > , index : VariantIdx ) {
1106
1152
let tcx = self . tcx ;
1107
1153
let variant = & def. variant ( index) ;
@@ -1121,7 +1167,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1121
1167
assert!( f. did. is_local( ) ) ;
1122
1168
f. did. index
1123
1169
} ) ) ;
1124
- self . encode_item_type ( def_id) ;
1125
1170
if variant. ctor_kind == CtorKind :: Fn {
1126
1171
// FIXME(eddyb) encode signature only in `encode_enum_variant_ctor`.
1127
1172
if let Some ( ctor_def_id) = variant. ctor_def_id {
@@ -1146,7 +1191,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1146
1191
1147
1192
record ! ( self . tables. kind[ def_id] <- EntryKind :: Variant ( self . lazy( data) ) ) ;
1148
1193
self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1149
- self . encode_item_type ( def_id) ;
1150
1194
if variant. ctor_kind == CtorKind :: Fn {
1151
1195
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1152
1196
}
@@ -1212,7 +1256,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1212
1256
debug ! ( "EncodeContext::encode_field({:?})" , def_id) ;
1213
1257
1214
1258
record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
1215
- self . encode_item_type ( def_id) ;
1216
1259
}
1217
1260
1218
1261
fn encode_struct_ctor ( & mut self , adt_def : ty:: AdtDef < ' tcx > , def_id : DefId ) {
@@ -1230,7 +1273,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1230
1273
record ! ( self . tables. repr_options[ def_id] <- adt_def. repr( ) ) ;
1231
1274
self . tables . constness . set ( def_id. index , hir:: Constness :: Const ) ;
1232
1275
record ! ( self . tables. kind[ def_id] <- EntryKind :: Struct ( self . lazy( data) ) ) ;
1233
- self . encode_item_type ( def_id) ;
1234
1276
if variant. ctor_kind == CtorKind :: Fn {
1235
1277
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1236
1278
}
@@ -1285,16 +1327,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1285
1327
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocType ( ty:: AssocItemContainer :: TraitContainer ) ) ;
1286
1328
}
1287
1329
}
1288
- match trait_item. kind {
1289
- ty:: AssocKind :: Const | ty:: AssocKind :: Fn => {
1290
- self . encode_item_type ( def_id) ;
1291
- }
1292
- ty:: AssocKind :: Type => {
1293
- if ast_item. defaultness . has_value ( ) {
1294
- self . encode_item_type ( def_id) ;
1295
- }
1296
- }
1297
- }
1298
1330
if trait_item. kind == ty:: AssocKind :: Fn {
1299
1331
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1300
1332
}
@@ -1341,7 +1373,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1341
1373
record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocType ( ty:: AssocItemContainer :: ImplContainer ) ) ;
1342
1374
}
1343
1375
}
1344
- self . encode_item_type ( def_id) ;
1345
1376
if let Some ( trait_item_def_id) = impl_item. trait_item_def_id {
1346
1377
self . tables . trait_item_def_id . set ( def_id. index , trait_item_def_id. into ( ) ) ;
1347
1378
}
@@ -1590,18 +1621,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1590
1621
}
1591
1622
_ => { }
1592
1623
}
1593
- match item. kind {
1594
- hir:: ItemKind :: Static ( ..)
1595
- | hir:: ItemKind :: Const ( ..)
1596
- | hir:: ItemKind :: Fn ( ..)
1597
- | hir:: ItemKind :: TyAlias ( ..)
1598
- | hir:: ItemKind :: OpaqueTy ( ..)
1599
- | hir:: ItemKind :: Enum ( ..)
1600
- | hir:: ItemKind :: Struct ( ..)
1601
- | hir:: ItemKind :: Union ( ..)
1602
- | hir:: ItemKind :: Impl { .. } => self . encode_item_type ( def_id) ,
1603
- _ => { }
1604
- }
1605
1624
if let hir:: ItemKind :: Fn ( ..) = item. kind {
1606
1625
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1607
1626
if tcx. is_intrinsic ( def_id) {
@@ -1615,13 +1634,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1615
1634
}
1616
1635
}
1617
1636
1618
- fn encode_info_for_generic_param ( & mut self , def_id : DefId , kind : EntryKind , encode_type : bool ) {
1619
- record ! ( self . tables. kind[ def_id] <- kind) ;
1620
- if encode_type {
1621
- self . encode_item_type ( def_id) ;
1622
- }
1623
- }
1624
-
1625
1637
fn encode_info_for_closure ( & mut self , hir_id : hir:: HirId ) {
1626
1638
let def_id = self . tcx . hir ( ) . local_def_id ( hir_id) ;
1627
1639
debug ! ( "EncodeContext::encode_info_for_closure({:?})" , def_id) ;
@@ -1638,16 +1650,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1638
1650
record ! ( self . tables. generator_diagnostic_data[ def_id. to_def_id( ) ] <- generator_diagnostic_data) ;
1639
1651
}
1640
1652
1641
- ty:: Closure ( .. ) => {
1653
+ ty:: Closure ( _ , substs ) => {
1642
1654
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: Closure ) ;
1655
+ record ! ( self . tables. fn_sig[ def_id. to_def_id( ) ] <- substs. as_closure( ) . sig( ) ) ;
1643
1656
}
1644
1657
1645
1658
_ => bug ! ( "closure that is neither generator nor closure" ) ,
1646
1659
}
1647
- self . encode_item_type ( def_id. to_def_id ( ) ) ;
1648
- if let ty:: Closure ( def_id, substs) = * ty. kind ( ) {
1649
- record ! ( self . tables. fn_sig[ def_id] <- substs. as_closure( ) . sig( ) ) ;
1650
- }
1651
1660
}
1652
1661
1653
1662
fn encode_info_for_anon_const ( & mut self , id : hir:: HirId ) {
@@ -1660,7 +1669,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1660
1669
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: AnonConst ) ;
1661
1670
record ! ( self . tables. mir_const_qualif[ def_id. to_def_id( ) ] <- qualifs) ;
1662
1671
record ! ( self . tables. rendered_const[ def_id. to_def_id( ) ] <- const_data) ;
1663
- self . encode_item_type ( def_id. to_def_id ( ) ) ;
1664
1672
}
1665
1673
1666
1674
fn encode_native_libraries ( & mut self ) -> LazyArray < NativeLib > {
@@ -1997,6 +2005,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1997
2005
} ;
1998
2006
self . tables . constness . set ( def_id. index , constness) ;
1999
2007
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignFn ) ;
2008
+ record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
2000
2009
}
2001
2010
hir:: ForeignItemKind :: Static ( ..) => {
2002
2011
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignStatic ) ;
@@ -2005,9 +2014,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
2005
2014
record ! ( self . tables. kind[ def_id] <- EntryKind :: ForeignType ) ;
2006
2015
}
2007
2016
}
2008
- self . encode_item_type ( def_id) ;
2009
2017
if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
2010
- record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
2011
2018
if tcx. is_intrinsic ( def_id) {
2012
2019
self . tables . is_intrinsic . set ( def_id. index , ( ) ) ;
2013
2020
}
@@ -2061,17 +2068,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
2061
2068
for param in generics. params {
2062
2069
let def_id = self . tcx . hir ( ) . local_def_id ( param. hir_id ) ;
2063
2070
match param. kind {
2064
- GenericParamKind :: Lifetime { .. } => continue ,
2065
- GenericParamKind :: Type { default, .. } => {
2066
- self . encode_info_for_generic_param (
2067
- def_id. to_def_id ( ) ,
2068
- EntryKind :: TypeParam ,
2069
- default. is_some ( ) ,
2070
- ) ;
2071
- }
2071
+ GenericParamKind :: Lifetime { .. } | GenericParamKind :: Type { .. } => { }
2072
2072
GenericParamKind :: Const { ref default, .. } => {
2073
2073
let def_id = def_id. to_def_id ( ) ;
2074
- self . encode_info_for_generic_param ( def_id, EntryKind :: ConstParam , true ) ;
2075
2074
if default. is_some ( ) {
2076
2075
record ! ( self . tables. const_param_default[ def_id] <- self . tcx. const_param_default( def_id) )
2077
2076
}
0 commit comments