Skip to content

rustc: Support --jobs options for limiting parallelism in various parts of the compiler - #159675

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
petrochenkov:jjj
Jul 31, 2026
Merged

rustc: Support --jobs options for limiting parallelism in various parts of the compiler#159675
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
petrochenkov:jjj

Conversation

@petrochenkov

@petrochenkov petrochenkov commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

View all comments

--jobs-frontend for the frontend, --jobs-backend for the backend, --jobs-linker for the linker, and -j/--jobs for the overall limit.
See the added docs for more details.
Part of rust-lang/compiler-team#1005.

Any suspicious option combinations are prohibited for now.
r? @bjorn3 @Zoxc

@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 21, 2026
Comment thread compiler/rustc_session/src/config.rs Outdated
/// `None` means everything is single-threaded and synchronization can be disabled.
#[derive(Clone, Copy)]
pub struct Jobs {
pub frontend: Option<NonZero<u8>>,

@petrochenkov petrochenkov Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub frontend: Option<NonZero<u8>>,
pub frontend: Option<NonZero<usize>>,

Probably can convert to usize after the range validation in parse_jobs_one is done, all the places that want this value accept usize.

View changes since the review

@petrochenkov petrochenkov Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usize is used here now.

Comment thread compiler/rustc_session/src/config.rs Outdated
check_upper_limit(backend, opt_name);
if zno_parallel_backend {
early_dcx
.early_fatal("cannot use both `--jobs-backend` and `-Zno-parallel-backend`");

@petrochenkov petrochenkov Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove -Zno-parallel-backend right away in this PR for simplicity, I don't expect it to be used as much as -Zthreads.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Zno-parallel-backend is removed now (or rather always reports an error saying to use --jobs-backend=1).

compiler.arg(input_file);

// Use a single thread for efficiency and a deterministic error message order
compiler.arg("-Zthreads=1");

@petrochenkov petrochenkov Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already the default, so it's not necessary (and it caused some option conflicts).

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't the default when setting the rust.parallel-frontend-threads bootstrap config to a different value, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any logic turning bootstrap's rust.parallel-frontend-threads into -Zthreads for tests.

Compiletest's own --parallel-frontend-threads flag adds -Zthreads to UI tests, but it's not enabled by default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like one of the CI jobs does pass that flag:

--parallel-frontend-threads="${PARALLEL_FRONTEND_THREADS}" \
This is an optional CI job, so if you break it, the merge would still work. Still it would be best to not break it unnecessarily.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to things like this I'll probably have to change the --jobs options from Opt to Multi right away.

-Zthreads=1 -Zthreads=2 works right now, but --jobs 1 --jobs 2 does not, as currently implemented.
Cargo also prohibits it - error: the argument '--jobs <N>' cannot be used multiple times, so I initially wanted to reproduce this more conservative behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an optional CI job, so if you break it, the merge would still work.

FWIW, making it non-optional is my next immediate task.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added //@ ignore-parallel-frontend to a couple of tests causing option conflicts, test runs with --parallel-frontend-threads pass now.

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_session/src/config.rs Outdated
true => None,
false => match jobs {
Some(n) => n,
None => NonZero::new(32), // back compat with historical behavior

@bjorn3 bjorn3 Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there was any cap when using a jobserver previously. The 32 tokens default is when there is no jobserver. And in any case I don't think the "The fixed number is used to have deterministic compilation across machines." comment is actually correct. Changing the max number of parallel threads doesn't affect determinism of the output at all. Only the amount of codegen units.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there was any cap when using a jobserver previously.

Yes, if there's an external jobserver, then there's no static limit on main, only the dynamic limit from that jobserver.
But in that case --jobs-backend is not currently respected anyway (see the FIXME in write.rs).
I can keep the default "unlimited" behavior when addressing the FIXME (in a separate later PR).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in any case I don't think the "The fixed number is used to have deterministic compilation across machines." comment is actually correct.

Yeah, that comment is removed now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a variant to preserve the historical behavior precisely, even when the FIXME in write.rs is addressed.

Opt,
"",
"jobs-backend",
"Limit on the number of parallel jobs used by backend",

@bjorn3 bjorn3 Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be respected when a jobserver exists?

View changes since the review

@petrochenkov petrochenkov Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, eventually (right now there's a FIXME about it in write.rs).
jobs_backend is the static upper limit, and the jobserver can limit work further within the 1 ..= jobs_backend range.

Comment thread compiler/rustc_session/src/config.rs
Comment thread src/doc/rustc/src/command-line-arguments.md
@Zoxc

Zoxc commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Why is -Zthreads kept given that --jobs-frontend seems to be a replacement?

I don't like the --jobs-frontend naming as the thread pool it limits is not intended nor is it actually limited to the frontend. A more accurate name would be a query system thread pool though it isn't strictly limited to that either, but it has to accommodate threads potentially blocking on queries which is notable.

@petrochenkov

petrochenkov commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Why is -Zthreads kept given that --jobs-frontend seems to be a replacement?

I expect a large number of users of -Zthreads, so it makes sense to migrate more gradually and support the old name for some time.

I don't like the --jobs-frontend naming as the thread pool it limits is not intended nor is it actually limited to the frontend. A more accurate name would be a query system thread pool though it isn't strictly limited to that either, but it has to accommodate threads potentially blocking on queries which is notable.

Better naming suggestions are welcome.
The last notable work in the "frontend" pool (besides the "main thread", which also belongs to the pool) is a part of codegen (MIR -> LLVM IR lowering) in fn codegen_crate, after that the pool still exists, but is not really used for parallel work.
(That's what I tried to document in src/doc/rustc/src/command-line-arguments.md.)

@rustbot

rustbot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

rustc-dev-guide is developed in its own repository. If possible, consider making this change to rust-lang/rustc-dev-guide instead.

cc @BoxyUwU, @tshepang

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Jul 23, 2026
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@petrochenkov

Copy link
Copy Markdown
Contributor Author

All the comments are addressed.
@rustbot ready

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment thread tests/ui/compile-flags/jobs/jobs-fail-gate.rs
Comment thread compiler/rustc_codegen_ssa/src/back/link.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/back/link.rs Outdated
@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread compiler/rustc_codegen_ssa/src/back/link.rs Outdated
@bjorn3

bjorn3 commented Jul 31, 2026

Copy link
Copy Markdown
Member

Implementation looks fine. And based on the MCP being accepted, I'm going to assume the CLI is fine too. Can still be adjusted before stabilization if necessary.

@bors r+

@rust-bors

rust-bors Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2b4375d has been approved by bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 31, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 31, 2026
rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler

`--jobs-frontend` for the frontend, `--jobs-backend` for the backend, `--jobs-linker` for the linker, and `-j`/`--jobs` for the overall limit.
See the added docs for more details.
Part of rust-lang/compiler-team#1005.

Any suspicious option combinations are prohibited for now.
r? @bjorn3 @Zoxc
rust-bors Bot pushed a commit that referenced this pull request Jul 31, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #160100 (Add "system" option to `override-allocator` directive)
 - #159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler)
 - #159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends)
 - #160233 (Bubble bad path error while parsing field to avoid unecessary second error)
 - #160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`)
 - #154202 (rustfmt: Format `cfg_select!`)
 - #158835 (rustc_passes: lint unused `#[path]` attributes on inline modules)
 - #159520 (Suggest `Vec<T>` instead of `[T]`)
 - #160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser)
 - #160066 (rustc_middle: lint attribute cleanups)
 - #160085 (Remove various superfluous lint attributes)
 - #160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters)
 - #160119 (fix query cycle in `coroutine_hidden_types` for the next solver)
 - #160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`)
 - #160157 (Remove outdated comments from `va_list.rs`)
 - #160159 (More accurately check for interior mutability in `invalid_reference_casting` lint)
 - #160208 (rustdoc: Fix crash when trying to list attributes on an opaque type)
 - #160244 (Rename splat to rustc_splat in error messages)
 - #160246 (dont fire `unused_mut` on `&pin mut self`)
 - #160247 (Configure backport nominations for rustfmt)
 - #160274 (renovate: update lock files weekly)
rust-bors Bot pushed a commit that referenced this pull request Jul 31, 2026
…uwer

Rollup of 22 pull requests

Successful merges:

 - #160100 (Add "system" option to `override-allocator` directive)
 - #160220 (Refactor: shrink region ext traits)
 - #159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler)
 - #159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends)
 - #160233 (Bubble bad path error while parsing field to avoid unecessary second error)
 - #160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`)
 - #154202 (rustfmt: Format `cfg_select!`)
 - #159520 (Suggest `Vec<T>` instead of `[T]`)
 - #159710 (Add rustdoc/cargo PGO profiles to reproducible artifacts)
 - #160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser)
 - #160066 (rustc_middle: lint attribute cleanups)
 - #160085 (Remove various superfluous lint attributes)
 - #160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters)
 - #160119 (fix query cycle in `coroutine_hidden_types` for the next solver)
 - #160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`)
 - #160157 (Remove outdated comments from `va_list.rs`)
 - #160159 (More accurately check for interior mutability in `invalid_reference_casting` lint)
 - #160208 (rustdoc: Fix crash when trying to list attributes on an opaque type)
 - #160244 (Rename splat to rustc_splat in error messages)
 - #160246 (dont fire `unused_mut` on `&pin mut self`)
 - #160247 (Configure backport nominations for rustfmt)
 - #160274 (renovate: update lock files weekly)
@rust-bors
rust-bors Bot merged commit 2eb8d70 into rust-lang:main Jul 31, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 31, 2026
rust-timer added a commit that referenced this pull request Jul 31, 2026
Rollup merge of #159675 - petrochenkov:jjj, r=bjorn3

rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler

`--jobs-frontend` for the frontend, `--jobs-backend` for the backend, `--jobs-linker` for the linker, and `-j`/`--jobs` for the overall limit.
See the added docs for more details.
Part of rust-lang/compiler-team#1005.

Any suspicious option combinations are prohibited for now.
r? @bjorn3 @Zoxc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants