@@ -759,7 +759,7 @@ mod desc {
759759 pub ( crate ) const parse_number: & str = "a number" ;
760760 pub ( crate ) const parse_opt_number: & str = parse_number;
761761 pub ( crate ) const parse_frame_pointer: & str = "one of `true`/`yes`/`on`, `false`/`no`/`off`, or (with -Zunstable-options) `non-leaf` or `always`" ;
762- pub ( crate ) const parse_threads: & str = parse_number ;
762+ pub ( crate ) const parse_threads: & str = "a number or `sync`" ;
763763 pub ( crate ) const parse_time_passes_format: & str = "`text` (default) or `json`" ;
764764 pub ( crate ) const parse_passes: & str = "a space-separated list of passes, or `all`" ;
765765 pub ( crate ) const parse_panic_strategy: & str = "either `unwind`, `abort`, or `immediate-abort`" ;
@@ -1067,22 +1067,23 @@ pub mod parse {
10671067 }
10681068 }
10691069
1070- pub ( crate ) fn parse_threads ( slot : & mut usize , v : Option < & str > ) -> bool {
1071- let ret = match v . and_then ( |s| s . parse ( ) . ok ( ) ) {
1072- Some ( 0 ) => {
1073- * slot = std :: thread:: available_parallelism ( ) . map_or ( 1 , NonZero :: < usize > :: get ) ;
1074- true
1075- }
1076- Some ( i ) => {
1077- * slot = i ;
1078- true
1079- }
1080- None => false ,
1070+ pub ( crate ) fn parse_threads ( slot : & mut Option < usize > , v : Option < & str > ) -> bool {
1071+ let Some ( s ) = v else { return false } ;
1072+ if s == "sync" {
1073+ // Enable synchronization despite only using one thread.
1074+ * slot = Some ( 1 ) ;
1075+ return true ;
1076+ }
1077+ let n = match s . parse ( ) . ok ( ) {
1078+ Some ( 0 ) => std :: thread :: available_parallelism ( ) . map_or ( 1 , NonZero :: < usize > :: get ) ,
1079+ Some ( i ) => i ,
1080+ None => return false ,
10811081 } ;
10821082 // We want to cap the number of threads here to avoid large numbers like 999999 and compiler panics.
10831083 // This solution was suggested here https://github.com/rust-lang/rust/issues/117638#issuecomment-1800925067
1084- * slot = slot. clone ( ) . min ( MAX_THREADS_CAP ) ;
1085- ret
1084+ let n = n. min ( MAX_THREADS_CAP ) ;
1085+ * slot = ( n > 1 ) . then_some ( n) ; // Enable synchronization if we're using more than one thread.
1086+ true
10861087 }
10871088
10881089 /// Use this for any numeric option that has a static default.
@@ -2670,12 +2671,12 @@ written to standard error output)"),
26702671 #[ rustc_lint_opt_deny_field_access( "use `Session::lto` instead of this field" ) ]
26712672 thinlto: Option <bool > = ( None , parse_opt_bool, [ TRACKED ] ,
26722673 "enable ThinLTO when possible" ) ,
2673- /// We default to 1 here since we want to behave like
2674+ /// We default to None here since we want to behave like
26742675 /// a sequential compiler for now. This'll likely be adjusted
26752676 /// in the future. Note that -Zthreads=0 is the way to get
26762677 /// the num_cpus behavior.
26772678 #[ rustc_lint_opt_deny_field_access( "use `Session::threads` instead of this field" ) ]
2678- threads: usize = ( 1 , parse_threads, [ UNTRACKED ] ,
2679+ threads: Option < usize > = ( None , parse_threads, [ UNTRACKED ] ,
26792680 "use a thread pool with N threads" ) ,
26802681 time_llvm_passes: bool = ( false , parse_bool, [ UNTRACKED ] ,
26812682 "measure time of each LLVM pass (default: no)" ) ,
0 commit comments