about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-07-08 20:23:39 +0200
committerGitHub <noreply@github.com>2024-07-08 20:23:39 +0200
commit9804cf9b5db2037734deab463ae8e1df56c8ea62 (patch)
tree7a8a4f5544622d162f17c17b2df5d443e2ebcade
parenta06e9c83f6bc6b9b69f1b0d9f1ab659f8f03db4d (diff)
parentf04d0c68eeeb32f2bf7477806482551f2a308ae0 (diff)
downloadrust-9804cf9b5db2037734deab463ae8e1df56c8ea62.tar.gz
rust-9804cf9b5db2037734deab463ae8e1df56c8ea62.zip
Rollup merge of #126427 - Oneirical:oktobertest, r=jieyouxu
Rewrite `intrinsic-unreachable`, `sepcomp-cci-copies`, `sepcomp-inlining` and `sepcomp-separate` `run-make` tests to rmake.rs

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).
-rw-r--r--src/tools/run-make-support/src/fs_wrapper.rs20
-rw-r--r--src/tools/run-make-support/src/lib.rs14
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt4
-rw-r--r--tests/run-make/intrinsic-unreachable/Makefile12
-rw-r--r--tests/run-make/intrinsic-unreachable/rmake.rs20
-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/Makefile9
-rw-r--r--tests/run-make/sepcomp-separate/rmake.rs15
11 files changed, 99 insertions, 62 deletions
diff --git a/src/tools/run-make-support/src/fs_wrapper.rs b/src/tools/run-make-support/src/fs_wrapper.rs
index 8a2bfce8b4a..0f0d6f6618c 100644
--- a/src/tools/run-make-support/src/fs_wrapper.rs
+++ b/src/tools/run-make-support/src/fs_wrapper.rs
@@ -1,7 +1,7 @@
 use std::fs;
 use std::path::Path;
 
-/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message.
 #[track_caller]
 pub fn remove_file<P: AsRef<Path>>(path: P) {
     fs::remove_file(path.as_ref())
@@ -18,21 +18,21 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
     ));
 }
 
-/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message.
 #[track_caller]
 pub fn create_file<P: AsRef<Path>>(path: P) {
     fs::File::create(path.as_ref())
         .expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
 }
 
-/// A wrapper around [`std::fs::read`] which includes the file path in the panic message..
+/// 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> {
     fs::read(path.as_ref())
         .expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display()))
 }
 
-/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message.
 #[track_caller]
 pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
     fs::read_to_string(path.as_ref()).expect(&format!(
@@ -41,14 +41,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
     ))
 }
 
-/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message.
 #[track_caller]
 pub fn read_dir<P: AsRef<Path>>(path: P) -> fs::ReadDir {
     fs::read_dir(path.as_ref())
         .expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display()))
 }
 
-/// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::write`] which includes the file path in the panic message.
 #[track_caller]
 pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
     fs::write(path.as_ref(), contents.as_ref()).expect(&format!(
@@ -57,7 +57,7 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
     ));
 }
 
-/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message.
 #[track_caller]
 pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
     fs::remove_dir_all(path.as_ref()).expect(&format!(
@@ -66,7 +66,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
     ));
 }
 
-/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message.
 #[track_caller]
 pub fn create_dir<P: AsRef<Path>>(path: P) {
     fs::create_dir(path.as_ref()).expect(&format!(
@@ -75,7 +75,7 @@ pub fn create_dir<P: AsRef<Path>>(path: P) {
     ));
 }
 
-/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message.
 #[track_caller]
 pub fn create_dir_all<P: AsRef<Path>>(path: P) {
     fs::create_dir_all(path.as_ref()).expect(&format!(
@@ -84,7 +84,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) {
     ));
 }
 
-/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message..
+/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message.
 #[track_caller]
 pub fn metadata<P: AsRef<Path>>(path: P) -> fs::Metadata {
     fs::metadata(path.as_ref()).expect(&format!(
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index f464a109e77..3fdf94804f1 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -303,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 31cb32d349a..184ef22317a 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -47,7 +47,6 @@ run-make/foreign-rust-exceptions/Makefile
 run-make/incr-add-rust-src-component/Makefile
 run-make/incr-foreign-head-span/Makefile
 run-make/interdependent-c-libraries/Makefile
-run-make/intrinsic-unreachable/Makefile
 run-make/issue-107094/Makefile
 run-make/issue-109934-lto-debuginfo/Makefile
 run-make/issue-14698/Makefile
@@ -130,9 +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/sepcomp-separate/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/Makefile b/tests/run-make/intrinsic-unreachable/Makefile
deleted file mode 100644
index ff9cc57098c..00000000000
--- a/tests/run-make/intrinsic-unreachable/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-include ../tools.mk
-
-# needs-asm-support
-# ignore-windows-msvc
-#
-# Because of Windows exception handling, the code is not necessarily any shorter.
-# https://github.com/llvm-mirror/llvm/commit/64b2297786f7fd6f5fa24cdd4db0298fbf211466
-
-all:
-	$(RUSTC) -O --emit asm exit-ret.rs
-	$(RUSTC) -O --emit asm exit-unreachable.rs
-	test `wc -l < $(TMPDIR)/exit-unreachable.s` -lt `wc -l < $(TMPDIR)/exit-ret.s`
diff --git a/tests/run-make/intrinsic-unreachable/rmake.rs b/tests/run-make/intrinsic-unreachable/rmake.rs
new file mode 100644
index 00000000000..7e78c8288b8
--- /dev/null
+++ b/tests/run-make/intrinsic-unreachable/rmake.rs
@@ -0,0 +1,20 @@
+// intrinsics::unreachable tells the compiler that a certain point in the code
+// is not reachable by any means, which enables some useful optimizations.
+// In this test, exit-unreachable contains this instruction and exit-ret does not,
+// which means the emitted artifacts should be shorter in length.
+// See https://github.com/rust-lang/rust/pull/16970
+
+//@ needs-asm-support
+//@ ignore-windows
+// Reason: Because of Windows exception handling, the code is not necessarily any shorter.
+
+use run_make_support::{fs_wrapper, rustc};
+
+fn main() {
+    rustc().opt().emit("asm").input("exit-ret.rs").run();
+    rustc().opt().emit("asm").input("exit-unreachable.rs").run();
+    assert!(
+        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/Makefile b/tests/run-make/sepcomp-separate/Makefile
deleted file mode 100644
index 62cf54a88fb..00000000000
--- a/tests/run-make/sepcomp-separate/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-include ../tools.mk
-
-# Test that separate compilation actually puts code into separate compilation
-# units.  `foo.rs` defines `magic_fn` in three different modules, which should
-# wind up in three different compilation units.
-
-all:
-	$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
-	[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*magic_fn)" -eq "3" ]
diff --git a/tests/run-make/sepcomp-separate/rmake.rs b/tests/run-make/sepcomp-separate/rmake.rs
new file mode 100644
index 00000000000..6f1d22424b5
--- /dev/null
+++ b/tests/run-make/sepcomp-separate/rmake.rs
@@ -0,0 +1,15 @@
+// Test that separate compilation actually puts code into separate compilation
+// units.  `foo.rs` defines `magic_fn` in three different modules, which should
+// wind up in three different compilation units.
+// 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).run();
+    let re = regex::Regex::new(r#"define\ .*magic_fn"#).unwrap();
+    assert_eq!(count_regex_matches_in_files_with_extension(&re, "ll"), 3);
+}