unison
unison copied to clipboard
enable dead code cleanup
Is your feature request related to a problem? Please describe.
When I refactor things, there are often definitions that are no longer needed, but it can be difficult to identify which ones they are.
Describe the solution you'd like
I think the simplest solution is a UCM command returns all of the definitions for which dependents is empty.
Describe alternatives you've considered
The simple approach will have lots of false positives – some of the “public API”, many doc terms, tests[^1]. And ideally the public API would be mentioned in README or other docs. A bit more explicitly, there could be something like an export list that could at least silence unused definitions that are intended to be part of the API.
But also false negatives – out-of-date docs that reference otherwise unused functions.
Finally, there are the transitively unused definitions – ones whose dependents only include other unused definitions. But unless there is some kind of “root” (like an export list and/or tests), this would include every definition.
Other languages have some tooling around this (e.g., Weeder in Haskell, as well as export lists at the module level), but Unison is different enough that these don’t fit well off the rack (e.g., other languages don’t have docs that are terms in the language creating false negatives). I don’t have a concrete suggestion for anything better than the simplest solution, but I bet Unison could end up with something pretty magical for this.
[^1]: Since tests get run automatically, they should always be considered dependencies of something.
One other piece of the puzzle might be a UCM command like tree that does a recursive ls