Skip to content

Commit f16710f

Browse files
committed
Parallelize passes
1 parent 4dfb32c commit f16710f

File tree

19 files changed

+69
-47
lines changed

19 files changed

+69
-47
lines changed

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
@@ -695,6 +695,13 @@ impl Crate {
695695
});
696696
}
697697

698+
pub fn par_deep_visit_items<'hir, V>(&'hir self, visitor: V)
699+
where V: intravisit::Visitor<'hir> + Clone + Sync + Send
700+
{
701+
let visitor = itemlikevisit::ClonableVisitor(visitor);
702+
self.par_visit_all_item_likes(&itemlikevisit::ParDeepVisitor(visitor));
703+
}
704+
698705
pub fn body(&self, id: BodyId) -> &Body {
699706
&self.bodies[&id]
700707
}

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

@@ -225,7 +224,7 @@ pub struct DerivedObligationCause<'tcx> {
225224
parent_trait_ref: ty::PolyTraitRef<'tcx>,
226225

227226
/// The parent trait had this cause
228-
parent_code: Rc<ObligationCauseCode<'tcx>>
227+
parent_code: Lrc<ObligationCauseCode<'tcx>>
229228
}
230229

231230
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;
@@ -3321,7 +3320,7 @@ impl<'tcx> TraitObligation<'tcx> {
33213320
if obligation.recursion_depth >= 0 {
33223321
let derived_cause = DerivedObligationCause {
33233322
parent_trait_ref: obligation.predicate.to_poly_trait_ref(),
3324-
parent_code: Rc::new(obligation.cause.code.clone())
3323+
parent_code: Lrc::new(obligation.cause.code.clone())
33253324
};
33263325
let derived_code = variant(derived_cause);
33273326
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

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

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))

src/librustc_const_eval/check_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use syntax::ast;
3737
use syntax::ptr::P;
3838
use syntax_pos::{Span, DUMMY_SP};
3939

40+
#[derive(Clone)]
4041
struct OuterVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
4142

4243
impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
@@ -52,7 +53,7 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
5253
}
5354

5455
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
55-
tcx.hir.krate().visit_all_item_likes(&mut OuterVisitor { tcx: tcx }.as_deep_visitor());
56+
tcx.hir.krate().par_deep_visit_items(OuterVisitor { tcx: tcx });
5657
tcx.sess.abort_if_errors();
5758
}
5859

src/librustc_const_eval/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#![feature(i128_type)]
2727
#![feature(from_ref)]
2828

29+
#![recursion_limit="256"]
30+
2931
extern crate arena;
3032
#[macro_use] extern crate syntax;
3133
#[macro_use] extern crate log;

src/librustc_passes/consts.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ pub fn provide(providers: &mut Providers) {
6161
}
6262

6363
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
64-
for &body_id in &tcx.hir.krate().body_ids {
65-
let def_id = tcx.hir.body_owner_def_id(body_id);
66-
tcx.const_is_rvalue_promotable_to_static(def_id);
67-
}
64+
tcx.par_body_owners(|def_id| { tcx.const_is_rvalue_promotable_to_static(def_id); });
6865
tcx.sess.abort_if_errors();
6966
}
7067

src/librustc_passes/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#![feature(rustc_diagnostic_macros)]
2323

24+
#![recursion_limit="256"]
25+
2426
#[macro_use]
2527
extern crate rustc;
2628
extern crate rustc_const_eval;

src/librustc_trans/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#![feature(conservative_impl_trait)]
3636
#![feature(optin_builtin_traits)]
3737

38+
#![recursion_limit="256"]
39+
3840
use rustc::dep_graph::WorkProduct;
3941
use syntax_pos::symbol::Symbol;
4042

src/librustc_trans_utils/symbol_names_test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ pub fn report_symbol_names<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
3333
}
3434

3535
tcx.dep_graph.with_ignore(|| {
36-
let mut visitor = SymbolNamesTest { tcx: tcx };
36+
let visitor = SymbolNamesTest { tcx: tcx };
3737
// FIXME(#37712) could use ItemLikeVisitor if trait items were item-like
38-
tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
38+
tcx.hir.krate().par_deep_visit_items(visitor);
3939
})
4040
}
4141

42+
#[derive(Clone)]
4243
struct SymbolNamesTest<'a, 'tcx:'a> {
4344
tcx: TyCtxt<'a, 'tcx, 'tcx>,
4445
}

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ impl<'a, 'tcx> ParItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'a, 'tcx> {
691691

692692
pub fn check_wf_new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorReported> {
693693
tcx.sess.track_errors(|| {
694-
let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
695-
tcx.hir.krate().visit_all_item_likes(&mut visit.as_deep_visitor());
694+
let visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
695+
tcx.hir.krate().par_deep_visit_items(visit);
696696
})
697697
}
698698

src/librustc_typeck/check/wfcheck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use errors::{DiagnosticBuilder, DiagnosticId};
2626
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
2727
use rustc::hir;
2828

29+
#[derive(Clone)]
2930
pub struct CheckTypeWellFormedVisitor<'a, 'tcx:'a> {
3031
tcx: TyCtxt<'a, 'tcx, 'tcx>,
3132
code: ObligationCauseCode<'tcx>,

src/librustc_typeck/check_unused.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use syntax::ast;
1515
use syntax_pos::{Span, DUMMY_SP};
1616

1717
use rustc::hir::def_id::LOCAL_CRATE;
18-
use rustc::hir::itemlikevisit::ItemLikeVisitor;
18+
use rustc::hir::itemlikevisit::ParItemLikeVisitor;
1919
use rustc::hir;
2020
use rustc::util::nodemap::DefIdSet;
2121

@@ -45,8 +45,8 @@ impl<'a, 'tcx> CheckVisitor<'a, 'tcx> {
4545
}
4646
}
4747

48-
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> {
49-
fn visit_item(&mut self, item: &hir::Item) {
48+
impl<'a, 'tcx, 'v> ParItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> {
49+
fn visit_item(&self, item: &hir::Item) {
5050
if item.vis == hir::Public || item.span == DUMMY_SP {
5151
return;
5252
}
@@ -55,10 +55,10 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> {
5555
}
5656
}
5757

58-
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) {
58+
fn visit_trait_item(&self, _trait_item: &hir::TraitItem) {
5959
}
6060

61-
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
61+
fn visit_impl_item(&self, _impl_item: &hir::ImplItem) {
6262
}
6363
}
6464

@@ -71,8 +71,8 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
7171
used_trait_imports.extend(imports.iter());
7272
}
7373

74-
let mut visitor = CheckVisitor { tcx, used_trait_imports };
75-
tcx.hir.krate().visit_all_item_likes(&mut visitor);
74+
let visitor = CheckVisitor { tcx, used_trait_imports };
75+
tcx.hir.krate().par_visit_all_item_likes(&visitor);
7676

7777
for &(def_id, span) in tcx.maybe_unused_extern_crates(LOCAL_CRATE).iter() {
7878
// The `def_id` here actually was calculated during resolution (at least

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ use syntax_pos::{Span, DUMMY_SP};
4747

4848
use rustc::hir::{self, map as hir_map};
4949
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
50-
use rustc::hir::itemlikevisit::{IntoVisitor, ParDeepVisitor};
5150
use rustc::hir::def::{Def, CtorKind};
5251
use rustc::hir::def_id::DefId;
5352

5453
///////////////////////////////////////////////////////////////////////////
5554
// Main entry point
5655

5756
pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
58-
let visitor = CollectItemTypesVisitor { tcx: tcx };
59-
tcx.hir.krate().par_visit_all_item_likes(&ParDeepVisitor(visitor));
57+
tcx.hir.krate().par_deep_visit_items(CollectItemTypesVisitor { tcx: tcx });
6058
}
6159

6260
pub fn provide(providers: &mut Providers) {
@@ -99,14 +97,6 @@ struct CollectItemTypesVisitor<'a, 'tcx: 'a> {
9997
tcx: TyCtxt<'a, 'tcx, 'tcx>
10098
}
10199

102-
impl<'a, 'tcx: 'a> IntoVisitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
103-
type Visitor = Self;
104-
105-
fn into_visitor(&self) -> Self {
106-
self.clone()
107-
}
108-
}
109-
110100
impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
111101
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
112102
NestedVisitorMap::OnlyBodies(&self.tcx.hir)

src/librustc_typeck/outlives/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
// except according to those terms.
1010

1111
use rustc::hir;
12-
use rustc::hir::itemlikevisit::ItemLikeVisitor;
12+
use rustc::hir::itemlikevisit::ParItemLikeVisitor;
1313
use rustc::ty::TyCtxt;
1414

1515
pub fn test_inferred_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16-
tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
16+
tcx.hir.krate().par_visit_all_item_likes(&mut OutlivesTest { tcx });
1717
}
1818

1919
struct OutlivesTest<'a, 'tcx: 'a> {
2020
tcx: TyCtxt<'a, 'tcx, 'tcx>
2121
}
2222

23-
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
24-
fn visit_item(&mut self, item: &'tcx hir::Item) {
23+
impl<'a, 'tcx> ParItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
24+
fn visit_item(&self, item: &'tcx hir::Item) {
2525
let item_def_id = self.tcx.hir.local_def_id(item.id);
2626

2727
// For unit testing: check for a special "rustc_outlives"
@@ -36,6 +36,6 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
3636
}
3737
}
3838

39-
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
40-
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
39+
fn visit_trait_item(&self, _: &'tcx hir::TraitItem) { }
40+
fn visit_impl_item(&self, _: &'tcx hir::ImplItem) { }
4141
}

0 commit comments

Comments
 (0)