Skip to content

Commit

Permalink
rewrite sepcomp-inlining and -separate to rmake.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 13, 2024
1 parent 659bda6 commit 9d50fdc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 44 deletions.
22 changes: 22 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,28 @@ pub fn uname() -> String {
output.stdout_utf8()
}

/// Inside a glob pattern of files (paths), read their contents and count the
/// number of regex matches with a given expression (re).
#[track_caller]
pub fn count_regex_matches_in_file_glob(re: &str, paths: &str) -> usize {
let re =
regex::Regex::new(re).expect(format!("Regex expression {re} is not valid.").as_str());
let paths =
glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
let mut match_count = 0;
use io::BufRead;
paths.filter_map(|entry| entry.ok()).filter(|path| path.is_file()).for_each(|path| {
let file = fs_wrapper::open_file(path);
let reader = io::BufReader::new(file);
reader
.lines()
.filter_map(|line| line.ok())
.filter(|line| re.is_match(line))
.for_each(|_| match_count += 1);
});
match_count
}

fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! {
if output.status().success() {
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ run-make/sanitizer-dylib-link/Makefile
run-make/sanitizer-staticlib-link/Makefile
run-make/separate-link-fail/Makefile
run-make/separate-link/Makefile
run-make/sepcomp-cci-copies/Makefile
run-make/sepcomp-inlining/Makefile
run-make/share-generics-dylib/Makefile
run-make/silly-file-names/Makefile
run-make/simd-ffi/Makefile
Expand Down
12 changes: 0 additions & 12 deletions tests/run-make/sepcomp-cci-copies/Makefile

This file was deleted.

13 changes: 13 additions & 0 deletions tests/run-make/sepcomp-cci-copies/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Check that cross-crate inlined items are inlined in all compilation units
// that refer to them, and not in any other compilation units.
// Note that we have to pass `-C codegen-units=6` because up to two CGUs may be
// created for each source module (see `rustc_const_eval::monomorphize::partitioning`).
// See https://github.com/rust-lang/rust/pull/16367

use run_make_support::{count_regex_matches_in_file_glob, rustc};

fn main() {
rustc().input("cci_lib.rs").run();
rustc().input("foo.rs").emit("llvm-ir").codegen_units(6).arg("-Zinline-in-all-cgus").run();
assert_eq!(count_regex_matches_in_file_glob(r#"define\ .*cci_fn"#, "foo.*.ll"), 2);
}
15 changes: 0 additions & 15 deletions tests/run-make/sepcomp-inlining/Makefile

This file was deleted.

19 changes: 19 additions & 0 deletions tests/run-make/sepcomp-inlining/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Test that #[inline] functions still get inlined across compilation unit
// boundaries. Compilation should produce three IR files, but only the two
// compilation units that have a usage of the #[inline] function should
// contain a definition. Also, the non-#[inline] function should be defined
// in only one compilation unit.
// See https://github.com/rust-lang/rust/pull/16367

use run_make_support::{count_regex_matches_in_file_glob, glob, regex, rustc};

fn main() {
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run();
assert_eq!(count_regex_matches_in_file_glob(r#"define\ i32\ .*inlined"#, "foo.*.ll"), 0);
assert_eq!(count_regex_matches_in_file_glob(r#"define\ internal\ .*inlined"#, "foo.*.ll"), 2);
assert_eq!(count_regex_matches_in_file_glob(r#"define\ hidden\ i32\ .*normal"#, "foo.*.ll"), 1);
assert_eq!(
count_regex_matches_in_file_glob(r#"declare\ hidden\ i32\ .*normal"#, "foo.*.ll"),
2
);
}
17 changes: 2 additions & 15 deletions tests/run-make/sepcomp-separate/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
// wind up in three different compilation units.
// See https://github.com/rust-lang/rust/pull/16367

use run_make_support::{fs_wrapper, glob, regex, rustc};
use std::io::{BufRead, BufReader};
use run_make_support::{count_regex_matches_in_file_glob, rustc};

fn main() {
let mut match_count = 0;
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run();
let re = regex::Regex::new(r#"define.*magic_fn"#).unwrap();
let paths = glob::glob("foo.*.ll").unwrap();
paths.filter_map(|entry| entry.ok()).filter(|path| path.is_file()).for_each(|path| {
let file = fs_wrapper::open_file(path);
let reader = BufReader::new(file);
reader
.lines()
.filter_map(|line| line.ok())
.filter(|line| re.is_match(line))
.for_each(|_| match_count += 1);
});
assert_eq!(match_count, 3);
assert_eq!(count_regex_matches_in_file_glob(r#"define\ .*magic_fn"#, "foo.*.ll"), 3);
}

0 comments on commit 9d50fdc

Please sign in to comment.