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

rustc_mir_transform: Enforce rustc::potential_query_instability lint #119252

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

Enselic
Copy link
Member

@Enselic Enselic commented Dec 23, 2023

Stop allowing rustc::potential_query_instability on all of rustc_mir_transform and instead allow it on a case-by-case basis if it is safe to do so. In this particular crate, all instances were safe to allow.

Part of #84447 which is E-help-wanted.

@rustbot
Copy link
Collaborator

rustbot commented Dec 23, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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 Dec 23, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 23, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

compiler/rustc_mir_transform/src/const_prop.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_transform/src/const_prop_lint.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_transform/src/coverage/counters.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_transform/src/dest_prop.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_transform/src/dest_prop.rs Outdated Show resolved Hide resolved
@WaffleLapkin
Copy link
Member

r? @cjgillot

since they already started review

@rustbot rustbot assigned cjgillot and unassigned WaffleLapkin Dec 27, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 29, 2023
coverage: Avoid a possible query stability hazard in `CoverageCounters`

rust-lang#119252 revealed a possible query stability hazard in `CoverageCounters`: we iterate over the entries of an `FxHashMap` in a way that allows the iteration order to potentially affect the relative creation order of MIR blocks.

I'm not sure whether there's an actual stability problem or not in practice, but it's certainly a hazard, and I don't see any reason not to switch over to `FxIndexMap` to avoid potential issues.

---

This can either be merged on its own, or incorporated into rust-lang#119252.

cc `@Enselic`
r? `@cjgillot`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 29, 2023
Rollup merge of rust-lang#119401 - Zalathar:query-stability, r=Nilstrieb

coverage: Avoid a possible query stability hazard in `CoverageCounters`

rust-lang#119252 revealed a possible query stability hazard in `CoverageCounters`: we iterate over the entries of an `FxHashMap` in a way that allows the iteration order to potentially affect the relative creation order of MIR blocks.

I'm not sure whether there's an actual stability problem or not in practice, but it's certainly a hazard, and I don't see any reason not to switch over to `FxIndexMap` to avoid potential issues.

---

This can either be merged on its own, or incorporated into rust-lang#119252.

cc `@Enselic`
r? `@cjgillot`
@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 29, 2023
@bors
Copy link
Contributor

bors commented Dec 30, 2023

☔ The latest upstream changes (presumably #116012) made this pull request unmergeable. Please resolve the merge conflicts.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 5, 2024
…ble, r=cjgillot

rustc_mir_transform: Make DestinationPropagation stable for queries

By using `FxIndexMap` instead of `FxHashMap`, so that the order of visiting of locals is deterministic.

We also need to bless
`copy_propagation_arg.foo.DestinationPropagation.panic*.diff`. Do not review the diff of the diff. Instead look at the diff files before and after this commit. Both before and after this commit, 3 statements are replaced with nop. It's just that due to change in ordering, different statements are replaced. But the net result is the same. In other words, compare this diff (before fix):
* https://github.com/rust-lang/rust/blob/090d5eac722000906cc00d991f2bf052b0e388c3/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

With this diff (after fix):
* https://github.com/rust-lang/rust/blob/f603babd63a607e155609dc0277806e559626ea0/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

and you can see that both before and after the fix, we replace 3 statements with `nop`s.

I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines.

This should fix [this](rust-lang#119252 (comment)) comment, but I wanted to make a separate PR for this fix for a simpler development and review process.

Part of rust-lang#84447 which is E-help-wanted.

r? `@cjgillot` who is reviewer for the highly related PR rust-lang#119252.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 5, 2024
…ble, r=cjgillot

rustc_mir_transform: Make DestinationPropagation stable for queries

By using `FxIndexMap` instead of `FxHashMap`, so that the order of visiting of locals is deterministic.

We also need to bless
`copy_propagation_arg.foo.DestinationPropagation.panic*.diff`. Do not review the diff of the diff. Instead look at the diff files before and after this commit. Both before and after this commit, 3 statements are replaced with nop. It's just that due to change in ordering, different statements are replaced. But the net result is the same. In other words, compare this diff (before fix):
* https://github.com/rust-lang/rust/blob/090d5eac722000906cc00d991f2bf052b0e388c3/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

With this diff (after fix):
* https://github.com/rust-lang/rust/blob/f603babd63a607e155609dc0277806e559626ea0/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

and you can see that both before and after the fix, we replace 3 statements with `nop`s.

I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines.

This should fix [this](rust-lang#119252 (comment)) comment, but I wanted to make a separate PR for this fix for a simpler development and review process.

Part of rust-lang#84447 which is E-help-wanted.

r? ```@cjgillot``` who is reviewer for the highly related PR rust-lang#119252.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 6, 2024
…ble, r=cjgillot

rustc_mir_transform: Make DestinationPropagation stable for queries

By using `FxIndexMap` instead of `FxHashMap`, so that the order of visiting of locals is deterministic.

We also need to bless
`copy_propagation_arg.foo.DestinationPropagation.panic*.diff`. Do not review the diff of the diff. Instead look at the diff files before and after this commit. Both before and after this commit, 3 statements are replaced with nop. It's just that due to change in ordering, different statements are replaced. But the net result is the same. In other words, compare this diff (before fix):
* https://github.com/rust-lang/rust/blob/090d5eac722000906cc00d991f2bf052b0e388c3/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

With this diff (after fix):
* https://github.com/rust-lang/rust/blob/f603babd63a607e155609dc0277806e559626ea0/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

and you can see that both before and after the fix, we replace 3 statements with `nop`s.

I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines.

This should fix [this](rust-lang#119252 (comment)) comment, but I wanted to make a separate PR for this fix for a simpler development and review process.

Part of rust-lang#84447 which is E-help-wanted.

r? `@cjgillot` who is reviewer for the highly related PR rust-lang#119252.
@bors bors closed this in #119591 Jan 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 6, 2024
Rollup merge of rust-lang#119591 - Enselic:DestinationPropagation-stable, r=cjgillot

rustc_mir_transform: Make DestinationPropagation stable for queries

By using `FxIndexMap` instead of `FxHashMap`, so that the order of visiting of locals is deterministic.

We also need to bless
`copy_propagation_arg.foo.DestinationPropagation.panic*.diff`. Do not review the diff of the diff. Instead look at the diff files before and after this commit. Both before and after this commit, 3 statements are replaced with nop. It's just that due to change in ordering, different statements are replaced. But the net result is the same. In other words, compare this diff (before fix):
* https://github.com/rust-lang/rust/blob/090d5eac722000906cc00d991f2bf052b0e388c3/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

With this diff (after fix):
* https://github.com/rust-lang/rust/blob/f603babd63a607e155609dc0277806e559626ea0/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

and you can see that both before and after the fix, we replace 3 statements with `nop`s.

I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines.

This should fix [this](rust-lang#119252 (comment)) comment, but I wanted to make a separate PR for this fix for a simpler development and review process.

Part of rust-lang#84447 which is E-help-wanted.

r? `@cjgillot` who is reviewer for the highly related PR rust-lang#119252.
@Enselic Enselic reopened this Jan 6, 2024
Stop allowing `rustc::potential_query_instability` on all of
rustc_mir_transform and instead allow it on a case-by-case basis if it
is safe to do so. In this particular crate, all instances were safe to
allow.
@Enselic Enselic force-pushed the rustc_mir_transform-query-stability branch from 1a0f173 to 6d8fb57 Compare January 6, 2024 18:12
@Enselic Enselic added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 6, 2024
@cjgillot
Copy link
Contributor

cjgillot commented Jan 6, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 6, 2024

📌 Commit 6d8fb57 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors 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 Jan 6, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2024
…mpiler-errors

Rollup of 6 pull requests

Successful merges:

 - rust-lang#119252 (rustc_mir_transform: Enforce `rustc::potential_query_instability` lint)
 - rust-lang#119548 (Use the current target instead of iterating over all targets)
 - rust-lang#119656 (document rounding behavior of rint/nearbyint for ties)
 - rust-lang#119657 (Fix typo in docs for slice::split_once, slice::rsplit_once)
 - rust-lang#119666 (Populate `yield` and `resume` types in MIR body while body is being initialized)
 - rust-lang#119679 (Ask for rustc version in diagnostic reports, remind users to update their toolchain)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2024
…mpiler-errors

Rollup of 6 pull requests

Successful merges:

 - rust-lang#119252 (rustc_mir_transform: Enforce `rustc::potential_query_instability` lint)
 - rust-lang#119548 (Use the current target instead of iterating over all targets)
 - rust-lang#119656 (document rounding behavior of rint/nearbyint for ties)
 - rust-lang#119657 (Fix typo in docs for slice::split_once, slice::rsplit_once)
 - rust-lang#119666 (Populate `yield` and `resume` types in MIR body while body is being initialized)
 - rust-lang#119679 (Ask for rustc version in diagnostic reports, remind users to update their toolchain)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b8e1a34 into rust-lang:master Jan 7, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2024
Rollup merge of rust-lang#119252 - Enselic:rustc_mir_transform-query-stability, r=cjgillot

rustc_mir_transform: Enforce `rustc::potential_query_instability` lint

Stop allowing `rustc::potential_query_instability` on all of rustc_mir_transform and instead allow it on a case-by-case basis if it is safe to do so. In this particular crate, all instances were safe to allow.

Part of rust-lang#84447 which is E-help-wanted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants