Skip to content

fix progress report being deduplicated #2524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
72 changes: 48 additions & 24 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ pub enum NonHaltingDiagnostic {
CreatedAlloc(AllocId, Size, Align, MemoryKind<MiriMemoryKind>),
FreedAlloc(AllocId),
RejectedIsolatedOp(String),
ProgressReport,
ProgressReport {
block_count: u64, // how many basic blocks have been run so far
},
Int2Ptr {
details: bool,
},
Expand Down Expand Up @@ -261,6 +263,7 @@ pub fn report_error<'tcx, 'mir>(
DiagLevel::Error,
&if let Some(title) = title { format!("{}: {}", title, msg[0]) } else { msg[0].clone() },
msg,
vec![],
helps,
&stacktrace,
);
Expand Down Expand Up @@ -307,6 +310,7 @@ fn report_msg<'mir, 'tcx>(
diag_level: DiagLevel,
title: &str,
span_msg: Vec<String>,
notes: Vec<(Option<SpanData>, String)>,
helps: Vec<(Option<SpanData>, String)>,
stacktrace: &[FrameInfo<'tcx>],
) {
Expand All @@ -331,17 +335,24 @@ fn report_msg<'mir, 'tcx>(
err.note("(no span available)");
}

// Show help messages.
if !helps.is_empty() {
for (span_data, help) in helps {
if let Some(span_data) = span_data {
err.span_help(span_data.span(), &help);
} else {
err.help(&help);
}
// Show note and help messages.
for (span_data, note) in &notes {
if let Some(span_data) = span_data {
err.span_note(span_data.span(), note);
} else {
err.note(note);
}
}
for (span_data, help) in &helps {
if let Some(span_data) = span_data {
err.span_help(span_data.span(), help);
} else {
err.help(help);
}
}
if notes.len() + helps.len() > 0 {
// Add visual separator before backtrace.
err.note("backtrace:");
err.note("BACKTRACE:");
}
// Add backtrace
for (idx, frame_info) in stacktrace.iter().enumerate() {
Expand Down Expand Up @@ -436,6 +447,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Show diagnostics.
for e in diagnostics.drain(..) {
use NonHaltingDiagnostic::*;

let (title, diag_level) = match e {
RejectedIsolatedOp(_) =>
("operation rejected by isolation", DiagLevel::Warning),
Int2Ptr { .. } => ("integer-to-pointer cast", DiagLevel::Warning),
CreatedPointerTag(..)
| PoppedPointerTag(..)
| CreatedCallId(..)
| CreatedAlloc(..)
| FreedAlloc(..)
| ProgressReport { .. }
| WeakMemoryOutdatedLoad =>
("tracking was triggered", DiagLevel::Note),
};

let msg = match e {
CreatedPointerTag(tag, None) =>
format!("created tag {tag:?}"),
Expand Down Expand Up @@ -465,26 +491,23 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
format!("freed allocation with id {id}"),
RejectedIsolatedOp(ref op) =>
format!("{op} was made to return an error due to isolation"),
ProgressReport =>
ProgressReport { .. } =>
format!("progress report: current operation being executed is here"),
Int2Ptr { .. } =>
format!("integer-to-pointer cast"),
WeakMemoryOutdatedLoad =>
format!("weak memory emulation: outdated value returned from load"),
};

let (title, diag_level) = match e {
RejectedIsolatedOp(_) =>
("operation rejected by isolation", DiagLevel::Warning),
Int2Ptr { .. } => ("integer-to-pointer cast", DiagLevel::Warning),
CreatedPointerTag(..)
| PoppedPointerTag(..)
| CreatedCallId(..)
| CreatedAlloc(..)
| FreedAlloc(..)
| ProgressReport
| WeakMemoryOutdatedLoad =>
("tracking was triggered", DiagLevel::Note),
let notes = match e {
ProgressReport { block_count } => {
// It is important that each progress report is slightly different, since
// identical diagnostics are being deduplicated.
vec![
(None, format!("so far, {block_count} basic blocks have been executed")),
]
}
_ => vec![],
};

let helps = match e {
Expand All @@ -500,7 +523,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
_ => vec![],
};

report_msg(this, diag_level, title, vec![msg], helps, &stacktrace);
report_msg(this, diag_level, title, vec![msg], notes, helps, &stacktrace);
}
});
}
Expand All @@ -519,6 +542,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
"the place in the program where the ICE was triggered",
vec![],
vec![],
vec![],
&stacktrace,
);
}
Expand Down
16 changes: 8 additions & 8 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ pub struct Evaluator<'mir, 'tcx> {

/// If `Some`, we will report the current stack every N basic blocks.
pub(crate) report_progress: Option<u32>,
/// The number of blocks that passed since the last progress report.
pub(crate) since_progress_report: u32,
// The total number of blocks that have been executed.
pub(crate) basic_block_count: u64,

/// Handle of the optional shared object file for external functions.
pub external_so_lib: Option<(libloading::Library, std::path::PathBuf)>,
Expand Down Expand Up @@ -433,7 +433,7 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
weak_memory: config.weak_memory_emulation,
preemption_rate: config.preemption_rate,
report_progress: config.report_progress,
since_progress_report: 0,
basic_block_count: 0,
external_so_lib: config.external_so_file.as_ref().map(|lib_file_path| {
// Check if host target == the session target.
if env!("TARGET") != target_triple {
Expand Down Expand Up @@ -992,14 +992,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
}

fn before_terminator(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
ecx.machine.basic_block_count += 1u64; // a u64 that is only incremented by 1 will "never" overflow
// Possibly report our progress.
if let Some(report_progress) = ecx.machine.report_progress {
if ecx.machine.since_progress_report >= report_progress {
register_diagnostic(NonHaltingDiagnostic::ProgressReport);
ecx.machine.since_progress_report = 0;
if ecx.machine.basic_block_count % u64::from(report_progress) == 0 {
register_diagnostic(NonHaltingDiagnostic::ProgressReport {
block_count: ecx.machine.basic_block_count,
});
}
// Cannot overflow, since it is strictly less than `report_progress`.
ecx.machine.since_progress_report += 1;
}
// These are our preemption points.
ecx.maybe_preempt_active_thread();
Expand Down
2 changes: 1 addition & 1 deletion tests/extern-so/fail/function_not_in_so.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | foo();
| ^^^^^ can't call foreign function: foo
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/function_not_in_so.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/deallocate-bad-alignment.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
note: inside `main` at $DIR/deallocate-bad-alignment.rs:LL:CC
--> $DIR/deallocate-bad-alignment.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/deallocate-bad-size.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
note: inside `main` at $DIR/deallocate-bad-size.rs:LL:CC
--> $DIR/deallocate-bad-size.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/deallocate-twice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
note: inside `main` at $DIR/deallocate-twice.rs:LL:CC
--> $DIR/deallocate-twice.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/global_system_mixup.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | FREE();
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::sys::PLATFORM::alloc::<impl std::alloc::GlobalAlloc for std::alloc::System>::dealloc` at RUSTLIB/std/src/sys/PLATFORM/alloc.rs:LL:CC
= note: inside `<std::alloc::System as std::alloc::Allocator>::deallocate` at RUSTLIB/std/src/alloc.rs:LL:CC
note: inside `main` at $DIR/global_system_mixup.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/no_global_allocator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | __rust_alloc(1, 1);
| ^^^^^^^^^^^^^^^^^^ can't call foreign function: __rust_alloc
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: backtrace:
= note: BACKTRACE:
= note: inside `start` at $DIR/no_global_allocator.rs:LL:CC

error: aborting due to previous error
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/reallocate-bad-size.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::alloc::realloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
note: inside `main` at $DIR/reallocate-bad-size.rs:LL:CC
--> $DIR/reallocate-bad-size.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/reallocate-change-alloc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | let _z = *x;
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/reallocate-change-alloc.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/reallocate-dangling.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::alloc::realloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
note: inside `main` at $DIR/reallocate-dangling.rs:LL:CC
--> $DIR/reallocate-dangling.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/alloc/stack_free.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `std::alloc::dealloc` at RUSTLIB/alloc/src/alloc.rs:LL:CC
= note: inside `<std::alloc::Global as std::alloc::Allocator>::deallocate` at RUSTLIB/alloc/src/alloc.rs:LL:CC
= note: inside `alloc::alloc::box_free::<i32, std::alloc::Global>` at RUSTLIB/alloc/src/alloc.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/box-cell-alias.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ help: <TAG> was later invalidated at offsets [0x0..0x1] by a Unique retag
|
LL | let res = helper(val, ptr);
| ^^^
= note: backtrace:
= note: BACKTRACE:
= note: inside `helper` at $DIR/box-cell-alias.rs:LL:CC
note: inside `main` at $DIR/box-cell-alias.rs:LL:CC
--> $DIR/box-cell-alias.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/branchless-select-i128-pointer.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LL | | )
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/branchless-select-i128-pointer.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | panic!()
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `thread_start` at RUSTLIB/std/src/panic.rs:LL:CC
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | panic!()
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `thread_start` at RUSTLIB/std/src/panic.rs:LL:CC
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/libc_pthread_join_detached.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/libc_pthread_join_detached.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/libc_pthread_join_joined.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/libc_pthread_join_joined.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/libc_pthread_join_main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0);
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside closure at $DIR/libc_pthread_join_main.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/libc_pthread_join_multiple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | ... assert_eq!(libc::pthread_join(native_copy, ptr::null_mut()), 0);
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside closure at $DIR/libc_pthread_join_multiple.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/libc_pthread_join_self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside closure at $DIR/libc_pthread_join_self.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/read_only_atomic_cmpxchg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ please report an issue at <https://github.com/rust-lang/miri/issues> if this is
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/read_only_atomic_cmpxchg.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/read_only_atomic_load.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ please report an issue at <https://github.com/rust-lang/miri/issues> if this is
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/read_only_atomic_load.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/thread_local_static_dealloc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | let _val = *dangling_ptr.0;
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `main` at $DIR/thread_local_static_dealloc.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/concurrency/unwind_top_of_stack.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | | }
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: BACKTRACE:
= note: inside `thread_start` at $DIR/unwind_top_of_stack.rs:LL:CC

error: aborting due to previous error
Expand Down
Loading