Skip to content

Commit 9d7eb55

Browse files
authored
Unrolled build for rust-lang#126427
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 32e6926 + f04d0c6 commit 9d7eb55

File tree

11 files changed

+99
-62
lines changed

11 files changed

+99
-62
lines changed

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

+10-10
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,21 @@ 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::read`] which includes the file path in the panic message.
2929
#[track_caller]
3030
pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {
3131
fs::read(path.as_ref())
3232
.expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display()))
3333
}
3434

35-
/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
35+
/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message.
3636
#[track_caller]
3737
pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
3838
fs::read_to_string(path.as_ref()).expect(&format!(
@@ -41,14 +41,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
4141
))
4242
}
4343

44-
/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
44+
/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message.
4545
#[track_caller]
4646
pub fn read_dir<P: AsRef<Path>>(path: P) -> fs::ReadDir {
4747
fs::read_dir(path.as_ref())
4848
.expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display()))
4949
}
5050

51-
/// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
51+
/// A wrapper around [`std::fs::write`] which includes the file path in the panic message.
5252
#[track_caller]
5353
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
5454
fs::write(path.as_ref(), contents.as_ref()).expect(&format!(
@@ -57,7 +57,7 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
5757
));
5858
}
5959

60-
/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
60+
/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message.
6161
#[track_caller]
6262
pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
6363
fs::remove_dir_all(path.as_ref()).expect(&format!(
@@ -66,7 +66,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
6666
));
6767
}
6868

69-
/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
69+
/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message.
7070
#[track_caller]
7171
pub fn create_dir<P: AsRef<Path>>(path: P) {
7272
fs::create_dir(path.as_ref()).expect(&format!(
@@ -75,7 +75,7 @@ pub fn create_dir<P: AsRef<Path>>(path: P) {
7575
));
7676
}
7777

78-
/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
78+
/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message.
7979
#[track_caller]
8080
pub fn create_dir_all<P: AsRef<Path>>(path: P) {
8181
fs::create_dir_all(path.as_ref()).expect(&format!(
@@ -84,7 +84,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) {
8484
));
8585
}
8686

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

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

+14
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,20 @@ pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, exp
303303
.is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned()))
304304
}
305305

306+
/// Gathers all files in the current working directory that have the extension `ext`, and counts
307+
/// the number of lines within that contain a match with the regex pattern `re`.
308+
pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
309+
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));
310+
311+
let mut count = 0;
312+
for file in fetched_files {
313+
let content = fs_wrapper::read_to_string(file);
314+
count += content.lines().filter(|line| re.is_match(&line)).count();
315+
}
316+
317+
count
318+
}
319+
306320
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
307321
/// available on the platform!
308322
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ run-make/foreign-rust-exceptions/Makefile
4747
run-make/incr-add-rust-src-component/Makefile
4848
run-make/incr-foreign-head-span/Makefile
4949
run-make/interdependent-c-libraries/Makefile
50-
run-make/intrinsic-unreachable/Makefile
5150
run-make/issue-107094/Makefile
5251
run-make/issue-109934-lto-debuginfo/Makefile
5352
run-make/issue-14698/Makefile
@@ -130,9 +129,6 @@ run-make/rustc-macro-dep-files/Makefile
130129
run-make/sanitizer-cdylib-link/Makefile
131130
run-make/sanitizer-dylib-link/Makefile
132131
run-make/sanitizer-staticlib-link/Makefile
133-
run-make/sepcomp-cci-copies/Makefile
134-
run-make/sepcomp-inlining/Makefile
135-
run-make/sepcomp-separate/Makefile
136132
run-make/share-generics-dylib/Makefile
137133
run-make/silly-file-names/Makefile
138134
run-make/simd-ffi/Makefile

tests/run-make/intrinsic-unreachable/Makefile

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
13+
fn main() {
14+
rustc().opt().emit("asm").input("exit-ret.rs").run();
15+
rustc().opt().emit("asm").input("exit-unreachable.rs").run();
16+
assert!(
17+
fs_wrapper::read_to_string("exit-unreachable.s").lines().count()
18+
< fs_wrapper::read_to_string("exit-ret.s").lines().count()
19+
);
20+
}

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

-12
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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::{
8+
count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc,
9+
shallow_find_files,
10+
};
11+
12+
fn main() {
13+
rustc().input("cci_lib.rs").run();
14+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(6).arg("-Zinline-in-all-cgus").run();
15+
let re = regex::Regex::new(r#"define\ .*cci_fn"#).unwrap();
16+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
17+
}

tests/run-make/sepcomp-inlining/Makefile

-15
This file was deleted.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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::{
9+
count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc,
10+
shallow_find_files,
11+
};
12+
13+
fn main() {
14+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run();
15+
let re = regex::Regex::new(r#"define\ i32\ .*inlined"#).unwrap();
16+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 0);
17+
let re = regex::Regex::new(r#"define\ internal\ .*inlined"#).unwrap();
18+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
19+
let re = regex::Regex::new(r#"define\ hidden\ i32\ .*normal"#).unwrap();
20+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 1);
21+
let re = regex::Regex::new(r#"declare\ hidden\ i32\ .*normal"#).unwrap();
22+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
23+
}

tests/run-make/sepcomp-separate/Makefile

-9
This file was deleted.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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::{
7+
count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc,
8+
shallow_find_files,
9+
};
10+
11+
fn main() {
12+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run();
13+
let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap();
14+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3);
15+
}

0 commit comments

Comments
 (0)