Find unused exports

Hello, Has anyone already made a tool to check if exported functions, data constructors, types, etc are unused within a set of modules? For my usage it would probably suffice if the tool only compared import lists against export lists as we compile with -Wall and 99% of our imports say exactly which names are imported (and that last 1% could easily be fixed to say as well). If the tool doesn't already exist is there an easy way to approximate it? Thanks, Jason

dagit:
Hello,
Has anyone already made a tool to check if exported functions, data constructors, types, etc are unused within a set of modules?
For my usage it would probably suffice if the tool only compared import lists against export lists as we compile with -Wall and 99% of our imports say exactly which names are imported (and that last 1% could easily be fixed to say as well).
If the tool doesn't already exist is there an easy way to approximate it?
Have you used the minimal imports flag? That might hint at what /exports/ can also be removed. -- Don

The relevant flag is: -ddump-minimal-imports
See http://www.haskell.org/ghc/docs/latest/html/users_guide/flag-reference.html#...
2008/11/15 Jason Dagit
Hello,
Has anyone already made a tool to check if exported functions, data constructors, types, etc are unused within a set of modules?
For my usage it would probably suffice if the tool only compared import lists against export lists as we compile with -Wall and 99% of our imports say exactly which names are imported (and that last 1% could easily be fixed to say as well).
If the tool doesn't already exist is there an easy way to approximate it?
Thanks, Jason _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Push the envelope. Watch it bend.

On Sun, Nov 16, 2008 at 5:35 AM, Thomas Schilling
The relevant flag is: -ddump-minimal-imports
See http://www.haskell.org/ghc/docs/latest/html/users_guide/flag-reference.html#...
The documentation says this:
-ddump-minimal-imports
Dump to the file "M.imports" (where M is the module being compiled) a "minimal" set of import declarations. You can safely replace all the import declarations in "M.hs" with those found in "M.imports". Why would you want to do that? Because the "minimal" imports (a) import everything explicitly, by name, and (b) import nothing that is not required. It can be quite painful to maintain this property by hand, so this flag is intended to reduce the labour.
I already know the minimal set of import for the modules. That's why I mentioned using -Wall; ghc will complain if you import something and don't use it. The problem is that you can export names that never get used in other modules. I would like a tool that can look over a project and tell me which exported names are never imported. These names correspond to things that can be removed from the project. Thanks, Jason

Within a set of modules, the minimal imports also give you the minimal
exports since each minimal export is required because it is imported
somewhere. Just compile all your modules with -ddump-minimal-imports,
then cat all your "*.import" files together and sort the result. The
minimal exports for module Foo will be listed as several lines of the
form "import Foo(x,y,z)", etc. From there on it's just a bit of text
munging to get it into your export list code (about two lines of
perl).
Michael D. Adams
2008/11/16 Jason Dagit
On Sun, Nov 16, 2008 at 5:35 AM, Thomas Schilling
wrote: The relevant flag is: -ddump-minimal-imports
See http://www.haskell.org/ghc/docs/latest/html/users_guide/flag-reference.html#...
The documentation says this:
-ddump-minimal-imports
Dump to the file "M.imports" (where M is the module being compiled) a "minimal" set of import declarations. You can safely replace all the import declarations in "M.hs" with those found in "M.imports". Why would you want to do that? Because the "minimal" imports (a) import everything explicitly, by name, and (b) import nothing that is not required. It can be quite painful to maintain this property by hand, so this flag is intended to reduce the labour.
I already know the minimal set of import for the modules. That's why I mentioned using -Wall; ghc will complain if you import something and don't use it.
The problem is that you can export names that never get used in other modules. I would like a tool that can look over a project and tell me which exported names are never imported. These names correspond to things that can be removed from the project.
Thanks, Jason
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, Nov 16, 2008 at 5:10 PM, Michael D. Adams
Within a set of modules, the minimal imports also give you the minimal exports since each minimal export is required because it is imported somewhere. Just compile all your modules with -ddump-minimal-imports, then cat all your "*.import" files together and sort the result. The minimal exports for module Foo will be listed as several lines of the form "import Foo(x,y,z)", etc. From there on it's just a bit of text munging to get it into your export list code (about two lines of perl).
Alright, that's the same manual process I do now. I didn't use -ddump-minimal-imports before because I didn't know about it and we maintain sufficiently minimal imports already. That and I used emacs macros instead of perl because I already know how to use emacs :) If I take the time to automate this I wonder if it's a worthwhile tool to upload to hackage. Sounds like others have been doing this sort of thing. Now if I just had a round touit... Thanks everyone! Jason

Jason Dagit
Hello,
Has anyone already made a tool to check if exported functions, data constructors, types, etc are unused within a set of modules?
My SourceGraph programme (available on Hackage) can do this with a few caveats: 1) Only supports functions, not data constructors, types, etc. 2) The project must be Cabalized 3) The functions exported must not be available from the library (though if it's an executable, then it will return all non-called functions that aren't called "main").
For my usage it would probably suffice if the tool only compared import lists against export lists
This is basically what SourceGraph does. Note that it hasn't been upgraded to GHC-6.10 yet, nor the HSE-4 series.

On Mon, Nov 17, 2008 at 4:36 PM, Ivan Lazar Miljenovic < Ivan.Miljenovic@gmail.com> wrote:
Jason Dagit
writes: Hello,
Has anyone already made a tool to check if exported functions, data constructors, types, etc are unused within a set of modules?
My SourceGraph programme (available on Hackage) can do this with a few caveats: 1) Only supports functions, not data constructors, types, etc. 2) The project must be Cabalized 3) The functions exported must not be available from the library (though if it's an executable, then it will return all non-called functions that aren't called "main").
Those restrictions should fit my case very well. I have a .cabal file, I'm mainly interested in functions, and it's just an executable not a library.
For my usage it would probably suffice if the tool only compared import lists against export lists
This is basically what SourceGraph does.
Note that it hasn't been upgraded to GHC-6.10 yet, nor the HSE-4 series.
I don't think that will be a problem. I still haven't upgraded to 6.10 due to it uninstalling 6.8 (has anyone fixed this on osx yet?). And we don't use view patterns so HSE-4 is hopefully not needed. Thanks, Jason
participants (5)
-
Don Stewart
-
Ivan Lazar Miljenovic
-
Jason Dagit
-
Michael D. Adams
-
Thomas Schilling