Bug 24778 – Warning for unused imports

Status
NEW
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-09-22T15:00:48Z
Last change time
2024-12-13T19:37:27Z
Assigned to
No Owner
Creator
Manu
Moved to GitHub: dmd#20515 →

Comments

Comment #0 by turkeyman — 2024-09-22T15:00:48Z
This has come up before... but I seriously, desperately want this. Detecting unused imports is most important to improve build times. I periodically try and cull old imports to improve build times, but it's difficult to do, and just a massive waste of time! I know people don't like warnings; but this is exactly what warnings should be for.
Comment #1 by turkeyman — 2024-09-22T15:02:56Z
I don't know any other language that can't do this, and people expect it to be available. We've had this in C# for over 20 years, and Java for much longer... we need this. It's an embarrassing omission.
Comment #2 by lance — 2024-09-22T15:22:43Z
(In reply to Manu from comment #0) > This has come up before... but I seriously, desperately want this. > Detecting unused imports is most important to improve build times. > I periodically try and cull old imports to improve build times, but it's > difficult to do, and just a massive waste of time! > > I know people don't like warnings; but this is exactly what warnings should > be for. Atila started a related thread a couple months ago: https://forum.dlang.org/post/[email protected] There was a tool posted in that thread that identifies unused global imports: https://forum.dlang.org/post/[email protected]
Comment #3 by ryuukk.dev — 2024-09-23T05:10:14Z
It should be builtin into the compiler People should learn to submit PRs to DMD In odin it is as simple as passing: -vet-unused-imports Checks for unused import declarations. Nobody wants to download external programs for such a basic, yet important, feature
Comment #4 by lance — 2024-09-23T18:45:17Z
(In reply to ryuukk_ from comment #3) > It should be builtin into the compiler > > People should learn to submit PRs to DMD > > In odin it is as simple as passing: > > -vet-unused-imports > Checks for unused import declarations. > > > > Nobody wants to download external programs for such a basic, yet important, > feature It's Razvan's script, so the problem is not lack of understanding of how to submit PRs. His post notes cases that will be hard to handle.
Comment #5 by razvan.nitu1305 — 2024-09-24T06:50:58Z
(In reply to Lance Bachmeier from comment #4) > (In reply to ryuukk_ from comment #3) > > It should be builtin into the compiler > > > > People should learn to submit PRs to DMD > > > > In odin it is as simple as passing: > > > > -vet-unused-imports > > Checks for unused import declarations. > > > > > > > > Nobody wants to download external programs for such a basic, yet important, > > feature > > It's Razvan's script, so the problem is not lack of understanding of how to > submit PRs. His post notes cases that will be hard to handle. I was trying to implement it using dmd as a library to see if it's possible, and if not to understand what changes are required to make it possible. Implementing this inside the compiler would actually be easier, provided that Walter does not oppose it.
Comment #6 by razvan.nitu1305 — 2024-09-24T12:23:04Z
Here's the dmd implementation: https://github.com/dlang/dmd/pull/16878
Comment #7 by dlang-bot — 2024-09-24T12:30:19Z
@RazvanN7 updated dlang/dmd pull request #16878 "Implement warnings for unused imports" mentioning this issue: - Add changelog entry + fix importc error + Fix Bugzilla Issue 24778 https://github.com/dlang/dmd/pull/16878
Comment #8 by b2.temp — 2024-09-24T12:57:29Z
RazvanN: I dont like how it's implemented. I remember I already suggested that in a forum discussion but, let's do it again: If it's implemented in the compiler it would be better to implements this as a "touched" system. You see when searching a symbol has worked and via an import, you flag that import as "touched". Then when the user asks for unused import you visit the tree and when it's an import node and that import has not been touched you emit the warning.
Comment #9 by razvan.nitu1305 — 2024-09-24T13:01:37Z
(In reply to basile-z from comment #8) > RazvanN: I dont like how it's implemented. > > I remember I already suggested that in a forum discussion but, let's do it > again: > > If it's implemented in the compiler it would be better to implements this as > a "touched" system. You see when searching a symbol has worked and via an > import, you flag that import as "touched". > > Then when the user asks for unused import you visit the tree and when it's > an import node and that import has not been touched you emit the warning. I am fully aware how to implement it. In fact you can see that my implementation does the same thing, however, in dmdlib you do not have all the information that the compiler does (yet, I hope).
Comment #10 by b2.temp — 2024-09-24T13:12:25Z
Sorry I was looking for a `search` overrides modified in dmodule.d but now I remember that you have removed it a few months ago.
Comment #11 by robert.schadek — 2024-12-13T19:37:27Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20515 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB