-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Perform unused assignment and unused variables lints on MIR. #142390
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
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer Some changes occurred in match lowering cc @Nadrieril Some changes occurred in match checking cc @Nadrieril Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Perform unused assignment and unused variables lints on MIR. Rebase of #101500 Fixes #51003. The first commit moves detection of uninhabited types from the current liveness pass to MIR building. In order to keep the same level of diagnostics, I had to instrument MIR a little more: - keep for which original local a guard local is created; - store in the `VarBindingForm` the list of introducer places and whether this was a shorthand pattern. I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas. Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable. <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end -->
Perform unused assignment and unused variables lints on MIR. Rebase of #101500 Fixes #51003. The first commit moves detection of uninhabited types from the current liveness pass to MIR building. In order to keep the same level of diagnostics, I had to instrument MIR a little more: - keep for which original local a guard local is created; - store in the `VarBindingForm` the list of introducer places and whether this was a shorthand pattern. I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas. Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable.
This comment has been minimized.
This comment has been minimized.
|
☀️ Try build successful - checks-actions |
|
Finished benchmarking commit (50ba7f2): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.8%, secondary 0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 1.3%, secondary 3.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 754.801s -> 755.907s (0.15%) |
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that #142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache. <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end -->
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that #142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache.
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that rust-lang/rust#142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache.
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that rust-lang/rust#142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache.
|
Nominating this PR for T-compiler discussion to boost signal the Zulip topic about the beta regressions that were reported @rustbot label I-compiler-nominated |
Perform unused assignment and unused variables lints on MIR. Rebase of rust-lang#101500 Fixes rust-lang#51003. The first commit moves detection of uninhabited types from the current liveness pass to MIR building. In order to keep the same level of diagnostics, I had to instrument MIR a little more: - keep for which original local a guard local is created; - store in the `VarBindingForm` the list of introducer places and whether this was a shorthand pattern. I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas. Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable.
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that rust-lang/rust#142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache.
Pre-compute MIR CFG caches for borrowck and other analyses I was puzzled that rust-lang/rust#142390 introduces additional computations of CFG traversals: borrowck computes them, right? It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses. This PR: - forces the computation of all caches in `mir_promoted` query; - modifies region renumbering to avoid dropping that cache.
### What
Add `#[allow(unreachable_code)]` attribute to the `error_from_error_val`
function for wasm targets to suppress a compiler warning introduced in
Rust 1.92.0.
### Why
I started seeing the following errors when building contracts using the
soroban-sdk:
```
warning: unreachable expression
--> soroban-sdk/src/env.rs:1770:6
|
1769 | self.env_impl.error_from_error_val(e)
| ------------------------------------- any code following this expression is unreachable
1770 | }
| ^ unreachable expression
|
note: this expression has type `Infallible`, which is uninhabited
--> soroban-sdk/src/env.rs:1769:9
|
1769 | self.env_impl.error_from_error_val(e)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default
```
It appears Rust 1.92.0 changed how `unreachable_code` warnings are
detected.
The `error_from_error_val` function returns `Infallible`, an uninhabited
type. This is intentional behaviour. The function is designed to never
return so the warning is suppressed.
I think this is probably the result of
rust-lang/rust#142390 which landed in 1.92.0,
but that change is quite deep and so I'm not certain of that.
In any case, I don't think what the code is doing here is incorrect,
just a new warning is highlighting that there's an unreachable condition
here, which is expected, so we should allow the condition.
…r=cjgillot Fix suppression of `unused_assignment` in binding of `unused_variable` Unused assignments to an unused variable should trigger only the `unused_variables` lint and not also the `unused_assignments` lint. This was previously implemented by checking whether the span of the assignee was within the span of the binding pattern, however that failed to capture situations was imported from elsewhere (eg from the input tokenstream of a proc-macro that generates the binding pattern). By comparing the span of the assignee to those of the variable introductions instead, a reported stable-to-stable regression is resolved. This fix also impacted some other preexisting tests, which had (undesirably) been triggering both the `unused_variables` and `unused_assignments` lints on the same initializing assignment; those tests have therefore now been updated to expect only the former lint. Fixes #151514 r? cjgillot (as author of reworked liveness testing in #142390)
…r=cjgillot Fix suppression of `unused_assignment` in binding of `unused_variable` Unused assignments to an unused variable should trigger only the `unused_variables` lint and not also the `unused_assignments` lint. This was previously implemented by checking whether the span of the assignee was within the span of the binding pattern, however that failed to capture situations was imported from elsewhere (eg from the input tokenstream of a proc-macro that generates the binding pattern). By comparing the span of the assignee to those of the variable introductions instead, a reported stable-to-stable regression is resolved. This fix also impacted some other preexisting tests, which had (undesirably) been triggering both the `unused_variables` and `unused_assignments` lints on the same initializing assignment; those tests have therefore now been updated to expect only the former lint. Fixes rust-lang/rust#151514 r? cjgillot (as author of reworked liveness testing in rust-lang/rust#142390)
…r=cjgillot Fix suppression of `unused_assignment` in binding of `unused_variable` Unused assignments to an unused variable should trigger only the `unused_variables` lint and not also the `unused_assignments` lint. This was previously implemented by checking whether the span of the assignee was within the span of the binding pattern, however that failed to capture situations was imported from elsewhere (eg from the input tokenstream of a proc-macro that generates the binding pattern). By comparing the span of the assignee to those of the variable introductions instead, a reported stable-to-stable regression is resolved. This fix also impacted some other preexisting tests, which had (undesirably) been triggering both the `unused_variables` and `unused_assignments` lints on the same initializing assignment; those tests have therefore now been updated to expect only the former lint. Fixes rust-lang/rust#151514 r? cjgillot (as author of reworked liveness testing in rust-lang/rust#142390)
…r=cjgillot Fix suppression of `unused_assignment` in binding of `unused_variable` Unused assignments to an unused variable should trigger only the `unused_variables` lint and not also the `unused_assignments` lint. This was previously implemented by checking whether the span of the assignee was within the span of the binding pattern, however that failed to capture situations was imported from elsewhere (eg from the input tokenstream of a proc-macro that generates the binding pattern). By comparing the span of the assignee to those of the variable introductions instead, a reported stable-to-stable regression is resolved. This fix also impacted some other preexisting tests, which had (undesirably) been triggering both the `unused_variables` and `unused_assignments` lints on the same initializing assignment; those tests have therefore now been updated to expect only the former lint. Fixes rust-lang/rust#151514 r? cjgillot (as author of reworked liveness testing in rust-lang/rust#142390)
…r=cjgillot Fix suppression of `unused_assignment` in binding of `unused_variable` Unused assignments to an unused variable should trigger only the `unused_variables` lint and not also the `unused_assignments` lint. This was previously implemented by checking whether the span of the assignee was within the span of the binding pattern, however that failed to capture situations was imported from elsewhere (eg from the input tokenstream of a proc-macro that generates the binding pattern). By comparing the span of the assignee to those of the variable introductions instead, a reported stable-to-stable regression is resolved. This fix also impacted some other preexisting tests, which had (undesirably) been triggering both the `unused_variables` and `unused_assignments` lints on the same initializing assignment; those tests have therefore now been updated to expect only the former lint. Fixes rust-lang/rust#151514 r? cjgillot (as author of reworked liveness testing in rust-lang/rust#142390)
Rebase of #101500
Fixes #51003.
The first commit moves detection of uninhabited types from the current liveness pass to MIR building.
In order to keep the same level of diagnostics, I had to instrument MIR a little more:
VarBindingFormthe list of introducer places and whether this was a shorthand pattern.I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas.
Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable.