Skip to content

Commit e8c5b81

Browse files
committed
Auto merge of #51383 - Zoxc:parallel-stuff, r=<try>
Run some stuff in parallel Requires #50699 to actually work correctly. r? @nikomatsakis
2 parents 685faa2 + 98a2688 commit e8c5b81

File tree

10 files changed

+61
-36
lines changed

10 files changed

+61
-36
lines changed

src/librustc/ty/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::cmp::{self, Ordering};
4444
use std::fmt;
4545
use std::hash::{Hash, Hasher};
4646
use std::ops::Deref;
47-
use rustc_data_structures::sync::Lrc;
47+
use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter};
4848
use std::slice;
4949
use std::vec::IntoIter;
5050
use std::mem;
@@ -2434,6 +2434,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24342434
.map(move |&body_id| self.hir.body_owner_def_id(body_id))
24352435
}
24362436

2437+
pub fn par_body_owners<F: Fn(DefId) + sync::Sync + sync::Send>(self, f: F) {
2438+
par_iter(&self.hir.krate().body_ids).for_each(|&body_id| {
2439+
f(self.hir.body_owner_def_id(body_id))
2440+
});
2441+
}
2442+
24372443
pub fn expr_span(self, id: NodeId) -> Span {
24382444
match self.hir.find(id) {
24392445
Some(hir_map::NodeExpr(e)) => {

src/librustc_borrowck/borrowck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ pub struct LoanDataFlowOperator;
6767
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
6868

6969
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
70-
for body_owner_def_id in tcx.body_owners() {
70+
tcx.par_body_owners(|body_owner_def_id| {
7171
tcx.borrowck(body_owner_def_id);
72-
}
72+
});
7373
}
7474

7575
pub fn provide(providers: &mut Providers) {

src/librustc_borrowck/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#![feature(from_ref)]
1818
#![feature(quote)]
1919

20+
#![recursion_limit="256"]
21+
2022
#[macro_use] extern crate log;
2123
extern crate syntax;
2224
extern crate syntax_pos;

src/librustc_driver/driver.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,9 @@ where
12641264

12651265
time(sess, "borrow checking", || borrowck::check_crate(tcx));
12661266

1267-
time(sess, "MIR borrow checking", || {
1268-
for def_id in tcx.body_owners() {
1269-
tcx.mir_borrowck(def_id);
1270-
}
1271-
});
1267+
time(sess,
1268+
"MIR borrow checking",
1269+
|| tcx.par_body_owners(|def_id| { tcx.mir_borrowck(def_id); }));
12721270

12731271
time(sess, "dumping chalk-like clauses", || {
12741272
rustc_traits::lowering::dump_program_clauses(tcx);

src/librustc_incremental/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#![feature(fs_read_write)]
1818
#![feature(specialization)]
1919

20+
#![recursion_limit="256"]
21+
2022
extern crate graphviz;
2123
#[macro_use] extern crate rustc;
2224
extern crate rustc_data_structures;

src/librustc_incremental/persist/save.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc::session::Session;
1313
use rustc::ty::TyCtxt;
1414
use rustc::util::common::time;
1515
use rustc_data_structures::fx::FxHashMap;
16+
use rustc_data_structures::sync::join;
1617
use rustc_serialize::Encodable as RustcEncodable;
1718
use rustc_serialize::opaque::Encoder;
1819
use std::io::{self, Cursor};
@@ -33,23 +34,28 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
3334
return;
3435
}
3536

36-
time(sess, "persist query result cache", || {
37-
save_in(sess,
38-
query_cache_path(sess),
39-
|e| encode_query_cache(tcx, e));
40-
});
37+
let query_cache_path = query_cache_path(sess);
38+
let dep_graph_path = dep_graph_path(sess);
4139

42-
if tcx.sess.opts.debugging_opts.incremental_queries {
40+
join(move || {
41+
if tcx.sess.opts.debugging_opts.incremental_queries {
42+
time(sess, "persist query result cache", || {
43+
save_in(sess,
44+
query_cache_path,
45+
|e| encode_query_cache(tcx, e));
46+
});
47+
}
48+
}, || {
4349
time(sess, "persist dep-graph", || {
4450
save_in(sess,
45-
dep_graph_path(sess),
51+
dep_graph_path,
4652
|e| {
4753
time(sess, "encode dep-graph", || {
4854
encode_dep_graph(tcx, e)
4955
})
5056
});
5157
});
52-
}
58+
});
5359

5460
dirty_clean::check_dirty_clean_annotations(tcx);
5561
})

src/librustc_mir/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
3434
#![feature(specialization)]
3535
#![feature(try_trait)]
3636

37+
#![recursion_limit="256"]
38+
3739
extern crate arena;
40+
3841
#[macro_use]
3942
extern crate bitflags;
4043
#[macro_use] extern crate log;

src/librustc_mir/monomorphize/collector.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ use rustc::mir::interpret::{Scalar, GlobalId, AllocType};
207207

208208
use monomorphize::{self, Instance};
209209
use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
210+
use rustc::util::common::time;
210211

211212
use monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};
212213

213214
use rustc_data_structures::bitvec::BitVector;
215+
use rustc_data_structures::sync::{ParallelIterator, par_iter, Lock};
214216

215217
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
216218
pub enum MonoItemCollectionMode {
@@ -298,22 +300,26 @@ pub fn collect_crate_mono_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
298300
mode: MonoItemCollectionMode)
299301
-> (FxHashSet<MonoItem<'tcx>>,
300302
InliningMap<'tcx>) {
301-
let roots = collect_roots(tcx, mode);
303+
let roots = time(tcx.sess, "collecting roots", || {
304+
collect_roots(tcx, mode)
305+
});
302306

303307
debug!("Building mono item graph, beginning at roots");
304-
let mut visited = FxHashSet();
305-
let mut recursion_depths = DefIdMap();
306-
let mut inlining_map = InliningMap::new();
307-
308-
for root in roots {
309-
collect_items_rec(tcx,
310-
root,
311-
&mut visited,
312-
&mut recursion_depths,
313-
&mut inlining_map);
314-
}
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);
319+
});
320+
});
315321

316-
(visited, inlining_map)
322+
(visited.into_inner(), inlining_map.into_inner())
317323
}
318324

319325
// Find all non-generic items by walking the HIR. These items serve as roots to
@@ -354,10 +360,10 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
354360
// Collect all monomorphized items reachable from `starting_point`
355361
fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
356362
starting_point: MonoItem<'tcx>,
357-
visited: &mut FxHashSet<MonoItem<'tcx>>,
363+
visited: &Lock<FxHashSet<MonoItem<'tcx>>>,
358364
recursion_depths: &mut DefIdMap<usize>,
359-
inlining_map: &mut InliningMap<'tcx>) {
360-
if !visited.insert(starting_point.clone()) {
365+
inlining_map: &Lock<InliningMap<'tcx>>) {
366+
if !visited.lock().insert(starting_point.clone()) {
361367
// We've been here already, no need to search again.
362368
return;
363369
}
@@ -425,7 +431,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
425431
fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
426432
caller: MonoItem<'tcx>,
427433
callees: &[MonoItem<'tcx>],
428-
inlining_map: &mut InliningMap<'tcx>) {
434+
inlining_map: &Lock<InliningMap<'tcx>>) {
429435
let is_inlining_candidate = |mono_item: &MonoItem<'tcx>| {
430436
mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy
431437
};
@@ -435,7 +441,7 @@ fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
435441
(*mono_item, is_inlining_candidate(mono_item))
436442
});
437443

438-
inlining_map.record_accesses(caller, accesses);
444+
inlining_map.lock().record_accesses(caller, accesses);
439445
}
440446

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

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,9 @@ fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum
702702
{
703703
debug_assert!(crate_num == LOCAL_CRATE);
704704
Ok(tcx.sess.track_errors(|| {
705-
for body_owner_def_id in tcx.body_owners() {
705+
tcx.par_body_owners(|body_owner_def_id| {
706706
ty::maps::queries::typeck_tables_of::ensure(tcx, body_owner_def_id);
707-
}
707+
});
708708
})?)
709709
}
710710

src/librustc_typeck/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ This API is completely unstable and subject to change.
8383
#![feature(slice_sort_by_cached_key)]
8484
#![feature(never_type)]
8585

86+
#![recursion_limit="256"]
87+
8688
#[macro_use] extern crate log;
8789
#[macro_use] extern crate syntax;
8890
extern crate syntax_pos;

0 commit comments

Comments
 (0)