Skip to content

Commit d580377

Browse files
committed
Parallelize passes
1 parent 5e10946 commit d580377

File tree

21 files changed

+101
-62
lines changed

21 files changed

+101
-62
lines changed

src/Cargo.lock

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/hir/itemlikevisit.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ pub trait IntoVisitor<'hir> {
101101
fn into_visitor(&self) -> Self::Visitor;
102102
}
103103

104+
#[derive(Clone)]
105+
pub struct ClonableVisitor<V>(pub V);
106+
107+
impl<'hir, V: Visitor<'hir> + Clone> IntoVisitor<'hir> for ClonableVisitor<V> {
108+
type Visitor = V;
109+
110+
fn into_visitor(&self) -> V {
111+
self.clone().0
112+
}
113+
}
114+
104115
pub struct ParDeepVisitor<V>(pub V);
105116

106117
impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor<V>

src/librustc/hir/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@ impl Crate {
592592
});
593593
}
594594

595+
pub fn par_deep_visit_items<'hir, V>(&'hir self, visitor: V)
596+
where V: intravisit::Visitor<'hir> + Clone + Sync + Send
597+
{
598+
let visitor = itemlikevisit::ClonableVisitor(visitor);
599+
self.par_visit_all_item_likes(&itemlikevisit::ParDeepVisitor(visitor));
600+
}
601+
595602
pub fn body(&self, id: BodyId) -> &Body {
596603
&self.bodies[&id]
597604
}

src/librustc/middle/intrinsicck.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
1919
use hir;
2020

2121
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
22-
let mut visitor = ItemVisitor {
23-
tcx,
24-
};
25-
tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
22+
tcx.hir.krate().par_deep_visit_items(ItemVisitor { tcx });
2623
}
2724

25+
#[derive(Clone)]
2826
struct ItemVisitor<'a, 'tcx: 'a> {
2927
tcx: TyCtxt<'a, 'tcx, 'tcx>
3028
}

src/librustc/middle/stability.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
324324
}
325325
}
326326

327+
#[derive(Clone)]
327328
struct MissingStabilityAnnotations<'a, 'tcx: 'a> {
328329
tcx: TyCtxt<'a, 'tcx, 'tcx>,
329330
access_levels: &'a AccessLevels,
@@ -466,10 +467,10 @@ impl<'a, 'tcx> Index<'tcx> {
466467
/// Cross-references the feature names of unstable APIs with enabled
467468
/// features and possibly prints errors.
468469
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
469-
let mut checker = Checker { tcx: tcx };
470-
tcx.hir.krate().visit_all_item_likes(&mut checker.as_deep_visitor());
470+
tcx.hir.krate().par_deep_visit_items(Checker { tcx: tcx });
471471
}
472472

473+
#[derive(Clone)]
473474
struct Checker<'a, 'tcx: 'a> {
474475
tcx: TyCtxt<'a, 'tcx, 'tcx>,
475476
}
@@ -733,7 +734,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
733734
};
734735
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span);
735736
intravisit::walk_crate(&mut missing, krate);
736-
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
737+
krate.par_deep_visit_items(missing);
737738
}
738739

739740
let ref declared_lib_features = sess.features.borrow().declared_lib_features;

src/librustc/traits/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use ty::error::{ExpectedFound, TypeError};
2626
use infer::{InferCtxt};
2727

2828
use rustc_data_structures::sync::Lrc;
29-
use std::rc::Rc;
3029
use syntax::ast;
3130
use syntax_pos::{Span, DUMMY_SP};
3231

@@ -210,7 +209,7 @@ pub struct DerivedObligationCause<'tcx> {
210209
parent_trait_ref: ty::PolyTraitRef<'tcx>,
211210

212211
/// The parent trait had this cause
213-
parent_code: Rc<ObligationCauseCode<'tcx>>
212+
parent_code: Lrc<ObligationCauseCode<'tcx>>
214213
}
215214

216215
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;

src/librustc/traits/select.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ use ty::fast_reject;
4141
use ty::relate::TypeRelation;
4242
use middle::lang_items;
4343

44-
use rustc_data_structures::sync::Lock;
44+
use rustc_data_structures::sync::{Lrc, Lock};
4545
use rustc_data_structures::bitvec::BitVector;
4646
use rustc_data_structures::snapshot_vec::{SnapshotVecDelegate, SnapshotVec};
4747
use std::iter;
4848
use std::cmp;
4949
use std::fmt;
5050
use std::marker::PhantomData;
5151
use std::mem;
52-
use std::rc::Rc;
5352
use syntax::abi::Abi;
5453
use hir;
5554
use lint;
@@ -3290,7 +3289,7 @@ impl<'tcx> TraitObligation<'tcx> {
32903289
if obligation.recursion_depth >= 0 {
32913290
let derived_cause = DerivedObligationCause {
32923291
parent_trait_ref: obligation.predicate.to_poly_trait_ref(),
3293-
parent_code: Rc::new(obligation.cause.code.clone())
3292+
parent_code: Lrc::new(obligation.cause.code.clone())
32943293
};
32953294
let derived_code = variant(derived_cause);
32963295
ObligationCause::new(obligation.cause.span, obligation.cause.body_id, derived_code)

src/librustc/traits/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ty::{self, Lift, TyCtxt};
1414
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1515

1616
use std::fmt;
17-
use std::rc::Rc;
17+
use rustc_data_structures::sync::Lrc;
1818

1919
// structural impls for the structs in traits
2020

@@ -252,7 +252,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> {
252252
tcx.lift(&*self.parent_code).map(|code| {
253253
traits::DerivedObligationCause {
254254
parent_trait_ref: trait_ref,
255-
parent_code: Rc::new(code)
255+
parent_code: Lrc::new(code)
256256
}
257257
})
258258
})

src/librustc/ty/context.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,17 +1130,25 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11301130

11311131
#[cfg(parallel_queries)]
11321132
let r = {
1133+
use std::time::Instant;
11331134
use util::common::PROFQ_CHAN;
1135+
use util::common::print_time_passes_entry;
11341136
use syntax;
11351137
use syntax_pos;
11361138
use rayon;
11371139

1140+
let pool_start = Instant::now();
1141+
11381142
let config = rayon::Configuration::new().num_threads(gcx.sess.query_threads())
11391143
.stack_size(16 * 1024 * 1024);
11401144

11411145
let with_pool = move |pool: &rayon::ThreadPool| {
11421146
pool.with_global_registry(|| {
1143-
tls::enter_global(gcx, f)
1147+
print_time_passes_entry(gcx.sess.time_passes(),
1148+
"rayon thread pool starting",
1149+
pool_start.elapsed());
1150+
1151+
(tls::enter_global(gcx, f), Instant::now())
11441152
})
11451153
};
11461154

@@ -1165,7 +1173,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11651173
}
11661174
}
11671175

1168-
try_with(&PROFQ_CHAN, |prof_chan| {
1176+
let (r, pool_end) = try_with(&PROFQ_CHAN, |prof_chan| {
11691177
try_with(&syntax::GLOBALS, |syntax_globals| {
11701178
try_with(&syntax_pos::GLOBALS, |syntax_pos_globals| {
11711179
let main_handler = move |worker: &mut FnMut()| {
@@ -1183,7 +1191,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11831191
rayon::ThreadPool::scoped_pool(config, main_handler, with_pool).unwrap()
11841192
})
11851193
})
1186-
})
1194+
});
1195+
1196+
print_time_passes_entry(gcx.sess.time_passes(),
1197+
"rayon thread pool stopping",
1198+
pool_end.elapsed());
1199+
1200+
r
11871201
};
11881202

11891203
#[cfg(not(parallel_queries))]

src/librustc/ty/structural_impls.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
2121
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
2222

2323
use std::rc::Rc;
24+
use std::sync::Arc;
2425

2526
///////////////////////////////////////////////////////////////////////////
2627
// Atomic structs
@@ -684,6 +685,16 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option<T> {
684685
}
685686
}
686687

688+
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
689+
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
690+
Arc::new((**self).fold_with(folder))
691+
}
692+
693+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
694+
(**self).visit_with(visitor)
695+
}
696+
}
697+
687698
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
688699
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
689700
Rc::new((**self).fold_with(folder))

0 commit comments

Comments
 (0)