Skip to content

Commit f04d0c6

Browse files
committed
rewrite sepcomp-inlining and -separate to rmake.rs
1 parent 2dda1e3 commit f04d0c6

File tree

10 files changed

+62
-57
lines changed

10 files changed

+62
-57
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,6 @@ dependencies = [
34213421
"ar",
34223422
"bstr",
34233423
"gimli 0.28.1",
3424-
"glob",
34253424
"object 0.34.0",
34263425
"regex",
34273426
"similar",

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

-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ pub fn create_file<P: AsRef<Path>>(path: P) {
2525
.expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
2626
}
2727

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-
3528
/// A wrapper around [`std::fs::read`] which includes the file path in the panic message.
3629
#[track_caller]
3730
pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::path::{Path, PathBuf};
2323

2424
pub use bstr;
2525
pub use gimli;
26-
pub use glob;
2726
pub use object;
2827
pub use regex;
2928
pub use wasmparser;
@@ -304,6 +303,20 @@ pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, exp
304303
.is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned()))
305304
}
306305

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+
307320
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
308321
/// available on the platform!
309322
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ run-make/rustc-macro-dep-files/Makefile
129129
run-make/sanitizer-cdylib-link/Makefile
130130
run-make/sanitizer-dylib-link/Makefile
131131
run-make/sanitizer-staticlib-link/Makefile
132-
run-make/sepcomp-cci-copies/Makefile
133-
run-make/sepcomp-inlining/Makefile
134132
run-make/share-generics-dylib/Makefile
135133
run-make/silly-file-names/Makefile
136134
run-make/simd-ffi/Makefile

tests/run-make/intrinsic-unreachable/rmake.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
// Reason: Because of Windows exception handling, the code is not necessarily any shorter.
1010

1111
use run_make_support::{fs_wrapper, rustc};
12-
use std::io::{BufRead, BufReader};
1312

1413
fn main() {
1514
rustc().opt().emit("asm").input("exit-ret.rs").run();
1615
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");
1916
assert!(
20-
BufReader::new(unreachable_file).lines().count() < BufReader::new(ret_file).lines().count()
17+
fs_wrapper::read_to_string("exit-unreachable.s").lines().count()
18+
< fs_wrapper::read_to_string("exit-ret.s").lines().count()
2119
);
2220
}

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/rmake.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@
33
// wind up in three different compilation units.
44
// See https://github.com/rust-lang/rust/pull/16367
55

6-
use run_make_support::{fs_wrapper, glob, regex, rustc};
7-
use std::io::{BufRead, BufReader};
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+
};
810

911
fn main() {
10-
let mut match_count = 0;
1112
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run();
12-
let re = regex::Regex::new(r#"define.*magic_fn"#).unwrap();
13-
let paths = glob::glob("foo.*.ll").unwrap();
14-
paths.filter_map(|entry| entry.ok()).filter(|path| path.is_file()).for_each(|path| {
15-
let file = fs_wrapper::open_file(path);
16-
let reader = BufReader::new(file);
17-
reader
18-
.lines()
19-
.filter_map(|line| line.ok())
20-
.filter(|line| re.is_match(line))
21-
.for_each(|_| match_count += 1);
22-
});
23-
assert_eq!(match_count, 3);
13+
let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap();
14+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3);
2415
}

0 commit comments

Comments
 (0)