Unused import tool

RazvanN razvan.nitu1305 at gmail.com
Tue Aug 15 10:54:39 UTC 2023


On Tuesday, 15 August 2023 at 09:28:53 UTC, Timon Gehr wrote:
> On 8/15/23 10:13, RazvanN wrote:
>> 
>> I have tested this tool with some dmd sources and have already 
>> identified [unused 
>> imports](https://github.com/dlang/dmd/pulls?q=is%3Apr+delete+unused+imports+author%3ARazvanN7+is%3Aopen>
> Not a big complaint, just something of which to be aware: 
> Removing imports that are actually unused but can be relevant 
> to the module will break forks on rebase. E.g., the removal of 
> `import dmd.tokens` from `attrib.d` broke my implementation of 
> UnpackDeclaration in the `tuple-syntax` branch.

There are other situations where this is problematic: versioned 
statements, debug code etc. However, I would argue that useless 
imports for various builds of the compiler should be removed as 
they come with a compilation penalty. The solution to this is to 
make the imports more localized (e.g. put the import in the 
versioned block that is used - although this is not ideal if 2 
multiple versions use the same import).

As for your specific case, I think it can be seen as removing a 
useless import that is then re-added once the patch is pushed to 
upstream. This is no different from any other interface 
modification: if someone adds a parameter to a function that you 
are using in your fork, then that will also break your code. 
Anyway, thanks for the heads up!

RazvanN


More information about the Digitalmars-d mailing list