Allow ignoring duplicate imports warnings for identifiers from Prelude
Motivation
There's been a general trend to re-export more things from Prelude
. In my opinion this is a good trend.
A recent example is the addition of Control.Applicative.liftA2
to Prelude
in ghc-9.6
.
I've recently helped prepare a codebase for 9.8
and a bunch of source files had to be updated to not trigger -Wredundant-imports
warnings.
Our codebase, as is common in industry, uses -Wall
. This warning is often a helpful one. It helps avoid overly long import lists, and is especially helpful with workflows where people use HLS or another automated tool that adds imports automatically (and sometimes overzealously).
So, there's two good things that are coming into conflict and causing a bit of churn, namely we need to update our imports whenever stuff is newly re-exported from Prelude
. I imagine this is even worse for library authors where you want to support several versions of base
, so you either have to ignore/disable this warning or use CPP.
While splitting the warning into two is helpful, it doesn't solve this issue, since I would like to get warnings on duplicate imports of identifiers -- just not ones from Prelude
. For the rest of this I'll assume that's been implemented.
Proposal
I think we could avoid this conflict by allowing one to opt-out of -Wduplicate-imports
warnings for duplicated identifiers exported from Prelude
.
I think this could come in one of two forms:
-
-Wno-duplicate-imports-from-prelude
explicitly opt-out ofPrelude
warnings. This might seem ad-hoc, butPrelude
is special anyway. -
-Wno-duplicate-imports=Prelude
. Allow opting out of specific modules. This is less ad-hoc but slightly more complicated. The semantics would be: not specifying a module selects all modules, and then specifying a specific module let's you opt-in/-out for that module.
In either case, such a feature would allow avoiding this papercut. This would be helpful for users like me who do care about redundant duplicated imports, but who don't want to update a bunch of imports when stuff is added to base
.
What do folks think? Would something like this require a GHC proposal (I'm guessing yes but I wanted to double-check)?