Skip to content

Commit 3521a2f

Browse files
committed
Auto merge of rust-lang#122246 - RalfJung:miri, r=RalfJung
Miri subtree update r? `@ghost` `@WaffleLapkin` when this lands, setting `MIRI_TEMP` should not be needed any more on the dev desktops.
2 parents 094a620 + 9a308d4 commit 3521a2f

36 files changed

+239
-260
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,7 @@ dependencies = [
24852485
"regex",
24862486
"rustc_version",
24872487
"smallvec",
2488+
"tempfile",
24882489
"ui_test 0.21.2",
24892490
]
24902491

src/tools/miri/.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r22.12.06
188188
- name: setup bot git name and email
189189
run: |
190-
git config --global user.name 'The Miri Conjob Bot'
190+
git config --global user.name 'The Miri Cronjob Bot'
191191
git config --global user.email 'miri@cron.bot'
192192
- name: get changes from rustc
193193
run: ./miri rustc-pull

src/tools/miri/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ dependencies = [
497497
"regex",
498498
"rustc_version",
499499
"smallvec",
500+
"tempfile",
500501
"ui_test",
501502
]
502503

src/tools/miri/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ ui_test = "0.21.1"
4545
rustc_version = "0.4"
4646
regex = "1.5.5"
4747
lazy_static = "1.4.0"
48+
tempfile = "3"
4849

4950
[package.metadata.rust-analyzer]
5051
# This crate uses #[feature(rustc_private)].
5152
# See https://github.com/rust-analyzer/rust-analyzer/pull/7891
5253
rustc_private = true
5354

5455
[[test]]
55-
name = "compiletest"
56+
name = "ui"
5657
harness = false
5758

5859
[features]

src/tools/miri/README.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ environment variable. We first document the most relevant and most commonly used
318318
and `warn-nobacktrace` are the supported actions. The default is to `abort`,
319319
which halts the machine. Some (but not all) operations also support continuing
320320
execution with a "permission denied" error being returned to the program.
321-
`warn` prints a full backtrace when that happens; `warn-nobacktrace` is less
322-
verbose. `hide` hides the warning entirely.
321+
`warn` prints a full backtrace each time that happens; `warn-nobacktrace` is less
322+
verbose and shown at most once per operation. `hide` hides the warning entirely.
323323
* `-Zmiri-num-cpus` states the number of available CPUs to be reported by miri. By default, the
324324
number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
325325
any way.
@@ -359,8 +359,6 @@ The remaining flags are for advanced use only, and more likely to change or be r
359359
Some of these are **unsound**, which means they can lead
360360
to Miri failing to detect cases of undefined behavior in a program.
361361

362-
* `-Zmiri-disable-abi-check` disables checking [function ABI]. Using this flag
363-
is **unsound**. This flag is **deprecated**.
364362
* `-Zmiri-disable-alignment-check` disables checking pointer alignment, so you
365363
can focus on other failures, but it means Miri can miss bugs in your program.
366364
Using this flag is **unsound**.
@@ -465,11 +463,7 @@ Moreover, Miri recognizes some environment variables:
465463
* `MIRI_LIB_SRC` defines the directory where Miri expects the sources of the
466464
standard library that it will build and use for interpretation. This directory
467465
must point to the `library` subdirectory of a `rust-lang/rust` repository
468-
checkout. Note that changing files in that directory does not automatically
469-
trigger a re-build of the standard library; you have to clear the Miri build
470-
cache with `cargo miri clean` or deleting it manually (on Linux, `rm -rf ~/.cache/miri`;
471-
on Windows, `rmdir /S "%LOCALAPPDATA%\rust-lang\miri\cache"`;
472-
and on macOS, `rm -rf ~/Library/Caches/org.rust-lang.miri`).
466+
checkout.
473467
* `MIRI_SYSROOT` (recognized by `cargo miri` and the Miri driver) indicates the sysroot to use. When
474468
using `cargo miri`, this skips the automatic setup -- only set this if you do not want to use the
475469
automatically created sysroot. For directly invoking the Miri driver, this variable (or a

src/tools/miri/ci/build-all-targets.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PLATFORM_SUPPORT_FILE=$(rustc +miri --print sysroot)/share/doc/rust/html/rustc/p
1212

1313
for target in $(python3 ci/scrape-targets.py $PLATFORM_SUPPORT_FILE); do
1414
# Wipe the cache before every build to minimize disk usage
15-
rm -rf ~/.cache/miri
15+
cargo +miri miri clean
1616
if cargo +miri miri setup --target $target 2>&1 | tee failures/$target; then
1717
# If the build succeeds, delete its output. If we have output, a build failed.
1818
rm $FAILS_DIR/$target

src/tools/miri/miri-script/src/commands.rs

+20-30
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,11 @@ impl Command {
510510
let miri_flags = flagsplit(&miri_flags);
511511
let toolchain = &e.toolchain;
512512
let extra_flags = &e.cargo_extra_flags;
513-
let edition_flags = (!have_edition).then_some("--edition=2021"); // keep in sync with `compiletest.rs`.`
513+
let edition_flags = (!have_edition).then_some("--edition=2021"); // keep in sync with `tests/ui.rs`.`
514514
if dep {
515515
cmd!(
516516
e.sh,
517-
"cargo +{toolchain} --quiet test --test compiletest {extra_flags...} --manifest-path {miri_manifest} -- --miri-run-dep-mode {miri_flags...} {edition_flags...} {flags...}"
517+
"cargo +{toolchain} --quiet test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {edition_flags...} {flags...}"
518518
).quiet().run()?;
519519
} else {
520520
cmd!(
@@ -526,37 +526,27 @@ impl Command {
526526
}
527527

528528
fn fmt(flags: Vec<OsString>) -> Result<()> {
529+
use itertools::Itertools;
530+
529531
let e = MiriEnv::new()?;
530-
let toolchain = &e.toolchain;
531532
let config_path = path!(e.miri_dir / "rustfmt.toml");
532533

533-
let mut cmd = cmd!(
534-
e.sh,
535-
"rustfmt +{toolchain} --edition=2021 --config-path {config_path} --unstable-features --skip-children {flags...}"
536-
);
537-
eprintln!("$ {cmd} ...");
538-
539-
// Add all the filenames to the command.
540-
// FIXME: `rustfmt` will follow the `mod` statements in these files, so we get a bunch of
541-
// duplicate diffs.
542-
for item in WalkDir::new(&e.miri_dir).into_iter().filter_entry(|entry| {
543-
let name = entry.file_name().to_string_lossy();
544-
let ty = entry.file_type();
545-
if ty.is_file() {
546-
name.ends_with(".rs")
547-
} else {
548-
// dir or symlink. skip `target` and `.git`.
549-
&name != "target" && &name != ".git"
550-
}
551-
}) {
552-
let item = item?;
553-
if item.file_type().is_file() {
554-
cmd = cmd.arg(item.into_path());
555-
}
556-
}
534+
// Collect each rust file in the miri repo.
535+
let files = WalkDir::new(&e.miri_dir)
536+
.into_iter()
537+
.filter_entry(|entry| {
538+
let name = entry.file_name().to_string_lossy();
539+
let ty = entry.file_type();
540+
if ty.is_file() {
541+
name.ends_with(".rs")
542+
} else {
543+
// dir or symlink. skip `target` and `.git`.
544+
&name != "target" && &name != ".git"
545+
}
546+
})
547+
.filter_ok(|item| item.file_type().is_file())
548+
.map_ok(|item| item.into_path());
557549

558-
// We want our own error message, repeating the command is too much.
559-
cmd.quiet().run().map_err(|_| anyhow!("`rustfmt` failed"))?;
560-
Ok(())
550+
e.format_files(files, &e.toolchain[..], &config_path, &flags[..])
561551
}
562552
}

src/tools/miri/miri-script/src/util.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::{OsStr, OsString};
2-
use std::path::PathBuf;
2+
use std::path::{Path, PathBuf};
33

4-
use anyhow::{Context, Result};
4+
use anyhow::{anyhow, Context, Result};
55
use dunce::canonicalize;
66
use path_macro::path;
77
use xshell::{cmd, Shell};
@@ -145,4 +145,48 @@ impl MiriEnv {
145145
.run()?;
146146
Ok(())
147147
}
148+
149+
/// Receives an iterator of files.
150+
/// Will format each file with the miri rustfmt config.
151+
/// Does not recursively format modules.
152+
pub fn format_files(
153+
&self,
154+
files: impl Iterator<Item = Result<PathBuf, walkdir::Error>>,
155+
toolchain: &str,
156+
config_path: &Path,
157+
flags: &[OsString],
158+
) -> anyhow::Result<()> {
159+
use itertools::Itertools;
160+
161+
let mut first = true;
162+
163+
// Format in batches as not all our files fit into Windows' command argument limit.
164+
for batch in &files.chunks(256) {
165+
// Build base command.
166+
let mut cmd = cmd!(
167+
self.sh,
168+
"rustfmt +{toolchain} --edition=2021 --config-path {config_path} --unstable-features --skip-children {flags...}"
169+
);
170+
if first {
171+
// Log an abbreviating command, and only once.
172+
eprintln!("$ {cmd} ...");
173+
first = false;
174+
}
175+
// Add files.
176+
for file in batch {
177+
// Make it a relative path so that on platforms with extremely tight argument
178+
// limits (like Windows), we become immune to someone cloning the repo
179+
// 50 directories deep.
180+
let file = file?;
181+
let file = file.strip_prefix(&self.miri_dir)?;
182+
cmd = cmd.arg(file);
183+
}
184+
185+
// Run rustfmt.
186+
// We want our own error message, repeating the command is too much.
187+
cmd.quiet().run().map_err(|_| anyhow!("`rustfmt` failed"))?;
188+
}
189+
190+
Ok(())
191+
}
148192
}

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1a1876c9790f168fb51afa335a7ba3e6fc267d75
1+
4d4bb491b65c300835442f6cb4f34fc9a5685c26

src/tools/miri/src/bin/miri.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
rustc::untranslatable_diagnostic
99
)]
1010

11+
// Some "regular" crates we want to share with rustc
12+
#[macro_use]
13+
extern crate tracing;
14+
15+
// The rustc crates we need
1116
extern crate rustc_data_structures;
1217
extern crate rustc_driver;
1318
extern crate rustc_hir;
@@ -16,8 +21,6 @@ extern crate rustc_log;
1621
extern crate rustc_metadata;
1722
extern crate rustc_middle;
1823
extern crate rustc_session;
19-
#[macro_use]
20-
extern crate tracing;
2124

2225
use std::env::{self, VarError};
2326
use std::num::NonZero;
@@ -202,16 +205,12 @@ fn rustc_logger_config() -> rustc_log::LoggerConfig {
202205
// rustc traced, but you can also do `MIRI_LOG=miri=trace,rustc_const_eval::interpret=debug`.
203206
if tracing::Level::from_str(&var).is_ok() {
204207
cfg.filter = Ok(format!(
205-
"rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var}"
208+
"rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var},miri={var}"
206209
));
207210
} else {
208211
cfg.filter = Ok(var);
209212
}
210213
}
211-
// Enable verbose entry/exit logging by default if MIRI_LOG is set.
212-
if matches!(cfg.verbose_entry_exit, Err(VarError::NotPresent)) {
213-
cfg.verbose_entry_exit = Ok(format!("1"));
214-
}
215214
}
216215

217216
cfg
@@ -342,7 +341,8 @@ fn main() {
342341
// (`install_ice_hook` might change `RUST_BACKTRACE`.)
343342
let env_snapshot = env::vars_os().collect::<Vec<_>>();
344343

345-
let args = rustc_driver::args::raw_args(&early_dcx).unwrap_or_else(|_| std::process::exit(rustc_driver::EXIT_FAILURE));
344+
let args = rustc_driver::args::raw_args(&early_dcx)
345+
.unwrap_or_else(|_| std::process::exit(rustc_driver::EXIT_FAILURE));
346346

347347
// If the environment asks us to actually be rustc, then do that.
348348
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
@@ -408,17 +408,11 @@ fn main() {
408408
miri_config.check_alignment = miri::AlignmentCheck::None;
409409
} else if arg == "-Zmiri-symbolic-alignment-check" {
410410
miri_config.check_alignment = miri::AlignmentCheck::Symbolic;
411-
} else if arg == "-Zmiri-check-number-validity" {
412-
eprintln!(
413-
"WARNING: the flag `-Zmiri-check-number-validity` no longer has any effect \
414-
since it is now enabled by default"
415-
);
416411
} else if arg == "-Zmiri-disable-abi-check" {
417412
eprintln!(
418-
"WARNING: the flag `-Zmiri-disable-abi-check` is deprecated and planned to be removed.\n\
419-
If you have a use-case for it, please file an issue."
413+
"WARNING: the flag `-Zmiri-disable-abi-check` no longer has any effect; \
414+
ABI checks cannot be disabled any more"
420415
);
421-
miri_config.check_abi = false;
422416
} else if arg == "-Zmiri-disable-isolation" {
423417
if matches!(isolation_enabled, Some(true)) {
424418
show_error!(
@@ -459,8 +453,6 @@ fn main() {
459453
miri_config.collect_leak_backtraces = false;
460454
} else if arg == "-Zmiri-panic-on-unsupported" {
461455
miri_config.panic_on_unsupported = true;
462-
} else if arg == "-Zmiri-tag-raw-pointers" {
463-
eprintln!("WARNING: `-Zmiri-tag-raw-pointers` has no effect; it is enabled by default");
464456
} else if arg == "-Zmiri-strict-provenance" {
465457
miri_config.provenance_mode = ProvenanceMode::Strict;
466458
} else if arg == "-Zmiri-permissive-provenance" {
@@ -476,10 +468,6 @@ fn main() {
476468
"scalar" => RetagFields::OnlyScalar,
477469
_ => show_error!("`-Zmiri-retag-fields` can only be `all`, `none`, or `scalar`"),
478470
};
479-
} else if arg == "-Zmiri-track-raw-pointers" {
480-
eprintln!(
481-
"WARNING: `-Zmiri-track-raw-pointers` has no effect; it is enabled by default"
482-
);
483471
} else if let Some(param) = arg.strip_prefix("-Zmiri-seed=") {
484472
if miri_config.seed.is_some() {
485473
show_error!("Cannot specify -Zmiri-seed multiple times!");

src/tools/miri/src/concurrency/thread.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,13 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
445445

446446
/// Set an active thread and return the id of the thread that was active before.
447447
fn set_active_thread_id(&mut self, id: ThreadId) -> ThreadId {
448-
let active_thread_id = self.active_thread;
449-
self.active_thread = id;
450-
assert!(self.active_thread.index() < self.threads.len());
451-
active_thread_id
448+
assert!(id.index() < self.threads.len());
449+
info!(
450+
"---------- Now executing on thread `{}` (previous: `{}`) ----------------------------------------",
451+
self.get_thread_display_name(id),
452+
self.get_thread_display_name(self.active_thread)
453+
);
454+
std::mem::replace(&mut self.active_thread, id)
452455
}
453456

454457
/// Get the id of the currently active thread.
@@ -735,6 +738,11 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
735738
for (id, thread) in threads {
736739
debug_assert_ne!(self.active_thread, id);
737740
if thread.state == ThreadState::Enabled {
741+
info!(
742+
"---------- Now executing on thread `{}` (previous: `{}`) ----------------------------------------",
743+
self.get_thread_display_name(id),
744+
self.get_thread_display_name(self.active_thread)
745+
);
738746
self.active_thread = id;
739747
break;
740748
}
@@ -882,7 +890,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
882890
instance,
883891
start_abi,
884892
&[*func_arg],
885-
Some(&ret_place.into()),
893+
Some(&ret_place),
886894
StackPopCleanup::Root { cleanup: true },
887895
)?;
888896

src/tools/miri/src/eval.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ pub struct MiriConfig {
9494
pub unique_is_unique: bool,
9595
/// Controls alignment checking.
9696
pub check_alignment: AlignmentCheck,
97-
/// Controls function [ABI](Abi) checking.
98-
pub check_abi: bool,
9997
/// Action for an op requiring communication with the host.
10098
pub isolated_op: IsolatedOp,
10199
/// Determines if memory leaks should be ignored.
@@ -162,7 +160,6 @@ impl Default for MiriConfig {
162160
borrow_tracker: Some(BorrowTrackerMethod::StackedBorrows),
163161
unique_is_unique: false,
164162
check_alignment: AlignmentCheck::Int,
165-
check_abi: true,
166163
isolated_op: IsolatedOp::Reject(RejectOpWith::Abort),
167164
ignore_leaks: false,
168165
forwarded_env_vars: vec![],
@@ -394,7 +391,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
394391
argv,
395392
Scalar::from_u8(sigpipe).into(),
396393
],
397-
Some(&ret_place.into()),
394+
Some(&ret_place),
398395
StackPopCleanup::Root { cleanup: true },
399396
)?;
400397
}
@@ -403,7 +400,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
403400
entry_instance,
404401
Abi::Rust,
405402
&[argc.into(), argv],
406-
Some(&ret_place.into()),
403+
Some(&ret_place),
407404
StackPopCleanup::Root { cleanup: true },
408405
)?;
409406
}

0 commit comments

Comments
 (0)