Skip to content

Commit 96d6efd

Browse files
committed
Emit errors without halting interpretation
1 parent 4411903 commit 96d6efd

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/diagnostics.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ pub fn register_err(e: InterpErrorInfo<'static>) {
7070
ECX.with(|ecx| ecx.borrow_mut().push(e));
7171
}
7272

73-
pub fn process_errors(mut f: impl FnMut(InterpErrorInfo<'static>)) {
74-
ECX.with(|ecx| {
75-
for e in ecx.borrow_mut().drain(..) {
76-
f(e);
77-
}
78-
});
73+
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
74+
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
75+
fn process_errors(&self) {
76+
let this = self.eval_context_ref();
77+
ECX.with(|ecx| {
78+
for e in ecx.borrow_mut().drain(..) {
79+
report_err(this, e);
80+
}
81+
});
82+
}
7983
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ pub use crate::shims::time::EvalContextExt as TimeEvalContextExt;
4242
pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
4343
pub use crate::shims::EvalContextExt as ShimsEvalContextExt;
4444

45-
pub use crate::diagnostics::{process_errors, register_err, report_err};
45+
pub use crate::diagnostics::{
46+
register_err, report_err, EvalContextExt as DiagnosticsEvalContextExt,
47+
};
4648
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
4749
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;
4850
pub use crate::machine::{

src/stacked_borrows.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ 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;
1314

14-
use crate::{
15-
AllocId, HelpersEvalContextExt, ImmTy, Immediate, InterpResult, MPlaceTy, MemoryKind,
16-
MiriMemoryKind, PlaceTy, Pointer, RangeMap, TerminationInfo,
17-
};
15+
use crate::*;
1816

1917
pub type PtrId = NonZeroU64;
2018
pub type CallId = NonZeroU64;
@@ -269,7 +267,12 @@ impl<'tcx> Stack {
269267
fn check_protector(item: &Item, tag: Option<Tag>, global: &GlobalState) -> InterpResult<'tcx> {
270268
if let Tag::Tagged(id) = item.tag {
271269
if Some(id) == global.tracked_pointer_tag {
272-
throw_machine_stop!(TerminationInfo::PoppedTrackedPointerTag(item.clone()));
270+
register_err(
271+
InterpError::MachineStop(Box::new(TerminationInfo::PoppedTrackedPointerTag(
272+
item.clone(),
273+
)))
274+
.into(),
275+
);
273276
}
274277
}
275278
if let Some(call) = item.protector {
@@ -630,6 +633,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
630633
this.write_immediate(val, place)?;
631634
}
632635

636+
this.process_errors();
637+
633638
Ok(())
634639
}
635640
}

0 commit comments

Comments
 (0)