Skip to content

Commit 77d1185

Browse files
committed
parallelize tidy checks
1 parent 5233edc commit 77d1185

File tree

5 files changed

+76
-39
lines changed

5 files changed

+76
-39
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5239,6 +5239,7 @@ name = "tidy"
52395239
version = "0.1.0"
52405240
dependencies = [
52415241
"cargo_metadata 0.11.1",
5242+
"crossbeam-utils 0.8.0",
52425243
"lazy_static",
52435244
"regex",
52445245
"walkdir",

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cargo_metadata = "0.11"
1010
regex = "1"
1111
lazy_static = "1"
1212
walkdir = "2"
13+
crossbeam-utils = "0.8.0"
1314

1415
[[bin]]
1516
name = "rust-tidy"

src/tools/tidy/src/bins.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ pub fn check(path: &Path, output: &Path, bad: &mut bool) {
3232
// readily create a file there to test.
3333
//
3434
// See #36706 and #74753 for context.
35-
let mut temp_path = path.join("tidy-test-file");
35+
//
36+
// We also add the thread ID to avoid threads trampling on each others files.
37+
let file_name = format!("t{}.tidy-test-file", std::thread::current().id().as_u64());
38+
let mut temp_path = path.join(&file_name);
3639
match fs::File::create(&temp_path).or_else(|_| {
37-
temp_path = output.join("tidy-test-file");
40+
temp_path = output.join(&file_name);
3841
fs::File::create(&temp_path)
3942
}) {
4043
Ok(file) => {

src/tools/tidy/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! to be used by tools.
55
66
#![cfg_attr(bootstrap, feature(str_split_once))]
7+
#![feature(thread_id_value)]
78

89
use std::fs::File;
910
use std::io::Read;
@@ -54,6 +55,12 @@ pub mod unit_tests;
5455
pub mod unstable_book;
5556

5657
fn filter_dirs(path: &Path) -> bool {
58+
// Filter out temporary files used by the bins module to probe the filesystem
59+
match path.extension() {
60+
Some(ext) if ext == "tidy-test-file" => return true,
61+
_ => {}
62+
}
63+
5764
let skip = [
5865
"compiler/rustc_codegen_cranelift",
5966
"src/llvm-project",

src/tools/tidy/src/main.rs

+62-37
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
77
use tidy::*;
88

9+
use crossbeam_utils::thread::scope;
910
use std::env;
1011
use std::path::PathBuf;
1112
use std::process;
13+
use std::sync::atomic::{AtomicBool, Ordering};
1214

1315
fn main() {
1416
let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into();
@@ -22,45 +24,68 @@ fn main() {
2224

2325
let args: Vec<String> = env::args().skip(1).collect();
2426

25-
let mut bad = false;
2627
let verbose = args.iter().any(|s| *s == "--verbose");
2728

28-
// Checks over tests.
29-
debug_artifacts::check(&src_path, &mut bad);
30-
ui_tests::check(&src_path, &mut bad);
31-
32-
// Checks that only make sense for the compiler.
33-
errors::check(&compiler_path, &mut bad);
34-
error_codes_check::check(&src_path, &mut bad);
35-
36-
// Checks that only make sense for the std libs.
37-
pal::check(&library_path, &mut bad);
38-
39-
// Checks that need to be done for both the compiler and std libraries.
40-
unit_tests::check(&src_path, &mut bad);
41-
unit_tests::check(&compiler_path, &mut bad);
42-
unit_tests::check(&library_path, &mut bad);
43-
44-
bins::check(&src_path, &output_directory, &mut bad);
45-
bins::check(&compiler_path, &output_directory, &mut bad);
46-
bins::check(&library_path, &output_directory, &mut bad);
47-
48-
style::check(&src_path, &mut bad);
49-
style::check(&compiler_path, &mut bad);
50-
style::check(&library_path, &mut bad);
51-
52-
edition::check(&src_path, &mut bad);
53-
edition::check(&compiler_path, &mut bad);
54-
edition::check(&library_path, &mut bad);
55-
56-
let collected = features::check(&src_path, &compiler_path, &library_path, &mut bad, verbose);
57-
unstable_book::check(&src_path, collected, &mut bad);
58-
59-
// Checks that are done on the cargo workspace.
60-
deps::check(&root_path, &cargo, &mut bad);
61-
extdeps::check(&root_path, &mut bad);
62-
63-
if bad {
29+
let bad = std::sync::Arc::new(AtomicBool::new(false));
30+
31+
scope(|s| {
32+
macro_rules! check {
33+
($p:ident $(, $args:expr)* ) => {
34+
s.spawn(|_| {
35+
let mut flag = false;
36+
$p::check($($args),* , &mut flag);
37+
if (flag) {
38+
bad.store(true, Ordering::Relaxed);
39+
}
40+
});
41+
}
42+
}
43+
44+
// Checks that are done on the cargo workspace.
45+
check!(deps, &root_path, &cargo);
46+
check!(extdeps, &root_path);
47+
48+
// Checks over tests.
49+
check!(debug_artifacts, &src_path);
50+
check!(ui_tests, &src_path);
51+
52+
// Checks that only make sense for the compiler.
53+
check!(errors, &compiler_path);
54+
check!(error_codes_check, &src_path);
55+
56+
// Checks that only make sense for the std libs.
57+
check!(pal, &library_path);
58+
59+
// Checks that need to be done for both the compiler and std libraries.
60+
check!(unit_tests, &src_path);
61+
check!(unit_tests, &compiler_path);
62+
check!(unit_tests, &library_path);
63+
64+
check!(bins, &src_path, &output_directory);
65+
check!(bins, &compiler_path, &output_directory);
66+
check!(bins, &library_path, &output_directory);
67+
68+
check!(style, &src_path);
69+
check!(style, &compiler_path);
70+
check!(style, &library_path);
71+
72+
check!(edition, &src_path);
73+
check!(edition, &compiler_path);
74+
check!(edition, &library_path);
75+
76+
let collected = {
77+
let mut flag = false;
78+
let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
79+
if flag {
80+
bad.store(true, Ordering::Relaxed);
81+
}
82+
r
83+
};
84+
check!(unstable_book, &src_path, collected);
85+
})
86+
.unwrap();
87+
88+
if bad.load(Ordering::Relaxed) {
6489
eprintln!("some tidy checks failed");
6590
process::exit(1);
6691
}

0 commit comments

Comments
 (0)