Skip to content

Commit 6dcca62

Browse files
committed
move -Zmiri-disable-isolation hint to help
1 parent a1b8238 commit 6dcca62

File tree

4 files changed

+60
-42
lines changed

4 files changed

+60
-42
lines changed

src/diagnostics.rs

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,78 @@ use rustc_span::DUMMY_SP;
44

55
use crate::*;
66

7+
/// Details of premature program termination.
8+
pub enum TerminationInfo {
9+
Exit(i64),
10+
Abort(Option<String>),
11+
UnsupportedInIsolation(String),
12+
}
13+
714
/// Miri specific diagnostics
815
pub enum NonHaltingDiagnostic {
916
PoppedTrackedPointerTag(Item),
1017
CreatedAlloc(AllocId),
1118
}
1219

1320
/// Emit a custom diagnostic without going through the miri-engine machinery
14-
pub fn report_diagnostic<'tcx, 'mir>(
21+
pub fn report_error<'tcx, 'mir>(
1522
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
1623
mut e: InterpErrorInfo<'tcx>,
1724
) -> Option<i64> {
1825
use InterpError::*;
19-
let title = match e.kind {
20-
Unsupported(_) => "unsupported operation",
21-
UndefinedBehavior(_) => "Undefined Behavior",
22-
InvalidProgram(_) => bug!("This error should be impossible in Miri: {}", e),
23-
ResourceExhaustion(_) => "resource exhaustion",
24-
MachineStop(_) => "program stopped",
25-
};
26-
let msg = match e.kind {
27-
MachineStop(ref info) => {
26+
27+
e.print_backtrace();
28+
let (title, msg, help) = match e.kind {
29+
MachineStop(info) => {
2830
let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
29-
match info {
30-
TerminationInfo::Exit(code) => return Some(*code),
31-
TerminationInfo::Abort(None) => format!("the evaluated program aborted execution"),
32-
TerminationInfo::Abort(Some(msg)) => format!("the evaluated program aborted execution: {}", msg),
33-
}
31+
use TerminationInfo::*;
32+
let (title, msg) = match info {
33+
Exit(code) => return Some(*code),
34+
Abort(None) =>
35+
("abnormal termination", format!("the evaluated program aborted execution")),
36+
Abort(Some(msg)) =>
37+
("abnormal termination", format!("the evaluated program aborted execution: {}", msg)),
38+
UnsupportedInIsolation(msg) =>
39+
("unsupported operation", format!("{}", msg)),
40+
};
41+
let help = match info {
42+
UnsupportedInIsolation(_) =>
43+
Some("pass the flag `-Zmiri-disable-isolation` to disable isolation"),
44+
_ => None,
45+
};
46+
(title, msg, help)
47+
}
48+
_ => {
49+
let (title, msg) = match e.kind {
50+
Unsupported(_) =>
51+
("unsupported operation", e.to_string()),
52+
UndefinedBehavior(_) =>
53+
("Undefined Behavior", e.to_string()),
54+
ResourceExhaustion(_) =>
55+
("resource exhaustion", e.to_string()),
56+
_ =>
57+
bug!("This error should be impossible in Miri: {}", e),
58+
};
59+
let help = match e.kind {
60+
Unsupported(UnsupportedOpInfo::NoMirFor(..)) =>
61+
Some("set `MIRI_SYSROOT` to a Miri sysroot, which you can prepare with `cargo miri setup`"),
62+
Unsupported(_) =>
63+
Some("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support"),
64+
UndefinedBehavior(UndefinedBehaviorInfo::UbExperimental(_)) =>
65+
Some("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental"),
66+
UndefinedBehavior(_) =>
67+
Some("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior"),
68+
_ => None,
69+
};
70+
(title, msg, help)
3471
}
35-
_ => e.to_string(),
36-
};
37-
let help = match e.kind {
38-
Unsupported(UnsupportedOpInfo::NoMirFor(..)) =>
39-
Some("set `MIRI_SYSROOT` to a Miri sysroot, which you can prepare with `cargo miri setup`"),
40-
Unsupported(_) =>
41-
Some("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support"),
42-
UndefinedBehavior(UndefinedBehaviorInfo::UbExperimental(_)) =>
43-
Some("this indicates a potential bug in the program: it violated *experimental* rules, and caused Undefined Behavior"),
44-
UndefinedBehavior(_) =>
45-
Some("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior"),
46-
_ => None,
4772
};
48-
e.print_backtrace();
4973
report_msg(ecx, &format!("{}: {}", title, msg), msg, help, true)
5074
}
5175

5276
/// Report an error or note (depending on the `error` argument) at the current frame's current statement.
5377
/// Also emits a full stacktrace of the interpreter stack.
54-
pub fn report_msg<'tcx, 'mir>(
78+
fn report_msg<'tcx, 'mir>(
5579
ecx: &InterpCx<'mir, 'tcx, Evaluator<'tcx>>,
5680
title: &str,
5781
span_msg: String,

src/eval.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ impl Default for MiriConfig {
5151
}
5252
}
5353

54-
/// Details of premature program termination.
55-
pub enum TerminationInfo {
56-
Exit(i64),
57-
Abort(Option<String>),
58-
}
59-
6054
/// Returns a freshly created `InterpCx`, along with an `MPlaceTy` representing
6155
/// the location where the return value of the `start` lang item will be
6256
/// written to.
@@ -229,6 +223,6 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
229223
}
230224
Some(return_code)
231225
}
232-
Err(e) => report_diagnostic(&ecx, e),
226+
Err(e) => report_error(&ecx, e),
233227
}
234228
}

src/helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
367367
/// case.
368368
fn check_no_isolation(&self, name: &str) -> InterpResult<'tcx> {
369369
if !self.eval_context_ref().machine.communicate {
370-
throw_unsup_format!(
371-
"`{}` not available when isolation is enabled (pass the flag `-Zmiri-disable-isolation` to disable isolation)",
370+
throw_machine_stop!(TerminationInfo::UnsupportedInIsolation(format!(
371+
"`{}` not available when isolation is enabled",
372372
name,
373-
)
373+
)))
374374
}
375375
Ok(())
376376
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
4545
pub use crate::shims::EvalContextExt as ShimsEvalContextExt;
4646

4747
pub use crate::diagnostics::{
48-
register_diagnostic, report_diagnostic, EvalContextExt as DiagnosticsEvalContextExt,
49-
NonHaltingDiagnostic,
48+
register_diagnostic, report_error, EvalContextExt as DiagnosticsEvalContextExt,
49+
TerminationInfo, NonHaltingDiagnostic,
5050
};
51-
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
51+
pub use crate::eval::{create_ecx, eval_main, MiriConfig};
5252
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;
5353
pub use crate::machine::{
5454
AllocExtra, Evaluator, FrameData, MemoryExtra, MiriEvalContext, MiriEvalContextExt,

0 commit comments

Comments
 (0)