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

616 views Asked by At

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.

2

There are 2 answers

2
Jon Purdy On BEST ANSWER

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.

0
alias On

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.