Skip to content

-Wunused-packages false negatives

Summary

Sometimes, removing the last import for a dependency doesn't trigger -Wunused-package. That's not that big of a deal by itself, but then later on, changing something unrelated might cause -Wunused-package to start being triggered again. Sometimes when this happens, running stack purge (to delete all GHC build artifacts) and building again goes back to it being a false negative.

In my current situation:

  1. I removed the last use of Data.DList from dlist in package A without removing it as a dependency, and GHC did not error with -Wunused-package
  2. I started working on a branch, where I didn't touch package A, but I edited package B which package A depends on
    • Note: package B doesn't have dlist as a dependency, but it does depend on package C, which does have dlist as a dependency
  3. Suddenly package A starts failing with -Wunused-package
  4. Cleaning my build environment with stack purge and rebuilding causes package A to stop erroring again (as a false negative)

I know the docs say GHC makes a best effort to find unused packages, and I know there are bound to be times where it doesn't find all of them. That being said, there are a few possible outcomes I can see for this ticket:

  • Close as won't fix
  • Fix the minimal repro as an incremental improvement to the warning
  • Keep this issue open as a central hub for all -Wunused-package false negative reports
  • Add documentation as to when you might see false negatives, and when those false negatives might start becoming true negatives

Steps to reproduce

Here's a minimal repro that shows the behavior I see, but it's different in that in my project, I didn't change parent at all.

minimal-repro.tar.gz

Expected behavior

In the minimal repro, -Wunused-packages should be triggered regardless of whether Generic is derived.

Environment

  • GHC version used: 8.10.4

Optional:

  • Operating System: MacOS
  • System Architecture:
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information