Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: fix auto builds and make sure that we always have at least a single CI job #124739

Closed
wants to merge 118 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
3fd8c64
doc note that f16 and f128 hardware support is limited
ultrabear Apr 13, 2024
fc37633
Support Result<T, E> across FFI when niche optimization can be used
MasterAwesome Mar 9, 2024
b3e6d52
We don't need to check for non-exhaustive fields
MasterAwesome Mar 9, 2024
08b85a1
Don't lint niche optimized variants in enums
MasterAwesome Mar 9, 2024
223d5eb
Add tests
MasterAwesome Mar 9, 2024
014ddac
Disallow single-variant enums
MasterAwesome Mar 9, 2024
b3f6511
Add a test against Result<(), ()>
MasterAwesome Mar 19, 2024
764f64f
Reword `is_niche_optimization_candidate` doc
MasterAwesome Mar 19, 2024
437ca26
Remove comment out of RFC's scope
MasterAwesome Mar 19, 2024
ed532cc
Put the RFC behind a feature gate `result_ffi_guarantees`
MasterAwesome Mar 19, 2024
2681edf
josh rustc-pull: check that no new root commits get created
RalfJung Apr 27, 2024
39f7a46
fix: usage of `deprecated` version of `Node.js`
hamirmahal Apr 27, 2024
f5ceb4e
Auto merge of #3519 - hamirmahal:fix/usage-of-deprecated-version-of-n…
bors Apr 27, 2024
45d9394
Auto merge of #3520 - RalfJung:josh-check, r=RalfJung
bors Apr 27, 2024
ee47a8e
Add doc comment to `pack_generic`
eduardosm Apr 27, 2024
b3b1b49
Clarify behavior of AVX2 gather when dest and offsets have different …
eduardosm Apr 27, 2024
b261535
Do not implement x86 SIMD abs with host integers
eduardosm Apr 27, 2024
5c6f95c
Auto merge of #3521 - eduardosm:avx2-2, r=RalfJung
bors Apr 28, 2024
b5482aa
file descriptors: make write take &mut self
RalfJung Apr 28, 2024
bc8ea93
Auto merge of #3524 - RalfJung:fd-write, r=RalfJung
bors Apr 28, 2024
622f697
Use the interpreted program's TZ variable in localtime_r
saethlin Apr 27, 2024
39dc6c1
Fix unwinding on 32-bit watchOS ARM
madsmtm Apr 28, 2024
9bed19e
Refactor UnixEnvVars::get so that it can be reused by getenv
saethlin Apr 28, 2024
7afef08
don't leak UnixEnvVars impl details into get_env_var
RalfJung Apr 29, 2024
1c7e827
Auto merge of #3523 - saethlin:localtime_r-env, r=RalfJung
bors Apr 29, 2024
1cf951e
Don’t print `Preparing a sysroot` when `-q`/`--quiet` is passed
narpfel May 1, 2024
4b42626
fix usage example for `--print-sysroot`
narpfel May 1, 2024
a2b3211
no longer strip `Preparing a sysroot` message from test output
narpfel May 1, 2024
b0bdbcc
Auto merge of #3531 - narpfel:quiet-sysroot, r=RalfJung
bors May 1, 2024
aa986f0
Tree Borrows: first apply transition, then check protector with new '…
RalfJung May 2, 2024
ca3defe
Auto merge of #3532 - RalfJung:tb-protectors, r=RalfJung
bors May 2, 2024
36caaa9
update host-float comments
RalfJung May 2, 2024
f6c0090
Auto merge of #3535 - RalfJung:host-float, r=RalfJung
bors May 2, 2024
c8e2336
Use sum type for `WorkflowRunType`
Kobzol May 2, 2024
92a3052
Parse try build CI job name from commit message
Kobzol May 2, 2024
3efdb4d
Make the regex more robust
Kobzol May 2, 2024
56bb517
Add assign
tiif May 2, 2024
6967d1c
Stabilize exclusive_range
RossSmyth Apr 28, 2024
57f00ce
Update clippy tests for stable exclusive_range
RossSmyth Apr 28, 2024
aeef180
Preparing for merge from rustc
May 3, 2024
3e2164f
Merge from rustc
May 3, 2024
b348e41
update comments and URL
RalfJung May 3, 2024
3c6d194
Auto merge of #3536 - tiif:add_rustbot_feat, r=RalfJung
bors May 3, 2024
4af1ba0
update lockfile
RalfJung May 3, 2024
5ce8532
Auto merge of #3537 - rust-lang:rustup-2024-05-03, r=RalfJung
bors May 3, 2024
fc218f2
Address review comments
Kobzol May 3, 2024
03589bf
run clippy on a Windows host
RalfJung May 3, 2024
8a31014
Auto merge of #3542 - RalfJung:clippy-win, r=RalfJung
bors May 3, 2024
0de07d8
Preparing for merge from rustc
RalfJung May 3, 2024
dcf956c
Auto merge of #3544 - RalfJung:rustup, r=RalfJung
bors May 3, 2024
eaf30ce
./miri run: support -v flag to print what it is doing
RalfJung May 3, 2024
692b769
Auto merge of #3545 - RalfJung:miri-run, r=RalfJung
bors May 3, 2024
aa71f9b
CI: no need to surround if: condition in expansion braces
RalfJung May 3, 2024
74701dc
Auto merge of #3547 - RalfJung:ci, r=RalfJung
bors May 3, 2024
6ce00aa
make many-seeds a mode of ./miri run rather than a separate command
RalfJung May 3, 2024
f7a3aa9
remove a hack that is no longer needed
RalfJung May 4, 2024
38715f7
Auto merge of #3548 - RalfJung:many-seeds, r=RalfJung
bors May 4, 2024
6559342
tls dtors: treat all unixes uniformly
RalfJung May 4, 2024
82456b4
Auto merge of #3550 - RalfJung:unix-tls, r=RalfJung
bors May 4, 2024
07a517a
macos: use getentropy from libc
RalfJung May 4, 2024
705d48c
Auto merge of #3551 - RalfJung:getentropy, r=RalfJung
bors May 4, 2024
459c6ce
Make file descriptors into refcount references
Luv-Ray May 4, 2024
d130eaa
speed up Windows runner: don't run GC_STRESS test
RalfJung May 4, 2024
502ed49
show time taken in run_tests_minimal
RalfJung May 4, 2024
7b57f12
Auto merge of #3533 - Luv-Ray:file-descriptors-to-refcount-references…
bors May 4, 2024
be874a4
move available-parallelism tests into shims/ folder
RalfJung May 4, 2024
57ff16b
rename integer test
RalfJung May 4, 2024
3046dbe
move intrinsics implementations and tests into dedicated folder
RalfJung May 4, 2024
a4355bb
fix grouping of target-specific LLVM shims
RalfJung May 4, 2024
52bf84f
move some minimal targets over to the macOS runner, to even out CI times
RalfJung May 4, 2024
9d4eea1
Auto merge of #3556 - RalfJung:intrinsics, r=RalfJung
bors May 4, 2024
49cd705
Auto merge of #3552 - RalfJung:ci, r=RalfJung
bors May 4, 2024
e1c3d67
Revert "moving out sched_getaffinity interception from linux'shim, Fr…
RalfJung May 4, 2024
8b4b259
update 'unsupported' message
RalfJung May 4, 2024
6df585a
freebsd: test std threadname and fs APIs
RalfJung May 4, 2024
38598e6
document unofficially supported OSes
RalfJung May 4, 2024
05e7850
make some tests not need output (so they work on wasm)
RalfJung May 4, 2024
fd15dc3
Auto merge of #3558 - RalfJung:unsupported, r=RalfJung
bors May 4, 2024
3a6faee
Auto merge of #3554 - RalfJung:freebsd, r=RalfJung
bors May 4, 2024
823e31d
add helper function to declare an extern static for a weak symbol
RalfJung May 4, 2024
19aa8a0
make statx a regular function (so we don't need to support the syscall)
RalfJung May 4, 2024
37537d1
Auto merge of #3559 - RalfJung:weak-extern-static, r=RalfJung
bors May 4, 2024
98bb8ac
sync: better error in invalid synchronization primitive ID
RalfJung May 4, 2024
86d7dff
factor some pthread offset into constants
RalfJung May 4, 2024
9503c41
also test pthread_condattr_getclock
RalfJung May 4, 2024
c3f2701
Auto merge of #3560 - RalfJung:sync-check-id, r=RalfJung
bors May 4, 2024
adb74ae
Preparing for merge from rustc
RalfJung May 4, 2024
0c98929
Merge from rustc
RalfJung May 4, 2024
c6e273c
bless and fmt
RalfJung May 4, 2024
a040df7
remove some dead code
RalfJung May 4, 2024
7eda989
Auto merge of #3557 - RalfJung:getaffinity, r=RalfJung
bors May 4, 2024
d0e7772
Auto merge of #3561 - RalfJung:rustup, r=RalfJung
bors May 4, 2024
43e6600
Implement lldb formattter for "clang encoded" enums (LLDB 18.1+)
Apr 23, 2024
cdf3f3c
only show the 'basic API common for this target' message when this is…
RalfJung May 4, 2024
82a8059
Auto merge of #3562 - RalfJung:unsupported, r=RalfJung
bors May 4, 2024
94f922a
Meta: Enable the triagebot transfer command
fmease May 4, 2024
89e8288
Preparing for merge from rustc
RalfJung May 4, 2024
8db37a3
Merge from rustc
RalfJung May 4, 2024
ef5a574
rustc_pull: explain order of operations
RalfJung May 4, 2024
85e061a
fix/extend some comments
RalfJung May 4, 2024
745e3f2
make ExitProcess Windows-only
RalfJung May 4, 2024
e3fe30d
Auto merge of #3563 - RalfJung:rustup, r=RalfJung
bors May 4, 2024
7ba8144
Implement `edition` method on `Rustdoc` type as well
GuillaumeGomez May 4, 2024
a64ba04
Migrate `run-make/doctests-runtool` to rmake
GuillaumeGomez May 4, 2024
b5051c5
update lockfile
RalfJung May 4, 2024
e30ad6f
Tgross feedback tweaks
ultrabear Apr 14, 2024
3ef2528
Make f16 and f128 docs clearer on platform support
ultrabear Apr 15, 2024
5aa2f9a
Make f128 docs mention lack of any normal platform support
ultrabear May 4, 2024
d9d6315
Auto merge of #124631 - Kobzol:arbitrary-try-build, r=pietroalbini
bors May 5, 2024
654afe3
Auto merge of #122253 - MasterAwesome:master, r=davidtwco
bors May 5, 2024
6e146c0
Auto merge of #124458 - VladimirMakaev:lldb-enum-formatter, r=Mark-Si…
bors May 5, 2024
8994315
Auto merge of #124459 - RossSmyth:stable_range, r=davidtwco
bors May 5, 2024
1867f48
Auto merge of #124494 - madsmtm:fix-32bit-watchos-unwind, r=Mark-Simu…
bors May 5, 2024
8b6f931
Auto merge of #124727 - RalfJung:miri-sync, r=RalfJung
bors May 5, 2024
3fbeedb
Auto merge of #123892 - ultrabear:ultrabear_softfloatdoc, r=workingju…
bors May 5, 2024
2e0982d
Auto merge of #124711 - GuillaumeGomez:migrate-doctests-runtool, r=ji…
bors May 5, 2024
69ffc0d
Auto merge of #124725 - fmease:enable-triagebot-transfer, r=jackh726
bors May 5, 2024
394f21c
CI: fix auto builds and make sure that we always have at least a sing…
Kobzol May 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make many-seeds a mode of ./miri run rather than a separate command
  • Loading branch information
RalfJung committed May 4, 2024
commit 6ce00aa99234c4771abb84ef9a1b46fc818a0d5f
13 changes: 6 additions & 7 deletions src/tools/miri/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ function run_tests {
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test -- tests/{pass,panic}
fi
if [ -n "${MANY_SEEDS-}" ]; then
# Also run some many-seeds tests. 64 seeds means this takes around a minute per test.
# (Need to invoke via explicit `bash -c` for Windows.)
# Also run some many-seeds tests.
time for FILE in tests/many-seeds/*.rs; do
MIRI_SEEDS=$MANY_SEEDS ./miri many-seeds "$BASH" -c "./miri run '$FILE'"
./miri run "--many-seeds=0..$MANY_SEEDS" "$FILE"
done
fi
if [ -n "${TEST_BENCH-}" ]; then
Expand Down Expand Up @@ -135,7 +134,7 @@ case $HOST_TARGET in
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
# Extra tier 1
# With reduced many-seed count to avoid spending too much time on that.
# (All OSes are run with 64 seeds at least once though via the macOS runner.)
# (All OSes and ABIs are run with 64 seeds at least once though via the macOS runner.)
MANY_SEEDS=16 MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
MANY_SEEDS=16 MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
MANY_SEEDS=16 MIRI_TEST_TARGET=x86_64-apple-darwin run_tests
Expand Down Expand Up @@ -164,9 +163,9 @@ case $HOST_TARGET in
;;
i686-pc-windows-msvc)
# Host
# Only smoke-test `many-seeds`; 64 runs of just the scoped-thread-leak test take 15min here!
# See <https://github.com/rust-lang/miri/issues/3509>.
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=1 TEST_BENCH=1 run_tests
# With reduced many-seeds count as this is the slowest runner already.
# (The macOS runner checks windows-msvc with full many-seeds count.)
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=16 TEST_BENCH=1 run_tests
# Extra tier 1
# We really want to ensure a Linux target works on a Windows host,
# and a 64bit target works on a 32bit host.
Expand Down
8 changes: 4 additions & 4 deletions src/tools/miri/miri-script/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,15 @@ checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6"

[[package]]
name = "xshell"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce2107fe03e558353b4c71ad7626d58ed82efaf56c54134228608893c77023ad"
checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437"
dependencies = [
"xshell-macros",
]

[[package]]
name = "xshell-macros"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e2c411759b501fb9501aac2b1b2d287a6e93e5bdcf13c25306b23e1b716dd0e"
checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852"
2 changes: 1 addition & 1 deletion src/tools/miri/miri-script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ itertools = "0.11"
path_macro = "1.0"
shell-words = "1.1"
anyhow = "1.0"
xshell = "0.2"
xshell = "0.2.6"
rustc_version = "0.4"
dunce = "1.0.4"
directories = "5"
96 changes: 42 additions & 54 deletions src/tools/miri/miri-script/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use std::ffi::OsString;
use std::io::Write;
use std::ops::Not;
use std::ops::Range;
use std::path::PathBuf;
use std::process;
use std::thread;
Expand Down Expand Up @@ -150,7 +151,6 @@ impl Command {
| Command::Fmt { .. }
| Command::Clippy { .. }
| Command::Cargo { .. } => Self::auto_actions()?,
| Command::ManySeeds { .. }
| Command::Toolchain { .. }
| Command::Bench { .. }
| Command::RustcPull { .. }
Expand All @@ -162,11 +162,11 @@ impl Command {
Command::Build { flags } => Self::build(flags),
Command::Check { flags } => Self::check(flags),
Command::Test { bless, flags } => Self::test(bless, flags),
Command::Run { dep, verbose, flags } => Self::run(dep, verbose, flags),
Command::Run { dep, verbose, many_seeds, flags } =>
Self::run(dep, verbose, many_seeds, flags),
Command::Fmt { flags } => Self::fmt(flags),
Command::Clippy { flags } => Self::clippy(flags),
Command::Cargo { flags } => Self::cargo(flags),
Command::ManySeeds { command } => Self::many_seeds(command),
Command::Bench { benches } => Self::bench(benches),
Command::Toolchain { flags } => Self::toolchain(flags),
Command::RustcPull { commit } => Self::rustc_pull(commit.clone()),
Expand Down Expand Up @@ -367,43 +367,6 @@ impl Command {
Ok(())
}

fn many_seeds(command: Vec<OsString>) -> Result<()> {
let seed_start: u64 = env::var("MIRI_SEED_START")
.unwrap_or_else(|_| "0".into())
.parse()
.context("failed to parse MIRI_SEED_START")?;
let seed_end: u64 = match (env::var("MIRI_SEEDS"), env::var("MIRI_SEED_END")) {
(Ok(_), Ok(_)) => bail!("Only one of MIRI_SEEDS and MIRI_SEED_END may be set"),
(Ok(seeds), Err(_)) =>
seed_start + seeds.parse::<u64>().context("failed to parse MIRI_SEEDS")?,
(Err(_), Ok(seed_end)) => seed_end.parse().context("failed to parse MIRI_SEED_END")?,
(Err(_), Err(_)) => seed_start + 256,
};
if seed_end <= seed_start {
bail!("the end of the seed range must be larger than the start.");
}

let Some((command_name, trailing_args)) = command.split_first() else {
bail!("expected many-seeds command to be non-empty");
};
let sh = Shell::new()?;
sh.set_var("MIRI_AUTO_OPS", "no"); // just in case we get recursively invoked
for seed in seed_start..seed_end {
println!("Trying seed: {seed}");
let mut miriflags = env::var_os("MIRIFLAGS").unwrap_or_default();
miriflags.push(format!(" -Zlayout-seed={seed} -Zmiri-seed={seed}"));
let status = cmd!(sh, "{command_name} {trailing_args...}")
.env("MIRIFLAGS", miriflags)
.quiet()
.run();
if let Err(err) = status {
println!("Failing seed: {seed}");
return Err(err.into());
}
}
Ok(())
}

fn bench(benches: Vec<OsString>) -> Result<()> {
// The hyperfine to use
let hyperfine = env::var("HYPERFINE");
Expand Down Expand Up @@ -495,7 +458,12 @@ impl Command {
Ok(())
}

fn run(dep: bool, verbose: bool, mut flags: Vec<OsString>) -> Result<()> {
fn run(
dep: bool,
verbose: bool,
many_seeds: Option<Range<u32>>,
mut flags: Vec<OsString>,
) -> Result<()> {
let mut e = MiriEnv::new()?;
// Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
// that we set the MIRI_SYSROOT up the right way. We must make sure that
Expand Down Expand Up @@ -526,26 +494,46 @@ impl Command {
flags.push("--sysroot".into());
flags.push(miri_sysroot.into());

// Then run the actual command. Also add MIRIFLAGS.
// Compute everything needed to run the actual command. Also add MIRIFLAGS.
let miri_manifest = path!(e.miri_dir / "Cargo.toml");
let miri_flags = e.sh.var("MIRIFLAGS").unwrap_or_default();
let miri_flags = flagsplit(&miri_flags);
let toolchain = &e.toolchain;
let extra_flags = &e.cargo_extra_flags;
let quiet_flag = if verbose { None } else { Some("--quiet") };
let mut cmd = if dep {
cmd!(
e.sh,
"cargo +{toolchain} {quiet_flag...} test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {flags...}"
)
} else {
cmd!(
e.sh,
"cargo +{toolchain} {quiet_flag...} run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {flags...}"
)
// This closure runs the command with the given `seed_flag` added between the MIRIFLAGS and
// the `flags` given on the command-line.
let run_miri = |sh: &Shell, seed_flag: Option<String>| -> Result<()> {
// The basic command that executes the Miri driver.
let mut cmd = if dep {
cmd!(
sh,
"cargo +{toolchain} {quiet_flag...} test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode"
)
} else {
cmd!(
sh,
"cargo +{toolchain} {quiet_flag...} run {extra_flags...} --manifest-path {miri_manifest} --"
)
};
cmd.set_quiet(!verbose);
// Add Miri flags
let cmd = cmd.args(&miri_flags).args(seed_flag).args(&flags);
// And run the thing.
Ok(cmd.run()?)
};
cmd.set_quiet(!verbose);
cmd.run()?;
// Run the closure once or many times.
if let Some(seed_range) = many_seeds {
e.run_many_times(seed_range, |sh, seed| {
eprintln!("Trying seed: {seed}");
run_miri(sh, Some(format!("-Zmiri-seed={seed}"))).map_err(|err| {
eprintln!("FAILING SEED: {seed}");
err
})
})?;
} else {
run_miri(&e.sh, None)?;
}
Ok(())
}

Expand Down
49 changes: 28 additions & 21 deletions src/tools/miri/miri-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
mod commands;
mod util;

use std::env;
use std::ffi::OsString;
use std::{env, ops::Range};

use anyhow::{anyhow, bail, Result};
use anyhow::{anyhow, bail, Context, Result};

#[derive(Clone, Debug)]
pub enum Command {
Expand Down Expand Up @@ -39,6 +39,7 @@ pub enum Command {
Run {
dep: bool,
verbose: bool,
many_seeds: Option<Range<u32>>,
/// Flags that are passed through to `miri`.
flags: Vec<OsString>,
},
Expand All @@ -55,10 +56,6 @@ pub enum Command {
/// Runs just `cargo <flags>` with the Miri-specific environment variables.
/// Mainly meant to be invoked by rust-analyzer.
Cargo { flags: Vec<OsString> },
/// Runs <command> over and over again with different seeds for Miri. The MIRIFLAGS
/// variable is set to its original value appended with ` -Zmiri-seed=$SEED` for
/// many different seeds.
ManySeeds { command: Vec<OsString> },
/// Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
Bench {
/// List of benchmarks to run. By default all benchmarks are run.
Expand Down Expand Up @@ -91,9 +88,11 @@ Just check miri. <flags> are passed to `cargo check`.
Build miri, set up a sysroot and then run the test suite. <flags> are passed
to the final `cargo test` invocation.

./miri run [--dep] [-v|--verbose] <flags>:
./miri run [--dep] [-v|--verbose] [--many-seeds|--many-seeds=..to|--many-seeds=from..to] <flags>:
Build miri, set up a sysroot and then run the driver with the given <flags>.
(Also respects MIRIFLAGS environment variable.)
If `--many-seeds` is present, Miri is run many times in parallel with different seeds.
The range defaults to `0..256`.

./miri fmt <flags>:
Format all sources and tests. <flags> are passed to `rustfmt`.
Expand All @@ -111,13 +110,6 @@ install`. Sets up the rpath such that the installed binary should work in any
working directory. Note that the binaries are placed in the `miri` toolchain
sysroot, to prevent conflicts with other toolchains.

./miri many-seeds <command>:
Runs <command> over and over again with different seeds for Miri. The MIRIFLAGS
variable is set to its original value appended with ` -Zmiri-seed=$SEED` for
many different seeds. MIRI_SEED_START controls the first seed to try (default: 0).
MIRI_SEEDS controls how many seeds are being tried (default: 256);
alternatively, MIRI_SEED_END controls the end of the (exclusive) seed range to try.

./miri bench <benches>:
Runs the benchmarks from bench-cargo-miri in hyperfine. hyperfine needs to be installed.
<benches> can explicitly list the benchmarks to run; by default, all of them are run.
Expand Down Expand Up @@ -165,22 +157,37 @@ fn main() -> Result<()> {
Some("run") => {
let mut dep = false;
let mut verbose = false;
while let Some(arg) = args.peek().and_then(|a| a.to_str()) {
match arg {
"--dep" => dep = true,
"-v" | "--verbose" => verbose = true,
_ => break, // not for us
let mut many_seeds = None;
while let Some(arg) = args.peek().and_then(|s| s.to_str()) {
if arg == "--dep" {
dep = true;
} else if arg == "-v" || arg == "--verbose" {
verbose = true;
} else if arg == "--many-seeds" {
many_seeds = Some(0..256);
} else if let Some(val) = arg.strip_prefix("--many-seeds=") {
let (from, to) = val.split_once("..").ok_or_else(|| {
anyhow!("invalid format for `--many-seeds`: expected `from..to`")
})?;
let from: u32 = if from.is_empty() {
0
} else {
from.parse().context("invalid `from` in `--many-seeds=from..to")?
};
let to: u32 = to.parse().context("invalid `to` in `--many-seeds=from..to")?;
many_seeds = Some(from..to);
} else {
break; // not for us
}
// Consume the flag, look at the next one.
args.next().unwrap();
}
Command::Run { dep, verbose, flags: args.collect() }
Command::Run { dep, verbose, many_seeds, flags: args.collect() }
}
Some("fmt") => Command::Fmt { flags: args.collect() },
Some("clippy") => Command::Clippy { flags: args.collect() },
Some("cargo") => Command::Cargo { flags: args.collect() },
Some("install") => Command::Install { flags: args.collect() },
Some("many-seeds") => Command::ManySeeds { command: args.collect() },
Some("bench") => Command::Bench { benches: args.collect() },
Some("toolchain") => Command::Toolchain { flags: args.collect() },
Some("rustc-pull") => {
Expand Down
53 changes: 53 additions & 0 deletions src/tools/miri/miri-script/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::ffi::{OsStr, OsString};
use std::ops::Range;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::thread;

use anyhow::{anyhow, Context, Result};
use dunce::canonicalize;
Expand Down Expand Up @@ -189,4 +192,54 @@ impl MiriEnv {

Ok(())
}

/// Run the given closure many times in parallel with access to the shell, once for each value in the `range`.
pub fn run_many_times(
&self,
range: Range<u32>,
run: impl Fn(&Shell, u32) -> Result<()> + Sync,
) -> Result<()> {
// `next` is atomic so threads can concurrently fetch their next value to run.
let next = AtomicU32::new(range.start);
let end = range.end; // exclusive!
let failed = AtomicBool::new(false);
thread::scope(|s| {
let mut handles = Vec::new();
// Spawn one worker per core.
for _ in 0..thread::available_parallelism()?.get() {
// Create a copy of the shell for this thread.
let local_shell = self.sh.clone();
let handle = s.spawn(|| -> Result<()> {
let local_shell = local_shell; // move the copy into this thread.
// Each worker thread keeps asking for numbers until we're all done.
loop {
let cur = next.fetch_add(1, Ordering::Relaxed);
if cur >= end {
// We hit the upper limit and are done.
break;
}
// Run the command with this seed.
run(&local_shell, cur).map_err(|err| {
// If we failed, tell everyone about this.
failed.store(true, Ordering::Relaxed);
err
})?;
// Check if some other command failed (in which case we'll stop as well).
if failed.load(Ordering::Relaxed) {
return Ok(());
}
}
Ok(())
});
handles.push(handle);
}
// Wait for all workers to be done.
for handle in handles {
handle.join().unwrap()?;
}
// If all workers succeeded, we can't have failed.
assert!(!failed.load(Ordering::Relaxed));
Ok(())
})
}
}