Skip to content

Commit 77732bc

Browse files
authored
Unrolled build for #160424
Rollup merge of #160424 - petrochenkov:jobdflt, r=bjorn3 Use `thread::available_parallelism` as the default limit for backend parallelism Instead of the old scheme with 32-or-unlimited, depending on inherited-ness of the jobserver. Not sure if this needs some wider discussion or not. In the most common case (rustc is called from cargo) nothing changes, because cargo already limits the parallelism to `thread::available_parallelism` by default, and passes this limit to rustc through jobserver. #160387 will become simpler if this PR is merged first. r? @bjorn3 @Zoxc
2 parents c9ff496 + 496056f commit 77732bc

2 files changed

Lines changed: 7 additions & 28 deletions

File tree

compiler/rustc_interface/src/interface.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_parse::lexer::StripTokens;
1515
use rustc_parse::new_parser_from_source_str;
1616
use rustc_parse::parser::Recovery;
1717
use rustc_query_impl::print_query_stack;
18-
use rustc_session::config::{self, BackendJobs, Cfg, CheckCfg, ExpectedValues, Input, OutFileName};
18+
use rustc_session::config::{self, Cfg, CheckCfg, ExpectedValues, Input, OutFileName};
1919
use rustc_session::parse::ParseSess;
2020
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, lint};
2121
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMapInputs};
@@ -375,9 +375,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
375375

376376
// Initialize jobserver as early as possible.
377377
let early_dcx = EarlyDiagCtxt::new(config.opts.error_format);
378-
if let Some(limit) =
379-
config.opts.jobs.frontend.max(config.opts.jobs.backend.map(BackendJobs::value))
380-
{
378+
if let Some(limit) = config.opts.jobs.frontend.max(config.opts.jobs.backend) {
381379
jobserver::initialize(limit.get(), |err| {
382380
let note = "the build environment is likely misconfigured";
383381
early_dcx.early_struct_warn(err).with_note(note).emit()

compiler/rustc_session/src/config.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,26 +1649,6 @@ impl PointerAuthOption {
16491649
}
16501650
}
16511651

1652-
#[derive(Clone, Copy)]
1653-
pub enum BackendJobs {
1654-
/// The number of backend jobs has a static limit.
1655-
Limited(NonZero<usize>),
1656-
/// The number of backend jobs is either unlimited if there's an inherited jobserver,
1657-
/// or limited to 32 if there's no inherited jobserver.
1658-
/// This variant exists only to preserve the historical behavior.
1659-
/// FIXME: Just use `thread::available_parallelism` as the default static limit.
1660-
UnlimitedOr32,
1661-
}
1662-
1663-
impl BackendJobs {
1664-
pub fn value(self) -> NonZero<usize> {
1665-
match self {
1666-
BackendJobs::Limited(n) => n,
1667-
BackendJobs::UnlimitedOr32 => NonZero::new(32).unwrap(),
1668-
}
1669-
}
1670-
}
1671-
16721652
#[derive(Clone, Copy)]
16731653
pub enum LinkerJobs {
16741654
/// Do not pass anything to the linker, use it's default behavior.
@@ -1682,7 +1662,7 @@ pub enum LinkerJobs {
16821662
#[derive(Clone, Copy)]
16831663
pub struct Jobs {
16841664
pub frontend: Option<NonZero<usize>>,
1685-
pub backend: Option<BackendJobs>,
1665+
pub backend: Option<NonZero<usize>>,
16861666
pub linker: LinkerJobs,
16871667
}
16881668

@@ -1735,11 +1715,12 @@ fn parse_jobs_all(
17351715
let backend =
17361716
parse_jobs_one(early_dcx, opt_name, &jobs_backend, unstable, &mut available);
17371717
check_upper_limit(backend, opt_name);
1738-
backend.map(BackendJobs::Limited)
1718+
backend
17391719
}
17401720
None => match jobs {
1741-
Some(n) => n.map(BackendJobs::Limited),
1742-
None => Some(BackendJobs::UnlimitedOr32),
1721+
Some(n) => n,
1722+
// Use all available parallelism as the default.
1723+
None => parse_jobs_one(early_dcx, "", "0", unstable, &mut available),
17431724
},
17441725
};
17451726
let linker = match matches.opt_str("jobs-linker") {

0 commit comments

Comments
 (0)