-
Notifications
You must be signed in to change notification settings - Fork 724
Description
Describe the bug
Distribution.Compat.Prelude currently imports GHC.Generics in a suspicious way:
| import GHC.Generics (Generic, K1 (unK1), M1 (unM1), Rep (..), U1 (U1), V1, (:*:) ((:*:)), (:+:) (L1, R1)) |
In particular, note the Rep (..) part. What does this mean? Rep is an associated type family of Generic, and there are no other identifiers "associated" with an associated type family. What's more, this line imports Generic without importing any of its methods (from and to), despite the fact that from is used later in the module:
| genericRnf = grnf . from |
The fact that this compiles at all is a lucky fluke. See GHC#23570. What's more, it's fragile: if GHC.Generics were to be refactored such that it re-exports the Generic class from a different module, then GHC would reject this code. I actually encountered this issue in practice in some in-progress GHC work that I'm doing (see here if you're curious), so this line of code in Cabal-syntax stands in the way of that work.
To Reproduce
At the moment, there's no issue with any released versions of GHC (and therefore nothing to reproduce). The only way to reproduce an actual build failure would be to compile Cabal-syntax with the development version of GHC contained in this in-progress merge request.
Expected behavior
I think the import should instead be this, which avoids any of the issues in GHC#23570:
diff --git a/Cabal-syntax/src/Distribution/Compat/Prelude.hs b/Cabal-syntax/src/Distribution/Compat/Prelude.hs
index 5edf0d92e..3cbf3c17a 100644
--- a/Cabal-syntax/src/Distribution/Compat/Prelude.hs
+++ b/Cabal-syntax/src/Distribution/Compat/Prelude.hs
@@ -248,7 +248,7 @@ import Data.Word (Word, Word16, Word32, Word64, Word8)
import Distribution.Compat.Binary (Binary (..))
import Distribution.Compat.Semigroup (Semigroup (..), gmappend, gmempty)
import Distribution.Compat.Typeable (TypeRep, Typeable, typeRep)
-import GHC.Generics (Generic, K1 (unK1), M1 (unM1), Rep (..), U1 (U1), V1, (:*:) ((:*:)), (:+:) (L1, R1))
+import GHC.Generics (Generic (..), K1 (unK1), M1 (unM1), U1 (U1), V1, (:*:) ((:*:)), (:+:) (L1, R1))
import System.Exit (ExitCode (..), exitFailure, exitSuccess, exitWith)
import Text.Read (readMaybe)