@@ -2,6 +2,7 @@ use std::env;
22use std:: ffi:: OsString ;
33use std:: io:: Write ;
44use std:: ops:: Not ;
5+ use std:: ops:: Range ;
56use std:: path:: PathBuf ;
67use std:: process;
78use std:: thread;
@@ -150,7 +151,6 @@ impl Command {
150151 | Command :: Fmt { .. }
151152 | Command :: Clippy { .. }
152153 | Command :: Cargo { .. } => Self :: auto_actions ( ) ?,
153- | Command :: ManySeeds { .. }
154154 | Command :: Toolchain { .. }
155155 | Command :: Bench { .. }
156156 | Command :: RustcPull { .. }
@@ -162,11 +162,11 @@ impl Command {
162162 Command :: Build { flags } => Self :: build ( flags) ,
163163 Command :: Check { flags } => Self :: check ( flags) ,
164164 Command :: Test { bless, flags } => Self :: test ( bless, flags) ,
165- Command :: Run { dep, verbose, flags } => Self :: run ( dep, verbose, flags) ,
165+ Command :: Run { dep, verbose, many_seeds, flags } =>
166+ Self :: run ( dep, verbose, many_seeds, flags) ,
166167 Command :: Fmt { flags } => Self :: fmt ( flags) ,
167168 Command :: Clippy { flags } => Self :: clippy ( flags) ,
168169 Command :: Cargo { flags } => Self :: cargo ( flags) ,
169- Command :: ManySeeds { command } => Self :: many_seeds ( command) ,
170170 Command :: Bench { benches } => Self :: bench ( benches) ,
171171 Command :: Toolchain { flags } => Self :: toolchain ( flags) ,
172172 Command :: RustcPull { commit } => Self :: rustc_pull ( commit. clone ( ) ) ,
@@ -367,43 +367,6 @@ impl Command {
367367 Ok ( ( ) )
368368 }
369369
370- fn many_seeds ( command : Vec < OsString > ) -> Result < ( ) > {
371- let seed_start: u64 = env:: var ( "MIRI_SEED_START" )
372- . unwrap_or_else ( |_| "0" . into ( ) )
373- . parse ( )
374- . context ( "failed to parse MIRI_SEED_START" ) ?;
375- let seed_end: u64 = match ( env:: var ( "MIRI_SEEDS" ) , env:: var ( "MIRI_SEED_END" ) ) {
376- ( Ok ( _) , Ok ( _) ) => bail ! ( "Only one of MIRI_SEEDS and MIRI_SEED_END may be set" ) ,
377- ( Ok ( seeds) , Err ( _) ) =>
378- seed_start + seeds. parse :: < u64 > ( ) . context ( "failed to parse MIRI_SEEDS" ) ?,
379- ( Err ( _) , Ok ( seed_end) ) => seed_end. parse ( ) . context ( "failed to parse MIRI_SEED_END" ) ?,
380- ( Err ( _) , Err ( _) ) => seed_start + 256 ,
381- } ;
382- if seed_end <= seed_start {
383- bail ! ( "the end of the seed range must be larger than the start." ) ;
384- }
385-
386- let Some ( ( command_name, trailing_args) ) = command. split_first ( ) else {
387- bail ! ( "expected many-seeds command to be non-empty" ) ;
388- } ;
389- let sh = Shell :: new ( ) ?;
390- sh. set_var ( "MIRI_AUTO_OPS" , "no" ) ; // just in case we get recursively invoked
391- for seed in seed_start..seed_end {
392- println ! ( "Trying seed: {seed}" ) ;
393- let mut miriflags = env:: var_os ( "MIRIFLAGS" ) . unwrap_or_default ( ) ;
394- miriflags. push ( format ! ( " -Zlayout-seed={seed} -Zmiri-seed={seed}" ) ) ;
395- let status = cmd ! ( sh, "{command_name} {trailing_args...}" )
396- . env ( "MIRIFLAGS" , miriflags)
397- . quiet ( )
398- . run ( ) ;
399- if let Err ( err) = status {
400- println ! ( "Failing seed: {seed}" ) ;
401- return Err ( err. into ( ) ) ;
402- }
403- }
404- Ok ( ( ) )
405- }
406-
407370 fn bench ( benches : Vec < OsString > ) -> Result < ( ) > {
408371 // The hyperfine to use
409372 let hyperfine = env:: var ( "HYPERFINE" ) ;
@@ -495,7 +458,12 @@ impl Command {
495458 Ok ( ( ) )
496459 }
497460
498- fn run ( dep : bool , verbose : bool , mut flags : Vec < OsString > ) -> Result < ( ) > {
461+ fn run (
462+ dep : bool ,
463+ verbose : bool ,
464+ many_seeds : Option < Range < u32 > > ,
465+ mut flags : Vec < OsString > ,
466+ ) -> Result < ( ) > {
499467 let mut e = MiriEnv :: new ( ) ?;
500468 // Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
501469 // that we set the MIRI_SYSROOT up the right way. We must make sure that
@@ -526,26 +494,46 @@ impl Command {
526494 flags. push ( "--sysroot" . into ( ) ) ;
527495 flags. push ( miri_sysroot. into ( ) ) ;
528496
529- // Then run the actual command. Also add MIRIFLAGS.
497+ // Compute everything needed to run the actual command. Also add MIRIFLAGS.
530498 let miri_manifest = path ! ( e. miri_dir / "Cargo.toml" ) ;
531499 let miri_flags = e. sh . var ( "MIRIFLAGS" ) . unwrap_or_default ( ) ;
532500 let miri_flags = flagsplit ( & miri_flags) ;
533501 let toolchain = & e. toolchain ;
534502 let extra_flags = & e. cargo_extra_flags ;
535503 let quiet_flag = if verbose { None } else { Some ( "--quiet" ) } ;
536- let mut cmd = if dep {
537- cmd ! (
538- e. sh,
539- "cargo +{toolchain} {quiet_flag...} test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode {miri_flags...} {flags...}"
540- )
541- } else {
542- cmd ! (
543- e. sh,
544- "cargo +{toolchain} {quiet_flag...} run {extra_flags...} --manifest-path {miri_manifest} -- {miri_flags...} {flags...}"
545- )
504+ // This closure runs the command with the given `seed_flag` added between the MIRIFLAGS and
505+ // the `flags` given on the command-line.
506+ let run_miri = |sh : & Shell , seed_flag : Option < String > | -> Result < ( ) > {
507+ // The basic command that executes the Miri driver.
508+ let mut cmd = if dep {
509+ cmd ! (
510+ sh,
511+ "cargo +{toolchain} {quiet_flag...} test {extra_flags...} --manifest-path {miri_manifest} --test ui -- --miri-run-dep-mode"
512+ )
513+ } else {
514+ cmd ! (
515+ sh,
516+ "cargo +{toolchain} {quiet_flag...} run {extra_flags...} --manifest-path {miri_manifest} --"
517+ )
518+ } ;
519+ cmd. set_quiet ( !verbose) ;
520+ // Add Miri flags
521+ let cmd = cmd. args ( & miri_flags) . args ( seed_flag) . args ( & flags) ;
522+ // And run the thing.
523+ Ok ( cmd. run ( ) ?)
546524 } ;
547- cmd. set_quiet ( !verbose) ;
548- cmd. run ( ) ?;
525+ // Run the closure once or many times.
526+ if let Some ( seed_range) = many_seeds {
527+ e. run_many_times ( seed_range, |sh, seed| {
528+ eprintln ! ( "Trying seed: {seed}" ) ;
529+ run_miri ( sh, Some ( format ! ( "-Zmiri-seed={seed}" ) ) ) . map_err ( |err| {
530+ eprintln ! ( "FAILING SEED: {seed}" ) ;
531+ err
532+ } )
533+ } ) ?;
534+ } else {
535+ run_miri ( & e. sh , None ) ?;
536+ }
549537 Ok ( ( ) )
550538 }
551539
0 commit comments