Skip to content

Use newtype enums for representing frontend and backend jobs - #163452

Open
Kobzol wants to merge 1 commit into
rust-lang:mainfrom
Kobzol:frontend-jobs-refactor
Open

Kobzol wants to merge 1 commit into
rust-lang:mainfrom
Kobzol:frontend-jobs-refactor

Conversation

@Kobzol

@Kobzol Kobzol commented Sep 28, 2026

Copy link
Copy Markdown
Member

I found the Option<NonZero<usize>> representation quite confusing. This PR replaces it with strongly typed enums, which helps with creating specialized methods (is_synchronized), and documenting what do the individual variants mean, rather than just working with Some/None and calling is_some().

Otherwise, the behavior should be unchanged.

I think that the MaybeParallel variant could also be named Synchronized, but there is no perfect solution here to really express what it means.

r? petrochenkov

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 28, 2026

/// Return the number of threads that we are using for the frontend.
/// Returns `None` if synchronization is not required.
pub fn parallel_thread_count(&self) -> Option<NonZero<usize>> {

@petrochenkov petrochenkov Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So much boilerplate and we still convert the "newtypes" back to an option in most places.
This is exactly what I wanted to avoid originally.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The actual representation is an Option<NonZero<usize>>, but I think that there is benefit to wrapping it, so that we make it easier to understand how exactly it behaves.

What about a compromise:

struct FrontendJobs(Option<NonZero<usize>>);

This allows us to document the behavior + add methods to the type to reduce confusion of how it behaves, vs just using is_none().

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

3 participants