Use MTRef and MTLock to avoid a RefCell

This commit is contained in:
John Kåre Alsaker 2018-06-08 17:49:21 +02:00
parent 8368f364e3
commit fe1cb88c08

View File

@ -212,7 +212,7 @@ use rustc::util::common::time;
use monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};
use rustc_data_structures::bitvec::BitVector;
use rustc_data_structures::sync::{ParallelIterator, par_iter, Lock};
use rustc_data_structures::sync::{MTRef, MTLock, ParallelIterator, par_iter};
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum MonoItemCollectionMode {
@ -305,19 +305,25 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
});
debug!("Building mono item graph, beginning at roots");
let visited = Lock::new(FxHashSet());
let inlining_map = Lock::new(InliningMap::new());
time(tcx.sess, "collecting mono items", || {
par_iter(roots).for_each(|root| {
let mut recursion_depths = DefIdMap();
collect_items_rec(tcx,
root,
&visited,
&mut recursion_depths,
&inlining_map);
let mut visited = MTLock::new(FxHashSet());
let mut inlining_map = MTLock::new(InliningMap::new());
{
let visited: MTRef<'_, _> = &mut visited;
let inlining_map: MTRef<'_, _> = &mut inlining_map;
time(tcx.sess, "collecting mono items", || {
par_iter(roots).for_each(|root| {
let mut recursion_depths = DefIdMap();
collect_items_rec(tcx,
root,
visited,
&mut recursion_depths,
inlining_map);
});
});
});
}
(visited.into_inner(), inlining_map.into_inner())
}
@ -360,10 +366,10 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Collect all monomorphized items reachable from `starting_point`
fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
starting_point: MonoItem<'tcx>,
visited: &Lock<FxHashSet<MonoItem<'tcx>>>,
visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
recursion_depths: &mut DefIdMap<usize>,
inlining_map: &Lock<InliningMap<'tcx>>) {
if !visited.lock().insert(starting_point.clone()) {
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
if !visited.lock_mut().insert(starting_point.clone()) {
// We've been here already, no need to search again.
return;
}
@ -434,7 +440,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
caller: MonoItem<'tcx>,
callees: &[MonoItem<'tcx>],
inlining_map: &Lock<InliningMap<'tcx>>) {
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| {
mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
};
@ -444,7 +450,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
(*mono_item, is_inlining_candidate(mono_item))
});
inlining_map.lock().record_accesses(caller, accesses);
inlining_map.lock_mut().record_accesses(caller, accesses);
}
fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,