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 Jul 5, 2024
1 parent 7bb6904 commit 64a7343
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 57 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3421,7 +3421,6 @@ dependencies = [
"ar",
"bstr",
"gimli 0.28.1",
"glob",
"object 0.34.0",
"regex",
"similar",
Expand Down
7 changes: 0 additions & 7 deletions src/tools/run-make-support/src/fs_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ pub fn create_file<P: AsRef<Path>>(path: P) {
.expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
}

/// A wrapper around [`std::fs::File::open`] which includes the file path in the panic message.
#[track_caller]
pub fn open_file<P: AsRef<Path>>(path: P) -> fs::File {
fs::File::open(path.as_ref())
.expect(&format!("the file in path \"{}\" could not be opened", path.as_ref().display()))
}

/// A wrapper around [`std::fs::read`] which includes the file path in the panic message.
#[track_caller]
pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {
Expand Down
1 change: 0 additions & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::path::{Path, PathBuf};

pub use bstr;
pub use gimli;
pub use glob;
pub use object;
pub use regex;
pub use wasmparser;
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 @@ -135,8 +135,6 @@ run-make/rustc-macro-dep-files/Makefile
run-make/sanitizer-cdylib-link/Makefile
run-make/sanitizer-dylib-link/Makefile
run-make/sanitizer-staticlib-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
6 changes: 2 additions & 4 deletions tests/run-make/intrinsic-unreachable/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
// Reason: Because of Windows exception handling, the code is not necessarily any shorter.

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

fn main() {
rustc().opt().emit("asm").input("exit-ret.rs").run();
rustc().opt().emit("asm").input("exit-unreachable.rs").run();
let unreachable_file = fs_wrapper::open_file("exit-unreachable.s");
let ret_file = fs_wrapper::open_file("exit-ret.s");
assert!(
BufReader::new(unreachable_file).lines().count() < BufReader::new(ret_file).lines().count()
fs_wrapper::read_to_string("exit-unreachable.s").lines().count()
< fs_wrapper::read_to_string("exit-ret.s").lines().count()
);
}
12 changes: 0 additions & 12 deletions tests/run-make/sepcomp-cci-copies/Makefile

This file was deleted.

26 changes: 26 additions & 0 deletions tests/run-make/sepcomp-cci-copies/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files};

fn main() {
rustc().input("cci_lib.rs").run();
rustc().input("foo.rs").emit("llvm-ir").codegen_units(6).arg("-Zinline-in-all-cgus").run();
let re = regex::Regex::new(r#"define\ .*cci_fn"#).unwrap();
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
}

fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));

let mut count = 0;
for file in fetched_files {
let content = fs_wrapper::read_to_string(file);
count += content.lines().filter(|line| re.is_match(&line)).count();
}

count
}
15 changes: 0 additions & 15 deletions tests/run-make/sepcomp-inlining/Makefile

This file was deleted.

32 changes: 32 additions & 0 deletions tests/run-make/sepcomp-inlining/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files};

fn main() {
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).arg("-Zinline-in-all-cgus").run();
let re = regex::Regex::new(r#"define\ i32\ .*inlined"#).unwrap();
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 0);
let re = regex::Regex::new(r#"define\ internal\ .*inlined"#).unwrap();
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
let re = regex::Regex::new(r#"define\ hidden\ i32\ .*normal"#).unwrap();
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 1);
let re = regex::Regex::new(r#"declare\ hidden\ i32\ .*normal"#).unwrap();
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 2);
}

fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));

let mut count = 0;
for file in fetched_files {
let content = fs_wrapper::read_to_string(file);
count += content.lines().filter(|line| re.is_match(&line)).count();
}

count
}
30 changes: 15 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,22 @@
// 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::{cwd, fs_wrapper, has_extension, regex, rustc, shallow_find_files};

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);
let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap();
assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3);
}

fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));

let mut count = 0;
for file in fetched_files {
let content = fs_wrapper::read_to_string(file);
count += content.lines().filter(|line| re.is_match(&line)).count();
}

count
}

0 comments on commit 64a7343

Please sign in to comment.