@@ -1193,6 +1193,82 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
1193
1193
}
1194
1194
}
1195
1195
1196
+ fn should_encode_fn_sig ( def_kind : DefKind ) -> bool {
1197
+ match def_kind {
1198
+ DefKind :: Fn | DefKind :: AssocFn | DefKind :: Ctor ( _, CtorKind :: Fn ) => true ,
1199
+
1200
+ DefKind :: Struct
1201
+ | DefKind :: Union
1202
+ | DefKind :: Enum
1203
+ | DefKind :: Variant
1204
+ | DefKind :: Field
1205
+ | DefKind :: Const
1206
+ | DefKind :: Static ( ..)
1207
+ | DefKind :: Ctor ( ..)
1208
+ | DefKind :: TyAlias
1209
+ | DefKind :: OpaqueTy
1210
+ | DefKind :: ImplTraitPlaceholder
1211
+ | DefKind :: ForeignTy
1212
+ | DefKind :: Impl { .. }
1213
+ | DefKind :: AssocConst
1214
+ | DefKind :: Closure
1215
+ | DefKind :: Generator
1216
+ | DefKind :: ConstParam
1217
+ | DefKind :: AnonConst
1218
+ | DefKind :: InlineConst
1219
+ | DefKind :: AssocTy
1220
+ | DefKind :: TyParam
1221
+ | DefKind :: Trait
1222
+ | DefKind :: TraitAlias
1223
+ | DefKind :: Mod
1224
+ | DefKind :: ForeignMod
1225
+ | DefKind :: Macro ( ..)
1226
+ | DefKind :: Use
1227
+ | DefKind :: LifetimeParam
1228
+ | DefKind :: GlobalAsm
1229
+ | DefKind :: ExternCrate => false ,
1230
+ }
1231
+ }
1232
+
1233
+ fn should_encode_constness ( def_kind : DefKind ) -> bool {
1234
+ match def_kind {
1235
+ DefKind :: Fn
1236
+ | DefKind :: AssocFn
1237
+ | DefKind :: Closure
1238
+ | DefKind :: Impl { of_trait : true }
1239
+ | DefKind :: Variant
1240
+ | DefKind :: Ctor ( ..) => true ,
1241
+
1242
+ DefKind :: Struct
1243
+ | DefKind :: Union
1244
+ | DefKind :: Enum
1245
+ | DefKind :: Field
1246
+ | DefKind :: Const
1247
+ | DefKind :: AssocConst
1248
+ | DefKind :: AnonConst
1249
+ | DefKind :: Static ( ..)
1250
+ | DefKind :: TyAlias
1251
+ | DefKind :: OpaqueTy
1252
+ | DefKind :: Impl { of_trait : false }
1253
+ | DefKind :: ImplTraitPlaceholder
1254
+ | DefKind :: ForeignTy
1255
+ | DefKind :: Generator
1256
+ | DefKind :: ConstParam
1257
+ | DefKind :: InlineConst
1258
+ | DefKind :: AssocTy
1259
+ | DefKind :: TyParam
1260
+ | DefKind :: Trait
1261
+ | DefKind :: TraitAlias
1262
+ | DefKind :: Mod
1263
+ | DefKind :: ForeignMod
1264
+ | DefKind :: Macro ( ..)
1265
+ | DefKind :: Use
1266
+ | DefKind :: LifetimeParam
1267
+ | DefKind :: GlobalAsm
1268
+ | DefKind :: ExternCrate => false ,
1269
+ }
1270
+ }
1271
+
1196
1272
fn should_encode_const ( def_kind : DefKind ) -> bool {
1197
1273
match def_kind {
1198
1274
DefKind :: Const | DefKind :: AssocConst | DefKind :: AnonConst | DefKind :: InlineConst => true ,
@@ -1305,6 +1381,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1305
1381
let v = self . tcx . variances_of ( def_id) ;
1306
1382
record_array ! ( self . tables. variances_of[ def_id] <- v) ;
1307
1383
}
1384
+ if should_encode_fn_sig ( def_kind) {
1385
+ record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1386
+ }
1308
1387
if should_encode_generics ( def_kind) {
1309
1388
let g = tcx. generics_of ( def_id) ;
1310
1389
record ! ( self . tables. generics_of[ def_id] <- g) ;
@@ -1315,11 +1394,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1315
1394
if should_encode_type ( tcx, local_id, def_kind) {
1316
1395
record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1317
1396
}
1397
+ if should_encode_constness ( def_kind) {
1398
+ self . tables . constness . set_some ( def_id. index , self . tcx . constness ( def_id) ) ;
1399
+ }
1318
1400
if let DefKind :: Fn | DefKind :: AssocFn = def_kind {
1319
1401
self . tables . asyncness . set_some ( def_id. index , tcx. asyncness ( def_id) ) ;
1320
- self . tables . constness . set_some ( def_id. index , tcx. constness ( def_id) ) ;
1321
1402
record_array ! ( self . tables. fn_arg_names[ def_id] <- tcx. fn_arg_names( def_id) ) ;
1322
- record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1323
1403
self . tables . is_intrinsic . set ( def_id. index , tcx. is_intrinsic ( def_id) ) ;
1324
1404
}
1325
1405
if let DefKind :: TyParam = def_kind {
@@ -1333,6 +1413,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1333
1413
record ! ( self . tables. super_predicates_of[ def_id] <- self . tcx. super_predicates_of( def_id) ) ;
1334
1414
record ! ( self . tables. implied_predicates_of[ def_id] <- self . tcx. implied_predicates_of( def_id) ) ;
1335
1415
}
1416
+ if let DefKind :: Generator = def_kind {
1417
+ self . encode_info_for_generator ( local_id) ;
1418
+ }
1336
1419
if let DefKind :: Enum | DefKind :: Struct | DefKind :: Union = def_kind {
1337
1420
self . encode_info_for_adt ( local_id) ;
1338
1421
}
@@ -1396,16 +1479,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1396
1479
} ;
1397
1480
record ! ( self . tables. variant_data[ variant. def_id] <- data) ;
1398
1481
1399
- self . tables . constness . set_some ( variant. def_id . index , hir:: Constness :: Const ) ;
1400
1482
record_array ! ( self . tables. associated_item_or_field_def_ids[ variant. def_id] <- variant. fields. iter( ) . map( |f| {
1401
1483
assert!( f. did. is_local( ) ) ;
1402
1484
f. did. index
1403
1485
} ) ) ;
1404
1486
1405
1487
if let Some ( ( CtorKind :: Fn , ctor_def_id) ) = variant. ctor {
1406
- self . tables . constness . set_some ( ctor_def_id. index , hir:: Constness :: Const ) ;
1407
1488
let fn_sig = tcx. fn_sig ( ctor_def_id) ;
1408
- record ! ( self . tables. fn_sig[ ctor_def_id] <- fn_sig) ;
1409
1489
// FIXME only encode signature for ctor_def_id
1410
1490
record ! ( self . tables. fn_sig[ variant. def_id] <- fn_sig) ;
1411
1491
}
@@ -1627,9 +1707,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1627
1707
matches ! ( opaque. origin, hir:: OpaqueTyOrigin :: TyAlias { .. } ) ,
1628
1708
) ;
1629
1709
}
1630
- hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness , .. } ) => {
1710
+ hir:: ItemKind :: Impl ( hir:: Impl { defaultness, .. } ) => {
1631
1711
self . tables . defaultness . set_some ( def_id. index , * defaultness) ;
1632
- self . tables . constness . set_some ( def_id. index , * constness) ;
1633
1712
self . tables . impl_polarity . set_some ( def_id. index , self . tcx . impl_polarity ( def_id) ) ;
1634
1713
1635
1714
if let Some ( trait_ref) = self . tcx . impl_trait_ref ( def_id) {
@@ -1689,28 +1768,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1689
1768
}
1690
1769
1691
1770
#[ instrument( level = "debug" , skip( self ) ) ]
1692
- fn encode_info_for_closure ( & mut self , def_id : LocalDefId ) {
1693
- // NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
1694
- // including on the signature, which is inferred in `typeck`.
1771
+ fn encode_info_for_generator ( & mut self , def_id : LocalDefId ) {
1695
1772
let typeck_result: & ' tcx ty:: TypeckResults < ' tcx > = self . tcx . typeck ( def_id) ;
1696
- let hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1697
- let ty = typeck_result. node_type ( hir_id) ;
1698
- match ty. kind ( ) {
1699
- ty:: Generator ( ..) => {
1700
- let data = self . tcx . generator_kind ( def_id) . unwrap ( ) ;
1701
- let generator_diagnostic_data = typeck_result. get_generator_diagnostic_data ( ) ;
1702
- record ! ( self . tables. generator_kind[ def_id. to_def_id( ) ] <- data) ;
1703
- record ! ( self . tables. generator_diagnostic_data[ def_id. to_def_id( ) ] <- generator_diagnostic_data) ;
1704
- }
1705
-
1706
- ty:: Closure ( _, substs) => {
1707
- let constness = self . tcx . constness ( def_id. to_def_id ( ) ) ;
1708
- self . tables . constness . set_some ( def_id. to_def_id ( ) . index , constness) ;
1709
- record ! ( self . tables. fn_sig[ def_id. to_def_id( ) ] <- ty:: EarlyBinder :: bind( substs. as_closure( ) . sig( ) ) ) ;
1710
- }
1711
-
1712
- _ => bug ! ( "closure that is neither generator nor closure" ) ,
1713
- }
1773
+ let data = self . tcx . generator_kind ( def_id) . unwrap ( ) ;
1774
+ let generator_diagnostic_data = typeck_result. get_generator_diagnostic_data ( ) ;
1775
+ record ! ( self . tables. generator_kind[ def_id. to_def_id( ) ] <- data) ;
1776
+ record ! ( self . tables. generator_diagnostic_data[ def_id. to_def_id( ) ] <- generator_diagnostic_data) ;
1714
1777
}
1715
1778
1716
1779
fn encode_native_libraries ( & mut self ) -> LazyArray < NativeLib > {
@@ -2059,10 +2122,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
2059
2122
fn nested_visit_map ( & mut self ) -> Self :: Map {
2060
2123
self . tcx . hir ( )
2061
2124
}
2062
- fn visit_expr ( & mut self , ex : & ' tcx hir:: Expr < ' tcx > ) {
2063
- intravisit:: walk_expr ( self , ex) ;
2064
- self . encode_info_for_expr ( ex) ;
2065
- }
2066
2125
fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
2067
2126
intravisit:: walk_item ( self , item) ;
2068
2127
self . encode_info_for_item ( item) ;
@@ -2087,12 +2146,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
2087
2146
}
2088
2147
}
2089
2148
}
2090
-
2091
- fn encode_info_for_expr ( & mut self , expr : & hir:: Expr < ' _ > ) {
2092
- if let hir:: ExprKind :: Closure ( closure) = expr. kind {
2093
- self . encode_info_for_closure ( closure. def_id ) ;
2094
- }
2095
- }
2096
2149
}
2097
2150
2098
2151
/// Used to prefetch queries which will be needed later by metadata encoding.
0 commit comments