@@ -7,7 +7,7 @@ use rustc_ast::visit::{VisitorResult, walk_list};
77use rustc_data_structures:: fingerprint:: Fingerprint ;
88use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
99use rustc_data_structures:: svh:: Svh ;
10- use rustc_data_structures:: sync:: { DynSend , DynSync , par_for_each_in, spawn , try_par_for_each_in} ;
10+ use rustc_data_structures:: sync:: { DynSend , DynSync , par_for_each_in, try_par_for_each_in} ;
1111use rustc_hir:: def:: { DefKind , Res } ;
1212use rustc_hir:: def_id:: { DefId , LOCAL_CRATE , LocalDefId , LocalModDefId } ;
1313use rustc_hir:: definitions:: { DefKey , DefPath , DefPathHash } ;
@@ -835,18 +835,8 @@ impl<'tcx> TyCtxt<'tcx> {
835835 }
836836
837837 #[ inline]
838- fn hir_opt_ident ( self , id : HirId ) -> Option < Ident > {
839- match self . hir_node ( id) {
840- Node :: Pat ( & Pat { kind : PatKind :: Binding ( _, _, ident, _) , .. } ) => Some ( ident) ,
841- // A `Ctor` doesn't have an identifier itself, but its parent
842- // struct/variant does. Compare with `hir::Map::span`.
843- Node :: Ctor ( ..) => match self . parent_hir_node ( id) {
844- Node :: Item ( item) => Some ( item. kind . ident ( ) . unwrap ( ) ) ,
845- Node :: Variant ( variant) => Some ( variant. ident ) ,
846- _ => unreachable ! ( ) ,
847- } ,
848- node => node. ident ( ) ,
849- }
838+ pub fn hir_opt_ident ( self , id : HirId ) -> Option < Ident > {
839+ self . hir_crate ( ( ) ) . opt_ident ( self , id)
850840 }
851841
852842 #[ inline]
@@ -1115,6 +1105,10 @@ impl<'tcx> intravisit::HirTyCtxt<'tcx> for TyCtxt<'tcx> {
11151105 fn hir_foreign_item ( & self , id : ForeignItemId ) -> & ' tcx ForeignItem < ' tcx > {
11161106 ( * self ) . hir_foreign_item ( id)
11171107 }
1108+
1109+ fn is_delayed ( & self , id : LocalDefId ) -> bool {
1110+ ( * self ) . hir_crate ( ( ) ) . delayed_ids . contains ( & id)
1111+ }
11181112}
11191113
11201114impl < ' tcx > pprust_hir:: PpAnn for TyCtxt < ' tcx > {
@@ -1212,8 +1206,14 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
12121206 upstream_crates
12131207}
12141208
1209+ #[ derive( Clone , Copy ) ]
1210+ enum ItemCollectionKind {
1211+ Crate ,
1212+ Mod ( LocalModDefId ) ,
1213+ }
1214+
12151215pub ( super ) fn hir_module_items ( tcx : TyCtxt < ' _ > , module_id : LocalModDefId ) -> ModuleItems {
1216- let mut collector = ItemCollector :: new ( tcx, false ) ;
1216+ let mut collector = ItemCollector :: new ( tcx, ItemCollectionKind :: Mod ( module_id ) ) ;
12171217
12181218 let ( hir_mod, span, hir_id) = tcx. hir_get_module ( module_id) ;
12191219 collector. visit_mod ( hir_mod, span, hir_id) ;
@@ -1245,26 +1245,8 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
12451245 }
12461246}
12471247
1248- fn force_delayed_owners_lowering ( tcx : TyCtxt < ' _ > ) {
1249- let krate = tcx. hir_crate ( ( ) ) ;
1250- for & id in & krate. delayed_ids {
1251- tcx. ensure_done ( ) . lower_delayed_owner ( id) ;
1252- }
1253-
1254- let ( _, krate) = krate. delayed_resolver . steal ( ) ;
1255- let prof = tcx. sess . prof . clone ( ) ;
1256-
1257- // Drop AST to free memory. It can be expensive so try to drop it on a separate thread.
1258- spawn ( move || {
1259- let _timer = prof. verbose_generic_activity ( "drop_ast" ) ;
1260- drop ( krate) ;
1261- } ) ;
1262- }
1263-
12641248pub ( crate ) fn hir_crate_items ( tcx : TyCtxt < ' _ > , _: ( ) ) -> ModuleItems {
1265- force_delayed_owners_lowering ( tcx) ;
1266-
1267- let mut collector = ItemCollector :: new ( tcx, true ) ;
1249+ let mut collector = ItemCollector :: new ( tcx, ItemCollectionKind :: Crate ) ;
12681250
12691251 // A "crate collector" and "module collector" start at a
12701252 // module item (the former starts at the crate root) but only
@@ -1327,9 +1309,9 @@ struct ItemCollector<'tcx> {
13271309}
13281310
13291311impl < ' tcx > ItemCollector < ' tcx > {
1330- fn new ( tcx : TyCtxt < ' tcx > , crate_collector : bool ) -> ItemCollector < ' tcx > {
1331- ItemCollector {
1332- crate_collector,
1312+ fn new ( tcx : TyCtxt < ' tcx > , collection_kind : ItemCollectionKind ) -> ItemCollector < ' tcx > {
1313+ let mut collector = ItemCollector {
1314+ crate_collector : matches ! ( collection_kind , ItemCollectionKind :: Crate ) ,
13331315 tcx,
13341316 submodules : Vec :: default ( ) ,
13351317 items : Vec :: default ( ) ,
@@ -1341,12 +1323,34 @@ impl<'tcx> ItemCollector<'tcx> {
13411323 nested_bodies : Vec :: default ( ) ,
13421324 delayed_lint_items : Vec :: default ( ) ,
13431325 eiis : Vec :: default ( ) ,
1326+ } ;
1327+
1328+ let delayed_kinds = tcx. hir_crate ( ( ) ) . delayed_owners_kinds ( ) ;
1329+ let delayed_kinds = delayed_kinds. filter ( |( id, _) | match collection_kind {
1330+ ItemCollectionKind :: Crate => true ,
1331+ ItemCollectionKind :: Mod ( mod_id) => tcx. parent_module_from_def_id ( * id) == mod_id,
1332+ } ) ;
1333+
1334+ // FIXME(fn_delegation): need to add delayed lints, eiis
1335+ for ( def_id, kind) in delayed_kinds {
1336+ let owner_id = OwnerId { def_id } ;
1337+
1338+ match kind {
1339+ DelayedOwnerKind :: Item => collector. items . push ( ItemId { owner_id } ) ,
1340+ DelayedOwnerKind :: ImplItem => collector. impl_items . push ( ImplItemId { owner_id } ) ,
1341+ DelayedOwnerKind :: TraitItem => collector. trait_items . push ( TraitItemId { owner_id } ) ,
1342+ } ;
1343+
1344+ collector. body_owners . push ( def_id) ;
13441345 }
1346+
1347+ collector
13451348 }
13461349}
13471350
13481351impl < ' hir > Visitor < ' hir > for ItemCollector < ' hir > {
13491352 type NestedFilter = nested_filter:: All ;
1353+ const VISIT_DELAYED : bool = false ;
13501354
13511355 fn maybe_tcx ( & mut self ) -> Self :: MaybeTyCtxt {
13521356 self . tcx
0 commit comments