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

2

11

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.

Shieh answered 23/8, 2013 at 18:28 Comment(0)
D
8

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.

Dunbar answered 24/8, 2013 at 6:46 Comment(2)
Thanks. I had considered about the code coverage route but thought I'd see if there was a better way. Maybe that's the quickest route to what I need. SourceGraph is something I'd not heard of. I tried to install it but have a bunch of version incompatibilities. Sigh. I'll try to resolve these on Monday or Tuesday (unless the code coverage works well).Shieh
I could not get Graphalyze to compile, and SourceGraph depends on it. Too bad because it looks as though there's a lot of useful information provided. I had a look at the code coverage tool and I will be able to answer my immediate question from it's output. So, my question is answered. Thanks!Shieh
A
1

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.

Aftercare answered 10/8, 2020 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.