Auto merge of #51383 - Zoxc:parallel-stuff, r=nikomatsakis
Run some stuff in parallel Requires https://github.com/rust-lang/rust/pull/50699 to actually work correctly. r? @nikomatsakis
This commit is contained in:
commit
1cfb628ead
@ -44,7 +44,7 @@ use std::cmp::{self, Ordering};
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Deref;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter};
|
||||
use std::slice;
|
||||
use std::vec::IntoIter;
|
||||
use std::mem;
|
||||
@ -2436,6 +2436,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
.map(move |&body_id| self.hir.body_owner_def_id(body_id))
|
||||
}
|
||||
|
||||
pub fn par_body_owners<F: Fn(DefId) + sync::Sync + sync::Send>(self, f: F) {
|
||||
par_iter(&self.hir.krate().body_ids).for_each(|&body_id| {
|
||||
f(self.hir.body_owner_def_id(body_id))
|
||||
});
|
||||
}
|
||||
|
||||
pub fn expr_span(self, id: NodeId) -> Span {
|
||||
match self.hir.find(id) {
|
||||
Some(hir_map::NodeExpr(e)) => {
|
||||
|
@ -67,9 +67,9 @@ pub struct LoanDataFlowOperator;
|
||||
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
|
||||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
for body_owner_def_id in tcx.body_owners() {
|
||||
tcx.par_body_owners(|body_owner_def_id| {
|
||||
tcx.borrowck(body_owner_def_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
@ -17,6 +17,8 @@
|
||||
#![feature(from_ref)]
|
||||
#![feature(quote)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
|
@ -26,6 +26,8 @@
|
||||
//!
|
||||
//! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
|
||||
//!
|
||||
//! `MTRef` is a immutable refernce if cfg!(parallel_queries), and an mutable reference otherwise.
|
||||
//!
|
||||
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
|
||||
//! depending on the value of cfg!(parallel_queries).
|
||||
|
||||
@ -126,6 +128,8 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
pub type MTRef<'a, T> = &'a mut T;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MTLock<T>(T);
|
||||
|
||||
@ -151,13 +155,8 @@ cfg_if! {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow(&self) -> &T {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn borrow_mut(&self) -> &T {
|
||||
&self.0
|
||||
pub fn lock_mut(&mut self) -> &mut T {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +220,37 @@ cfg_if! {
|
||||
pub use std::sync::Arc as Lrc;
|
||||
pub use std::sync::Weak as Weak;
|
||||
|
||||
pub use self::Lock as MTLock;
|
||||
pub type MTRef<'a, T> = &'a T;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MTLock<T>(Lock<T>);
|
||||
|
||||
impl<T> MTLock<T> {
|
||||
#[inline(always)]
|
||||
pub fn new(inner: T) -> Self {
|
||||
MTLock(Lock::new(inner))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.0.into_inner()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
self.0.get_mut()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn lock(&self) -> LockGuard<T> {
|
||||
self.0.lock()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn lock_mut(&self) -> LockGuard<T> {
|
||||
self.lock()
|
||||
}
|
||||
}
|
||||
|
||||
use parking_lot::Mutex as InnerLock;
|
||||
use parking_lot::RwLock as InnerRwLock;
|
||||
|
@ -1272,11 +1272,9 @@ where
|
||||
|
||||
time(sess, "borrow checking", || borrowck::check_crate(tcx));
|
||||
|
||||
time(sess, "MIR borrow checking", || {
|
||||
for def_id in tcx.body_owners() {
|
||||
tcx.mir_borrowck(def_id);
|
||||
}
|
||||
});
|
||||
time(sess,
|
||||
"MIR borrow checking",
|
||||
|| tcx.par_body_owners(|def_id| { tcx.mir_borrowck(def_id); }));
|
||||
|
||||
time(sess, "dumping chalk-like clauses", || {
|
||||
rustc_traits::lowering::dump_program_clauses(tcx);
|
||||
|
@ -17,6 +17,8 @@
|
||||
#![feature(fs_read_write)]
|
||||
#![feature(specialization)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
extern crate graphviz;
|
||||
#[macro_use] extern crate rustc;
|
||||
extern crate rustc_data_structures;
|
||||
|
@ -13,6 +13,7 @@ use rustc::session::Session;
|
||||
use rustc::ty::TyCtxt;
|
||||
use rustc::util::common::time;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::join;
|
||||
use rustc_serialize::Encodable as RustcEncodable;
|
||||
use rustc_serialize::opaque::Encoder;
|
||||
use std::io::{self, Cursor};
|
||||
@ -33,23 +34,28 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
return;
|
||||
}
|
||||
|
||||
time(sess, "persist query result cache", || {
|
||||
save_in(sess,
|
||||
query_cache_path(sess),
|
||||
|e| encode_query_cache(tcx, e));
|
||||
});
|
||||
let query_cache_path = query_cache_path(sess);
|
||||
let dep_graph_path = dep_graph_path(sess);
|
||||
|
||||
if tcx.sess.opts.debugging_opts.incremental_queries {
|
||||
join(move || {
|
||||
if tcx.sess.opts.debugging_opts.incremental_queries {
|
||||
time(sess, "persist query result cache", || {
|
||||
save_in(sess,
|
||||
query_cache_path,
|
||||
|e| encode_query_cache(tcx, e));
|
||||
});
|
||||
}
|
||||
}, || {
|
||||
time(sess, "persist dep-graph", || {
|
||||
save_in(sess,
|
||||
dep_graph_path(sess),
|
||||
dep_graph_path,
|
||||
|e| {
|
||||
time(sess, "encode dep-graph", || {
|
||||
encode_dep_graph(tcx, e)
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
dirty_clean::check_dirty_clean_annotations(tcx);
|
||||
})
|
||||
|
@ -34,7 +34,10 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
||||
#![feature(specialization)]
|
||||
#![feature(try_trait)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
extern crate arena;
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[macro_use] extern crate log;
|
||||
|
@ -207,10 +207,12 @@ use rustc::mir::interpret::{Scalar, GlobalId, AllocType};
|
||||
|
||||
use monomorphize::{self, Instance};
|
||||
use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
|
||||
use rustc::util::common::time;
|
||||
|
||||
use monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};
|
||||
|
||||
use rustc_data_structures::bitvec::BitVector;
|
||||
use rustc_data_structures::sync::{MTRef, MTLock, ParallelIterator, par_iter};
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub enum MonoItemCollectionMode {
|
||||
@ -298,22 +300,32 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
mode: MonoItemCollectionMode)
|
||||
-> (FxHashSet<MonoItem<'tcx>>,
|
||||
InliningMap<'tcx>) {
|
||||
let roots = collect_roots(tcx, mode);
|
||||
let roots = time(tcx.sess, "collecting roots", || {
|
||||
collect_roots(tcx, mode)
|
||||
});
|
||||
|
||||
debug!("Building mono item graph, beginning at roots");
|
||||
let mut visited = FxHashSet();
|
||||
let mut recursion_depths = DefIdMap();
|
||||
let mut inlining_map = InliningMap::new();
|
||||
|
||||
for root in roots {
|
||||
collect_items_rec(tcx,
|
||||
root,
|
||||
&mut visited,
|
||||
&mut recursion_depths,
|
||||
&mut 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, inlining_map)
|
||||
(visited.into_inner(), inlining_map.into_inner())
|
||||
}
|
||||
|
||||
// Find all non-generic items by walking the HIR. These items serve as roots to
|
||||
@ -354,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: &mut FxHashSet<MonoItem<'tcx>>,
|
||||
visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
|
||||
recursion_depths: &mut DefIdMap<usize>,
|
||||
inlining_map: &mut InliningMap<'tcx>) {
|
||||
if !visited.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;
|
||||
}
|
||||
@ -428,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: &mut InliningMap<'tcx>) {
|
||||
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>) {
|
||||
let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| {
|
||||
mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
|
||||
};
|
||||
@ -438,7 +450,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
(*mono_item, is_inlining_candidate(mono_item))
|
||||
});
|
||||
|
||||
inlining_map.record_accesses(caller, accesses);
|
||||
inlining_map.lock_mut().record_accesses(caller, accesses);
|
||||
}
|
||||
|
||||
fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
@ -702,9 +702,9 @@ fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum
|
||||
{
|
||||
debug_assert!(crate_num == LOCAL_CRATE);
|
||||
Ok(tcx.sess.track_errors(|| {
|
||||
for body_owner_def_id in tcx.body_owners() {
|
||||
tcx.par_body_owners(|body_owner_def_id| {
|
||||
ty::query::queries::typeck_tables_of::ensure(tcx, body_owner_def_id);
|
||||
}
|
||||
});
|
||||
})?)
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,8 @@ This API is completely unstable and subject to change.
|
||||
#![feature(slice_sort_by_cached_key)]
|
||||
#![feature(never_type)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user