Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8a21f48

Browse files
Rollup merge of rust-lang#126427 - Oneirical:oktobertest, r=jieyouxu
Rewrite `intrinsic-unreachable`, `sepcomp-cci-copies`, `sepcomp-inlining` and `sepcomp-separate` `run-make` tests to rmake.rs Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).
2 parents 328d55a + ea30a9d commit 8a21f48

File tree

13 files changed

+121
-62
lines changed

13 files changed

+121
-62
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,6 +3476,7 @@ dependencies = [
34763476
"object 0.34.0",
34773477
"regex",
34783478
"similar",
3479+
"walkdir",
34793480
"wasmparser",
34803481
]
34813482

src/tools/run-make-support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ similar = "2.5.0"
99
wasmparser = "0.118.2"
1010
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1111
gimli = "0.28.1"
12+
walkdir = "2.5.0"

src/tools/run-make-support/src/fs_wrapper.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs;
22
use std::path::Path;
33

4-
/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message..
4+
/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message.
55
#[track_caller]
66
pub fn remove_file<P: AsRef<Path>>(path: P) {
77
fs::remove_file(path.as_ref())
@@ -18,21 +18,28 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
1818
));
1919
}
2020

21-
/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
21+
/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message.
2222
#[track_caller]
2323
pub fn create_file<P: AsRef<Path>>(path: P) {
2424
fs::File::create(path.as_ref())
2525
.expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
2626
}
2727

28-
/// A wrapper around [`std::fs::read`] which includes the file path in the panic message..
28+
/// A wrapper around [`std::fs::File::open`] which includes the file path in the panic message.
29+
#[track_caller]
30+
pub fn open_file<P: AsRef<Path>>(path: P) -> fs::File {
31+
fs::File::open(path.as_ref())
32+
.expect(&format!("the file in path \"{}\" could not be opened", path.as_ref().display()))
33+
}
34+
35+
/// A wrapper around [`std::fs::read`] which includes the file path in the panic message.
2936
#[track_caller]
3037
pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {
3138
fs::read(path.as_ref())
3239
.expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display()))
3340
}
3441

35-
/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
42+
/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message.
3643
#[track_caller]
3744
pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
3845
fs::read_to_string(path.as_ref()).expect(&format!(
@@ -41,14 +48,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
4148
))
4249
}
4350

44-
/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
51+
/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message.
4552
#[track_caller]
4653
pub fn read_dir<P: AsRef<Path>>(path: P) -> fs::ReadDir {
4754
fs::read_dir(path.as_ref())
4855
.expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display()))
4956
}
5057

51-
/// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
58+
/// A wrapper around [`std::fs::write`] which includes the file path in the panic message.
5259
#[track_caller]
5360
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
5461
fs::write(path.as_ref(), contents.as_ref()).expect(&format!(
@@ -57,7 +64,7 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
5764
));
5865
}
5966

60-
/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
67+
/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message.
6168
#[track_caller]
6269
pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
6370
fs::remove_dir_all(path.as_ref()).expect(&format!(
@@ -66,7 +73,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
6673
));
6774
}
6875

69-
/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
76+
/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message.
7077
#[track_caller]
7178
pub fn create_dir<P: AsRef<Path>>(path: P) {
7279
fs::create_dir(path.as_ref()).expect(&format!(
@@ -75,7 +82,7 @@ pub fn create_dir<P: AsRef<Path>>(path: P) {
7582
));
7683
}
7784

78-
/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
85+
/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message.
7986
#[track_caller]
8087
pub fn create_dir_all<P: AsRef<Path>>(path: P) {
8188
fs::create_dir_all(path.as_ref()).expect(&format!(
@@ -84,7 +91,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) {
8491
));
8592
}
8693

87-
/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message..
94+
/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message.
8895
#[track_caller]
8996
pub fn metadata<P: AsRef<Path>>(path: P) -> fs::Metadata {
9097
fs::metadata(path.as_ref()).expect(&format!(

src/tools/run-make-support/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::path::{Path, PathBuf};
2424
pub use gimli;
2525
pub use object;
2626
pub use regex;
27+
pub use walkdir;
2728
pub use wasmparser;
2829

2930
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
@@ -277,6 +278,39 @@ pub fn uname() -> String {
277278
output.stdout_utf8()
278279
}
279280

281+
/// Search for all files in the current working directory with the extension `ext`,
282+
/// read their contents and count the
283+
/// number of regex matches with a given expression (re).
284+
#[track_caller]
285+
pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
286+
use std::io::BufRead;
287+
use walkdir::{DirEntry, WalkDir};
288+
289+
let walker = WalkDir::new(cwd()).into_iter();
290+
291+
fn is_hidden(entry: &DirEntry) -> bool {
292+
entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false)
293+
}
294+
295+
let mut count = 0;
296+
297+
for entry in walker.filter_entry(|e| !is_hidden(e)) {
298+
let entry = entry.expect("failed to get DirEntry");
299+
if !entry.path().is_file() {
300+
continue;
301+
}
302+
303+
if !entry.path().extension().is_some_and(|e| e == ext) {
304+
continue;
305+
}
306+
307+
let content = fs_wrapper::read(entry.path());
308+
count += content.lines().filter(|line| re.is_match(&line.as_ref().unwrap())).count();
309+
}
310+
311+
count
312+
}
313+
280314
fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! {
281315
if output.status().success() {
282316
eprintln!("command unexpectedly succeeded at line {caller_line_number}");

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ run-make/incr-add-rust-src-component/Makefile
6464
run-make/incr-foreign-head-span/Makefile
6565
run-make/inline-always-many-cgu/Makefile
6666
run-make/interdependent-c-libraries/Makefile
67-
run-make/intrinsic-unreachable/Makefile
6867
run-make/invalid-library/Makefile
6968
run-make/invalid-so/Makefile
7069
run-make/issue-107094/Makefile
@@ -187,9 +186,6 @@ run-make/sanitizer-dylib-link/Makefile
187186
run-make/sanitizer-staticlib-link/Makefile
188187
run-make/separate-link-fail/Makefile
189188
run-make/separate-link/Makefile
190-
run-make/sepcomp-cci-copies/Makefile
191-
run-make/sepcomp-inlining/Makefile
192-
run-make/sepcomp-separate/Makefile
193189
run-make/share-generics-dylib/Makefile
194190
run-make/silly-file-names/Makefile
195191
run-make/simd-ffi/Makefile

tests/run-make/intrinsic-unreachable/Makefile

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// intrinsics::unreachable tells the compiler that a certain point in the code
2+
// is not reachable by any means, which enables some useful optimizations.
3+
// In this test, exit-unreachable contains this instruction and exit-ret does not,
4+
// which means the emitted artifacts should be shorter in length.
5+
// See https://github.com/rust-lang/rust/pull/16970
6+
7+
//@ needs-asm-support
8+
//@ ignore-windows
9+
// Reason: Because of Windows exception handling, the code is not necessarily any shorter.
10+
11+
use run_make_support::{fs_wrapper, rustc};
12+
use std::io::{BufRead, BufReader};
13+
14+
fn main() {
15+
rustc().opt().emit("asm").input("exit-ret.rs").run();
16+
rustc().opt().emit("asm").input("exit-unreachable.rs").run();
17+
let unreachable_file = fs_wrapper::open_file("exit-unreachable.s");
18+
let ret_file = fs_wrapper::open_file("exit-ret.s");
19+
assert!(
20+
BufReader::new(unreachable_file).lines().count() < BufReader::new(ret_file).lines().count()
21+
);
22+
}

tests/run-make/sepcomp-cci-copies/Makefile

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Check that cross-crate inlined items are inlined in all compilation units
2+
// that refer to them, and not in any other compilation units.
3+
// Note that we have to pass `-C codegen-units=6` because up to two CGUs may be
4+
// created for each source module (see `rustc_const_eval::monomorphize::partitioning`).
5+
// See https://github.com/rust-lang/rust/pull/16367
6+
7+
use run_make_support::{count_regex_matches_in_files_with_extension, regex, rustc};
8+
9+
fn main() {
10+
rustc().input("cci_lib.rs").run();
11+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(6).arg("-Zinline-in-all-cgus").run();
12+
let re = regex::Regex::new(r#"define\ .*cci_fn"#).unwrap();
13+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
14+
}

tests/run-make/sepcomp-inlining/Makefile

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test that #[inline] functions still get inlined across compilation unit
2+
// boundaries. Compilation should produce three IR files, but only the two
3+
// compilation units that have a usage of the #[inline] function should
4+
// contain a definition. Also, the non-#[inline] function should be defined
5+
// in only one compilation unit.
6+
// See https://github.com/rust-lang/rust/pull/16367
7+
8+
use run_make_support::{count_regex_matches_in_files_with_extension, regex, rustc};
9+
10+
fn main() {
11+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run();
12+
let re = regex::Regex::new(r#"define\ i32\ .*inlined"#).unwrap();
13+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 0);
14+
let re = regex::Regex::new(r#"define\ internal\ .*inlined"#).unwrap();
15+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
16+
let re = regex::Regex::new(r#"define\ hidden\ i32\ .*normal"#).unwrap();
17+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 1);
18+
let re = regex::Regex::new(r#"declare\ hidden\ i32\ .*normal"#).unwrap();
19+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
20+
}

tests/run-make/sepcomp-separate/Makefile

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Test that separate compilation actually puts code into separate compilation
2+
// units. `foo.rs` defines `magic_fn` in three different modules, which should
3+
// wind up in three different compilation units.
4+
// See https://github.com/rust-lang/rust/pull/16367
5+
6+
use run_make_support::{count_regex_matches_in_files_with_extension, regex, rustc};
7+
8+
fn main() {
9+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run();
10+
let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap();
11+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3);
12+
}

0 commit comments

Comments
 (0)