Skip to content

Commit 0194bed

Browse files
committed
Auto merge of #57394 - euclio:compiletest-optimization, r=Mark-Simulacrum
slightly optimize compiletest test collection Save quite a few syscalls and avoiding pushing in a loop.
2 parents a651777 + 2a9ad77 commit 0194bed

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

src/tools/compiletest/src/main.rs

+27-34
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ pub fn run_tests(config: &Config) {
489489
// Let tests know which target they're running as
490490
env::set_var("TARGET", &config.target);
491491

492-
let res = test::run_tests_console(&opts, tests.into_iter().collect());
492+
let res = test::run_tests_console(&opts, tests);
493493
match res {
494494
Ok(true) => {}
495495
Ok(false) => panic!("Some tests failed"),
@@ -548,22 +548,18 @@ fn collect_tests_from_dir(
548548
relative_dir_path: &Path,
549549
tests: &mut Vec<test::TestDescAndFn>,
550550
) -> io::Result<()> {
551-
// Ignore directories that contain a file
552-
// `compiletest-ignore-dir`.
553-
for file in fs::read_dir(dir)? {
554-
let file = file?;
555-
let name = file.file_name();
556-
if name == *"compiletest-ignore-dir" {
557-
return Ok(());
558-
}
559-
if name == *"Makefile" && config.mode == Mode::RunMake {
560-
let paths = TestPaths {
561-
file: dir.to_path_buf(),
562-
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
563-
};
564-
tests.extend(make_test(config, &paths));
565-
return Ok(());
566-
}
551+
// Ignore directories that contain a file named `compiletest-ignore-dir`.
552+
if dir.join("compiletest-ignore-dir").exists() {
553+
return Ok(());
554+
}
555+
556+
if config.mode == Mode::RunMake && dir.join("Makefile").exists() {
557+
let paths = TestPaths {
558+
file: dir.to_path_buf(),
559+
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
560+
};
561+
tests.extend(make_test(config, &paths));
562+
return Ok(());
567563
}
568564

569565
// If we find a test foo/bar.rs, we have to build the
@@ -577,8 +573,7 @@ fn collect_tests_from_dir(
577573

578574
// Add each `.rs` file as a test, and recurse further on any
579575
// subdirectories we find, except for `aux` directories.
580-
let dirs = fs::read_dir(dir)?;
581-
for file in dirs {
576+
for file in fs::read_dir(dir)? {
582577
let file = file?;
583578
let file_path = file.path();
584579
let file_name = file.file_name();
@@ -679,7 +674,7 @@ fn collect_timestamps(path: &PathBuf) -> impl Iterator<Item=FileTime> {
679674
WalkDir::new(path)
680675
.into_iter()
681676
.map(|entry| entry.unwrap())
682-
.filter(|entry| entry.metadata().unwrap().is_file())
677+
.filter(|entry| entry.file_type().is_file())
683678
.map(|entry| mtime(entry.path()))
684679
}
685680

@@ -707,14 +702,12 @@ fn up_to_date(
707702
.expect("Could not find Rust source root");
708703
let stamp = mtime(&stamp_name);
709704
let mut inputs = vec![mtime(&testpaths.file), mtime(&config.rustc_path)];
710-
for aux in props.aux.iter() {
711-
inputs.push(mtime(&testpaths
712-
.file
713-
.parent()
714-
.unwrap()
715-
.join("auxiliary")
716-
.join(aux)));
717-
}
705+
inputs.extend(
706+
props
707+
.aux
708+
.iter()
709+
.map(|aux| mtime(&testpaths.file.parent().unwrap().join("auxiliary").join(aux))),
710+
);
718711
// Relevant pretty printer files
719712
let pretty_printer_files = [
720713
"src/etc/debugger_pretty_printers_common.py",
@@ -723,20 +716,20 @@ fn up_to_date(
723716
"src/etc/lldb_batchmode.py",
724717
"src/etc/lldb_rust_formatters.py",
725718
];
726-
for pretty_printer_file in &pretty_printer_files {
727-
inputs.push(mtime(&rust_src_dir.join(pretty_printer_file)));
728-
}
719+
inputs.extend(pretty_printer_files.iter().map(|pretty_printer_file| {
720+
mtime(&rust_src_dir.join(pretty_printer_file))
721+
}));
729722
inputs.extend(collect_timestamps(&config.run_lib_path));
730723
if let Some(ref rustdoc_path) = config.rustdoc_path {
731724
inputs.push(mtime(&rustdoc_path));
732725
inputs.push(mtime(&rust_src_dir.join("src/etc/htmldocck.py")));
733726
}
734727

735728
// UI test files.
736-
for extension in UI_EXTENSIONS {
729+
inputs.extend(UI_EXTENSIONS.iter().map(|extension| {
737730
let path = &expected_output_path(testpaths, revision, &config.compare_mode, extension);
738-
inputs.push(mtime(path));
739-
}
731+
mtime(path)
732+
}));
740733

741734
// Compiletest itself.
742735
inputs.extend(collect_timestamps(&rust_src_dir.join("src/tools/compiletest/")));

0 commit comments

Comments
 (0)