Skip to content

Commit

Permalink
Run module lint passes in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Mar 28, 2019
1 parent cd32f9b commit dee389f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use self::TargetLint::*;

use std::slice;
use rustc_data_structures::sync::{ReadGuard, Lock, join};
use rustc_data_structures::sync::{ReadGuard, Lock, ParallelIterator, join, par_iter};
use crate::lint::{EarlyLintPass, LateLintPass, EarlyLintPassObject, LateLintPassObject};
use crate::lint::{LintArray, Level, Lint, LintId, LintPass, LintBuffer};
use crate::lint::builtin::BuiltinLintDiagnostics;
Expand Down Expand Up @@ -56,7 +56,7 @@ pub struct LintStore {
pre_expansion_passes: Option<Vec<EarlyLintPassObject>>,
early_passes: Option<Vec<EarlyLintPassObject>>,
late_passes: Lock<Option<Vec<LateLintPassObject>>>,
late_module_passes: Lock<Option<Vec<LateLintPassObject>>>,
late_module_passes: Vec<LateLintPassObject>,

/// Lints indexed by name.
by_name: FxHashMap<String, TargetLint>,
Expand Down Expand Up @@ -144,7 +144,7 @@ impl LintStore {
pre_expansion_passes: Some(vec![]),
early_passes: Some(vec![]),
late_passes: Lock::new(Some(vec![])),
late_module_passes: Lock::new(Some(vec![])),
late_module_passes: vec![],
by_name: Default::default(),
future_incompatible: Default::default(),
lint_groups: Default::default(),
Expand Down Expand Up @@ -200,7 +200,7 @@ impl LintStore {
self.push_pass(sess, from_plugin, &pass);
if !register_only {
if per_module {
self.late_module_passes.lock().as_mut().unwrap().push(pass);
self.late_module_passes.push(pass);
} else {
self.late_passes.lock().as_mut().unwrap().push(pass);
}
Expand Down Expand Up @@ -1277,14 +1277,12 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(

late_lint_mod_pass(tcx, module_def_id, builtin_lints);

let mut passes = tcx.sess.lint_store.borrow().late_module_passes.lock().take().unwrap();
let mut passes: Vec<_> = tcx.sess.lint_store.borrow().late_module_passes
.iter().map(|pass| pass.fresh_late_pass()).collect();

if !passes.is_empty() {
late_lint_mod_pass(tcx, module_def_id, LateLintPassObjects { lints: &mut passes[..] });
}

// Put the passes back in the session.
*tcx.sess.lint_store.borrow().late_module_passes.lock() = Some(passes);
}

fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
Expand Down Expand Up @@ -1342,16 +1340,14 @@ fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
});
}

let mut passes = tcx.sess.lint_store.borrow().late_module_passes.lock().take().unwrap();
let mut passes: Vec<_> = tcx.sess.lint_store.borrow().late_module_passes
.iter().map(|pass| pass.fresh_late_pass()).collect();

for pass in &mut passes {
time(tcx.sess, &format!("running late module lint: {}", pass.name()), || {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
});
}

// Put the passes back in the session.
*tcx.sess.lint_store.borrow().late_module_passes.lock() = Some(passes);
}

// Put the passes back in the session.
Expand All @@ -1371,9 +1367,9 @@ pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
}, || {
time(tcx.sess, "module lints", || {
// Run per-module lints
for &module in tcx.hir().krate().modules.keys() {
par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| {
tcx.ensure().lint_mod(tcx.hir().local_def_id(module));
}
});
});
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ macro_rules! expand_lint_pass_methods {
macro_rules! declare_late_lint_pass {
([], [$hir:tt], [$($methods:tt)*]) => (
pub trait LateLintPass<'a, $hir>: LintPass {
fn fresh_late_pass(&self) -> LateLintPassObject {
panic!()
}
expand_lint_pass_methods!(&LateContext<'a, $hir>, [$($methods)*]);
}
)
Expand Down

0 comments on commit dee389f

Please sign in to comment.