Skip to content

Commit 90a8f2f

Browse files
committed
Make the non-halting diagnostic scheme independent of InterpError
1 parent c0a7fd5 commit 90a8f2f

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

src/diagnostics.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use rustc_mir::interpret::InterpErrorInfo;
2+
use std::cell::RefCell;
23

34
use crate::*;
45

6+
pub enum NonHaltingDiagnostic {
7+
PoppedTrackedPointerTag(Item),
8+
}
9+
510
pub fn report_err<'tcx, 'mir>(
611
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
712
mut e: InterpErrorInfo<'tcx>,
@@ -12,8 +17,6 @@ pub fn report_err<'tcx, 'mir>(
1217
let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
1318
match info {
1419
TerminationInfo::Exit(code) => return Some(*code),
15-
TerminationInfo::PoppedTrackedPointerTag(item) =>
16-
format!("popped tracked tag for item {:?}", item),
1720
TerminationInfo::Abort => format!("the evaluated program aborted execution"),
1821
}
1922
}
@@ -25,11 +28,23 @@ pub fn report_err<'tcx, 'mir>(
2528
_ => e.to_string(),
2629
};
2730
e.print_backtrace();
31+
report_msg(ecx, msg, true)
32+
}
33+
34+
pub fn report_msg<'tcx, 'mir>(
35+
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
36+
msg: String,
37+
error: bool,
38+
) -> Option<i64> {
2839
if let Some(frame) = ecx.stack().last() {
2940
let span = frame.current_source_info().unwrap().span;
3041

31-
let msg = format!("Miri evaluation error: {}", msg);
32-
let mut err = ecx.tcx.sess.struct_span_err(span, msg.as_str());
42+
let mut err = if error {
43+
let msg = format!("Miri evaluation error: {}", msg);
44+
ecx.tcx.sess.struct_span_err(span, msg.as_str())
45+
} else {
46+
ecx.tcx.sess.diagnostic().span_note_diag(span, msg.as_str())
47+
};
3348
let frames = ecx.generate_stacktrace(None);
3449
err.span_label(span, msg);
3550
// We iterate with indices because we need to look at the next frame (the caller).
@@ -61,12 +76,11 @@ pub fn report_err<'tcx, 'mir>(
6176
return None;
6277
}
6378

64-
use std::cell::RefCell;
6579
thread_local! {
66-
static ECX: RefCell<Vec<InterpErrorInfo<'static>>> = RefCell::new(Vec::new());
80+
static ECX: RefCell<Vec<NonHaltingDiagnostic>> = RefCell::new(Vec::new());
6781
}
6882

69-
pub fn register_err(e: InterpErrorInfo<'static>) {
83+
pub fn register_err(e: NonHaltingDiagnostic) {
7084
ECX.with(|ecx| ecx.borrow_mut().push(e));
7185
}
7286

@@ -76,7 +90,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7690
let this = self.eval_context_ref();
7791
ECX.with(|ecx| {
7892
for e in ecx.borrow_mut().drain(..) {
79-
report_err(this, e);
93+
let msg = match e {
94+
NonHaltingDiagnostic::PoppedTrackedPointerTag(item) =>
95+
format!("popped tracked tag for item {:?}", item),
96+
};
97+
report_msg(this, msg, false);
8098
}
8199
});
82100
}

src/eval.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub struct MiriConfig {
3333
/// Details of premature program termination.
3434
pub enum TerminationInfo {
3535
Exit(i64),
36-
PoppedTrackedPointerTag(Item),
3736
Abort,
3837
}
3938

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
4343
pub use crate::shims::EvalContextExt as ShimsEvalContextExt;
4444

4545
pub use crate::diagnostics::{
46-
register_err, report_err, EvalContextExt as DiagnosticsEvalContextExt,
46+
register_err, report_err, EvalContextExt as DiagnosticsEvalContextExt, NonHaltingDiagnostic,
4747
};
4848
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
4949
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;

src/stacked_borrows.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::rc::Rc;
1010
use rustc_hir::Mutability;
1111
use rustc::mir::RetagKind;
1212
use rustc::ty::{self, layout::Size};
13-
use rustc_mir::interpret::InterpError;
1413

1514
use crate::*;
1615

@@ -267,12 +266,7 @@ impl<'tcx> Stack {
267266
fn check_protector(item: &Item, tag: Option<Tag>, global: &GlobalState) -> InterpResult<'tcx> {
268267
if let Tag::Tagged(id) = item.tag {
269268
if Some(id) == global.tracked_pointer_tag {
270-
register_err(
271-
InterpError::MachineStop(Box::new(TerminationInfo::PoppedTrackedPointerTag(
272-
item.clone(),
273-
)))
274-
.into(),
275-
);
269+
register_err(NonHaltingDiagnostic::PoppedTrackedPointerTag(item.clone()));
276270
}
277271
}
278272
if let Some(call) = item.protector {

0 commit comments

Comments
 (0)