@@ -206,10 +206,12 @@ use rustc::mir::mono::MonoItem;
206
206
207
207
use monomorphize:: { self , Instance } ;
208
208
use rustc:: util:: nodemap:: { FxHashSet , FxHashMap , DefIdMap } ;
209
+ use rustc:: util:: common:: time;
209
210
210
211
use monomorphize:: item:: { MonoItemExt , DefPathBasedNames , InstantiationMode } ;
211
212
212
213
use rustc_data_structures:: bitvec:: BitVector ;
214
+ use rustc_data_structures:: sync:: { ParallelIterator , par_iter, Lock } ;
213
215
214
216
use syntax:: attr;
215
217
@@ -301,22 +303,26 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
301
303
mode : MonoItemCollectionMode )
302
304
-> ( FxHashSet < MonoItem < ' tcx > > ,
303
305
InliningMap < ' tcx > ) {
304
- let roots = collect_roots ( tcx, mode) ;
306
+ let roots = time ( tcx. sess . time_passes ( ) , "collecting roots" , || {
307
+ collect_roots ( tcx, mode)
308
+ } ) ;
305
309
306
310
debug ! ( "Building mono item graph, beginning at roots" ) ;
307
- let mut visited = FxHashSet ( ) ;
308
- let mut recursion_depths = DefIdMap ( ) ;
309
- let mut inlining_map = InliningMap :: new ( ) ;
310
-
311
- for root in roots {
312
- collect_items_rec ( tcx,
313
- root,
314
- & mut visited,
315
- & mut recursion_depths,
316
- & mut inlining_map) ;
317
- }
311
+ let visited = Lock :: new ( FxHashSet ( ) ) ;
312
+ let inlining_map = Lock :: new ( InliningMap :: new ( ) ) ;
313
+
314
+ time ( tcx. sess . time_passes ( ) , "collecting mono items" , || {
315
+ par_iter ( roots) . for_each ( |root| {
316
+ let mut recursion_depths = DefIdMap ( ) ;
317
+ collect_items_rec ( tcx,
318
+ root,
319
+ & visited,
320
+ & mut recursion_depths,
321
+ & inlining_map) ;
322
+ } ) ;
323
+ } ) ;
318
324
319
- ( visited, inlining_map)
325
+ ( visited. into_inner ( ) , inlining_map. into_inner ( ) )
320
326
}
321
327
322
328
// Find all non-generic items by walking the HIR. These items serve as roots to
@@ -355,10 +361,10 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
355
361
// Collect all monomorphized items reachable from `starting_point`
356
362
fn collect_items_rec < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
357
363
starting_point : MonoItem < ' tcx > ,
358
- visited : & mut FxHashSet < MonoItem < ' tcx > > ,
364
+ visited : & Lock < FxHashSet < MonoItem < ' tcx > > > ,
359
365
recursion_depths : & mut DefIdMap < usize > ,
360
- inlining_map : & mut InliningMap < ' tcx > ) {
361
- if !visited. insert ( starting_point. clone ( ) ) {
366
+ inlining_map : & Lock < InliningMap < ' tcx > > ) {
367
+ if !visited. lock ( ) . insert ( starting_point. clone ( ) ) {
362
368
// We've been here already, no need to search again.
363
369
return ;
364
370
}
@@ -415,7 +421,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
415
421
fn record_accesses < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
416
422
caller : MonoItem < ' tcx > ,
417
423
callees : & [ MonoItem < ' tcx > ] ,
418
- inlining_map : & mut InliningMap < ' tcx > ) {
424
+ inlining_map : & Lock < InliningMap < ' tcx > > ) {
419
425
let is_inlining_candidate = |mono_item : & MonoItem < ' tcx > | {
420
426
mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
421
427
} ;
@@ -425,7 +431,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
425
431
( * mono_item, is_inlining_candidate ( mono_item) )
426
432
} ) ;
427
433
428
- inlining_map. record_accesses ( caller, accesses) ;
434
+ inlining_map. lock ( ) . record_accesses ( caller, accesses) ;
429
435
}
430
436
431
437
fn check_recursion_limit < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments