Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dead code and/or how to generate a cross reference from Haskell source

I've got some unused functionality in my codebase, but it's hard to identify. The code has evolved over the last year as I explore its problem space and possible solutions. What I'm needing to do is find that unused code so I can get rid of it. I'm happy if it deals with the problem on an exportable name basis.GHC has warnings that deal with non-exported unused code. Any tools specific to this task would be of interest.

However, I'm curious about a comprehensive cross referencing tool. I can find the unused code with such a tool. Years ago when I was working in C and assembler, I found that a good xref was a pretty handy tool, useful for many different purposes.

I'm getting nowhere with googling. Apparently in Haskell the dominant meaning of cross-reference is within literate programming. Though maybe something there would be useful.

like image 707
hutch Avatar asked Aug 23 '13 18:08

hutch


2 Answers

I don’t know of such a tool, so in the past I have done a bit of a hack instead.

If you have a comprehensive test suite, you can run it with GHC’s code coverage tracing enabled. Compile with -fhpc and use hpc markup to generate annotated source. This gives you the union of unused code and untested code, both of which you would probably like to address anyway.

SourceGraph can give you a bunch of information which you may also find useful.

like image 162
Jon Purdy Avatar answered Oct 21 '22 00:10

Jon Purdy


There is now a tool for this very purpose: https://hackage.haskell.org/package/weeder

It's been around since 2017, and while it has limitations, it definitely helps with large codebases.

like image 33
alias Avatar answered Oct 21 '22 01:10

alias