-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove special-cased stable hashing for HIR module #92259
Conversation
All other 'containers' (e.g. `impl` blocks) hashed their contents in the normal, order-dependent way. However, `Mod` was hashing its contents in a (sort-of) order-independent way. However, the exact order is exposed to consumers through `Mod.item_ids`, and through query results like `hir_module_items`. Therefore, stable hashing needs to take the order of items into account, to avoid fingerprint ICEs. Unforuntately, I was unable to directly build a reproducer for the ICE, due to the behavior of `Fingerprint::combine_commutative`. This operation swaps the upper and lower `u64` when constructing the result, which makes the function non-associative. Since we start the hashing of module items by combining `Fingerprint::ZERO` with the first item, it's difficult to actually build an example where changing the order of module items leaves the final hash unchanged. However, this appears to have been hit in practice in rust-lang#92218 While we're not able to reproduce it, the fact that proc-macros are involved (which can give an entire module the same span, preventing any span-related invalidations) makes me confident that the root cause of that issue is our method of hashing module items. This PR removes all of the special handling for `Mod`, instead deriving a `HashStable` implementation. This makes `Mod` consistent with other 'contains' like `Impl`, which hash their contents through the typical derive of `HashStable`.
(rust-highfive has picked a reviewer for you, use r? to override) |
let def_path_hash = id.to_stable_hash_key(hcx); | ||
def_path_hash.0 | ||
}) | ||
.fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combine_commutative
can be removed, since it isn't used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that it might be used again in the future, so I kept it. cc @michaelwoerister
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's keep it please. I might have a concrete use for it soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For similar use case that ignores order of combined fingerprints? In that case we should fix the implementation instead of leaving it broken: when used as here it doesn't completely ignore the order when combining more than two fingerprints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened to #92528 to remove unintentional swap of lower and upper part of the result.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit da3f196 with merge 07ade458e48a7b28ab8b88f501a29c9d03cac2fe... |
☀️ Try build successful - checks-actions |
Queued 07ade458e48a7b28ab8b88f501a29c9d03cac2fe with parent f8abed9, future comparison URL. |
Finished benchmarking commit (07ade458e48a7b28ab8b88f501a29c9d03cac2fe): comparison url. Summary: This change led to small relevant mixed results 🤷 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Aaron1011! Great find!
let def_path_hash = id.to_stable_hash_key(hcx); | ||
def_path_hash.0 | ||
}) | ||
.fold(Fingerprint::ZERO, |a, b| a.combine_commutative(b)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's keep it please. I might have a concrete use for it soon.
@bors r+ |
📌 Commit da3f196 has been approved by |
⌛ Testing commit da3f196 with merge bf286ba644d05e5f5f1369a1edd68ae695ae4a04... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
⌛ Testing commit da3f196 with merge bd7cd2fee41575e5378c11171d0975555c590e5a... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
1 similar comment
☀️ Test successful - checks-actions |
Finished benchmarking commit (2b681ac): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
All other 'containers' (e.g.
impl
blocks) hashed their contentsin the normal, order-dependent way. However,
Mod
was hashingits contents in a (sort-of) order-independent way. However, the
exact order is exposed to consumers through
Mod.item_ids
,and through query results like
hir_module_items
. Therefore,stable hashing needs to take the order of items into account,
to avoid fingerprint ICEs.
Unforuntately, I was unable to directly build a reproducer
for the ICE, due to the behavior of
Fingerprint::combine_commutative
.This operation swaps the upper and lower
u64
when constructing theresult, which makes the function non-associative. Since we start
the hashing of module items by combining
Fingerprint::ZERO
withthe first item, it's difficult to actually build an example where
changing the order of module items leaves the final hash unchanged.
However, this appears to have been hit in practice in #92218
While we're not able to reproduce it, the fact that proc-macros
are involved (which can give an entire module the same span, preventing
any span-related invalidations) makes me confident that the root
cause of that issue is our method of hashing module items.
This PR removes all of the special handling for
Mod
, instead derivinga
HashStable
implementation. This makesMod
consistent with other'contains' like
Impl
, which hash their contents through the typicalderive of
HashStable
.