@@ -805,6 +805,7 @@ macro_rules! options {
805
805
pub const parse_list: Option <& str > = Some ( "a space-separated list of strings" ) ;
806
806
pub const parse_opt_list: Option <& str > = Some ( "a space-separated list of strings" ) ;
807
807
pub const parse_opt_comma_list: Option <& str > = Some ( "a comma-separated list of strings" ) ;
808
+ pub const parse_threads: Option <& str > = Some ( "a number" ) ;
808
809
pub const parse_uint: Option <& str > = Some ( "a number" ) ;
809
810
pub const parse_passes: Option <& str > =
810
811
Some ( "a space-separated list of passes, or `all`" ) ;
@@ -948,6 +949,14 @@ macro_rules! options {
948
949
}
949
950
}
950
951
952
+ fn parse_threads( slot: & mut usize , v: Option <& str >) -> bool {
953
+ match v. and_then( |s| s. parse( ) . ok( ) ) {
954
+ Some ( 0 ) => { * slot = :: num_cpus:: get( ) ; true } ,
955
+ Some ( i) => { * slot = i; true } ,
956
+ None => false
957
+ }
958
+ }
959
+
951
960
fn parse_uint( slot: & mut usize , v: Option <& str >) -> bool {
952
961
match v. and_then( |s| s. parse( ) . ok( ) ) {
953
962
Some ( i) => { * slot = i; true } ,
@@ -1251,7 +1260,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
1251
1260
"prints the LLVM optimization passes being run" ) ,
1252
1261
ast_json: bool = ( false , parse_bool, [ UNTRACKED ] ,
1253
1262
"print the AST as JSON and halt" ) ,
1254
- threads: Option <usize > = ( None , parse_opt_uint, [ UNTRACKED ] ,
1263
+ // We default to 1 here since we want to behave like
1264
+ // a sequential compiler for now. This'll likely be adjusted
1265
+ // in the future. Note that -Zthreads=0 is the way to get
1266
+ // the num_cpus behavior.
1267
+ threads: usize = ( 1 , parse_threads, [ UNTRACKED ] ,
1255
1268
"use a thread pool with N threads" ) ,
1256
1269
ast_json_noexpand: bool = ( false , parse_bool, [ UNTRACKED ] ,
1257
1270
"print the pre-expansion AST as JSON and halt" ) ,
@@ -2146,14 +2159,14 @@ pub fn build_session_options_and_crate_config(
2146
2159
}
2147
2160
}
2148
2161
2149
- if debugging_opts. threads == Some ( 0 ) {
2162
+ if debugging_opts. threads == 0 {
2150
2163
early_error (
2151
2164
error_format,
2152
2165
"value for threads must be a positive non-zero integer" ,
2153
2166
) ;
2154
2167
}
2155
2168
2156
- if debugging_opts. threads . unwrap_or ( 1 ) > 1 && debugging_opts. fuel . is_some ( ) {
2169
+ if debugging_opts. threads > 1 && debugging_opts. fuel . is_some ( ) {
2157
2170
early_error (
2158
2171
error_format,
2159
2172
"optimization fuel is incompatible with multiple threads" ,
0 commit comments