Skip to content

Commit 1e630eb

Browse files
committed
Parallelize passes
1 parent 1e7e800 commit 1e630eb

File tree

17 files changed

+59
-40
lines changed

17 files changed

+59
-40
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
@@ -758,6 +758,13 @@ impl Crate {
758758
});
759759
}
760760

761+
pub fn par_deep_visit_items<'hir, V>(&'hir self, visitor: V)
762+
where V: intravisit::Visitor<'hir> + Clone + Sync + Send
763+
{
764+
let visitor = itemlikevisit::ClonableVisitor(visitor);
765+
self.par_visit_all_item_likes(&itemlikevisit::ParDeepVisitor(visitor));
766+
}
767+
761768
pub fn body(&self, id: BodyId) -> &Body {
762769
&self.bodies[&id]
763770
}

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,8 +467,7 @@ 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

473473
/// Check whether an item marked with `deprecated(since="X")` is currently
@@ -494,6 +494,7 @@ pub fn deprecation_in_effect(since: &str) -> bool {
494494
}
495495
}
496496

497+
#[derive(Clone)]
497498
struct Checker<'a, 'tcx: 'a> {
498499
tcx: TyCtxt<'a, 'tcx, 'tcx>,
499500
}
@@ -807,7 +808,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
807808
};
808809
missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span);
809810
intravisit::walk_crate(&mut missing, krate);
810-
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
811+
krate.par_deep_visit_items(missing);
811812
}
812813

813814
let ref declared_lib_features = tcx.features().declared_lib_features;

src/librustc/traits/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use infer::{InferCtxt};
3232

3333
use rustc_data_structures::sync::Lrc;
3434
use std::fmt::Debug;
35-
use std::rc::Rc;
3635
use syntax::ast;
3736
use syntax_pos::{Span, DUMMY_SP};
3837

@@ -261,7 +260,7 @@ pub struct DerivedObligationCause<'tcx> {
261260
parent_trait_ref: ty::PolyTraitRef<'tcx>,
262261

263262
/// The parent trait had this cause
264-
parent_code: Rc<ObligationCauseCode<'tcx>>
263+
parent_code: Lrc<ObligationCauseCode<'tcx>>
265264
}
266265

267266
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
@@ -44,13 +44,12 @@ use ty::relate::TypeRelation;
4444
use middle::lang_items;
4545
use mir::interpret::{GlobalId};
4646

47-
use rustc_data_structures::sync::Lock;
47+
use rustc_data_structures::sync::{Lrc, Lock};
4848
use rustc_data_structures::bitvec::BitVector;
4949
use std::iter;
5050
use std::cmp;
5151
use std::fmt;
5252
use std::mem;
53-
use std::rc::Rc;
5453
use rustc_target::spec::abi::Abi;
5554
use hir;
5655
use util::nodemap::{FxHashMap, FxHashSet};
@@ -3406,7 +3405,7 @@ impl<'tcx> TraitObligation<'tcx> {
34063405
if obligation.recursion_depth >= 0 {
34073406
let derived_cause = DerivedObligationCause {
34083407
parent_trait_ref: obligation.predicate.to_poly_trait_ref(),
3409-
parent_code: Rc::new(obligation.cause.code.clone())
3408+
parent_code: Lrc::new(obligation.cause.code.clone())
34103409
};
34113410
let derived_code = variant(derived_cause);
34123411
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
@@ -16,7 +16,7 @@ use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1616
use ty::{self, Lift, TyCtxt};
1717

1818
use std::fmt;
19-
use std::rc::Rc;
19+
use rustc_data_structures::sync::Lrc;
2020

2121
// structural impls for the structs in traits
2222

@@ -246,7 +246,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> {
246246
tcx.lift(&*self.parent_code)
247247
.map(|code| traits::DerivedObligationCause {
248248
parent_trait_ref: trait_ref,
249-
parent_code: Rc::new(code),
249+
parent_code: Lrc::new(code),
250250
})
251251
})
252252
}

src/librustc/ty/structural_impls.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_data_structures::sync::Lrc;
2222
use mir::interpret;
2323

2424
use std::rc::Rc;
25+
use std::sync::Arc;
2526

2627
///////////////////////////////////////////////////////////////////////////
2728
// Atomic structs
@@ -699,6 +700,16 @@ EnumTypeFoldableImpl! {
699700
} where T: TypeFoldable<'tcx>
700701
}
701702

703+
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
704+
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
705+
Arc::new((**self).fold_with(folder))
706+
}
707+
708+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
709+
(**self).visit_with(visitor)
710+
}
711+
}
712+
702713
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
703714
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
704715
Rc::new((**self).fold_with(folder))

src/librustc_codegen_llvm/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#![feature(slice_sort_by_cached_key)]
3131
#![feature(optin_builtin_traits)]
3232

33+
#![recursion_limit="256"]
34+
3335
use rustc::dep_graph::WorkProduct;
3436
use syntax_pos::symbol::Symbol;
3537

src/librustc_codegen_utils/symbol_names_test.rs

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

3434
tcx.dep_graph.with_ignore(|| {
3535
let mut visitor = SymbolNamesTest { tcx: tcx };
36+
// FIXME: Try parallel version
3637
tcx.hir.krate().visit_all_item_likes(&mut visitor);
3738
})
3839
}
3940

41+
#[derive(Clone)]
4042
struct SymbolNamesTest<'a, 'tcx:'a> {
4143
tcx: TyCtxt<'a, 'tcx, 'tcx>,
4244
}

src/librustc_mir/hair/pattern/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_passes/lib.rs

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

2121
#![feature(rustc_diagnostic_macros)]
2222

23+
#![recursion_limit="256"]
24+
2325
#[macro_use]
2426
extern crate rustc;
2527
extern crate rustc_mir;

src/librustc_passes/rvalue_promotion.rs

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

5353
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
54-
for &body_id in &tcx.hir.krate().body_ids {
55-
let def_id = tcx.hir.body_owner_def_id(body_id);
56-
tcx.const_is_rvalue_promotable_to_static(def_id);
57-
}
54+
tcx.par_body_owners(|def_id| { tcx.const_is_rvalue_promotable_to_static(def_id); });
5855
tcx.sess.abort_if_errors();
5956
}
6057

src/librustc_typeck/check/mod.rs

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

683683
pub fn check_wf_new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), ErrorReported> {
684684
tcx.sess.track_errors(|| {
685-
let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
686-
tcx.hir.krate().visit_all_item_likes(&mut visit.as_deep_visitor());
685+
let visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx);
686+
tcx.hir.krate().par_deep_visit_items(visit);
687687
})
688688
}
689689

src/librustc_typeck/check/wfcheck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ fn check_false_global_bounds<'a, 'gcx, 'tcx>(
727727
fcx.select_all_obligations_or_error();
728728
}
729729

730+
#[derive(Clone)]
730731
pub struct CheckTypeWellFormedVisitor<'a, 'tcx: 'a> {
731732
tcx: TyCtxt<'a, 'tcx, 'tcx>,
732733
}

src/librustc_typeck/collect.rs

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

5151
use rustc::hir::{self, map as hir_map, CodegenFnAttrs, CodegenFnAttrFlags, Unsafety};
5252
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
53-
use rustc::hir::itemlikevisit::{IntoVisitor, ParDeepVisitor};
5453
use rustc::hir::def::{Def, CtorKind};
5554
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
5655

5756
///////////////////////////////////////////////////////////////////////////
5857
// Main entry point
5958

6059
pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
61-
let visitor = CollectItemTypesVisitor { tcx: tcx };
62-
tcx.hir.krate().par_visit_all_item_likes(&ParDeepVisitor(visitor));
60+
tcx.hir.krate().par_deep_visit_items(CollectItemTypesVisitor { tcx: tcx });
6361
}
6462

6563
pub fn provide(providers: &mut Providers) {
@@ -104,14 +102,6 @@ struct CollectItemTypesVisitor<'a, 'tcx: 'a> {
104102
tcx: TyCtxt<'a, 'tcx, 'tcx>
105103
}
106104

107-
impl<'a, 'tcx: 'a> IntoVisitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
108-
type Visitor = Self;
109-
110-
fn into_visitor(&self) -> Self {
111-
self.clone()
112-
}
113-
}
114-
115105
impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
116106
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
117107
NestedVisitorMap::OnlyBodies(&self.tcx.hir)

src/librustc_typeck/outlives/test.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +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
17-
.krate()
18-
.visit_all_item_likes(&mut OutlivesTest { tcx });
16+
tcx.hir.krate().par_visit_all_item_likes(&mut OutlivesTest { tcx });
1917
}
2018

2119
struct OutlivesTest<'a, 'tcx: 'a> {
2220
tcx: TyCtxt<'a, 'tcx, 'tcx>,
2321
}
2422

25-
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
26-
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) {
2725
let item_def_id = self.tcx.hir.local_def_id(item.id);
2826

2927
// For unit testing: check for a special "rustc_outlives"
@@ -40,6 +38,6 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
4038
}
4139
}
4240

43-
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
44-
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
41+
fn visit_trait_item(&self, _: &'tcx hir::TraitItem) { }
42+
fn visit_impl_item(&self, _: &'tcx hir::ImplItem) { }
4543
}

0 commit comments

Comments
 (0)