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

Merge RedundantImport into UnusedImport for suggesting removing spans #122165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chenyukang
Copy link
Member

Fixes #121315

I also changed the label of diagnostics for RedundantImport to be compatible with UnusedImport, or any other better ways?

r? @petrochenkov

@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 Mar 8, 2024
@chenyukang chenyukang force-pushed the yukang-fix-121315-suggest-removing branch from 723ac6f to adb87a0 Compare March 8, 2024 01:36
@chenyukang chenyukang force-pushed the yukang-fix-121315-suggest-removing branch from adb87a0 to 2f8b7b7 Compare March 8, 2024 03:08
@chenyukang chenyukang force-pushed the yukang-fix-121315-suggest-removing branch from 2f8b7b7 to 5a1485b Compare March 8, 2024 03:17
@petrochenkov
Copy link
Contributor

Let's run benchmarks first, to check whether it will perform as horribly as it looks, with all the repeated crate visiting and AST cloning.
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 11, 2024
@bors
Copy link
Contributor

bors commented Mar 11, 2024

⌛ Trying commit 5a1485b with merge 000d1c6...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2024
…-removing, r=<try>

Merge RedundantImport into UnusedImport for suggesting removing spans

Fixes rust-lang#121315

I also changed the label of diagnostics for RedundantImport to be compatible with UnusedImport, or any other better ways?

r? `@petrochenkov`
@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 11, 2024
@bors
Copy link
Contributor

bors commented Mar 11, 2024

☀️ Try build successful - checks-actions
Build commit: 000d1c6 (000d1c672c221bf654ea63dea55353a4550e8539)

1 similar comment
@bors
Copy link
Contributor

bors commented Mar 11, 2024

☀️ Try build successful - checks-actions
Build commit: 000d1c6 (000d1c672c221bf654ea63dea55353a4550e8539)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (000d1c6): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

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 may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.0% [0.2%, 10.6%] 75
Regressions ❌
(secondary)
1.4% [0.7%, 5.5%] 14
Improvements ✅
(primary)
-0.5% [-0.5%, -0.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.0% [-0.5%, 10.6%] 76

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.8% [2.0%, 5.1%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
9.2% [1.6%, 30.8%] 39
Regressions ❌
(secondary)
3.4% [3.4%, 3.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.2% [-8.9%, -3.6%] 8
All ❌✅ (primary) 9.2% [1.6%, 30.8%] 39

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 647.596s -> 647.694s (0.02%)
Artifact size: 310.01 MiB -> 309.93 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 11, 2024
@petrochenkov
Copy link
Contributor

#122165 (comment)

Yep, pretty bad.

@petrochenkov
Copy link
Contributor

In general, I'd like to see the whole unused import pass to be rewritten.
The existing removal span collection logic (working on AST) was added without much consideration for the previous used-ness tracking logic (working on "lowered" imports).
I'll try to look how it can be done better ~tomorrow.

@chenyukang
Copy link
Member Author

I was also worried about the performance, I thought the code change is not in the hot path, seems I'm wrong.

Yep, let's rethink it...

@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 12, 2024
@petrochenkov
Copy link
Contributor

So how I'd expect the check_unused pass to work at high level:

  • First we walk all lowered imports in the crate, using for module in self.arenas.local_modules().iter() { ... }, and collect a table T keyed on NodeIds and containing all the necessary usedness and redundantness info.
    • This walk and table makes Resolves::potentially_unused_imports and Resolver::used_imports fields unnecessary, they can be removed
  • Then we walk the whole crate once by a large visitor and process every use (or extern crate) item in it
    • Each use item is processed by a small visitor that collects spans of all unused/redundant imports in the item to build the removal multispan
    • AST of use items has NodeIds that we use to look into the table T to retrieve usedness/redundantness
    • This way we never have to clone pieces of AST

@petrochenkov petrochenkov 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 Mar 12, 2024
@Dylan-DPC
Copy link
Member

@chenyukang any updates on this? thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

"item TryFrom is imported redundantly" doesn't have automatic fix
6 participants