Skip to content

Simplify HashStable#155018

Merged
rust-bors[bot] merged 8 commits intorust-lang:mainfrom
nnethercote:simplify-HashStable
Apr 30, 2026
Merged

Simplify HashStable#155018
rust-bors[bot] merged 8 commits intorust-lang:mainfrom
nnethercote:simplify-HashStable

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

@nnethercote nnethercote commented Apr 9, 2026

View all comments

This PR:

  • Simplifies the HashStable trait, by moving its generic parameter from the trait to its single method.
  • Eliminates the need for the non-obvious derive(HashStable)/derive(HashStable_Generic) distinction.
  • Reduces the need for, and clarifies, the non-obvious derive(HashStable)/derive(HashStable_NoContext) distinction.

r? @fee1-dead

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-meta Area: Issues & PRs about the rust-lang/rust repository itself F-autodiff `#![feature(autodiff)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 9, 2026
@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Copy Markdown
Contributor Author

nnethercote commented Apr 9, 2026

Why on earth is Span 96 bits on aarch64-gnu-llvm-21-1 when it only contains a u32 and two u16s?

@nnethercote
Copy link
Copy Markdown
Contributor Author

I just tried PR on an aarch64-unknown-linux-gnu box that I have and it compiled fine. Weird.

@rust-bors

This comment has been minimized.

/// visible.
pub trait HashStableContext {
/// The main event: stable hashing of a span.
fn span_hash_stable(&mut self, span: RawSpan, hasher: &mut StableHasher);
Copy link
Copy Markdown
Contributor

@petrochenkov petrochenkov Apr 9, 2026

Choose a reason for hiding this comment

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

View changes since the review

Suggested change
fn span_hash_stable(&mut self, span: RawSpan, hasher: &mut StableHasher);
fn span_hash_stable(&mut self, span: Self::Span, hasher: &mut StableHasher);

Perhaps Span, DefId and RawDefPathHash could be associated types in HashStableContext?
Then impl HashStableContext for StableHashingContext could fill them with concrete types.

If that works then "type erased" versions of the aforementioned types could be avoided.

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 tried that but I couldn't get it to work.

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.

Specifically, if I add an associate type MySpan to the trait, then in Span::hash_stable I get this error:

error[E0308]: mismatched types
    --> compiler/rustc_span/src/lib.rs:2793:30
     |
2793 |         hcx.span_hash_stable(*self, hasher)
     |             ---------------- ^^^^^ expected associated type, found `Span`
     |             |
     |             arguments to this method are incorrect
     |
     = note: expected associated type `<Hcx as HashStableContext>::MySpan`
                         found struct `span_encoding::Span`
help: consider constraining the associated type `<Hcx as HashStableContext>::MySpan` to `span_encoding::Span`
     |
2791 |     fn hash_stable<Hcx: HashStableContext<MySpan = span_encoding::Span>>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
     |                                          ++++++++++++++++++++++++++++++

Then if I try the help suggestion I get this error:

error[E0271]: type mismatch resolving `<Hcx as HashStableContext>::MySpan == Span`
    --> compiler/rustc_span/src/lib.rs:2791:43
     |
2791 | ...ashStableContext<MySpan = Span>>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
     |                     ^^^^^^^^^^^^^ expected `Span`, found associated type
     |
     = note:       expected struct `span_encoding::Span`
             found associated type `<Hcx as HashStableContext>::MySpan`
note: the requirement `<Hcx as HashStableContext>::MySpan == span_encoding::Span` appears on the `impl`'s method `hash_stable` but not on the corresponding trait's method
    --> compiler/rustc_data_structures/src/stable_hasher.rs:82:8

In other words, the impl method no longer matches the trait method.

Maybe there's a way around this? I couldn't find one.

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.

You can probably make it work with appropriate bounds on the associated types for the impl, but that's going to be crate dependent so still doesn't play nicely with the proc macro. I think you'd need to keep the generic on the trait too.

@rust-bors

This comment has been minimized.

@nnethercote
Copy link
Copy Markdown
Contributor Author

This is blocked by #154924.

@nnethercote nnethercote added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 10, 2026
@nnethercote
Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 10, 2026
@nnethercote nnethercote force-pushed the simplify-HashStable branch from 9e9a113 to ce139ba Compare April 10, 2026 05:24
@nnethercote
Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 10, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 10, 2026

☀️ Try build successful (CI)
Build commit: 959be73 (959be73237e12c458b274d84f125d94f71fe1d9e, parent: dd82fd2034e5c86c6f0f8070dc5679703cc4fe03)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (959be73): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.4% [0.1%, 1.2%] 68
Regressions ❌
(secondary)
0.4% [0.2%, 1.5%] 23
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 3
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 4
All ❌✅ (primary) 0.4% [-0.2%, 1.2%] 71

Max RSS (memory usage)

Results (secondary 6.0%)

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)
6.0% [6.0%, 6.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary 2.8%)

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)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 488.849s -> 492.643s (0.78%)
Artifact size: 395.54 MiB -> 395.57 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Apr 10, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 29, 2026

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.

@nnethercote
Copy link
Copy Markdown
Contributor Author

I added a new commit with the requested comment.

@bors r=fee1-dead p=1 (conflict-prone)

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

📌 Commit 20060c6 has been approved by fee1-dead

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 30, 2026
Simplify `HashStable`



This PR:
- Simplifies the `HashStable` trait, by moving its generic parameter from the trait to its single method.
- Eliminates the need for the non-obvious `derive(HashStable)`/`derive(HashStable_Generic)` distinction.
- Reduces the need for, and clarifies, the non-obvious `derive(HashStable)`/`derive(HashStable_NoContext)` distinction.

r? @fee1-dead
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job dist-x86_64-msvc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 30, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 30, 2026

💔 Test for e4a01d5 failed: CI. Failed job:

@nnethercote
Copy link
Copy Markdown
Contributor Author

Unclear what went wrong. The last lines in the failing log are "Vendoring" steps. Doesn't seem related to anything in this PR.

@bors retry

@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 Apr 30, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 30, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 30, 2026

☀️ Test successful - CI
Approved by: fee1-dead
Duration: 3h 7m 54s
Pushing f53b654 to main...

@rust-bors rust-bors Bot merged commit f53b654 into rust-lang:main Apr 30, 2026
12 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 30, 2026
@rust-bors rust-bors Bot mentioned this pull request Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 57f772f (parent) -> f53b654 (this PR)

Test differences

Show 80 test diffs

80 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard f53b654a8882fd5fc036c4ca7a4ff41ce32497a6 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-gnu-llvm-21: 1h 39m -> 1h 11m (-28.1%)
  2. i686-msvc-1: 2h 16m -> 2h 54m (+27.7%)
  3. dist-aarch64-linux: 2h 30m -> 1h 54m (-24.3%)
  4. x86_64-gnu-gcc: 1h 24m -> 1h 5m (-22.9%)
  5. x86_64-gnu-llvm-22-3: 1h 55m -> 1h 29m (-22.7%)
  6. x86_64-rust-for-linux: 39m 2s -> 46m 12s (+18.4%)
  7. dist-x86_64-solaris: 1h 29m -> 1h 45m (+18.0%)
  8. i686-gnu-nopt-1: 1h 49m -> 2h 7m (+16.3%)
  9. dist-apple-various: 1h 40m -> 1h 56m (+16.0%)
  10. dist-x86_64-apple: 1h 50m -> 2h 6m (+14.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f53b654): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.2%, 0.3%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -0.9%, secondary -3.0%)

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)
- - 0
Improvements ✅
(primary)
-0.9% [-0.9%, -0.9%] 1
Improvements ✅
(secondary)
-3.0% [-3.5%, -2.0%] 4
All ❌✅ (primary) -0.9% [-0.9%, -0.9%] 1

Cycles

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

Binary size

Results (secondary -0.1%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) - - 0

Bootstrap: 483.007s -> 487.787s (0.99%)
Artifact size: 391.00 MiB -> 390.97 MiB (-0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Apr 30, 2026
@nnethercote nnethercote deleted the simplify-HashStable branch April 30, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic F-autodiff `#![feature(autodiff)]` merged-by-bors This PR was explicitly merged by bors. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants