@@ -8,10 +8,12 @@ use crate::middle::cstore::CrateStoreDyn;
88use crate :: ty:: query:: Providers ;
99use rustc_data_structures:: fx:: FxHashMap ;
1010use rustc_data_structures:: svh:: Svh ;
11+
12+ use rustc_data_structures:: sync:: { self , par_for_each} ;
1113use rustc_hir:: def:: { DefKind , Res } ;
1214use rustc_hir:: def_id:: { DefId , DefIndex , LocalDefId , CRATE_DEF_INDEX } ;
1315use rustc_hir:: intravisit;
14- use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
16+ use rustc_hir:: itemlikevisit:: { ItemLikeVisitor , ParItemLikeVisitor } ;
1517use rustc_hir:: print:: Nested ;
1618use rustc_hir:: * ;
1719use rustc_index:: vec:: IndexVec ;
@@ -582,6 +584,40 @@ impl<'hir> Map<'hir> {
582584 }
583585 }
584586
587+ /// A parallel version of `visit_item_likes_in_module`.
588+ pub fn par_visit_item_likes_in_module < V > ( & self , module : DefId , visitor : & V )
589+ where
590+ V : ParItemLikeVisitor < ' hir > + sync:: Sync ,
591+ {
592+ let hir_id = self . as_local_hir_id ( module) . unwrap ( ) ;
593+
594+ // Read the module so we'll be re-executed if new items
595+ // appear immediately under in the module. If some new item appears
596+ // in some nested item in the module, we'll be re-executed due to reads
597+ // in the expect_* calls the loops below
598+ self . read ( hir_id) ;
599+
600+ let module = & self . forest . krate . modules [ & hir_id] ;
601+
602+ parallel ! (
603+ {
604+ par_for_each( & module. items, |id| {
605+ visitor. visit_item( self . expect_item( * id) ) ;
606+ } ) ;
607+ } ,
608+ {
609+ par_for_each( & module. trait_items, |id| {
610+ visitor. visit_trait_item( self . expect_trait_item( id. hir_id) ) ;
611+ } ) ;
612+ } ,
613+ {
614+ par_for_each( & module. impl_items, |id| {
615+ visitor. visit_impl_item( self . expect_impl_item( id. hir_id) ) ;
616+ } ) ;
617+ }
618+ ) ;
619+ }
620+
585621 /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
586622 pub fn get ( & self , id : HirId ) -> Node < ' hir > {
587623 // read recorded by `find`
0 commit comments