July 16, 2024

On Thursday, 11 July 2024 at 10:28:35 UTC, Atila Neves wrote:

>

It'd be amazing if one could hit a key/key combination and have all imports pared down to the absolute minimum (and made local). If only I had the time...

Imagine being lazy, typing "import std;" at module-scope, writing some code and... boom. "Hand-written" local imports everywhere. One can dream.

I have a small program that uses dmd as a library that:

  • identifies unused global imports
  • provides a list of the symbols that are being used for each global import

It can easily be updated to also store the location for each of the usage sites for the imported symbols. By having the location you can approximate in what function you are in. That being said, it's not going to work with alias declarations and enums because those are eagerly substituted by the compiler when doing semantic analysis (the tool traverses the tree after sema was performed).

I think this small script can be used to at least automatically transform global imports into selective ones.

The fundamental problem with dmd as a library is that we still can't properly hook into the compiler internals. We are stuck to performing sema and then trying to extract information from the enriched tree, which kind of sucks.

RazvanN

July 16, 2024

On Tuesday, 16 July 2024 at 15:25:39 UTC, RazvanN wrote:

>

On Thursday, 11 July 2024 at 10:28:35 UTC, Atila Neves wrote:

>

[...]

I have a small program that uses dmd as a library that:

  • identifies unused global imports
  • provides a list of the symbols that are being used for each global import

[...]

Forgot to provide a link: https://github.com/RazvanN7/Unused-Import/blob/master/unused_import.d .

August 10

On Tuesday, 16 July 2024 at 15:27:09 UTC, RazvanN wrote:

>

Forgot to provide a link: https://github.com/RazvanN7/Unused-Import/blob/master/unused_import.d .

It would be nice if we could expand on this and add support for dub, so this tool can go through the list of source files given by dub, with import paths also from dub. How difficult do you reckon this would be to implement on top of your proof-of-concept code?

August 10

On Sunday, 10 August 2025 at 11:39:14 UTC, Dejan Lekic wrote:

>

if we are nercoing, why wasnt it shipped in tools? or was it not usable?

1 2
Next ›   Last »