-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Audit and handle remaining cases of rustc::potential_query_instability lint (iterating HashMaps) #84447
Copy link
Copy link
Open
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The iteration order of a
HashMapdepends on theHashvalue of the keys. In rustc, theHashvalue of a key can change between compilation sessions, even if theHashStablevalue remains the same (e.g.DefId,Symbol, etc.). This means that iterating over aHashMapcan cause a query to produce different results given the same (as determined byHashStable) input. This can be quite subtle, as demonstrated by #82272 (comment)To eliminate this source of issues, we should make an internal rustc-only lint for iterating over a
HashMapin any way. This will need to cover explicit method calls (e.g..keys()and.values()), as well as any usage of theIntoIteratorimpl forHashMap.Note that we don't want to ban the usage of
HashMaps with unstable keys - as long as they're only used for lookup (and not iteration), it's much more efficient than repeatedly converting to the stable form of a key (e.g.DefId->DefPathHashorSymbol->String).