@@ -307,6 +307,15 @@ fn parse_comma_list<T: FromStr>(input: &str) -> Result<Vec<T>, T::Err> {
307
307
input. split ( ',' ) . map ( str:: parse :: < T > ) . collect ( )
308
308
}
309
309
310
+ /// Parses the input as a float in the range from 0.0 to 1.0 (inclusive).
311
+ fn parse_rate ( input : & str ) -> Result < f64 , & ' static str > {
312
+ match input. parse :: < f64 > ( ) {
313
+ Ok ( rate) if rate >= 0.0 && rate <= 1.0 => Ok ( rate) ,
314
+ Ok ( _) => Err ( "must be between `0.0` and `1.0`" ) ,
315
+ Err ( _) => Err ( "requires a `f64` between `0.0` and `1.0`" ) ,
316
+ }
317
+ }
318
+
310
319
#[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
311
320
fn jemalloc_magic ( ) {
312
321
// These magic runes are copied from
@@ -499,14 +508,9 @@ fn main() {
499
508
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-env-forward=" ) {
500
509
miri_config. forwarded_env_vars . push ( param. to_owned ( ) ) ;
501
510
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-track-pointer-tag=" ) {
502
- let ids: Vec < u64 > = match parse_comma_list ( param) {
503
- Ok ( ids) => ids,
504
- Err ( err) =>
505
- show_error ! (
506
- "-Zmiri-track-pointer-tag requires a comma separated list of valid `u64` arguments: {}" ,
507
- err
508
- ) ,
509
- } ;
511
+ let ids: Vec < u64 > = parse_comma_list ( param) . unwrap_or_else ( |err| {
512
+ show_error ! ( "-Zmiri-track-pointer-tag requires a comma separated list of valid `u64` arguments: {err}" )
513
+ } ) ;
510
514
for id in ids. into_iter ( ) . map ( miri:: BorTag :: new) {
511
515
if let Some ( id) = id {
512
516
miri_config. tracked_pointer_tags . insert ( id) ;
@@ -515,14 +519,9 @@ fn main() {
515
519
}
516
520
}
517
521
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-track-call-id=" ) {
518
- let ids: Vec < u64 > = match parse_comma_list ( param) {
519
- Ok ( ids) => ids,
520
- Err ( err) =>
521
- show_error ! (
522
- "-Zmiri-track-call-id requires a comma separated list of valid `u64` arguments: {}" ,
523
- err
524
- ) ,
525
- } ;
522
+ let ids: Vec < u64 > = parse_comma_list ( param) . unwrap_or_else ( |err| {
523
+ show_error ! ( "-Zmiri-track-call-id requires a comma separated list of valid `u64` arguments: {err}" )
524
+ } ) ;
526
525
for id in ids. into_iter ( ) . map ( miri:: CallId :: new) {
527
526
if let Some ( id) = id {
528
527
miri_config. tracked_call_ids . insert ( id) ;
@@ -531,70 +530,37 @@ fn main() {
531
530
}
532
531
}
533
532
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-track-alloc-id=" ) {
534
- let ids: Vec < miri:: AllocId > = match parse_comma_list :: < NonZero < u64 > > ( param) {
535
- Ok ( ids) => ids. into_iter ( ) . map ( miri:: AllocId ) . collect ( ) ,
536
- Err ( err) =>
537
- show_error ! (
538
- "-Zmiri-track-alloc-id requires a comma separated list of valid non-zero `u64` arguments: {}" ,
539
- err
540
- ) ,
541
- } ;
542
- miri_config. tracked_alloc_ids . extend ( ids) ;
533
+ let ids = parse_comma_list :: < NonZero < u64 > > ( param) . unwrap_or_else ( |err| {
534
+ show_error ! ( "-Zmiri-track-alloc-id requires a comma separated list of valid non-zero `u64` arguments: {err}" )
535
+ } ) ;
536
+ miri_config. tracked_alloc_ids . extend ( ids. into_iter ( ) . map ( miri:: AllocId ) ) ;
543
537
} else if arg == "-Zmiri-track-alloc-accesses" {
544
538
miri_config. track_alloc_accesses = true ;
545
539
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-address-reuse-rate=" ) {
546
- let rate = match param. parse :: < f64 > ( ) {
547
- Ok ( rate) if rate >= 0.0 && rate <= 1.0 => rate,
548
- Ok ( _) =>
549
- show_error ! (
550
- "-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`"
551
- ) ,
552
- Err ( err) =>
553
- show_error ! (
554
- "-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}" ,
555
- err
556
- ) ,
557
- } ;
558
- miri_config. address_reuse_rate = rate;
540
+ miri_config. address_reuse_rate = parse_rate ( param)
541
+ . unwrap_or_else ( |err| show_error ! ( "-Zmiri-address-reuse-rate {err}" ) ) ;
542
+ } else if let Some ( param) = arg. strip_prefix ( "-Zmiri-address-reuse-cross-thread-rate=" ) {
543
+ miri_config. address_reuse_cross_thread_rate = parse_rate ( param)
544
+ . unwrap_or_else ( |err| show_error ! ( "-Zmiri-address-reuse-cross-thread-rate {err}" ) ) ;
559
545
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-compare-exchange-weak-failure-rate=" ) {
560
- let rate = match param. parse :: < f64 > ( ) {
561
- Ok ( rate) if rate >= 0.0 && rate <= 1.0 => rate,
562
- Ok ( _) =>
563
- show_error ! (
564
- "-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`"
565
- ) ,
566
- Err ( err) =>
567
- show_error ! (
568
- "-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}" ,
569
- err
570
- ) ,
571
- } ;
572
- miri_config. cmpxchg_weak_failure_rate = rate;
546
+ miri_config. cmpxchg_weak_failure_rate = parse_rate ( param) . unwrap_or_else ( |err| {
547
+ show_error ! ( "-Zmiri-compare-exchange-weak-failure-rate {err}" )
548
+ } ) ;
573
549
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-preemption-rate=" ) {
574
- let rate = match param. parse :: < f64 > ( ) {
575
- Ok ( rate) if rate >= 0.0 && rate <= 1.0 => rate,
576
- Ok ( _) => show_error ! ( "-Zmiri-preemption-rate must be between `0.0` and `1.0`" ) ,
577
- Err ( err) =>
578
- show_error ! (
579
- "-Zmiri-preemption-rate requires a `f64` between `0.0` and `1.0`: {}" ,
580
- err
581
- ) ,
582
- } ;
583
- miri_config. preemption_rate = rate;
550
+ miri_config. preemption_rate =
551
+ parse_rate ( param) . unwrap_or_else ( |err| show_error ! ( "-Zmiri-preemption-rate {err}" ) ) ;
584
552
} else if arg == "-Zmiri-report-progress" {
585
553
// This makes it take a few seconds between progress reports on my laptop.
586
554
miri_config. report_progress = Some ( 1_000_000 ) ;
587
555
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-report-progress=" ) {
588
- let interval = match param. parse :: < u32 > ( ) {
589
- Ok ( i) => i,
590
- Err ( err) => show_error ! ( "-Zmiri-report-progress requires a `u32`: {}" , err) ,
591
- } ;
556
+ let interval = param. parse :: < u32 > ( ) . unwrap_or_else ( |err| {
557
+ show_error ! ( "-Zmiri-report-progress requires a `u32`: {}" , err)
558
+ } ) ;
592
559
miri_config. report_progress = Some ( interval) ;
593
560
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-provenance-gc=" ) {
594
- let interval = match param. parse :: < u32 > ( ) {
595
- Ok ( i) => i,
596
- Err ( err) => show_error ! ( "-Zmiri-provenance-gc requires a `u32`: {}" , err) ,
597
- } ;
561
+ let interval = param. parse :: < u32 > ( ) . unwrap_or_else ( |err| {
562
+ show_error ! ( "-Zmiri-provenance-gc requires a `u32`: {}" , err)
563
+ } ) ;
598
564
miri_config. gc_interval = interval;
599
565
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-measureme=" ) {
600
566
miri_config. measureme_out = Some ( param. to_string ( ) ) ;
@@ -619,23 +585,20 @@ fn main() {
619
585
show_error ! ( "-Zmiri-extern-so-file `{}` does not exist" , filename) ;
620
586
}
621
587
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-num-cpus=" ) {
622
- let num_cpus = match param. parse :: < u32 > ( ) {
623
- Ok ( i) => i,
624
- Err ( err) => show_error ! ( "-Zmiri-num-cpus requires a `u32`: {}" , err) ,
625
- } ;
626
-
588
+ let num_cpus = param
589
+ . parse :: < u32 > ( )
590
+ . unwrap_or_else ( |err| show_error ! ( "-Zmiri-num-cpus requires a `u32`: {}" , err) ) ;
627
591
miri_config. num_cpus = num_cpus;
628
592
} else if let Some ( param) = arg. strip_prefix ( "-Zmiri-force-page-size=" ) {
629
- let page_size = match param. parse :: < u64 > ( ) {
630
- Ok ( i ) =>
631
- if i . is_power_of_two ( ) {
632
- i * 1024
633
- } else {
634
- show_error ! ( "-Zmiri-force-page-size requires a power of 2: {}" , i )
635
- } ,
636
- Err ( err ) => show_error ! ( "-Zmiri-force-page-size requires a `u64` : {}" , err ) ,
593
+ let page_size = param. parse :: < u64 > ( ) . unwrap_or_else ( |err| {
594
+ show_error ! ( "-Zmiri-force-page-size requires a `u64`: {}" , err )
595
+ } ) ;
596
+ // Convert from kilobytes to bytes.
597
+ let page_size = if page_size . is_power_of_two ( ) {
598
+ page_size * 1024
599
+ } else {
600
+ show_error ! ( "-Zmiri-force-page-size requires a power of 2 : {page_size}" ) ;
637
601
} ;
638
-
639
602
miri_config. page_size = Some ( page_size) ;
640
603
} else {
641
604
// Forward to rustc.
0 commit comments