haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.61k stars 691 forks source link

Cross-cutting concerns between GHC & Cabal regarding Unit IDs & GHC reporting #8003

Open Kleidukos opened 2 years ago

Kleidukos commented 2 years ago

Context: When reporting about unused packages, GHC currently doesn't insert any information about the cabal component that is faulty. This results in an unhelpful output when multiple components get caught by the -Wunused-packages flag.

This is a behaviour that was reported in this GHC ticket, in which @mpickering and @michaelpj gave helpful insights.

In the discussion, @mpickering suggests that GHC could insert Unit IDs in the location part of a diagnostic.

This would make it appear as

Cabal-3.6.0.0-<sha256>: error: [-Wunused-packages, -Werror=unused-packages]
    The following packages were specified via -package or -package-id flags,
    but were not needed for compilation:
      - postgresql-simple-0.6.4

and especially notes about unit Ids:

It's an internal detail. I suggest that it's up to Cabal to more clearly separate the output into components with readable names if desired

I think this is one case where such a distinction is desired. An optimal output would be:

lib:libraryName: error: [-Wunused-packages, -Werror=unused-packages]
    The following packages were specified via -package or -package-id flags,
    but were not needed for compilation:
      - postgresql-simple-0.6.4
michaelpj commented 2 years ago

Note that this generally applies to errors that the user sees when Cabal is compiling multiple components. Even simple errors can be hard to locate in their originating component. A classic example is:

Main.hs:44:70: error:
    Not in scope: ‘X’

Which Main.hs? If you have a few executables or test suites, you might have many!

It would be great if cabal could disambiguate all such errors. The simplest way would be to prefix the name of the component before all output lines from building that component.