summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-06-23 17:50:15 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-06-28 09:19:46 -0400
commit42f797b0ad034a92389e7081aa50ef4ab3434d01 (patch)
tree8a198d5f6b2e51fe3578586c44445d76dbe4e96d /testsuite/tests/deriving
parentd8ba9e6f951a2f8c6e2429a8b2dcb035c392908f (diff)
downloadhaskell-42f797b0ad034a92389e7081aa50ef4ab3434d01.tar.gz
Use NHsCoreTy to embed types into GND-generated code
`GeneralizedNewtypeDeriving` is in the unique situation where it must produce an `LHsType GhcPs` from a Core `Type`. Historically, this was done with the `typeToLHsType` function, which walked over the entire `Type` and attempted to construct an `LHsType` with the same overall structure. `typeToLHsType` is quite complicated, however, and has been the subject of numerous bugs over the years (e.g., #14579). Luckily, there is an easier way to accomplish the same thing: the `XHsType` constructor of `HsType`. `XHsType` bundles an `NHsCoreTy`, which allows embedding a Core `Type` directly into an `HsType`, avoiding the need to laboriously convert from one to another (as `typeToLHsType` did). Moreover, renaming and typechecking an `XHsType` is simple, since one doesn't need to do anything to a Core `Type`... ...well, almost. For the reasons described in `Note [Typechecking NHsCoreTys]` in `GHC.Tc.Gen.HsType`, we must apply a substitution that we build from the local `tcl_env` type environment. But that's a relatively modest price to pay. Now that `GeneralizedNewtypeDeriving` uses `NHsCoreTy`, the `typeToLHsType` function no longer has any uses in GHC, so this patch rips it out. Some additional tweaks to `hsTypeNeedsParens` were necessary to make the new `-ddump-deriv` output correctly parenthesized, but other than that, this patch is quite straightforward. This is a mostly internal refactoring, although it is likely that `GeneralizedNewtypeDeriving`-generated code will now need fewer language extensions in certain situations than it did before.
Diffstat (limited to 'testsuite/tests/deriving')
-rw-r--r--testsuite/tests/deriving/should_compile/T14578.stderr49
-rw-r--r--testsuite/tests/deriving/should_compile/T14579.stderr30
-rw-r--r--testsuite/tests/deriving/should_fail/T15073.stderr3
-rw-r--r--testsuite/tests/deriving/should_fail/deriving-via-fail5.stderr4
4 files changed, 37 insertions, 49 deletions
diff --git a/testsuite/tests/deriving/should_compile/T14578.stderr b/testsuite/tests/deriving/should_compile/T14578.stderr
index 58376989db..0018ebe569 100644
--- a/testsuite/tests/deriving/should_compile/T14578.stderr
+++ b/testsuite/tests/deriving/should_compile/T14578.stderr
@@ -9,18 +9,20 @@ Derived class instances:
GHC.Base.sconcat ::
GHC.Base.NonEmpty (T14578.Wat f g a) -> T14578.Wat f g a
GHC.Base.stimes ::
- forall (b :: TYPE 'GHC.Types.LiftedRep).
- GHC.Real.Integral b => b -> T14578.Wat f g a -> T14578.Wat f g a
+ forall b.
+ GHC.Real.Integral b =>
+ b -> T14578.Wat f g a -> T14578.Wat f g a
(GHC.Base.<>)
= GHC.Prim.coerce
@(T14578.App (Data.Functor.Compose.Compose f g) a
-> T14578.App (Data.Functor.Compose.Compose f g) a
- -> T14578.App (Data.Functor.Compose.Compose f g) a)
+ -> T14578.App (Data.Functor.Compose.Compose f g) a)
@(T14578.Wat f g a -> T14578.Wat f g a -> T14578.Wat f g a)
((GHC.Base.<>) @(T14578.App (Data.Functor.Compose.Compose f g) a))
GHC.Base.sconcat
= GHC.Prim.coerce
- @(GHC.Base.NonEmpty (T14578.App (Data.Functor.Compose.Compose f g) a)
+ @(GHC.Base.NonEmpty
+ (T14578.App (Data.Functor.Compose.Compose f g) a)
-> T14578.App (Data.Functor.Compose.Compose f g) a)
@(GHC.Base.NonEmpty (T14578.Wat f g a) -> T14578.Wat f g a)
(GHC.Base.sconcat
@@ -29,7 +31,7 @@ Derived class instances:
= GHC.Prim.coerce
@(b
-> T14578.App (Data.Functor.Compose.Compose f g) a
- -> T14578.App (Data.Functor.Compose.Compose f g) a)
+ -> T14578.App (Data.Functor.Compose.Compose f g) a)
@(b -> T14578.Wat f g a -> T14578.Wat f g a)
(GHC.Base.stimes
@(T14578.App (Data.Functor.Compose.Compose f g) a))
@@ -37,13 +39,8 @@ Derived class instances:
instance GHC.Base.Functor f =>
GHC.Base.Functor (T14578.App f) where
GHC.Base.fmap ::
- forall (a :: TYPE 'GHC.Types.LiftedRep)
- (b :: TYPE 'GHC.Types.LiftedRep).
- (a -> b) -> T14578.App f a -> T14578.App f b
- (GHC.Base.<$) ::
- forall (a :: TYPE 'GHC.Types.LiftedRep)
- (b :: TYPE 'GHC.Types.LiftedRep).
- a -> T14578.App f b -> T14578.App f a
+ forall a b. (a -> b) -> T14578.App f a -> T14578.App f b
+ (GHC.Base.<$) :: forall a b. a -> T14578.App f b -> T14578.App f a
GHC.Base.fmap
= GHC.Prim.coerce
@((a -> b) -> f a -> f b)
@@ -55,25 +52,17 @@ Derived class instances:
instance GHC.Base.Applicative f =>
GHC.Base.Applicative (T14578.App f) where
- GHC.Base.pure ::
- forall (a :: TYPE 'GHC.Types.LiftedRep). a -> T14578.App f a
+ GHC.Base.pure :: forall a. a -> T14578.App f a
(GHC.Base.<*>) ::
- forall (a :: TYPE 'GHC.Types.LiftedRep)
- (b :: TYPE 'GHC.Types.LiftedRep).
+ forall a b.
T14578.App f (a -> b) -> T14578.App f a -> T14578.App f b
GHC.Base.liftA2 ::
- forall (a :: TYPE 'GHC.Types.LiftedRep)
- (b :: TYPE 'GHC.Types.LiftedRep)
- (c :: TYPE 'GHC.Types.LiftedRep).
+ forall a b c.
(a -> b -> c) -> T14578.App f a -> T14578.App f b -> T14578.App f c
(GHC.Base.*>) ::
- forall (a :: TYPE 'GHC.Types.LiftedRep)
- (b :: TYPE 'GHC.Types.LiftedRep).
- T14578.App f a -> T14578.App f b -> T14578.App f b
+ forall a b. T14578.App f a -> T14578.App f b -> T14578.App f b
(GHC.Base.<*) ::
- forall (a :: TYPE 'GHC.Types.LiftedRep)
- (b :: TYPE 'GHC.Types.LiftedRep).
- T14578.App f a -> T14578.App f b -> T14578.App f a
+ forall a b. T14578.App f a -> T14578.App f b -> T14578.App f a
GHC.Base.pure
= GHC.Prim.coerce
@(a -> f a) @(a -> T14578.App f a) (GHC.Base.pure @f)
@@ -105,15 +94,13 @@ Derived type family instances:
==================== Filling in method body ====================
-GHC.Base.Semigroup [T14578.App f[ssk:1] a[ssk:1]]
- GHC.Base.sconcat = GHC.Base.$dmsconcat
- @(T14578.App f[ssk:1] a[ssk:1])
+GHC.Base.Semigroup [T14578.App f a]
+ GHC.Base.sconcat = GHC.Base.$dmsconcat @(T14578.App f a)
==================== Filling in method body ====================
-GHC.Base.Semigroup [T14578.App f[ssk:1] a[ssk:1]]
- GHC.Base.stimes = GHC.Base.$dmstimes
- @(T14578.App f[ssk:1] a[ssk:1])
+GHC.Base.Semigroup [T14578.App f a]
+ GHC.Base.stimes = GHC.Base.$dmstimes @(T14578.App f a)
diff --git a/testsuite/tests/deriving/should_compile/T14579.stderr b/testsuite/tests/deriving/should_compile/T14579.stderr
index 81212022ef..31545c6de7 100644
--- a/testsuite/tests/deriving/should_compile/T14579.stderr
+++ b/testsuite/tests/deriving/should_compile/T14579.stderr
@@ -8,34 +8,36 @@ Derived class instances:
T14579.Glurp a -> T14579.Glurp a -> GHC.Types.Bool
(GHC.Classes.==)
= GHC.Prim.coerce
- @(T14579.Wat @a ('Data.Proxy.Proxy @a)
- -> T14579.Wat @a ('Data.Proxy.Proxy @a) -> GHC.Types.Bool)
+ @(T14579.Wat 'Data.Proxy.Proxy
+ -> T14579.Wat 'Data.Proxy.Proxy -> GHC.Types.Bool)
@(T14579.Glurp a -> T14579.Glurp a -> GHC.Types.Bool)
- ((GHC.Classes.==) @(T14579.Wat @a ('Data.Proxy.Proxy @a)))
+ ((GHC.Classes.==) @(T14579.Wat 'Data.Proxy.Proxy))
(GHC.Classes./=)
= GHC.Prim.coerce
- @(T14579.Wat @a ('Data.Proxy.Proxy @a)
- -> T14579.Wat @a ('Data.Proxy.Proxy @a) -> GHC.Types.Bool)
+ @(T14579.Wat 'Data.Proxy.Proxy
+ -> T14579.Wat 'Data.Proxy.Proxy -> GHC.Types.Bool)
@(T14579.Glurp a -> T14579.Glurp a -> GHC.Types.Bool)
- ((GHC.Classes./=) @(T14579.Wat @a ('Data.Proxy.Proxy @a)))
+ ((GHC.Classes./=) @(T14579.Wat 'Data.Proxy.Proxy))
instance forall a (x :: Data.Proxy.Proxy a).
GHC.Classes.Eq a =>
GHC.Classes.Eq (T14579.Wat x) where
(GHC.Classes.==) ::
- T14579.Wat @a x -> T14579.Wat @a x -> GHC.Types.Bool
+ T14579.Wat x[sk:1] -> T14579.Wat x[sk:1] -> GHC.Types.Bool
(GHC.Classes./=) ::
- T14579.Wat @a x -> T14579.Wat @a x -> GHC.Types.Bool
+ T14579.Wat x[sk:1] -> T14579.Wat x[sk:1] -> GHC.Types.Bool
(GHC.Classes.==)
= GHC.Prim.coerce
- @(GHC.Maybe.Maybe a -> GHC.Maybe.Maybe a -> GHC.Types.Bool)
- @(T14579.Wat @a x -> T14579.Wat @a x -> GHC.Types.Bool)
- ((GHC.Classes.==) @(GHC.Maybe.Maybe a))
+ @(GHC.Maybe.Maybe a[sk:1]
+ -> GHC.Maybe.Maybe a[sk:1] -> GHC.Types.Bool)
+ @(T14579.Wat x[sk:1] -> T14579.Wat x[sk:1] -> GHC.Types.Bool)
+ ((GHC.Classes.==) @(GHC.Maybe.Maybe a[sk:1]))
(GHC.Classes./=)
= GHC.Prim.coerce
- @(GHC.Maybe.Maybe a -> GHC.Maybe.Maybe a -> GHC.Types.Bool)
- @(T14579.Wat @a x -> T14579.Wat @a x -> GHC.Types.Bool)
- ((GHC.Classes./=) @(GHC.Maybe.Maybe a))
+ @(GHC.Maybe.Maybe a[sk:1]
+ -> GHC.Maybe.Maybe a[sk:1] -> GHC.Types.Bool)
+ @(T14579.Wat x[sk:1] -> T14579.Wat x[sk:1] -> GHC.Types.Bool)
+ ((GHC.Classes./=) @(GHC.Maybe.Maybe a[sk:1]))
Derived type family instances:
diff --git a/testsuite/tests/deriving/should_fail/T15073.stderr b/testsuite/tests/deriving/should_fail/T15073.stderr
index 129efe496d..f39fd19bbc 100644
--- a/testsuite/tests/deriving/should_fail/T15073.stderr
+++ b/testsuite/tests/deriving/should_fail/T15073.stderr
@@ -2,8 +2,7 @@
T15073.hs:8:12: error:
• Illegal unboxed tuple type as function argument: (# Foo a #)
Perhaps you intended to use UnboxedTuples
- • In the type signature:
- p :: Foo a -> Solo# @'GHC.Types.LiftedRep (Foo a)
+ • In the type signature: p :: Foo a -> (# Foo a #)
When typechecking the code for ‘p’
in a derived instance for ‘P (Foo a)’:
To see the code I am typechecking, use -ddump-deriv
diff --git a/testsuite/tests/deriving/should_fail/deriving-via-fail5.stderr b/testsuite/tests/deriving/should_fail/deriving-via-fail5.stderr
index a0a19ab65d..497e955896 100644
--- a/testsuite/tests/deriving/should_fail/deriving-via-fail5.stderr
+++ b/testsuite/tests/deriving/should_fail/deriving-via-fail5.stderr
@@ -59,12 +59,12 @@ deriving-via-fail5.hs:8:1: error:
at deriving-via-fail5.hs:(8,1)-(9,24)
• In the expression:
GHC.Prim.coerce
- @([] (Identity b) -> ShowS) @([] (Foo4 a) -> ShowS)
+ @([Identity b] -> ShowS) @([Foo4 a] -> ShowS)
(showList @(Identity b))
In an equation for ‘showList’:
showList
= GHC.Prim.coerce
- @([] (Identity b) -> ShowS) @([] (Foo4 a) -> ShowS)
+ @([Identity b] -> ShowS) @([Foo4 a] -> ShowS)
(showList @(Identity b))
When typechecking the code for ‘showList’
in a derived instance for ‘Show (Foo4 a)’: