Skip to content

Commit 9e13218

Browse files
committed
Deprecate -Zmiri-disable-isolation flag
Replaced all the instances of it with new option `-Zmiri-isolated-op=allow`. Replaced `communicate` member in machine with a helper method to check for isolation.
1 parent 185db15 commit 9e13218

31 files changed

+53
-54
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ doesn't expose any environment to the program, so running
164164
`RUST_BACKTRACE=1 cargo miri test` will not do what you expect.
165165

166166
To get a backtrace, you need to disable isolation
167-
[using `-Zmiri-disable-isolation`][miri-flags]:
167+
[using `-Zmiri-isolated-op=allow`][miri-flags]:
168168

169169
```sh
170-
RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test
170+
RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-isolated-op=allow" cargo miri test
171171
```
172172

173173
#### "found possibly newer version of crate `std` which `<dependency>` depends on"
@@ -214,9 +214,13 @@ environment variable:
214214
as out-of-bounds accesses) first. Setting this flag means Miri can miss bugs
215215
in your program. However, this can also help to make Miri run faster. Using
216216
this flag is **unsound**.
217-
* `-Zmiri-disable-isolation` disables host isolation. As a consequence,
218-
the program has access to host resources such as environment variables, file
219-
systems, and randomness.
217+
* `-Zmiri-isolated-op=<action>` sets machine behaviour for ops which require
218+
communication with the host. Action can be `hide`, `warn`, `warn-nobacktrace`,
219+
or `allow`. By default, miri returns an error about isolation and prints a
220+
warning without backtrace (`warn-nobacktrace`). To trace call sites, use
221+
`warn`, which enables backtraces. `hide` suppresses warning. `allow` disables
222+
isolation. As a consequence, the program has access to host resources such as
223+
environment variables, file systems, and randomness.
220224
* `-Zmiri-env-exclude=<var>` keeps the `var` environment variable isolated from
221225
the host so that it cannot be accessed by the program. Can be used multiple
222226
times to exclude several variables. On Windows, the `TERM` environment

src/bin/miri.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ fn main() {
227227
"-Zmiri-symbolic-alignment-check" => {
228228
miri_config.check_alignment = miri::AlignmentCheck::Symbolic;
229229
}
230-
"-Zmiri-disable-isolation" => {
231-
miri_config.communicate = true;
232-
miri_config.isolated_op = miri::IsolatedOp::Allow;
233-
}
234230
"-Zmiri-ignore-leaks" => {
235231
miri_config.ignore_leaks = true;
236232
}

src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn report_error<'tcx, 'mir>(
7171
#[rustfmt::skip]
7272
let helps = match info {
7373
UnsupportedInIsolation(_) =>
74-
vec![format!("pass the flag `-Zmiri-disable-isolation` to disable isolation")],
74+
vec![format!("pass the flag `-Zmiri-isolated-op=allow` to disable isolation")],
7575
ExperimentalUb { url, .. } =>
7676
vec![
7777
format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental"),

src/eval.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum AlignmentCheck {
2222
Int,
2323
}
2424

25-
#[derive(Copy, Clone, Debug)]
25+
#[derive(Copy, Clone, Debug, PartialEq)]
2626
pub enum RejectOpWith {
2727
/// Do not print warning about rejected isolated op
2828
NoWarning,
@@ -34,7 +34,7 @@ pub enum RejectOpWith {
3434
WarningWithoutBacktrace,
3535
}
3636

37-
#[derive(Copy, Clone, Debug)]
37+
#[derive(Copy, Clone, Debug, PartialEq)]
3838
pub enum IsolatedOp {
3939
/// Reject op requiring communication with the host. Usually, miri
4040
/// generates a fake error for such op, and prints a warning
@@ -54,8 +54,6 @@ pub struct MiriConfig {
5454
pub stacked_borrows: bool,
5555
/// Controls alignment checking.
5656
pub check_alignment: AlignmentCheck,
57-
/// Determines if communication with the host environment is enabled.
58-
pub communicate: bool,
5957
/// Action for an op requiring communication with the host.
6058
pub isolated_op: IsolatedOp,
6159
/// Determines if memory leaks should be ignored.
@@ -87,7 +85,6 @@ impl Default for MiriConfig {
8785
validate: true,
8886
stacked_borrows: true,
8987
check_alignment: AlignmentCheck::Int,
90-
communicate: false,
9188
isolated_op: IsolatedOp::Reject(RejectOpWith::WarningWithoutBacktrace),
9289
ignore_leaks: false,
9390
excluded_env_vars: vec![],
@@ -252,7 +249,7 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
252249
}
253250
SchedulingAction::ExecuteTimeoutCallback => {
254251
assert!(
255-
ecx.machine.communicate,
252+
ecx.machine.communicate(),
256253
"scheduler callbacks require disabled isolation, but the code \
257254
that created the callback did not check it"
258255
);

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
140140

141141
let mut data = vec![0; usize::try_from(len).unwrap()];
142142

143-
if this.machine.communicate {
143+
if this.machine.communicate() {
144144
// Fill the buffer using the host's rng.
145145
getrandom::getrandom(&mut data)
146146
.map_err(|err| err_unsup_format!("host getrandom failed: {}", err))?;
@@ -391,7 +391,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
391391
/// disabled. It returns an error using the `name` of the foreign function if this is not the
392392
/// case.
393393
fn check_no_isolation(&self, name: &str) -> InterpResult<'tcx> {
394-
if !self.eval_context_ref().machine.communicate {
394+
if !self.eval_context_ref().machine.communicate() {
395395
isolation_error(name)?;
396396
}
397397
Ok(())

src/machine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ pub struct Evaluator<'mir, 'tcx> {
249249
/// TLS state.
250250
pub(crate) tls: TlsData<'tcx>,
251251

252-
/// If enabled, the `env_vars` field is populated with the host env vars during initialization
253-
/// and random number generation is delegated to the host.
254-
pub(crate) communicate: bool,
255-
256252
/// What should Miri do when an op requires communicating with the host,
257253
/// such as accessing host env vars, random number generation, and
258254
/// file system access.
@@ -289,7 +285,6 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
289285
argv: None,
290286
cmd_line: None,
291287
tls: TlsData::default(),
292-
communicate: config.communicate,
293288
isolated_op: config.isolated_op,
294289
validate: config.validate,
295290
file_handler: Default::default(),
@@ -300,6 +295,10 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
300295
static_roots: Vec::new(),
301296
}
302297
}
298+
299+
pub(crate) fn communicate(&self) -> bool {
300+
self.isolated_op == IsolatedOp::Allow
301+
}
303302
}
304303

305304
/// A rustc InterpCx for Miri.

src/shims/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> EnvVars<'tcx> {
4646
excluded_env_vars.push("TERM".to_owned());
4747
}
4848

49-
if ecx.machine.communicate {
49+
if ecx.machine.communicate() {
5050
for (name, value) in env::vars() {
5151
if !excluded_env_vars.contains(&name) {
5252
let var_ptr = match target_os {

src/shims/posix/fs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
662662
let fd = this.read_scalar(fd_op)?.to_i32()?;
663663

664664
if let Some(file_descriptor) = this.machine.file_handler.handles.remove(&fd) {
665-
let result = file_descriptor.close(this.machine.communicate)?;
665+
let result = file_descriptor.close(this.machine.communicate())?;
666666
this.try_unwrap_io_result(result)
667667
} else {
668668
this.handle_not_found()
@@ -688,6 +688,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
688688
// host's and target's `isize`. This saves us from having to handle overflows later.
689689
let count = count.min(this.machine_isize_max() as u64).min(isize::MAX as u64);
690690

691+
let communicate = this.machine.communicate();
691692
if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) {
692693
trace!("read: FD mapped to {:?}", file_descriptor);
693694
// We want to read at most `count` bytes. We are sure that `count` is not negative
@@ -697,7 +698,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
697698
// `File::read` never returns a value larger than `count`,
698699
// so this cannot fail.
699700
let result = file_descriptor
700-
.read(this.machine.communicate, &mut bytes)?
701+
.read(communicate, &mut bytes)?
701702
.map(|c| i64::try_from(c).unwrap());
702703

703704
match result {
@@ -734,10 +735,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
734735
// host's and target's `isize`. This saves us from having to handle overflows later.
735736
let count = count.min(this.machine_isize_max() as u64).min(isize::MAX as u64);
736737

738+
let communicate = this.machine.communicate();
737739
if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) {
738740
let bytes = this.memory.read_bytes(buf, Size::from_bytes(count))?;
739741
let result = file_descriptor
740-
.write(this.machine.communicate, &bytes)?
742+
.write(communicate, &bytes)?
741743
.map(|c| i64::try_from(c).unwrap());
742744
this.try_unwrap_io_result(result)
743745
} else {
@@ -771,9 +773,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
771773
return Ok(-1);
772774
};
773775

776+
let communicate = this.machine.communicate();
774777
if let Some(file_descriptor) = this.machine.file_handler.handles.get_mut(&fd) {
775778
let result = file_descriptor
776-
.seek(this.machine.communicate, seek_from)?
779+
.seek(communicate, seek_from)?
777780
.map(|offset| i64::try_from(offset).unwrap());
778781
this.try_unwrap_io_result(result)
779782
} else {

test-cargo-miri/run-test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_cargo_miri_run():
8282
"run.default.stdout.ref", "run.default.stderr.ref",
8383
stdin=b'12\n21\n',
8484
env={
85-
'MIRIFLAGS': "-Zmiri-disable-isolation",
85+
'MIRIFLAGS': "-Zmiri-isolated-op=allow",
8686
'MIRITESTVAR': "wrongval", # make sure the build.rs value takes precedence
8787
},
8888
)
@@ -99,7 +99,7 @@ def test_cargo_miri_run():
9999
test("`cargo miri run` (subcrate, no ioslation)",
100100
cargo_miri("run") + ["-p", "subcrate"],
101101
"run.subcrate.stdout.ref", "run.subcrate.stderr.ref",
102-
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
102+
env={'MIRIFLAGS': "-Zmiri-isolated-op=allow"},
103103
)
104104

105105
def test_cargo_miri_test():
@@ -116,7 +116,7 @@ def test_cargo_miri_test():
116116
test("`cargo miri test` (no isolation, no doctests)",
117117
cargo_miri("test") + ["--bins", "--tests"], # no `--lib`, we disabled that in `Cargo.toml`
118118
"test.cross-target.stdout.ref", "test.stderr-empty.ref",
119-
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
119+
env={'MIRIFLAGS': "-Zmiri-isolated-op=allow"},
120120
)
121121
test("`cargo miri test` (raw-ptr tracking)",
122122
cargo_miri("test"),
@@ -138,7 +138,7 @@ def test_cargo_miri_test():
138138
test("`cargo miri test` (subcrate, no isolation)",
139139
cargo_miri("test") + ["-p", "subcrate"],
140140
"test.subcrate.stdout.ref", "test.stderr-proc-macro.ref",
141-
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
141+
env={'MIRIFLAGS': "-Zmiri-isolated-op=allow"},
142142
)
143143

144144
os.chdir(os.path.dirname(os.path.realpath(__file__)))

tests/compile-fail/data_race/dangling_thread_async_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2-
// compile-flags: -Zmiri-disable-isolation
2+
// compile-flags: -Zmiri-isolated-op=allow
33

44
use std::thread::{spawn, sleep};
55
use std::time::Duration;

0 commit comments

Comments
 (0)