about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-06-13 15:02:08 -0400
committerOneirical <manchot@videotron.ca>2024-07-08 10:14:42 -0400
commitf04d0c68eeeb32f2bf7477806482551f2a308ae0 (patch)
tree5b873939ab55d7abe9ce9436bb6ab3b5b17bbad0
parent2dda1e31bead614a45e7f51c86dc14cf6a4ebe1c (diff)
downloadrust-f04d0c68eeeb32f2bf7477806482551f2a308ae0.tar.gz
rust-f04d0c68eeeb32f2bf7477806482551f2a308ae0.zip
rewrite sepcomp-inlining and -separate to rmake.rs
-rw-r--r--Cargo.lock1
-rw-r--r--src/tools/run-make-support/src/fs_wrapper.rs7
-rw-r--r--src/tools/run-make-support/src/lib.rs15
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt2
-rw-r--r--tests/run-make/intrinsic-unreachable/rmake.rs6
-rw-r--r--tests/run-make/sepcomp-cci-copies/Makefile12
-rw-r--r--tests/run-make/sepcomp-cci-copies/rmake.rs17
-rw-r--r--tests/run-make/sepcomp-inlining/Makefile15
-rw-r--r--tests/run-make/sepcomp-inlining/rmake.rs23
-rw-r--r--tests/run-make/sepcomp-separate/rmake.rs21
10 files changed, 62 insertions, 57 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 05e5685270e..afeb9faec09 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3421,7 +3421,6 @@ dependencies = [
  "ar",
  "bstr",
  "gimli 0.28.1",
- "glob",
  "object 0.34.0",
  "regex",
  "similar",
diff --git a/src/tools/run-make-support/src/fs_wrapper.rs b/src/tools/run-make-support/src/fs_wrapper.rs
index d65c10b17c9..0f0d6f6618c 100644
--- a/src/tools/run-make-support/src/fs_wrapper.rs
+++ b/src/tools/run-make-support/src/fs_wrapper.rs
@@ -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> {
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 068b022599e..3fdf94804f1 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -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;
@@ -304,6 +303,20 @@ pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, exp
         .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned()))
 }
 
+/// Gathers all files in the current working directory that have the extension `ext`, and counts
+/// the number of lines within that contain a match with the regex pattern `re`.
+pub 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
+}
+
 /// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
 /// available on the platform!
 #[track_caller]
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 233c2d0b808..184ef22317a 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -129,8 +129,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
diff --git a/tests/run-make/intrinsic-unreachable/rmake.rs b/tests/run-make/intrinsic-unreachable/rmake.rs
index 5e62a966c54..7e78c8288b8 100644
--- a/tests/run-make/intrinsic-unreachable/rmake.rs
+++ b/tests/run-make/intrinsic-unreachable/rmake.rs
@@ -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()
     );
 }
diff --git a/tests/run-make/sepcomp-cci-copies/Makefile b/tests/run-make/sepcomp-cci-copies/Makefile
deleted file mode 100644
index df289d0b0b1..00000000000
--- a/tests/run-make/sepcomp-cci-copies/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-include ../tools.mk
-
-# 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`).
-
-all:
-	$(RUSTC) cci_lib.rs
-	$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=6 \
-		-Z inline-in-all-cgus
-	[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*cci_fn)" -eq "2" ]
diff --git a/tests/run-make/sepcomp-cci-copies/rmake.rs b/tests/run-make/sepcomp-cci-copies/rmake.rs
new file mode 100644
index 00000000000..612a73977fe
--- /dev/null
+++ b/tests/run-make/sepcomp-cci-copies/rmake.rs
@@ -0,0 +1,17 @@
+// 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_files_with_extension, 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);
+}
diff --git a/tests/run-make/sepcomp-inlining/Makefile b/tests/run-make/sepcomp-inlining/Makefile
deleted file mode 100644
index 327aeb75e5e..00000000000
--- a/tests/run-make/sepcomp-inlining/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-include ../tools.mk
-
-# 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.
-
-all:
-	$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \
-		-Z inline-in-all-cgus
-	[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ i32\ .*inlined)" -eq "0" ]
-	[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ internal\ i32\ .*inlined)" -eq "2" ]
-	[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ hidden\ i32\ .*normal)" -eq "1" ]
-	[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c declare\ hidden\ i32\ .*normal)" -eq "2" ]
diff --git a/tests/run-make/sepcomp-inlining/rmake.rs b/tests/run-make/sepcomp-inlining/rmake.rs
new file mode 100644
index 00000000000..de7551b9a51
--- /dev/null
+++ b/tests/run-make/sepcomp-inlining/rmake.rs
@@ -0,0 +1,23 @@
+// 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_files_with_extension, 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);
+}
diff --git a/tests/run-make/sepcomp-separate/rmake.rs b/tests/run-make/sepcomp-separate/rmake.rs
index d3ef2450a84..6f1d22424b5 100644
--- a/tests/run-make/sepcomp-separate/rmake.rs
+++ b/tests/run-make/sepcomp-separate/rmake.rs
@@ -3,22 +3,13 @@
 // 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_files_with_extension, 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);
 }