Skip to content

Avoid Hash::hash when stable-hashing various types - #165578

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
Zalathar:hash
Nov 12, 2026
Merged

rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
Zalathar:hash

Conversation

@Zalathar

@Zalathar Zalathar commented Nov 7, 2026

Copy link
Copy Markdown
Member

This PR makes StableHash independent of stdlib-dependent Hash impls for several types, to avoid potential inconsistency in stable hashing between stage1 and stage2 compilers.

This covers all of the StableHash impls that I'm aware of. However, there are still various other places in the compiler where we rely on Hash::hash for hashes that probably should be made consistent between compiler stages.

@rustbot

rustbot commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Nov 7, 2026
@rustbot

rustbot commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

r? @adwinwhite

rustbot has assigned @adwinwhite.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, incremental
  • compiler, incremental expanded to 79 candidates
  • Random selection from 22 candidates

@Zalathar

Zalathar commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Neutral perf run from the previous incarnation of this PR: #165218 (comment)

(Earlier drafts had perf impact due to Span changes, which were extracted to #165381.)

@adwinwhite

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 11, 2026
Avoid `Hash::hash` when stable-hashing various types
@rust-bors

This comment has been minimized.

@adwinwhite adwinwhite left a comment •

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.

Looks good!
r=me after perf

View changes since this review

Comment thread compiler/rustc_index/src/bit_set.rs Resolved
@adwinwhite

Copy link
Copy Markdown
Contributor

Sorry, missed your comment on perf.
@bors try cancel

@rust-bors

rust-bors Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

Hint: if you want to run another try build, you do not need to manually cancel the previous one. Just run @bors try and bors will cancel the previous build automatically.

LangItem might eventually be the type that forces us to support
`#[derive(StableHash)]` for enums with more than 256 variants.
This commit also removes `#[derive(Hash)]` from the affected types, since it is
no longer used.

If these types need a plain Hash impl is needed in the future, it could
potentially share the `stable_hash_inner` implementation.
By moving away from the old `impl_stable_traits_for_trivial_type!` macro, this
commit has the side-effect of removing unused StableOrd impls for some types.
Those impls could potentially be re-added if they are ever needed.
@rustbot

rustbot commented Nov 11, 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.

@Zalathar

Copy link
Copy Markdown
Member Author

Since I rebased and made some minor tweaks, might as well another perf run just to double-check.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 11, 2026
Avoid `Hash::hash` when stable-hashing various types
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 5154534 (5154534cf59c84b3794cf557591bdb5035004dcd)
Base parent: 9c56488 (9c5648833e5ceb667a708d53c00b83ecc9e610d5)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5154534): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

Results (secondary 1.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.4% [1.4%, 1.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 482.775s -> 481.658s (-0.23%)
Artifact size: 406.47 MiB -> 407.16 MiB (0.17%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 11, 2026
@adwinwhite

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b864cd3 has been approved by adwinwhite

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 Nov 12, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 12, 2026
Avoid `Hash::hash` when stable-hashing various types

This PR makes StableHash independent of stdlib-dependent Hash impls for several types, to avoid potential inconsistency in stable hashing between stage1 and stage2 compilers.

This covers all of the StableHash impls that I'm aware of. However, there are still various other places in the compiler where we rely on `Hash::hash` for hashes that probably should be made consistent between compiler stages.
rust-bors Bot pushed a commit that referenced this pull request Nov 12, 2026
Rollup of 6 pull requests

Successful merges:

 - #165778 (Bump stage0 to 1.101.0-beta.1)
 - #163077 (feat: support nested functions with `#[offload_kernel]`)
 - #165578 (Avoid `Hash::hash` when stable-hashing various types)
 - #165729 (tests: Add regression test for infinite recursive dereference)
 - #165819 (Avoid redundant scans when extracting stage0 archives)
 - #165822 (Remove unused compiler modules and types)
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 12, 2026
Avoid `Hash::hash` when stable-hashing various types

This PR makes StableHash independent of stdlib-dependent Hash impls for several types, to avoid potential inconsistency in stable hashing between stage1 and stage2 compilers.

This covers all of the StableHash impls that I'm aware of. However, there are still various other places in the compiler where we rely on `Hash::hash` for hashes that probably should be made consistent between compiler stages.
rust-bors Bot pushed a commit that referenced this pull request Nov 12, 2026
Rollup of 12 pull requests

Successful merges:

 - #165804 (cg_llvm: Use an invariant lifetime brand for LLVM values)
 - #165778 (Bump stage0 to 1.101.0-beta.1)
 - #165412 (Implement `core::ops::FnAddr`)
 - #165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - #165818 (do not lint `redundant_lifetimes` on items from external macros)
 - #163077 (feat: support nested functions with `#[offload_kernel]`)
 - #164795 (Extend support of lint `explicit_outlives_requirements` to checked type aliases)
 - #165578 (Avoid `Hash::hash` when stable-hashing various types)
 - #165729 (tests: Add regression test for infinite recursive dereference)
 - #165819 (Avoid redundant scans when extracting stage0 archives)
 - #165822 (Remove unused compiler modules and types)
 - #165824 (Add regression test for HRTB projection bound with TryFrom error)
rust-bors Bot pushed a commit that referenced this pull request Nov 12, 2026
Rollup of 11 pull requests

Successful merges:

 - #165804 (cg_llvm: Use an invariant lifetime brand for LLVM values)
 - #165778 (Bump stage0 to 1.101.0-beta.1)
 - #165412 (Implement `core::ops::FnAddr`)
 - #165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - #165818 (do not lint `redundant_lifetimes` on items from external macros)
 - #163077 (feat: support nested functions with `#[offload_kernel]`)
 - #164795 (Extend support of lint `explicit_outlives_requirements` to checked type aliases)
 - #165578 (Avoid `Hash::hash` when stable-hashing various types)
 - #165729 (tests: Add regression test for infinite recursive dereference)
 - #165822 (Remove unused compiler modules and types)
 - #165824 (Add regression test for HRTB projection bound with TryFrom error)
@rust-bors
rust-bors Bot merged commit 0400592 into rust-lang:main Nov 12, 2026
15 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 12, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 12, 2026
Rollup merge of #165578 - Zalathar:hash, r=adwinwhite

Avoid `Hash::hash` when stable-hashing various types

This PR makes StableHash independent of stdlib-dependent Hash impls for several types, to avoid potential inconsistency in stable hashing between stage1 and stage2 compilers.

This covers all of the StableHash impls that I'm aware of. However, there are still various other places in the compiler where we rely on `Hash::hash` for hashes that probably should be made consistent between compiler stages.
@Zalathar
Zalathar deleted the hash branch November 12, 2026 08:20
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Nov 13, 2026
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#165804 (cg_llvm: Use an invariant lifetime brand for LLVM values)
 - rust-lang/rust#165778 (Bump stage0 to 1.101.0-beta.1)
 - rust-lang/rust#165412 (Implement `core::ops::FnAddr`)
 - rust-lang/rust#165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - rust-lang/rust#165818 (do not lint `redundant_lifetimes` on items from external macros)
 - rust-lang/rust#163077 (feat: support nested functions with `#[offload_kernel]`)
 - rust-lang/rust#164795 (Extend support of lint `explicit_outlives_requirements` to checked type aliases)
 - rust-lang/rust#165578 (Avoid `Hash::hash` when stable-hashing various types)
 - rust-lang/rust#165729 (tests: Add regression test for infinite recursive dereference)
 - rust-lang/rust#165822 (Remove unused compiler modules and types)
 - rust-lang/rust#165824 (Add regression test for HRTB projection bound with TryFrom error)
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 13, 2026
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#165804 (cg_llvm: Use an invariant lifetime brand for LLVM values)
 - rust-lang/rust#165778 (Bump stage0 to 1.101.0-beta.1)
 - rust-lang/rust#165412 (Implement `core::ops::FnAddr`)
 - rust-lang/rust#165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - rust-lang/rust#165818 (do not lint `redundant_lifetimes` on items from external macros)
 - rust-lang/rust#163077 (feat: support nested functions with `#[offload_kernel]`)
 - rust-lang/rust#164795 (Extend support of lint `explicit_outlives_requirements` to checked type aliases)
 - rust-lang/rust#165578 (Avoid `Hash::hash` when stable-hashing various types)
 - rust-lang/rust#165729 (tests: Add regression test for infinite recursive dereference)
 - rust-lang/rust#165822 (Remove unused compiler modules and types)
 - rust-lang/rust#165824 (Add regression test for HRTB projection bound with TryFrom error)
folkertdev pushed a commit to folkertdev/stdarch that referenced this pull request Nov 16, 2026
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#165804 (cg_llvm: Use an invariant lifetime brand for LLVM values)
 - rust-lang/rust#165778 (Bump stage0 to 1.101.0-beta.1)
 - rust-lang/rust#165412 (Implement `core::ops::FnAddr`)
 - rust-lang/rust#165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax)
 - rust-lang/rust#165818 (do not lint `redundant_lifetimes` on items from external macros)
 - rust-lang/rust#163077 (feat: support nested functions with `#[offload_kernel]`)
 - rust-lang/rust#164795 (Extend support of lint `explicit_outlives_requirements` to checked type aliases)
 - rust-lang/rust#165578 (Avoid `Hash::hash` when stable-hashing various types)
 - rust-lang/rust#165729 (tests: Add regression test for infinite recursive dereference)
 - rust-lang/rust#165822 (Remove unused compiler modules and types)
 - rust-lang/rust#165824 (Add regression test for HRTB projection bound with TryFrom error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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