Skip to content

DepKind cleanups - #160406

Open
nnethercote wants to merge 3 commits into
rust-lang:mainfrom
nnethercote:DepKind-cleanups
Open

DepKind cleanups#160406
nnethercote wants to merge 3 commits into
rust-lang:mainfrom
nnethercote:DepKind-cleanups

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

Details in individual commits.

r? Zalathar

This commit changes `DEP_KIND_NUM_VARIANTS` so it's an associated const
(renamed as `DepKind::NUM_VARIANTS`) obtained via
`std::mem::variant_count`, removing the paranoid consecutiveness check.
The commit also replaces multiple `DepKind::MAX as usize + 1`
occurrences with `DepKind::NUM_VARIANTS`.
It contains pre-stringified versions of all the `DepKind` variants. But
we can just stringify on demand using `format!("{:?}")`.
@rustbot rustbot added 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 Aug 2, 2026
@rustbot

rustbot commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Zalathar is not on the review rotation at the moment.
They may take a while to respond.

/// pack information into the unused bits. u16 matches the `repr(u16)` on `DepKind`.
pub(crate) const MAX: u16 = {
let max = Self::NUM_VARIANTS - 1;
assert!(max < u16::MAX as usize);

@cjgillot cjgillot Aug 3, 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.

Why do we bother asserting? If the subtraction underflows, the constant won't compile, will it?

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.

NUM_VARIANTS is a usize. The intent here isn't to detect underflow, but to ensure there aren't more than 64K variants.

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.

And while the variant count is presumably capped by #[repr(u16)] on the enum, this assertion has the benefit of making max as u16 obviously correct.

Comment thread compiler/rustc_middle/src/dep_graph/dep_node.rs Outdated
@Zalathar

Zalathar commented Aug 3, 2026

Copy link
Copy Markdown
Member

Looks good, thanks.

r=me when PR CI is green.

@Zalathar

Zalathar commented Aug 3, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a707cbf has been approved by Zalathar

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@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 Aug 3, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 3, 2026
…lathar

`DepKind` cleanups

Details in individual commits.

r? Zalathar
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 3, 2026
…lathar

`DepKind` cleanups

Details in individual commits.

r? Zalathar
rust-bors Bot pushed a commit that referenced this pull request Aug 3, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #159844 (Subtree cg_gcc sync (2026-07-24))
 - #160406 (`DepKind` cleanups)
 - #159303 (Fix ICE for direct inline const generic defaults)
 - #160314 (fix borrowck ICE for consts with fn pointer type)
 - #160322 (ElaborateBoxDeref: remove unnecessary projection)
 - #160384 (Add PR body notes for Cargo lock file maintenance)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 3, 2026
…lathar

`DepKind` cleanups

Details in individual commits.

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

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

4 participants