Skip to content

Commit 837c679

Browse files
committed
Auto merge of rust-lang#2699 - RalfJung:schedule-refactor, r=RalfJung
refactor scheduler Refactors the scheduler to use something akin to a generator -- a callback that will be invoked when the stack of a thread is empty, which has the chance to push a new stack frame or do other things and then indicates whether this thread is done, or should be scheduled again. (Unfortunately I think we [cannot use actual generators](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Generators.20that.20borrow.20on.20each.20resume.3F) here.) The interpreter loop is now a proper infinite loop, the only way to leave it is for some kind of interrupt to be triggered (represented as `InterpError`) -- unifying how we handle 'exit when calling `process::exit`' and 'exit when main thread quits'. The last commit implements an alternative approach to rust-lang/miri#2660 using this new structure. Fixes rust-lang/miri#2629.
2 parents 9622070 + 7453d7e commit 837c679

File tree

15 files changed

+412
-327
lines changed

15 files changed

+412
-327
lines changed

cargo-miri/src/setup.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,10 @@ 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());
106-
}
102+
if only_setup && !print_sysroot {
103+
// Forward output.
107104
} else {
105+
// Supress output.
108106
command.stdout(process::Stdio::null());
109107
command.stderr(process::Stdio::null());
110108
}
@@ -120,7 +118,9 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
120118
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
121119

122120
// Do the build.
123-
if only_setup {
121+
if print_sysroot {
122+
// Be silent.
123+
} else if only_setup {
124124
// We want to be explicit.
125125
eprintln!("Preparing a sysroot for Miri (target: {target})...");
126126
} else {
@@ -143,7 +143,9 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
143143
)
144144
}
145145
});
146-
if only_setup {
146+
if print_sysroot {
147+
// Be silent.
148+
} else if only_setup {
147149
eprintln!("A sysroot for Miri is now available in `{}`.", sysroot_dir.display());
148150
} else {
149151
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

0 commit comments

Comments
 (0)