about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-04 09:21:33 +0000
committerbors <bors@rust-lang.org>2024-03-04 09:21:33 +0000
commite87f82578d4474fc1034b6aeaa8414ba690f165d (patch)
tree183d5b5c09caf31c020ae17f755cd270e8148653
parentede97c651094cbdd5d70925e43c7726a9ca83c5a (diff)
parentf70feaf604366c4e90e9d17ecd406fa182e54583 (diff)
downloadrust-e87f82578d4474fc1034b6aeaa8414ba690f165d.tar.gz
rust-e87f82578d4474fc1034b6aeaa8414ba690f165d.zip
Auto merge of #3351 - RalfJung:diagnostic-dedup-considered-harmful, r=RalfJung
disable diagnostic deduplication

`@oli-obk` is there a better way to do this? Ideally we'd only set this when interpretation starts but the value in the compiler session seems to be immutable. I assume people will do `cargo check` before `cargo miri` so hopefully this won't lead to too much confusion.

Fixes https://github.com/rust-lang/miri/issues/3350
-rw-r--r--src/tools/miri/README.md4
-rw-r--r--src/tools/miri/src/helpers.rs17
-rw-r--r--src/tools/miri/src/lib.rs3
-rw-r--r--src/tools/miri/tests/fail/const-ub-checks.stderr8
-rw-r--r--src/tools/miri/tests/fail/erroneous_const2.stderr8
-rw-r--r--src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs1
6 files changed, 36 insertions, 5 deletions
diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md
index 5eb8c0fa7c9..63756624677 100644
--- a/src/tools/miri/README.md
+++ b/src/tools/miri/README.md
@@ -318,8 +318,8 @@ environment variable. We first document the most relevant and most commonly used
   and `warn-nobacktrace` are the supported actions. The default is to `abort`,
   which halts the machine. Some (but not all) operations also support continuing
   execution with a "permission denied" error being returned to the program.
-  `warn` prints a full backtrace when that happens; `warn-nobacktrace` is less
-  verbose. `hide` hides the warning entirely.
+  `warn` prints a full backtrace each time that happens; `warn-nobacktrace` is less
+  verbose and shown at most once per operation. `hide` hides the warning entirely.
 * `-Zmiri-num-cpus` states the number of available CPUs to be reported by miri. By default, the
   number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
   any way.
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index 65260254ae2..c3f4deb7c2e 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -1,6 +1,8 @@
 use std::cmp;
+use std::collections::BTreeSet;
 use std::iter;
 use std::num::NonZero;
+use std::sync::Mutex;
 use std::time::Duration;
 
 use rustc_apfloat::ieee::{Double, Single};
@@ -603,9 +605,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
         match reject_with {
             RejectOpWith::Abort => isolation_abort_error(op_name),
             RejectOpWith::WarningWithoutBacktrace => {
-                this.tcx
-                    .dcx()
-                    .warn(format!("{op_name} was made to return an error due to isolation"));
+                // This exists to reduce verbosity; make sure we emit the warning at most once per
+                // operation.
+                static EMITTED_WARNINGS: Mutex<BTreeSet<String>> = Mutex::new(BTreeSet::new());
+
+                let mut emitted_warnings = EMITTED_WARNINGS.lock().unwrap();
+                if !emitted_warnings.contains(op_name) {
+                    // First time we are seeing this.
+                    emitted_warnings.insert(op_name.to_owned());
+                    this.tcx
+                        .dcx()
+                        .warn(format!("{op_name} was made to return an error due to isolation"));
+                }
                 Ok(())
             }
             RejectOpWith::Warning => {
diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs
index e1d0bc1c183..c0d1afa8023 100644
--- a/src/tools/miri/src/lib.rs
+++ b/src/tools/miri/src/lib.rs
@@ -143,4 +143,7 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[
     "-Zmir-keep-place-mention",
     "-Zmir-opt-level=0",
     "-Zmir-enable-passes=-CheckAlignment",
+    // Deduplicating diagnostics means we miss events when tracking what happens during an
+    // execution. Let's not do that.
+    "-Zdeduplicate-diagnostics=no",
 ];
diff --git a/src/tools/miri/tests/fail/const-ub-checks.stderr b/src/tools/miri/tests/fail/const-ub-checks.stderr
index 700a96a9062..f6ac480f069 100644
--- a/src/tools/miri/tests/fail/const-ub-checks.stderr
+++ b/src/tools/miri/tests/fail/const-ub-checks.stderr
@@ -10,6 +10,14 @@ note: erroneous constant encountered
 LL |     let _x = UNALIGNED_READ;
    |              ^^^^^^^^^^^^^^
 
+note: erroneous constant encountered
+  --> $DIR/const-ub-checks.rs:LL:CC
+   |
+LL |     let _x = UNALIGNED_READ;
+   |              ^^^^^^^^^^^^^^
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
 error: aborting due to 1 previous error
 
 For more information about this error, try `rustc --explain E0080`.
diff --git a/src/tools/miri/tests/fail/erroneous_const2.stderr b/src/tools/miri/tests/fail/erroneous_const2.stderr
index 47b06fa8aaa..22274367074 100644
--- a/src/tools/miri/tests/fail/erroneous_const2.stderr
+++ b/src/tools/miri/tests/fail/erroneous_const2.stderr
@@ -16,6 +16,14 @@ note: erroneous constant encountered
 LL |     println!("{}", FOO);
    |                    ^^^
    |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+note: erroneous constant encountered
+  --> $DIR/erroneous_const2.rs:LL:CC
+   |
+LL |     println!("{}", FOO);
+   |                    ^^^
+   |
    = note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to 1 previous error
diff --git a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
index 648c004c97c..d21f953672d 100644
--- a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
+++ b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs
@@ -219,6 +219,7 @@ fn wait_wake_bitset() {
     t.join().unwrap();
 }
 
+// Crucial test which relies on the SeqCst fences in futex wait/wake.
 fn concurrent_wait_wake() {
     const FREE: i32 = 0;
     const HELD: i32 = 1;