Skip to content

Commit d5f31bd

Browse files
committed
implement manual deduplication for isolation-error=warn-nobacktrace
1 parent fbafd36 commit d5f31bd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/tools/miri/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ environment variable. We first document the most relevant and most commonly used
318318
and `warn-nobacktrace` are the supported actions. The default is to `abort`,
319319
which halts the machine. Some (but not all) operations also support continuing
320320
execution with a "permission denied" error being returned to the program.
321-
`warn` prints a full backtrace when that happens; `warn-nobacktrace` is less
322-
verbose. `hide` hides the warning entirely.
321+
`warn` prints a full backtrace each time that happens; `warn-nobacktrace` is less
322+
verbose and shown at most once per operation. `hide` hides the warning entirely.
323323
* `-Zmiri-num-cpus` states the number of available CPUs to be reported by miri. By default, the
324324
number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
325325
any way.

src/tools/miri/src/helpers.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::cmp;
2+
use std::collections::BTreeSet;
23
use std::iter;
34
use std::num::NonZero;
5+
use std::sync::Mutex;
46
use std::time::Duration;
57

68
use rustc_apfloat::ieee::{Double, Single};
@@ -603,9 +605,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
603605
match reject_with {
604606
RejectOpWith::Abort => isolation_abort_error(op_name),
605607
RejectOpWith::WarningWithoutBacktrace => {
606-
this.tcx
607-
.dcx()
608-
.warn(format!("{op_name} was made to return an error due to isolation"));
608+
// This exists to reduce verbosity; make sure we emit the warning at most once per
609+
// operation.
610+
static EMITTED_WARNINGS: Mutex<BTreeSet<String>> = Mutex::new(BTreeSet::new());
611+
612+
let mut emitted_warnings = EMITTED_WARNINGS.lock().unwrap();
613+
if !emitted_warnings.contains(op_name) {
614+
// First time we are seeing this.
615+
emitted_warnings.insert(op_name.to_owned());
616+
this.tcx
617+
.dcx()
618+
.warn(format!("{op_name} was made to return an error due to isolation"));
619+
}
609620
Ok(())
610621
}
611622
RejectOpWith::Warning => {

0 commit comments

Comments
 (0)