Unused import tool

RazvanN razvan.nitu1305 at gmail.com
Wed Aug 16 07:27:34 UTC 2023


On Wednesday, 16 August 2023 at 05:26:11 UTC, Basile B. wrote:

> You can handle nested import declarations without the scope. 
> The trick would be to use a single visitor and a 2D import 
> list, i.e`ImportInfo[][] imports;`. The first dim matches to a 
> scope, so when you enter a scope (BlockStmt, AggrDecl, etc) you 
> push the local imports, and when you leave the scope, you check 
> and pop. Styx 
> [Example](https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/lint.sx?ref_type=heads#L247), (which has same semantics as D about out-of-order decls).
>

Indeed, there are solutions to this problem. Another one is to 
treat scope as dscanner does now (the scope is just an integer 
which is incremented and decremented whenever a scope is 
entered/left), however, I was hoping to leverage most of the 
existing logic in the compiler.

>
> This is why I think that such a tool should be integrated to 
> the compiler.
>

I am now looking for a way to integrate this in the compiler to 
better understand what the compiler would need to expose in order 
to properly implement this. I thought it would be easy, 
unfortunately, when dmd does symbol resolution, the search 
methods work on a list of imported scopes (e.g. modules or 
mixins) and currently there is no way to tie the imported scope 
to a specific import declaration/statement. DMD's code could be 
altered to store the import instead of the module, however, 
Walter has made it clear that such linting behavior will not be 
accepted in dmd.

RazvanN



More information about the Digitalmars-d mailing list