Skip to content

Commit

Permalink
Auto merge of #51383 - Zoxc:parallel-stuff, r=<try>
Browse files Browse the repository at this point in the history
Run some stuff in parallel

Requires #50699 to actually work correctly.

r? @nikomatsakis
  • Loading branch information
bors committed Jun 6, 2018
2 parents 685faa2 + 98a2688 commit e8c5b81
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 36 deletions.
8 changes: 7 additions & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2434,6 +2434,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)) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_borrowck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#![feature(from_ref)]
#![feature(quote)]

#![recursion_limit="256"]

#[macro_use] extern crate log;
extern crate syntax;
extern crate syntax_pos;
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,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);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_incremental/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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);
})
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 24 additions & 18 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{ParallelIterator, par_iter, Lock};

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum MonoItemCollectionMode {
Expand Down Expand Up @@ -298,22 +300,26 @@ 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 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);
});
});

(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
Expand Down Expand Up @@ -354,10 +360,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: &Lock<FxHashSet<MonoItem<'tcx>>>,
recursion_depths: &mut DefIdMap<usize>,
inlining_map: &mut InliningMap<'tcx>) {
if !visited.insert(starting_point.clone()) {
inlining_map: &Lock<InliningMap<'tcx>>) {
if !visited.lock().insert(starting_point.clone()) {
// We've been here already, no need to search again.
return;
}
Expand Down Expand Up @@ -425,7 +431,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: &Lock<InliningMap<'tcx>>) {
let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| {
mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
};
Expand All @@ -435,7 +441,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().record_accesses(caller, accesses);
}

fn check_recursion_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::maps::queries::typeck_tables_of::ensure(tcx, body_owner_def_id);
}
});
})?)
}

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e8c5b81

Please sign in to comment.