Skip to content

Commit dbffbe5

Browse files
committed
Document all the things
1 parent bfc7a7e commit dbffbe5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/diagnostics.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use std::cell::RefCell;
33

44
use crate::*;
55

6+
/// Miri specific diagnostics
67
pub enum NonHaltingDiagnostic {
78
PoppedTrackedPointerTag(Item),
89
}
910

10-
pub fn report_err<'tcx, 'mir>(
11+
/// Emit a custom diagnostic without going through the miri-engine machinery
12+
pub fn report_diagnostic<'tcx, 'mir>(
1113
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
1214
mut e: InterpErrorInfo<'tcx>,
1315
) -> Option<i64> {
@@ -31,6 +33,8 @@ pub fn report_err<'tcx, 'mir>(
3133
report_msg(ecx, msg, true)
3234
}
3335

36+
/// Report an error or note (depending on the `error` argument) at the current frame's current statement.
37+
/// Also emits a full stacktrace of the interpreter stack.
3438
pub fn report_msg<'tcx, 'mir>(
3539
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
3640
msg: String,
@@ -80,12 +84,15 @@ thread_local! {
8084
static DIAGNOSTICS: RefCell<Vec<NonHaltingDiagnostic>> = RefCell::new(Vec::new());
8185
}
8286

87+
/// Schedule a diagnostic for emitting. This function works even if you have no `InterpCx` available.
88+
/// The diagnostic will be emitted after the current interpreter step is finished.
8389
pub fn register_diagnostic(e: NonHaltingDiagnostic) {
8490
DIAGNOSTICS.with(|diagnostics| diagnostics.borrow_mut().push(e));
8591
}
8692

8793
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
8894
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
95+
/// Emit all diagnostics that were registed with `register_diagnostics`
8996
fn process_diagnostics(&self) {
9097
let this = self.eval_context_ref();
9198
DIAGNOSTICS.with(|diagnostics| {

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,6 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
206206
}
207207
Some(return_code)
208208
}
209-
Err(e) => report_err(&ecx, e),
209+
Err(e) => report_diagnostic(&ecx, e),
210210
}
211211
}

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_diagnostic, report_err, EvalContextExt as DiagnosticsEvalContextExt, NonHaltingDiagnostic,
46+
register_diagnostic, report_diagnostic, EvalContextExt as DiagnosticsEvalContextExt, NonHaltingDiagnostic,
4747
};
4848
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
4949
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;

0 commit comments

Comments
 (0)