Skip to content

Lifted type variables kinds are often not expressed in terms of Type

While looking at !4612 (merged) I noticed that if we disable the equation in GHC.Iface.Type.isIfaceLiftedTypeKind that identifies types that are equivalent to Type but not expressed in terms of the type synonym then we see changes in test output.

Specifically, this patch:

diff --git a/compiler/GHC/Iface/Type.hs b/compiler/GHC/Iface/Type.hs
index eaba819a74..513aa31e30 100644
--- a/compiler/GHC/Iface/Type.hs
+++ b/compiler/GHC/Iface/Type.hs
@@ -419,8 +419,6 @@ ifaceTyConHasKey tc key = ifaceTyConName tc `hasKey` key
 isIfaceLiftedTypeKind :: IfaceKind -> Bool
 isIfaceLiftedTypeKind (IfaceTyConApp tc IA_Nil)
   = isLiftedTypeKindTyConName (ifaceTyConName tc)
-isIfaceLiftedTypeKind (IfaceTyConApp tc1 args1)
-  = isIfaceTyConAppLiftedTypeKind tc1 args1
 isIfaceLiftedTypeKind _ = False
 
 -- | Given a kind constructor K and arguments A, returns true if

results in changes like this one in T8851:

--- "/run/user/1000/ghctest-5ay_76ps/test   spaces/testsuite/tests/deriving/should_fail/T8851.run/T8851.stderr.normalised"      2021-03-01 19:51:15.152529605 -0500
+++ "/run/user/1000/ghctest-5ay_76ps/test   spaces/testsuite/tests/deriving/should_fail/T8851.run/T8851.comp.stderr.normalised" 2021-03-01 19:51:15.153529600 -0500
@@ -2,10 +2,10 @@
 T8851.hs:24:12:
     Couldn't match type ‘Parser’ with ‘MyParser’
       arising from the coercion of the method ‘notFollowedBy’
-        from type ‘forall a.
+          from type ‘forall (a :: *).
                    (Monad Parser, Show a) =>
                    Parser a -> Parser ()’
-          to type ‘forall a.
+            to type ‘forall (a :: *).
                    (Monad MyParser, Show a) =>
                    MyParser a -> MyParser ()’
     When deriving the instance for (Parsing MyParser)

This suggests that there are many places (specifically in type variables kinds) that are not benefitting from the optimisation described in Note [Prefer Type over TYPE 'LiftedRep]. This deserves investigation.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information