Skip to content

Commit fe1cb88

Browse files
committed
Use MTRef and MTLock to avoid a RefCell
1 parent 8368f36 commit fe1cb88

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/librustc_mir/monomorphize/collector.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ use rustc::util::common::time;
212212
use monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};
213213

214214
use rustc_data_structures::bitvec::BitVector;
215-
use rustc_data_structures::sync::{ParallelIterator, par_iter, Lock};
215+
use rustc_data_structures::sync::{MTRef, MTLock, ParallelIterator, par_iter};
216216

217217
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
218218
pub enum MonoItemCollectionMode {
@@ -305,19 +305,25 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
305305
});
306306

307307
debug!("Building mono item graph, beginning at roots");
308-
let visited = Lock::new(FxHashSet());
309-
let inlining_map = Lock::new(InliningMap::new());
310-
311-
time(tcx.sess, "collecting mono items", || {
312-
par_iter(roots).for_each(|root| {
313-
let mut recursion_depths = DefIdMap();
314-
collect_items_rec(tcx,
315-
root,
316-
&visited,
317-
&mut recursion_depths,
318-
&inlining_map);
308+
309+
let mut visited = MTLock::new(FxHashSet());
310+
let mut inlining_map = MTLock::new(InliningMap::new());
311+
312+
{
313+
let visited: MTRef<'_, _> = &mut visited;
314+
let inlining_map: MTRef<'_, _> = &mut inlining_map;
315+
316+
time(tcx.sess, "collecting mono items", || {
317+
par_iter(roots).for_each(|root| {
318+
let mut recursion_depths = DefIdMap();
319+
collect_items_rec(tcx,
320+
root,
321+
visited,
322+
&mut recursion_depths,
323+
inlining_map);
324+
});
319325
});
320-
});
326+
}
321327

322328
(visited.into_inner(), inlining_map.into_inner())
323329
}
@@ -360,10 +366,10 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
360366
// Collect all monomorphized items reachable from `starting_point`
361367
fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
362368
starting_point: MonoItem<'tcx>,
363-
visited: &Lock<FxHashSet<MonoItem<'tcx>>>,
369+
visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
364370
recursion_depths: &mut DefIdMap<usize>,
365-
inlining_map: &Lock<InliningMap<'tcx>>) {
366-
if !visited.lock().insert(starting_point.clone()) {
371+
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
372+
if !visited.lock_mut().insert(starting_point.clone()) {
367373
// We've been here already, no need to search again.
368374
return;
369375
}
@@ -434,7 +440,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
434440
fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
435441
caller: MonoItem<'tcx>,
436442
callees: &[MonoItem<'tcx>],
437-
inlining_map: &Lock<InliningMap<'tcx>>) {
443+
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
438444
let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| {
439445
mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
440446
};
@@ -444,7 +450,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
444450
(*mono_item, is_inlining_candidate(mono_item))
445451
});
446452

447-
inlining_map.lock().record_accesses(caller, accesses);
453+
inlining_map.lock_mut().record_accesses(caller, accesses);
448454
}
449455

450456
fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

0 commit comments

Comments
 (0)