@@ -17,9 +17,8 @@ use rustc_hir::def_id::{
17
17
CrateNum , DefId , DefIndex , LocalDefId , CRATE_DEF_ID , CRATE_DEF_INDEX , LOCAL_CRATE ,
18
18
} ;
19
19
use rustc_hir:: definitions:: DefPathData ;
20
- use rustc_hir:: intravisit:: { self , Visitor } ;
20
+ use rustc_hir:: intravisit;
21
21
use rustc_hir:: lang_items:: LangItem ;
22
- use rustc_middle:: hir:: nested_filter;
23
22
use rustc_middle:: middle:: debugger_visualizer:: DebuggerVisualizerFile ;
24
23
use rustc_middle:: middle:: dependency_format:: Linkage ;
25
24
use rustc_middle:: middle:: exported_symbols:: {
@@ -450,18 +449,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
450
449
LazyArray :: from_position_and_num_elems ( pos, len)
451
450
}
452
451
453
- fn encode_info_for_items ( & mut self ) {
454
- self . encode_info_for_mod ( CRATE_DEF_ID ) ;
455
-
456
- // Proc-macro crates only export proc-macro items, which are looked
457
- // up using `proc_macro_data`
458
- if self . is_proc_macro {
459
- return ;
460
- }
461
-
462
- self . tcx . hir ( ) . visit_all_item_likes_in_crate ( self ) ;
463
- }
464
-
465
452
fn encode_def_path_table ( & mut self ) {
466
453
let table = self . tcx . def_path_table ( ) ;
467
454
if self . is_proc_macro {
@@ -607,8 +594,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
607
594
608
595
_ = stat ! ( "def-ids" , || self . encode_def_ids( ) ) ;
609
596
610
- _ = stat ! ( "items" , || self . encode_info_for_items( ) ) ;
611
-
612
597
let interpret_alloc_index = stat ! ( "interpret-alloc-index" , || {
613
598
let mut interpret_alloc_index = Vec :: new( ) ;
614
599
let mut n = 0 ;
@@ -1341,10 +1326,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1341
1326
}
1342
1327
1343
1328
fn encode_def_ids ( & mut self ) {
1329
+ self . encode_info_for_mod ( CRATE_DEF_ID ) ;
1330
+
1331
+ // Proc-macro crates only export proc-macro items, which are looked
1332
+ // up using `proc_macro_data`
1344
1333
if self . is_proc_macro {
1345
1334
return ;
1346
1335
}
1336
+
1347
1337
let tcx = self . tcx ;
1338
+
1348
1339
for local_id in tcx. iter_local_def_id ( ) {
1349
1340
let def_id = local_id. to_def_id ( ) ;
1350
1341
let def_kind = tcx. opt_def_kind ( local_id) ;
@@ -1390,6 +1381,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1390
1381
record ! ( self . tables. explicit_predicates_of[ def_id] <- self . tcx. explicit_predicates_of( def_id) ) ;
1391
1382
let inferred_outlives = self . tcx . inferred_outlives_of ( def_id) ;
1392
1383
record_defaulted_array ! ( self . tables. inferred_outlives_of[ def_id] <- inferred_outlives) ;
1384
+
1385
+ for param in & g. params {
1386
+ if let ty:: GenericParamDefKind :: Const { has_default : true , .. } = param. kind {
1387
+ let default = self . tcx . const_param_default ( param. def_id ) ;
1388
+ record ! ( self . tables. const_param_default[ param. def_id] <- default ) ;
1389
+ }
1390
+ }
1393
1391
}
1394
1392
if should_encode_type ( tcx, local_id, def_kind) {
1395
1393
record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
@@ -1440,6 +1438,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1440
1438
if let DefKind :: Enum | DefKind :: Struct | DefKind :: Union = def_kind {
1441
1439
self . encode_info_for_adt ( local_id) ;
1442
1440
}
1441
+ if let DefKind :: Mod = def_kind {
1442
+ self . encode_info_for_mod ( local_id) ;
1443
+ }
1444
+ if let DefKind :: Macro ( _) = def_kind {
1445
+ self . encode_info_for_macro ( local_id) ;
1446
+ }
1447
+ if let DefKind :: OpaqueTy = def_kind {
1448
+ self . encode_explicit_item_bounds ( def_id) ;
1449
+ self . tables
1450
+ . is_type_alias_impl_trait
1451
+ . set ( def_id. index , self . tcx . is_type_alias_impl_trait ( def_id) ) ;
1452
+ }
1443
1453
if tcx. impl_method_has_trait_impl_trait_tys ( def_id)
1444
1454
&& let Ok ( table) = self . tcx . collect_return_position_impl_trait_in_trait_tys ( def_id)
1445
1455
{
@@ -1513,10 +1523,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1513
1523
}
1514
1524
}
1515
1525
1526
+ #[ tracing:: instrument( level = "debug" , skip( self ) ) ]
1516
1527
fn encode_info_for_mod ( & mut self , local_def_id : LocalDefId ) {
1517
1528
let tcx = self . tcx ;
1518
1529
let def_id = local_def_id. to_def_id ( ) ;
1519
- debug ! ( "EncodeContext::encode_info_for_mod({:?})" , def_id) ;
1520
1530
1521
1531
// If we are encoding a proc-macro crates, `encode_info_for_mod` will
1522
1532
// only ever get called for the crate root. We still want to encode
@@ -1689,40 +1699,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1689
1699
} )
1690
1700
}
1691
1701
1692
- fn encode_info_for_item ( & mut self , item : & ' tcx hir :: Item < ' tcx > ) {
1693
- let def_id = item . owner_id . to_def_id ( ) ;
1694
- debug ! ( "EncodeContext::encode_info_for_item({:?})" , def_id ) ;
1702
+ # [ tracing :: instrument ( level = "debug" , skip ( self ) ) ]
1703
+ fn encode_info_for_macro ( & mut self , def_id : LocalDefId ) {
1704
+ let tcx = self . tcx ;
1695
1705
1696
- match item. kind {
1697
- hir:: ItemKind :: Macro ( ref macro_def, _) => {
1698
- self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
1699
- record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
1700
- }
1701
- hir:: ItemKind :: Mod ( ..) => {
1702
- self . encode_info_for_mod ( item. owner_id . def_id ) ;
1703
- }
1704
- hir:: ItemKind :: OpaqueTy ( ref opaque) => {
1705
- self . encode_explicit_item_bounds ( def_id) ;
1706
- self . tables . is_type_alias_impl_trait . set (
1707
- def_id. index ,
1708
- matches ! ( opaque. origin, hir:: OpaqueTyOrigin :: TyAlias { .. } ) ,
1709
- ) ;
1710
- }
1711
- hir:: ItemKind :: ExternCrate ( _)
1712
- | hir:: ItemKind :: Use ( ..)
1713
- | hir:: ItemKind :: Impl ( ..)
1714
- | hir:: ItemKind :: Trait ( ..)
1715
- | hir:: ItemKind :: TraitAlias ( ..)
1716
- | hir:: ItemKind :: Static ( ..)
1717
- | hir:: ItemKind :: Const ( ..)
1718
- | hir:: ItemKind :: Enum ( ..)
1719
- | hir:: ItemKind :: Struct ( ..)
1720
- | hir:: ItemKind :: Union ( ..)
1721
- | hir:: ItemKind :: ForeignMod { .. }
1722
- | hir:: ItemKind :: GlobalAsm ( ..)
1723
- | hir:: ItemKind :: Fn ( ..)
1724
- | hir:: ItemKind :: TyAlias ( ..) => { }
1725
- }
1706
+ let hir:: ItemKind :: Macro ( ref macro_def, _) = tcx. hir ( ) . expect_item ( def_id) . kind else { bug ! ( ) } ;
1707
+ self . tables . is_macro_rules . set ( def_id. local_def_index , macro_def. macro_rules ) ;
1708
+ record ! ( self . tables. macro_definition[ def_id. to_def_id( ) ] <- & * macro_def. body) ;
1726
1709
}
1727
1710
1728
1711
#[ tracing:: instrument( level = "debug" , skip( self ) ) ]
@@ -2100,39 +2083,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
2100
2083
}
2101
2084
}
2102
2085
2103
- // FIXME(eddyb) make metadata encoding walk over all definitions, instead of HIR.
2104
- impl < ' a , ' tcx > Visitor < ' tcx > for EncodeContext < ' a , ' tcx > {
2105
- type NestedFilter = nested_filter:: OnlyBodies ;
2106
-
2107
- fn nested_visit_map ( & mut self ) -> Self :: Map {
2108
- self . tcx . hir ( )
2109
- }
2110
- fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
2111
- intravisit:: walk_item ( self , item) ;
2112
- self . encode_info_for_item ( item) ;
2113
- }
2114
- fn visit_generics ( & mut self , generics : & ' tcx hir:: Generics < ' tcx > ) {
2115
- intravisit:: walk_generics ( self , generics) ;
2116
- self . encode_info_for_generics ( generics) ;
2117
- }
2118
- }
2119
-
2120
- impl < ' a , ' tcx > EncodeContext < ' a , ' tcx > {
2121
- fn encode_info_for_generics ( & mut self , generics : & hir:: Generics < ' tcx > ) {
2122
- for param in generics. params {
2123
- match param. kind {
2124
- hir:: GenericParamKind :: Lifetime { .. } | hir:: GenericParamKind :: Type { .. } => { }
2125
- hir:: GenericParamKind :: Const { ref default, .. } => {
2126
- let def_id = param. def_id . to_def_id ( ) ;
2127
- if default. is_some ( ) {
2128
- record ! ( self . tables. const_param_default[ def_id] <- self . tcx. const_param_default( def_id) )
2129
- }
2130
- }
2131
- }
2132
- }
2133
- }
2134
- }
2135
-
2136
2086
/// Used to prefetch queries which will be needed later by metadata encoding.
2137
2087
/// Only a subset of the queries are actually prefetched to keep this code smaller.
2138
2088
fn prefetch_mir ( tcx : TyCtxt < ' _ > ) {
0 commit comments