Skip to content

Commit 954fc4f

Browse files
committed
rewrite sepcomp-inlining and -separate to rmake.rs
1 parent 659bda6 commit 954fc4f

File tree

7 files changed

+54
-44
lines changed

7 files changed

+54
-44
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,26 @@ pub fn uname() -> String {
245245
output.stdout_utf8()
246246
}
247247

248+
/// Inside a glob pattern of files (paths), read their contents and count the
249+
/// number of regex matches with a given expression (re).
250+
#[track_caller]
251+
pub fn count_regex_matches_in_file_glob(re: &str, paths: &str) -> usize {
252+
let re = regex::Regex::new(re).expect(format!("Regex expression {} is not valid.", re));
253+
let paths = glob::glob(paths).expect(format!("Glob expression {} is not valid.", paths));
254+
let mut match_count = 0;
255+
use io::BufRead;
256+
paths.filter_map(|entry| entry.ok()).filter(|path| path.is_file()).for_each(|path| {
257+
let file = fs_wrapper::open_file(path);
258+
let reader = io::BufReader::new(file);
259+
reader
260+
.lines()
261+
.filter_map(|line| line.ok())
262+
.filter(|line| re.is_match(line))
263+
.for_each(|_| match_count += 1);
264+
});
265+
match_count
266+
}
267+
248268
fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! {
249269
if output.status().success() {
250270
eprintln!("command unexpectedly succeeded at line {caller_line_number}");

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ run-make/sanitizer-dylib-link/Makefile
208208
run-make/sanitizer-staticlib-link/Makefile
209209
run-make/separate-link-fail/Makefile
210210
run-make/separate-link/Makefile
211-
run-make/sepcomp-cci-copies/Makefile
212-
run-make/sepcomp-inlining/Makefile
213211
run-make/share-generics-dylib/Makefile
214212
run-make/silly-file-names/Makefile
215213
run-make/simd-ffi/Makefile

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

-12
This file was deleted.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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_file_glob, 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+
assert_eq!(count_regex_matches_in_file_glob(r#"define\ .*cci_fn"#, "foo.*.ll"), 2);
13+
}

tests/run-make/sepcomp-inlining/Makefile

-15
This file was deleted.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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_file_glob, glob, regex, rustc};
9+
10+
fn main() {
11+
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run();
12+
assert_eq!(count_regex_matches_in_file_glob(r#"define\ i32\ .*inlined"#, "foo.*.ll"), 0);
13+
assert_eq!(count_regex_matches_in_file_glob(r#"define\ internal\ .*inlined"#, "foo.*.ll"), 2);
14+
assert_eq!(count_regex_matches_in_file_glob(r#"define\ hidden\ i32\ .*normal"#, "foo.*.ll"), 1);
15+
assert_eq!(
16+
count_regex_matches_in_file_glob(r#"declare\ hidden\ i32\ .*normal"#, "foo.*.ll"),
17+
2
18+
);
19+
}

tests/run-make/sepcomp-separate/rmake.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@
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::{count_regex_matches_in_file_glob, rustc};
87

98
fn main() {
10-
let mut match_count = 0;
119
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);
10+
assert_eq!(count_regex_matches_in_file_glob(r#"define\ .*magic_fn"#, "foo.*.ll"), 3);
2411
}

0 commit comments

Comments
 (0)