Skip to content
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

Audit and handle remaining cases of rustc::potential_query_instability lint (iterating HashMaps) #84447

Open
Aaron1011 opened this issue Apr 22, 2021 · 17 comments
Labels
A-incr-comp Area: Incremental compilation C-cleanup Category: PRs that clean code up or issues documenting cleanup. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Apr 22, 2021

The iteration order of a HashMap depends on the Hash value of the keys. In rustc, the Hash value of a key can change between compilation sessions, even if the HashStable value remains the same (e.g. DefId, Symbol, etc.). This means that iterating over a HashMap can cause a query to produce different results given the same (as determined by HashStable) 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 HashMap in any way. This will need to cover explicit method calls (e.g. .keys() and .values()), as well as any usage of the IntoIterator impl for HashMap.

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 -> DefPathHash or Symbol -> String).

@Aaron1011 Aaron1011 self-assigned this Apr 22, 2021
@Aaron1011 Aaron1011 added A-incr-comp Area: Incremental compilation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 22, 2021
@bjorn3
Copy link
Member

bjorn3 commented Apr 23, 2021

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),

#64131 added the StableMap wrapper for FxHashMap that doesn't expose the iteration order.

@jyn514
Copy link
Member

jyn514 commented Apr 23, 2021

@bjorn3 see #84446

@cjgillot
Copy link
Contributor

cjgillot commented Jul 5, 2022

The lint exists since #89558, and has allowed on all compiler crates as rustc::potential_query_instability.
We now need to stop allowing it in the compiler.

Steps, for each crate except rustc_data_structures:

  • remove the allow(rustc::potential_query_instability) in lib.rs;
  • replace the FxHash{Map,Set} by FxIndex{Map,Set} where necessary.

Please reach out on zulip if there are any questions.

@cjgillot cjgillot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jul 5, 2022
@fee1-dead
Copy link
Member

fee1-dead commented Jul 7, 2022

@rustbot claim

@rustbot release-assignment

@rustbot rustbot assigned fee1-dead and unassigned Aaron1011 and fee1-dead Jul 7, 2022
@NiklasJonsson
Copy link
Contributor

It seems like no one is assigned to this and I'd like to give it a try so assigning myself.

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 14, 2022
…etrochenkov

remove allow(rustc::potential_query_instability) in rustc_span

Also, avoid sorting before debug output as iteration order can now be
relied upon.

Related rust-lang#84447
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 23, 2022
…ompiler-errors

rustc_expand: Switch FxHashMap to FxIndexMap where iteration is used

Relates rust-lang#84447
@NiklasJonsson
Copy link
Contributor

I was hoping to get back to this after vacation but I haven't had the time and I likely won't in the near future. I've converted some of the modules to use the stable hash containers but there is a decent amount left so it is probably possible to have multiple people working on this, assuming some coordination.

There are two outstanding PRs from me that I will finish up. The first is #99334 and seems ready to merge. Second one is #99065 which requires the get_many_mut feature to be merged for the stable hash containers indexmap-rs/indexmap#238, which in turn is waiting on the stabilization of the matching features on the standard hash containers (#97601).

@rustbot release-assignment

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 12, 2022
…oli-obk

rustc_error, rustc_private: Switch to stable hash containers

Relates rust-lang#84447
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Sep 22, 2022
rustc_error, rustc_private: Switch to stable hash containers

Relates rust-lang/rust#84447
@CastilloDel
Copy link
Contributor

I'm gonna give this a try
@rustbot claim

bors added a commit to rust-lang-ci/rust that referenced this issue Oct 3, 2024
…instability_lint_for_rustc_metadata, r=compiler-errors

Handle `rustc_metadata` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_metadata/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_metadata/src/lib.rs#L3) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 3, 2024
…y-instability-lint-for-rustc-query-impl, r=compiler-errors

Handle `rustc_query_impl` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_query_impl/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_query_impl/src/lib.rs#L5) <s>and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors</s> (was not necessary for this PR).

A somewhat tracking issue: rust-lang#84447

r? ``@compiler-errors``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 4, 2024
Rollup merge of rust-lang#131192 - ismailarilik:handle-potential-query-instability-lint-for-rustc-query-impl, r=compiler-errors

Handle `rustc_query_impl` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_query_impl/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_query_impl/src/lib.rs#L5) <s>and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors</s> (was not necessary for this PR).

A somewhat tracking issue: rust-lang#84447

r? ``@compiler-errors``
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Oct 4, 2024
…ty_lint_for_rustc_metadata, r=compiler-errors

Handle `rustc_metadata` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_metadata/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_metadata/src/lib.rs#L3) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang/rust#84447
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 4, 2024
…instability-lint-for-librustdoc, r=<try>

Handle `librustdoc` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/librustdoc/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/lib.rs#L23) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
@ismailarilik
Copy link
Contributor

The lint exists since #89558, and has allowed on all compiler crates as rustc::potential_query_instability. We now need to stop allowing it in the compiler.

Steps, for each crate except rustc_data_structures:

* remove the `allow(rustc::potential_query_instability)` in `lib.rs`;

* replace the `FxHash{Map,Set}` by `FxIndex{Map,Set}` where necessary.

Please reach out on zulip if there are any questions.

@cjgillot You specified rustc_data_structures as an exception here. So what should be done for it? Is it nothing or another approach?

BTW, with the PRs I recently opened, there is not much left to fix but I will open another PR for the remainings.

@cjgillot
Copy link
Contributor

cjgillot commented Oct 5, 2024

rustc_data_structures is a small crate with support code. The lint is meant to avoid accidentally introducing non-determinism in compiler code.

The only thing that would be needed for rustc_data_structures is to review all the places where there is an #[allow(rustc::potential_query_instability)] and put a comment there explaining why it's ok.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 5, 2024
…y-instability-lint-for-rustc-interface, r=cjgillot

Handle `rustc_interface` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` occurrences from [`compiler/rustc_interface/`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_interface/) <s>and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors</s> (was not necessary for this PR).

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 5, 2024
Rollup merge of rust-lang#131280 - ismailarilik:handle-potential-query-instability-lint-for-rustc-interface, r=cjgillot

Handle `rustc_interface` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` occurrences from [`compiler/rustc_interface/`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_interface/) <s>and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors</s> (was not necessary for this PR).

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 5, 2024
…instability-lint-for-librustdoc, r=notriddle

Handle `librustdoc` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/librustdoc/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/lib.rs#L23) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
@ismailarilik
Copy link
Contributor

rustc_data_structures is a small crate with support code. The lint is meant to avoid accidentally introducing non-determinism in compiler code.

The only thing that would be needed for rustc_data_structures is to review all the places where there is an #[allow(rustc::potential_query_instability)] and put a comment there explaining why it's ok.

@cjgillot there is just one #[allow(rustc::potential_query_instability)] for rustc_data_structures in lib.rs. Is your statement here is enough for rationale explanation? (I was thinking to add it as a comment above the allow statement.)

bors added a commit to rust-lang-ci/rust that referenced this issue Oct 6, 2024
…instability-lint-for-librustdoc, r=notriddle

Handle `librustdoc` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/librustdoc/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/lib.rs#L23) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
@ismailarilik
Copy link
Contributor

For migrated ones, perf might be improved by removing some sort calls which were only added to provide order stability but I don't know how I can find them easily.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 12, 2024
…y-instability-lint-for-clippy, r=xFrednet

Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 12, 2024
…y-instability-lint-for-clippy, r=xFrednet

Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 12, 2024
…y-instability-lint-for-clippy, r=xFrednet

Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 13, 2024
Rollup merge of rust-lang#131277 - ismailarilik:handle-potential-query-instability-lint-for-clippy, r=xFrednet

Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447
RalfJung pushed a commit to RalfJung/miri that referenced this issue Oct 14, 2024
…ty-lint-for-librustdoc, r=notriddle

Handle `librustdoc` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/librustdoc/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/librustdoc/lib.rs#L23) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang/rust#84447

r? `@compiler-errors`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Oct 18, 2024
…lity-lint-for-clippy, r=xFrednet

Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang/rust#84447
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 24, 2024
…instability-lint-for-rustc-resolve, r=<try>

Handle `rustc_resolve` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_resolve/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/lib.rs#L12) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 28, 2024
…instability-lint-for-rustc-resolve, r=<try>

Handle `rustc_resolve` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_resolve/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/lib.rs#L12) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 9, 2024
…instability-lint-for-rustc-resolve, r=<try>

Handle `rustc_resolve` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_resolve/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/lib.rs#L12) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: rust-lang#84447

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-cleanup Category: PRs that clean code up or issues documenting cleanup. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests