Skip to content

Commit 92d06b4

Browse files
committed
Fix compiler panic with a large number of threads
1 parent 16422db commit 92d06b4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: compiler/rustc_session/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24642464
early_dcx.early_fatal("value for threads must be a positive non-zero integer");
24652465
}
24662466

2467+
if unstable_opts.threads == parse::MAX_THREADS_CAP {
2468+
early_dcx.early_warn(format!("number of threads was capped at {}", parse::MAX_THREADS_CAP));
2469+
}
2470+
24672471
let fuel = unstable_opts.fuel.is_some() || unstable_opts.print_fuel.is_some();
24682472
if fuel && unstable_opts.threads > 1 {
24692473
early_dcx.early_fatal("optimization fuel is incompatible with multiple threads");

Diff for: compiler/rustc_session/src/options.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,11 @@ mod desc {
457457
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
458458
}
459459

460-
mod parse {
460+
pub mod parse {
461461
use std::str::FromStr;
462462

463463
pub(crate) use super::*;
464+
pub(crate) const MAX_THREADS_CAP: usize = 256;
464465

465466
/// This is for boolean options that don't take a value and start with
466467
/// `no-`. This style of option is deprecated.
@@ -663,7 +664,9 @@ mod parse {
663664
true
664665
}
665666
Some(i) => {
666-
*slot = i;
667+
// We want to cap the number of threads here to avoid large numbers like 999999 and compiler panics.
668+
// This solution was suggested here https://github.com/rust-lang/rust/issues/117638#issuecomment-1800925067
669+
*slot = i.min(MAX_THREADS_CAP);
667670
true
668671
}
669672
None => false,

0 commit comments

Comments
 (0)