Skip to content

Commit 64a7343

Browse files
committed
rewrite sepcomp-inlining and -separate to rmake.rs
1 parent 7bb6904 commit 64a7343

File tree

10 files changed

+75
-57
lines changed

10 files changed

+75
-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

-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;

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ run-make/rustc-macro-dep-files/Makefile
135135
run-make/sanitizer-cdylib-link/Makefile
136136
run-make/sanitizer-dylib-link/Makefile
137137
run-make/sanitizer-staticlib-link/Makefile
138-
run-make/sepcomp-cci-copies/Makefile
139-
run-make/sepcomp-inlining/Makefile
140138
run-make/share-generics-dylib/Makefile
141139
run-make/silly-file-names/Makefile
142140
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.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files};
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+
}
15+
16+
fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
17+
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));
18+
19+
let mut count = 0;
20+
for file in fetched_files {
21+
let content = fs_wrapper::read_to_string(file);
22+
count += content.lines().filter(|line| re.is_match(&line)).count();
23+
}
24+
25+
count
26+
}

tests/run-make/sepcomp-inlining/Makefile

-15
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files};
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+
}
21+
22+
fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
23+
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));
24+
25+
let mut count = 0;
26+
for file in fetched_files {
27+
let content = fs_wrapper::read_to_string(file);
28+
count += content.lines().filter(|line| re.is_match(&line)).count();
29+
}
30+
31+
count
32+
}

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
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::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files};
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+
let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap();
11+
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3);
12+
}
13+
14+
fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
15+
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));
16+
17+
let mut count = 0;
18+
for file in fetched_files {
19+
let content = fs_wrapper::read_to_string(file);
20+
count += content.lines().filter(|line| re.is_match(&line)).count();
21+
}
22+
23+
count
2424
}

0 commit comments

Comments
 (0)