Skip to content

Commit d04b972

Browse files
committed
remove --many-seeds from ./miri run
1 parent 0bd76e1 commit d04b972

File tree

4 files changed

+30
-120
lines changed

4 files changed

+30
-120
lines changed

src/tools/miri/ci/ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ function run_tests {
6666
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test $TARGET_FLAG tests/{pass,panic}
6767
fi
6868
if [ -n "${MANY_SEEDS-}" ]; then
69-
# Also run some many-seeds tests. (Also tests `./miri run`.)
69+
# Run many-seeds tests. (Also tests `./miri run`.)
7070
time for FILE in tests/many-seeds/*.rs; do
71-
./miri run "--many-seeds=0..$MANY_SEEDS" $TARGET_FLAG "$FILE"
71+
./miri run "-Zmiri-many-seeds=0..$MANY_SEEDS" $TARGET_FLAG "$FILE"
7272
done
7373
fi
7474
if [ -n "${TEST_BENCH-}" ]; then

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

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22
use std::ffi::{OsStr, OsString};
33
use std::fs::File;
44
use std::io::{BufReader, BufWriter, Write};
5-
use std::ops::{Not, Range};
5+
use std::ops::Not;
66
use std::path::PathBuf;
77
use std::time::Duration;
88
use std::{env, net, process};
@@ -178,8 +178,8 @@ impl Command {
178178
Command::Check { flags } => Self::check(flags),
179179
Command::Test { bless, flags, target, coverage } =>
180180
Self::test(bless, flags, target, coverage),
181-
Command::Run { dep, verbose, many_seeds, target, edition, flags } =>
182-
Self::run(dep, verbose, many_seeds, target, edition, flags),
181+
Command::Run { dep, verbose, target, edition, flags } =>
182+
Self::run(dep, verbose, target, edition, flags),
183183
Command::Doc { flags } => Self::doc(flags),
184184
Command::Fmt { flags } => Self::fmt(flags),
185185
Command::Clippy { flags } => Self::clippy(flags),
@@ -586,7 +586,6 @@ impl Command {
586586
fn run(
587587
dep: bool,
588588
verbose: bool,
589-
many_seeds: Option<Range<u32>>,
590589
target: Option<String>,
591590
edition: Option<String>,
592591
flags: Vec<String>,
@@ -614,48 +613,34 @@ impl Command {
614613
early_flags.push("--sysroot".into());
615614
early_flags.push(miri_sysroot.into());
616615

617-
// Compute everything needed to run the actual command. Also add MIRIFLAGS.
616+
// Compute flags.
618617
let miri_flags = e.sh.var("MIRIFLAGS").unwrap_or_default();
619618
let miri_flags = flagsplit(&miri_flags);
620619
let quiet_flag = if verbose { None } else { Some("--quiet") };
621-
// This closure runs the command with the given `seed_flag` added between the MIRIFLAGS and
622-
// the `flags` given on the command-line.
623-
let run_miri = |e: &MiriEnv, seed_flag: Option<String>| -> Result<()> {
624-
// The basic command that executes the Miri driver.
625-
let mut cmd = if dep {
626-
// We invoke the test suite as that has all the logic for running with dependencies.
627-
e.cargo_cmd(".", "test")
628-
.args(&["--test", "ui"])
629-
.args(quiet_flag)
630-
.arg("--")
631-
.args(&["--miri-run-dep-mode"])
632-
} else {
633-
cmd!(e.sh, "{miri_bin}")
634-
};
635-
cmd.set_quiet(!verbose);
636-
// Add Miri flags
637-
let mut cmd = cmd.args(&miri_flags).args(&seed_flag).args(&early_flags).args(&flags);
638-
// For `--dep` we also need to set the target in the env var.
639-
if dep {
640-
if let Some(target) = &target {
641-
cmd = cmd.env("MIRI_TEST_TARGET", target);
642-
}
643-
}
644-
// And run the thing.
645-
Ok(cmd.run()?)
646-
};
647-
// Run the closure once or many times.
648-
if let Some(seed_range) = many_seeds {
649-
e.run_many_times(seed_range, |e, seed| {
650-
eprintln!("Trying seed: {seed}");
651-
run_miri(e, Some(format!("-Zmiri-seed={seed}"))).inspect_err(|_| {
652-
eprintln!("FAILING SEED: {seed}");
653-
})
654-
})?;
620+
621+
// Run Miri.
622+
// The basic command that executes the Miri driver.
623+
let mut cmd = if dep {
624+
// We invoke the test suite as that has all the logic for running with dependencies.
625+
e.cargo_cmd(".", "test")
626+
.args(&["--test", "ui"])
627+
.args(quiet_flag)
628+
.arg("--")
629+
.args(&["--miri-run-dep-mode"])
655630
} else {
656-
run_miri(&e, None)?;
631+
cmd!(e.sh, "{miri_bin}")
632+
};
633+
cmd.set_quiet(!verbose);
634+
// Add Miri flags
635+
let mut cmd = cmd.args(&miri_flags).args(&early_flags).args(&flags);
636+
// For `--dep` we also need to set the target in the env var.
637+
if dep {
638+
if let Some(target) = &target {
639+
cmd = cmd.env("MIRI_TEST_TARGET", target);
640+
}
657641
}
658-
Ok(())
642+
// Finally, run the thing.
643+
Ok(cmd.run()?)
659644
}
660645

661646
fn fmt(flags: Vec<String>) -> Result<()> {

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,9 @@ mod commands;
44
mod coverage;
55
mod util;
66

7-
use std::ops::Range;
8-
9-
use anyhow::{Context, Result, anyhow, bail};
7+
use anyhow::{Result, bail};
108
use clap::{Parser, Subcommand};
119

12-
/// Parses a seed range
13-
///
14-
/// This function is used for the `--many-seeds` flag. It expects the range in the form
15-
/// `<from>..<to>`. `<from>` is inclusive, `<to>` is exclusive. `<from>` can be omitted,
16-
/// in which case it is assumed to be `0`.
17-
fn parse_range(val: &str) -> anyhow::Result<Range<u32>> {
18-
let (from, to) = val
19-
.split_once("..")
20-
.ok_or_else(|| anyhow!("invalid format for `--many-seeds`: expected `from..to`"))?;
21-
let from: u32 = if from.is_empty() {
22-
0
23-
} else {
24-
from.parse().context("invalid `from` in `--many-seeds=from..to")?
25-
};
26-
let to: u32 = to.parse().context("invalid `to` in `--many-seeds=from..to")?;
27-
Ok(from..to)
28-
}
29-
3010
#[derive(Clone, Debug, Subcommand)]
3111
pub enum Command {
3212
/// Installs the miri driver and cargo-miri to the sysroot of the active toolchain.
@@ -81,9 +61,6 @@ pub enum Command {
8161
/// Show build progress.
8262
#[arg(long, short)]
8363
verbose: bool,
84-
/// Run the driver with the seeds in the given range (`..to` or `from..to`, default: `0..64`).
85-
#[arg(long, value_parser = parse_range)]
86-
many_seeds: Option<Range<u32>>,
8764
/// The cross-interpretation target.
8865
#[arg(long)]
8966
target: Option<String>,

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

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::ffi::{OsStr, OsString};
22
use std::io::BufRead;
3-
use std::ops::Range;
43
use std::path::{Path, PathBuf};
5-
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
6-
use std::{env, iter, thread};
4+
use std::{env, iter};
75

86
use anyhow::{Context, Result, anyhow, bail};
97
use dunce::canonicalize;
@@ -29,7 +27,6 @@ pub fn flagsplit(flags: &str) -> Vec<String> {
2927
}
3028

3129
/// Some extra state we track for building Miri, such as the right RUSTFLAGS.
32-
#[derive(Clone)]
3330
pub struct MiriEnv {
3431
/// miri_dir is the root of the miri repository checkout we are working in.
3532
pub miri_dir: PathBuf,
@@ -240,53 +237,4 @@ impl MiriEnv {
240237

241238
Ok(())
242239
}
243-
244-
/// Run the given closure many times in parallel with access to the shell, once for each value in the `range`.
245-
pub fn run_many_times(
246-
&self,
247-
range: Range<u32>,
248-
run: impl Fn(&Self, u32) -> Result<()> + Sync,
249-
) -> Result<()> {
250-
// `next` is atomic so threads can concurrently fetch their next value to run.
251-
let next = AtomicU32::new(range.start);
252-
let end = range.end; // exclusive!
253-
let failed = AtomicBool::new(false);
254-
thread::scope(|s| {
255-
let mut handles = Vec::new();
256-
// Spawn one worker per core.
257-
for _ in 0..thread::available_parallelism()?.get() {
258-
// Create a copy of the environment for this thread.
259-
let local_miri = self.clone();
260-
let handle = s.spawn(|| -> Result<()> {
261-
let local_miri = local_miri; // move the copy into this thread.
262-
// Each worker thread keeps asking for numbers until we're all done.
263-
loop {
264-
let cur = next.fetch_add(1, Ordering::Relaxed);
265-
if cur >= end {
266-
// We hit the upper limit and are done.
267-
break;
268-
}
269-
// Run the command with this seed.
270-
run(&local_miri, cur).inspect_err(|_| {
271-
// If we failed, tell everyone about this.
272-
failed.store(true, Ordering::Relaxed);
273-
})?;
274-
// Check if some other command failed (in which case we'll stop as well).
275-
if failed.load(Ordering::Relaxed) {
276-
return Ok(());
277-
}
278-
}
279-
Ok(())
280-
});
281-
handles.push(handle);
282-
}
283-
// Wait for all workers to be done.
284-
for handle in handles {
285-
handle.join().unwrap()?;
286-
}
287-
// If all workers succeeded, we can't have failed.
288-
assert!(!failed.load(Ordering::Relaxed));
289-
Ok(())
290-
})
291-
}
292240
}

0 commit comments

Comments
 (0)