Skip to content

Commit acda22d

Browse files
committed
Auto merge of #123264 - matthiaskrgr:rollup-smyy7j9, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #123189 (Log BOLT args in bootstrap `rustc` shim) - #123211 (Stop calling visitors `V`) - #123242 (pattern analysis: Require enum indices to be contiguous) - #123260 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e5da77b + 3153731 commit acda22d

File tree

21 files changed

+214
-186
lines changed

21 files changed

+214
-186
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ harness = false
5959
[features]
6060
default = ["stack-cache"]
6161
stack-cache = []
62+
stack-cache-consistency-check = ["stack-cache"]
6263

6364
# Be aware that this file is inside a workspace when used via the
6465
# submodule in the rustc repo. That means there are many cargo features

cargo-miri/src/phases.rs

+38-40
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,27 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
179179
);
180180
}
181181
cmd.env("RUSTC_WRAPPER", &cargo_miri_path);
182+
// There's also RUSTC_WORKSPACE_WRAPPER, which gets in the way of our own wrapping.
183+
if env::var_os("RUSTC_WORKSPACE_WRAPPER").is_some() {
184+
println!(
185+
"WARNING: Ignoring `RUSTC_WORKSPACE_WRAPPER` environment variable, Miri does not support wrapping."
186+
);
187+
}
188+
cmd.env_remove("RUSTC_WORKSPACE_WRAPPER");
182189
// We are going to invoke `MIRI` for everything, not `RUSTC`.
183190
if env::var_os("RUSTC").is_some() && env::var_os("MIRI").is_none() {
184191
println!(
185192
"WARNING: Ignoring `RUSTC` environment variable; set `MIRI` if you want to control the binary used as the driver."
186193
);
187194
}
188-
// Build scripts (and also cargo: https://github.com/rust-lang/cargo/issues/10885) will invoke
189-
// `rustc` even when `RUSTC_WRAPPER` is set. To make sure everything is coherent, we want that
190-
// to be the Miri driver, but acting as rustc, on the target level. (Target, rather than host,
191-
// is needed for cross-interpretation situations.) This is not a perfect emulation of real rustc
192-
// (it might be unable to produce binaries since the sysroot is check-only), but it's as close
193-
// as we can get, and it's good enough for autocfg.
195+
// Ideally we would set RUSTC to some non-existent path, so we can be sure our wrapping is
196+
// always applied. However, buggy build scripts (https://github.com/eyre-rs/eyre/issues/84) and
197+
// also cargo (https://github.com/rust-lang/cargo/issues/10885) will invoke `rustc` even when
198+
// `RUSTC_WRAPPER` is set, bypassing the wrapper. To make sure everything is coherent, we want
199+
// that to be the Miri driver, but acting as rustc, on the target level. (Target, rather than
200+
// host, is needed for cross-interpretation situations.) This is not a perfect emulation of real
201+
// rustc (it might be unable to produce binaries since the sysroot is check-only), but it's as
202+
// close as we can get, and it's good enough for autocfg.
194203
//
195204
// In `main`, we need the value of `RUSTC` to distinguish RUSTC_WRAPPER invocations from rustdoc
196205
// or TARGET_RUNNER invocations, so we canonicalize it here to make it exceedingly unlikely that
@@ -247,6 +256,16 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
247256
/// Cargo does not give us this information directly, so we need to check
248257
/// various command-line flags.
249258
fn is_runnable_crate() -> bool {
259+
// Determine whether this is cargo invoking rustc to get some infos. Ideally we'd check "is
260+
// there a filename passed to rustc", but that's very hard as we would have to know whether
261+
// e.g. `--print foo` is a booolean flag `--print` followed by filename `foo` or equivalent
262+
// to `--print=foo`. So instead we use this more fragile approach of detecting the presence
263+
// of a "query" flag rather than the absence of a filename.
264+
let info_query = get_arg_flag_value("--print").is_some() || has_arg_flag("-vV");
265+
if info_query {
266+
// Nothing to run.
267+
return false;
268+
}
250269
let is_bin = get_arg_flag_value("--crate-type").as_deref().unwrap_or("bin") == "bin";
251270
let is_test = has_arg_flag("--test");
252271
is_bin || is_test
@@ -285,16 +304,9 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
285304
}
286305
}
287306

288-
// phase_cargo_miri set `MIRI_BE_RUSTC` for when build scripts directly invoke the driver;
289-
// however, if we get called back by cargo here, we'll carefully compute the right flags
290-
// ourselves, so we first un-do what the earlier phase did.
291-
env::remove_var("MIRI_BE_RUSTC");
292-
293307
let verbose = std::env::var("MIRI_VERBOSE")
294308
.map_or(0, |verbose| verbose.parse().expect("verbosity flag must be an integer"));
295309
let target_crate = is_target_crate();
296-
// Determine whether this is cargo invoking rustc to get some infos.
297-
let info_query = get_arg_flag_value("--print").is_some() || has_arg_flag("-vV");
298310

299311
let store_json = |info: CrateRunInfo| {
300312
if get_arg_flag_value("--emit").unwrap_or_default().split(',').any(|e| e == "dep-info") {
@@ -321,7 +333,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
321333
}
322334
};
323335

324-
let runnable_crate = !info_query && is_runnable_crate();
336+
let runnable_crate = is_runnable_crate();
325337

326338
if runnable_crate && target_crate {
327339
assert!(
@@ -395,7 +407,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
395407
let mut emit_link_hack = false;
396408
// Arguments are treated very differently depending on whether this crate is
397409
// for interpretation by Miri, or for use by a build script / proc macro.
398-
if !info_query && target_crate {
410+
if target_crate {
399411
// Forward arguments, but remove "link" from "--emit" to make this a check-only build.
400412
let emit_flag = "--emit";
401413
while let Some(arg) = args.next() {
@@ -429,17 +441,14 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
429441
cmd.arg("-C").arg("panic=abort");
430442
}
431443
} else {
432-
// For host crates (but not when we are just printing some info),
433-
// we might still have to set the sysroot.
434-
if !info_query {
435-
// When we're running `cargo-miri` from `x.py` we need to pass the sysroot explicitly
436-
// due to bootstrap complications.
437-
if let Some(sysroot) = std::env::var_os("MIRI_HOST_SYSROOT") {
438-
cmd.arg("--sysroot").arg(sysroot);
439-
}
444+
// This is a host crate.
445+
// When we're running `cargo-miri` from `x.py` we need to pass the sysroot explicitly
446+
// due to bootstrap complications.
447+
if let Some(sysroot) = std::env::var_os("MIRI_HOST_SYSROOT") {
448+
cmd.arg("--sysroot").arg(sysroot);
440449
}
441450

442-
// For host crates or when we are printing, just forward everything.
451+
// Forward everything.
443452
cmd.args(args);
444453
}
445454

@@ -451,9 +460,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
451460

452461
// Run it.
453462
if verbose > 0 {
454-
eprintln!(
455-
"[cargo-miri rustc] target_crate={target_crate} runnable_crate={runnable_crate} info_query={info_query}"
456-
);
463+
eprintln!("[cargo-miri rustc] target_crate={target_crate} runnable_crate={runnable_crate}");
457464
}
458465

459466
// Create a stub .rlib file if "link" was requested by cargo.
@@ -480,11 +487,6 @@ pub enum RunnerPhase {
480487
}
481488

482489
pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: RunnerPhase) {
483-
// phase_cargo_miri set `MIRI_BE_RUSTC` for when build scripts directly invoke the driver;
484-
// however, if we get called back by cargo here, we'll carefully compute the right flags
485-
// ourselves, so we first un-do what the earlier phase did.
486-
env::remove_var("MIRI_BE_RUSTC");
487-
488490
let verbose = std::env::var("MIRI_VERBOSE")
489491
.map_or(0, |verbose| verbose.parse().expect("verbosity flag must be an integer"));
490492

@@ -542,15 +544,13 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
542544
// but when we run here, cargo does not interpret the JSON any more. `--json`
543545
// then also needs to be dropped.
544546
let mut args = info.args.into_iter();
545-
let error_format_flag = "--error-format";
546-
let json_flag = "--json";
547547
while let Some(arg) = args.next() {
548548
if arg == "--extern" {
549549
forward_patched_extern_arg(&mut args, &mut cmd);
550-
} else if let Some(suffix) = arg.strip_prefix(error_format_flag) {
550+
} else if let Some(suffix) = arg.strip_prefix("--error-format") {
551551
assert!(suffix.starts_with('='));
552552
// Drop this argument.
553-
} else if let Some(suffix) = arg.strip_prefix(json_flag) {
553+
} else if let Some(suffix) = arg.strip_prefix("--json") {
554554
assert!(suffix.starts_with('='));
555555
// Drop this argument.
556556
} else {
@@ -589,13 +589,11 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
589589
let rustdoc = env::var("MIRI_ORIG_RUSTDOC").unwrap_or("rustdoc".to_string());
590590
let mut cmd = Command::new(rustdoc);
591591

592-
let extern_flag = "--extern";
593-
let runtool_flag = "--runtool";
594592
while let Some(arg) = args.next() {
595-
if arg == extern_flag {
593+
if arg == "--extern" {
596594
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
597595
forward_patched_extern_arg(&mut args, &mut cmd);
598-
} else if arg == runtool_flag {
596+
} else if arg == "--runtool" {
599597
// An existing --runtool flag indicates cargo is running in cross-target mode, which we don't support.
600598
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
601599
// otherwise, we won't be called as rustdoc at all.

cargo-miri/src/util.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ pub fn find_miri() -> PathBuf {
101101
}
102102

103103
pub fn miri() -> Command {
104-
Command::new(find_miri())
104+
let mut cmd = Command::new(find_miri());
105+
// We never want to inherit this from the environment.
106+
// However, this is sometimes set in the environment to work around build scripts that don't
107+
// honor RUSTC_WRAPPER. So remove it again in case it is set.
108+
cmd.env_remove("MIRI_BE_RUSTC");
109+
cmd
105110
}
106111

107112
pub fn miri_for_host() -> Command {

ci/ci.sh

+16-9
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,24 @@ if [ "$HOST_TARGET" = i686-pc-windows-msvc ]; then
2222
BASH="C:/Program Files/Git/usr/bin/bash"
2323
fi
2424

25-
# Determine configuration for installed build
26-
echo "Installing release version of Miri"
25+
# Global configuration
2726
export RUSTFLAGS="-D warnings"
2827
export CARGO_INCREMENTAL=0
2928
export CARGO_EXTRA_FLAGS="--locked"
29+
30+
# Determine configuration for installed build
31+
echo "Installing release version of Miri"
3032
./miri install
3133

32-
# Prepare debug build for direct `./miri` invocations
33-
echo "Building debug version of Miri"
34+
echo "Checking various feature flag configurations"
3435
./miri check --no-default-features # make sure this can be built
35-
./miri check --all-features # and this, too
36+
./miri check # and this, too
37+
# `--all-features` is used for the build below, so no extra check needed.
38+
39+
# Prepare debug build for direct `./miri` invocations.
40+
# We enable all features to make sure the Stacked Borrows consistency check runs.
41+
echo "Building debug version of Miri"
42+
export CARGO_EXTRA_FLAGS="$CARGO_EXTRA_FLAGS --all-features"
3643
./miri build --all-targets # the build that all the `./miri test` below will use
3744

3845
endgroup
@@ -46,8 +53,8 @@ function run_tests {
4653
fi
4754

4855
## ui test suite
49-
# On the host and on Linux, also stress-test the GC.
50-
if [ -z "${MIRI_TEST_TARGET:-}" ] || [ "$HOST_TARGET" = x86_64-unknown-linux-gnu ]; then
56+
# On the host, also stress-test the GC.
57+
if [ -z "${MIRI_TEST_TARGET:-}" ]; then
5158
MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-provenance-gc=1" ./miri test
5259
else
5360
./miri test
@@ -130,6 +137,8 @@ case $HOST_TARGET in
130137
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
131138
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
132139
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
140+
MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
141+
MIRI_TEST_TARGET=arm-unknown-linux-gnueabi run_tests
133142
# Some targets are only partially supported.
134143
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
135144
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple pthread-threadname libc-getentropy libc-getrandom libc-misc libc-fs atomic env align num_cpus
@@ -145,9 +154,7 @@ case $HOST_TARGET in
145154
MIRI_TEST_TARGET=x86_64-pc-windows-msvc run_tests
146155
;;
147156
i686-pc-windows-msvc)
148-
MIRI_TEST_TARGET=arm-unknown-linux-gnueabi run_tests
149157
MIRI_TEST_TARGET=x86_64-unknown-linux-gnu run_tests
150-
MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
151158
;;
152159
*)
153160
echo "FATAL: unknown OS"

miri-script/src/commands.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,11 @@ impl Command {
479479
Ok(())
480480
}
481481

482-
fn run(dep: bool, flags: Vec<OsString>) -> Result<()> {
482+
fn run(dep: bool, mut flags: Vec<OsString>) -> Result<()> {
483483
let mut e = MiriEnv::new()?;
484484
// Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
485-
// that we set the MIRI_SYSROOT up the right way.
485+
// that we set the MIRI_SYSROOT up the right way. We must make sure that
486+
// MIRI_TEST_TARGET and `--target` are in sync.
486487
use itertools::Itertools;
487488
let target = flags
488489
.iter()
@@ -493,33 +494,35 @@ impl Command {
493494
// Found it!
494495
e.sh.set_var("MIRI_TEST_TARGET", target);
495496
} else if let Ok(target) = std::env::var("MIRI_TEST_TARGET") {
496-
// Make sure miri actually uses this target.
497-
let miriflags = e.sh.var("MIRIFLAGS").unwrap_or_default();
498-
e.sh.set_var("MIRIFLAGS", format!("{miriflags} --target {target}"));
497+
// Convert `MIRI_TEST_TARGET` into `--target`.
498+
flags.push("--target".into());
499+
flags.push(target.into());
499500
}
500-
// Scan for "--edition" (we'll set one ourselves if that flag is not present).
501+
// Scan for "--edition", set one ourselves if that flag is not present.
501502
let have_edition =
502503
flags.iter().take_while(|arg| *arg != "--").any(|arg| *arg == "--edition");
504+
if !have_edition {
505+
flags.push("--edition=2021".into()); // keep in sync with `tests/ui.rs`.`
506+
}
503507

504508
// Prepare a sysroot.
505509
e.build_miri_sysroot(/* quiet */ true)?;
506510

507-
// Then run the actual command.
511+
// Then run the actual command. Also add MIRIFLAGS.
508512
let miri_manifest = path!(e.miri_dir / "Cargo.toml");
509513
let miri_flags = e.sh.var("MIRIFLAGS").unwrap_or_default();
510514
let miri_flags = flagsplit(&miri_flags);
511515
let toolchain = &e.toolchain;
512516
let extra_flags = &e.cargo_extra_flags;
513-
let edition_flags = (!have_edition).then_some("--edition=2021"); // keep in sync with `tests/ui.rs`.`
514517
if dep {
515518
cmd!(
516519
e.sh,
517-
"cargo +{toolchain} --quiet test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {edition_flags...} {flags...}"
520+
"cargo +{toolchain} --quiet test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {flags...}"
518521
).quiet().run()?;
519522
} else {
520523
cmd!(
521524
e.sh,
522-
"cargo +{toolchain} --quiet run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {edition_flags...} {flags...}"
525+
"cargo +{toolchain} --quiet run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {flags...}"
523526
).quiet().run()?;
524527
}
525528
Ok(())

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cb7c63606e53715f94f3ba04d38e50772e4cd23d
1+
5baf1e13f568b61e121953bf6a3d09faee7dd446

src/borrow_tracker/stacked_borrows/stack.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'tcx> Stack {
146146
/// Panics if any of the caching mechanisms have broken,
147147
/// - The StackCache indices don't refer to the parallel items,
148148
/// - There are no Unique items outside of first_unique..last_unique
149-
#[cfg(all(feature = "stack-cache", debug_assertions))]
149+
#[cfg(feature = "stack-cache-consistency-check")]
150150
fn verify_cache_consistency(&self) {
151151
// Only a full cache needs to be valid. Also see the comments in find_granting_cache
152152
// and set_unknown_bottom.
@@ -190,7 +190,7 @@ impl<'tcx> Stack {
190190
tag: ProvenanceExtra,
191191
exposed_tags: &FxHashSet<BorTag>,
192192
) -> Result<Option<usize>, ()> {
193-
#[cfg(all(feature = "stack-cache", debug_assertions))]
193+
#[cfg(feature = "stack-cache-consistency-check")]
194194
self.verify_cache_consistency();
195195

196196
let ProvenanceExtra::Concrete(tag) = tag else {
@@ -327,7 +327,7 @@ impl<'tcx> Stack {
327327
// This primes the cache for the next access, which is almost always the just-added tag.
328328
self.cache.add(new_idx, new);
329329

330-
#[cfg(debug_assertions)]
330+
#[cfg(feature = "stack-cache-consistency-check")]
331331
self.verify_cache_consistency();
332332
}
333333

@@ -410,7 +410,7 @@ impl<'tcx> Stack {
410410
self.unique_range.end = self.unique_range.end.min(disable_start);
411411
}
412412

413-
#[cfg(all(feature = "stack-cache", debug_assertions))]
413+
#[cfg(feature = "stack-cache-consistency-check")]
414414
self.verify_cache_consistency();
415415

416416
Ok(())
@@ -465,7 +465,7 @@ impl<'tcx> Stack {
465465
self.unique_range = 0..0;
466466
}
467467

468-
#[cfg(all(feature = "stack-cache", debug_assertions))]
468+
#[cfg(feature = "stack-cache-consistency-check")]
469469
self.verify_cache_consistency();
470470
Ok(())
471471
}

src/borrow_tracker/tree_borrows/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ type S = &'static str;
365365
/// Pretty-printing details
366366
///
367367
/// Example:
368-
/// ```
368+
/// ```rust,ignore (private type)
369369
/// DisplayFmtWrapper {
370370
/// top: '>',
371371
/// bot: '<',
@@ -393,7 +393,7 @@ struct DisplayFmtWrapper {
393393
/// Formating of the permissions on each range.
394394
///
395395
/// Example:
396-
/// ```
396+
/// ```rust,ignore (private type)
397397
/// DisplayFmtPermission {
398398
/// open: "[",
399399
/// sep: "|",
@@ -425,7 +425,7 @@ struct DisplayFmtPermission {
425425
/// Formating of the tree structure.
426426
///
427427
/// Example:
428-
/// ```
428+
/// ```rust,ignore (private type)
429429
/// DisplayFmtPadding {
430430
/// join_middle: "|-",
431431
/// join_last: "'-",
@@ -463,7 +463,7 @@ struct DisplayFmtPadding {
463463
/// How to show whether a location has been accessed
464464
///
465465
/// Example:
466-
/// ```
466+
/// ```rust,ignore (private type)
467467
/// DisplayFmtAccess {
468468
/// yes: " ",
469469
/// no: "?",

0 commit comments

Comments
 (0)