@@ -2,6 +2,7 @@ use std::env;
2
2
use std:: ffi:: OsString ;
3
3
use std:: io:: Write ;
4
4
use std:: ops:: Not ;
5
+ use std:: ops:: Range ;
5
6
use std:: path:: PathBuf ;
6
7
use std:: process;
7
8
use std:: thread;
@@ -150,7 +151,6 @@ impl Command {
150
151
| Command :: Fmt { .. }
151
152
| Command :: Clippy { .. }
152
153
| Command :: Cargo { .. } => Self :: auto_actions ( ) ?,
153
- | Command :: ManySeeds { .. }
154
154
| Command :: Toolchain { .. }
155
155
| Command :: Bench { .. }
156
156
| Command :: RustcPull { .. }
@@ -162,11 +162,11 @@ impl Command {
162
162
Command :: Build { flags } => Self :: build ( flags) ,
163
163
Command :: Check { flags } => Self :: check ( flags) ,
164
164
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) ,
166
167
Command :: Fmt { flags } => Self :: fmt ( flags) ,
167
168
Command :: Clippy { flags } => Self :: clippy ( flags) ,
168
169
Command :: Cargo { flags } => Self :: cargo ( flags) ,
169
- Command :: ManySeeds { command } => Self :: many_seeds ( command) ,
170
170
Command :: Bench { benches } => Self :: bench ( benches) ,
171
171
Command :: Toolchain { flags } => Self :: toolchain ( flags) ,
172
172
Command :: RustcPull { commit } => Self :: rustc_pull ( commit. clone ( ) ) ,
@@ -367,43 +367,6 @@ impl Command {
367
367
Ok ( ( ) )
368
368
}
369
369
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
-
407
370
fn bench ( benches : Vec < OsString > ) -> Result < ( ) > {
408
371
// The hyperfine to use
409
372
let hyperfine = env:: var ( "HYPERFINE" ) ;
@@ -495,7 +458,12 @@ impl Command {
495
458
Ok ( ( ) )
496
459
}
497
460
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 < ( ) > {
499
467
let mut e = MiriEnv :: new ( ) ?;
500
468
// Scan for "--target" to overwrite the "MIRI_TEST_TARGET" env var so
501
469
// that we set the MIRI_SYSROOT up the right way. We must make sure that
@@ -526,26 +494,46 @@ impl Command {
526
494
flags. push ( "--sysroot" . into ( ) ) ;
527
495
flags. push ( miri_sysroot. into ( ) ) ;
528
496
529
- // Then run the actual command. Also add MIRIFLAGS.
497
+ // Compute everything needed to run the actual command. Also add MIRIFLAGS.
530
498
let miri_manifest = path ! ( e. miri_dir / "Cargo.toml" ) ;
531
499
let miri_flags = e. sh . var ( "MIRIFLAGS" ) . unwrap_or_default ( ) ;
532
500
let miri_flags = flagsplit ( & miri_flags) ;
533
501
let toolchain = & e. toolchain ;
534
502
let extra_flags = & e. cargo_extra_flags ;
535
503
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 ( ) ?)
546
524
} ;
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
+ }
549
537
Ok ( ( ) )
550
538
}
551
539
0 commit comments