Skip to content

Commit da27bb3

Browse files
authored
Rollup merge of rust-lang#105214 - RalfJung:miri, r=RalfJung
update Miri r? `@ghost`
2 parents 8d33f31 + 9562aac commit da27bb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1073
-907
lines changed

CONTRIBUTING.md

+14-47
Original file line numberDiff line numberDiff line change
@@ -203,65 +203,32 @@ for more information about configuring VS Code and `rust-analyzer`.
203203

204204
[rdg-r-a]: https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc
205205

206-
## Advanced topic: other build environments
206+
## Advanced topic: Working on Miri in the rustc tree
207207

208208
We described above the simplest way to get a working build environment for Miri,
209209
which is to use the version of rustc indicated by `rustc-version`. But
210210
sometimes, that is not enough.
211211

212-
### Building Miri with a locally built rustc
212+
A big part of the Miri driver is shared with rustc, so working on Miri will
213+
sometimes require also working on rustc itself. In this case, you should *not*
214+
work in a clone of the Miri repository, but in a clone of the
215+
[main Rust repository](https://github.com/rust-lang/rust/). There is a copy of
216+
Miri located at `src/tools/miri` that you can work on directly. A maintainer
217+
will eventually sync those changes back into this repository.
213218

214-
[building Miri with a locally built rustc]: #building-miri-with-a-locally-built-rustc
219+
When working on Miri in the rustc tree, here's how you can run tests:
215220

216-
A big part of the Miri driver lives in rustc, so working on Miri will sometimes
217-
require using a locally built rustc. The bug you want to fix may actually be on
218-
the rustc side, or you just need to get more detailed trace of the execution
219-
than what is possible with release builds -- in both cases, you should develop
220-
Miri against a rustc you compiled yourself, with debug assertions (and hence
221-
tracing) enabled.
222-
223-
The setup for a local rustc works as follows:
224-
```sh
225-
# Clone the rust-lang/rust repo.
226-
git clone https://github.com/rust-lang/rust rustc
227-
cd rustc
228-
# Create a config.toml with defaults for working on Miri.
229-
./x.py setup compiler
230-
# Now edit `config.toml` and under `[rust]` set `debug-assertions = true`.
231-
232-
# Build a stage 2 rustc, and build the rustc libraries with that rustc.
233-
# This step can take 30 minutes or more.
234-
./x.py build --stage 2 compiler/rustc
235-
# If you change something, you can get a faster rebuild by doing
236-
./x.py build --keep-stage 0 --stage 2 compiler/rustc
237-
# You may have to change the architecture in the next command
238-
rustup toolchain link stage2 build/x86_64-unknown-linux-gnu/stage2
239-
# Now cd to your Miri directory, then configure rustup
240-
rustup override set stage2
241221
```
242-
243-
Note: When you are working with a locally built rustc or any other toolchain that
244-
is not the same as the one in `rust-version`, you should not have `.auto-everything` or
245-
`.auto-toolchain` as that will keep resetting your toolchain.
246-
247-
```sh
248-
rm -f .auto-everything .auto-toolchain
222+
./x.py test miri --stage 0
249223
```
250224

251-
Important: You need to delete the Miri cache when you change the stdlib; otherwise the
252-
old, chached version will be used. On Linux, the cache is located at `~/.cache/miri`,
253-
and on Windows, it is located at `%LOCALAPPDATA%\rust-lang\miri\cache`; the exact
254-
location is printed after the library build: "A libstd for Miri is now available in ...".
255-
256-
Note: `./x.py --stage 2 compiler/rustc` currently errors with `thread 'main'
257-
panicked at 'fs::read(stamp) failed with No such file or directory (os error 2)`,
258-
you can simply ignore that error; Miri will build anyway.
225+
`--bless` will work, too.
259226

260-
For more information about building and configuring a local compiler,
261-
see <https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html>.
227+
You can also directly run Miri on a Rust source file:
262228

263-
With this, you should now have a working development setup! See
264-
[above](#building-and-testing-miri) for how to proceed working on Miri.
229+
```
230+
./x.py run miri --stage 0 --args src/tools/miri/tests/pass/hello.rs
231+
```
265232

266233
## Advanced topic: Syncing with the rustc repo
267234

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ libloading = "0.7"
3939

4040
[dev-dependencies]
4141
colored = "2"
42-
ui_test = "0.4"
42+
ui_test = "0.5"
4343
rustc_version = "0.4"
4444
# Features chosen to match those required by env_logger, to avoid rebuilds
4545
regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }

cargo-miri/src/phases.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
9494
let target = target.as_ref().unwrap_or(host);
9595

9696
// We always setup.
97-
setup(&subcommand, target, &rustc_version);
97+
setup(&subcommand, target, &rustc_version, verbose);
9898

9999
// Invoke actual cargo for the job, but with different flags.
100100
// We re-use `cargo test` and `cargo run`, which makes target and binary handling very easy but
@@ -486,8 +486,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
486486
continue;
487487
} else if verbose > 0 {
488488
eprintln!(
489-
"[cargo-miri runner] Overwriting run-time env var {:?}={:?} with build-time value {:?}",
490-
name, old_val, val
489+
"[cargo-miri runner] Overwriting run-time env var {name:?}={old_val:?} with build-time value {val:?}"
491490
);
492491
}
493492
}

cargo-miri/src/setup.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::util::*;
1313
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
1414
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
1515
/// done all this already.
16-
pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta) {
16+
pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta, verbose: usize) {
1717
let only_setup = matches!(subcommand, MiriCommand::Setup);
1818
let ask_user = !only_setup;
1919
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
@@ -99,12 +99,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
9999
// `config.toml`.
100100
command.env("RUSTC_WRAPPER", "");
101101

102-
if only_setup {
103-
if print_sysroot {
104-
// Be extra sure there is no noise on stdout.
105-
command.stdout(process::Stdio::null());
102+
if only_setup && !print_sysroot {
103+
// Forward output. Even make it verbose, if requested.
104+
for _ in 0..verbose {
105+
command.arg("-v");
106106
}
107107
} else {
108+
// Supress output.
108109
command.stdout(process::Stdio::null());
109110
command.stderr(process::Stdio::null());
110111
}
@@ -120,7 +121,9 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
120121
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
121122

122123
// Do the build.
123-
if only_setup {
124+
if print_sysroot {
125+
// Be silent.
126+
} else if only_setup {
124127
// We want to be explicit.
125128
eprintln!("Preparing a sysroot for Miri (target: {target})...");
126129
} else {
@@ -143,7 +146,9 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
143146
)
144147
}
145148
});
146-
if only_setup {
149+
if print_sysroot {
150+
// Be silent.
151+
} else if only_setup {
147152
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
148153
} else {
149154
eprintln!("done");

ci.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ function run_tests {
4040
./miri test
4141
if [ -z "${MIRI_TEST_TARGET+exists}" ]; then
4242
# Only for host architecture: tests with optimizations (`-O` is what cargo passes, but crank MIR
43-
# optimizations up all the way).
44-
# Optimizations change diagnostics (mostly backtraces), so we don't check them
45-
#FIXME(#2155): we want to only run the pass and panic tests here, not the fail tests.
43+
# optimizations up all the way, too).
44+
# Optimizations change diagnostics (mostly backtraces), so we don't check
45+
# them. Also error locations change so we don't run the failing tests.
4646
MIRIFLAGS="${MIRIFLAGS:-} -O -Zmir-opt-level=4" MIRI_SKIP_UI_CHECKS=1 ./miri test -- tests/{pass,panic}
47+
48+
# Also run some many-seeds tests. 64 seeds means this takes around a minute per test.
49+
for FILE in tests/many-seeds/*.rs; do
50+
MIRI_SEEDS=64 CARGO_EXTRA_FLAGS="$CARGO_EXTRA_FLAGS -q" ./miri many-seeds ./miri run "$FILE"
51+
done
4752
fi
4853

4954
## test-cargo-miri

miri

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Mainly meant to be invoked by rust-analyzer.
3636
./miri many-seeds <command>:
3737
Runs <command> over and over again with different seeds for Miri. The MIRIFLAGS
3838
variable is set to its original value appended with ` -Zmiri-seed=$SEED` for
39-
many different seeds.
39+
many different seeds. The MIRI_SEEDS variable controls how many seeds are being
40+
tried; MIRI_SEED_START controls the first seed to try.
4041
4142
./miri bench <benches>:
4243
Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
@@ -174,7 +175,9 @@ rustc-push)
174175
fi
175176
;;
176177
many-seeds)
177-
for SEED in $(seq 0 255); do
178+
MIRI_SEED_START=${MIRI_SEED_START:-0} # default to 0
179+
MIRI_SEEDS=${MIRI_SEEDS:-256} # default to 256
180+
for SEED in $(seq $MIRI_SEED_START $(( $MIRI_SEED_START + $MIRI_SEEDS - 1 )) ); do
178181
echo "Trying seed: $SEED"
179182
MIRIFLAGS="$MIRIFLAGS -Zlayout-seed=$SEED -Zmiri-seed=$SEED" $@ || { echo "Failing seed: $SEED"; break; }
180183
done
@@ -249,6 +252,8 @@ export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR $RUSTFLAGS"
249252
# Build a sysroot and set MIRI_SYSROOT to use it. Arguments are passed to `cargo miri setup`.
250253
build_sysroot() {
251254
if ! MIRI_SYSROOT="$($CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup --print-sysroot "$@")"; then
255+
# Run it again so the user can see the error.
256+
$CARGO run $CARGO_EXTRA_FLAGS --manifest-path "$MIRIDIR"/cargo-miri/Cargo.toml -- miri setup "$@"
252257
echo "'cargo miri setup' failed"
253258
exit 1
254259
fi

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
454784afba5bf35b5ff14ada0e31265ad1d75e73
1+
cef44f53034eac46be3a0e3eec7b2b3d4ef5140b

src/bin/miri.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ fn init_late_loggers(tcx: TyCtxt<'_>) {
192192
if log::Level::from_str(&var).is_ok() {
193193
env::set_var(
194194
"RUSTC_LOG",
195-
format!(
196-
"rustc_middle::mir::interpret={0},rustc_const_eval::interpret={0}",
197-
var
198-
),
195+
format!("rustc_middle::mir::interpret={var},rustc_const_eval::interpret={var}"),
199196
);
200197
} else {
201198
env::set_var("RUSTC_LOG", &var);
@@ -317,7 +314,7 @@ fn main() {
317314
} else if arg == "-Zmiri-disable-validation" {
318315
miri_config.validate = false;
319316
} else if arg == "-Zmiri-disable-stacked-borrows" {
320-
miri_config.stacked_borrows = false;
317+
miri_config.borrow_tracker = None;
321318
} else if arg == "-Zmiri-disable-data-race-detector" {
322319
miri_config.data_race_detector = false;
323320
miri_config.weak_memory_emulation = false;
@@ -413,7 +410,7 @@ fn main() {
413410
err
414411
),
415412
};
416-
for id in ids.into_iter().map(miri::SbTag::new) {
413+
for id in ids.into_iter().map(miri::BorTag::new) {
417414
if let Some(id) = id {
418415
miri_config.tracked_pointer_tags.insert(id);
419416
} else {

0 commit comments

Comments
 (0)