GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:23:13Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/13197Perplexing levity polymorphism issue2019-07-07T18:23:13ZBen GamariPerplexing levity polymorphism issueI would have expected this to compile since the levity polymorphism patch (along with [D2038](https://phabricator.haskell.org/D2038)) was merged, but sadly it seems the typechecker isn't quite clever enough yet (or perhaps I'm the not cl...I would have expected this to compile since the levity polymorphism patch (along with [D2038](https://phabricator.haskell.org/D2038)) was merged, but sadly it seems the typechecker isn't quite clever enough yet (or perhaps I'm the not clever one),
```hs
{-# LANGUAGE GADTs, PolyKinds, PatternSynonyms, RankNTypes,
TypeOperators, ViewPatterns #-}
{-# LANGUAGE TypeInType #-}
module Test where
import Data.Kind
import GHC.Exts
data TypeRep (a :: k) where
TypeCon :: String -> TypeRep a
TypeApp :: forall k1 k2 (f :: k1 -> k2) (x :: k1). TypeRep f -> TypeRep x -> TypeRep (f x)
TypeFun :: forall r1 r2 (a :: TYPE r1) (b :: TYPE r2). TypeRep a -> TypeRep b -> TypeRep (a -> b)
data SomeTypeRep where
SomeTypeRep :: forall k (a :: k). TypeRep a -> SomeTypeRep
data (a :: k1) :~~: (b :: k2) where
HRefl :: a :~~: a
eqTypeRep :: TypeRep (a :: k1) -> TypeRep (b :: k2) -> Maybe (a :~~: b)
eqTypeRep = undefined
typeRepKind :: forall (k :: *). forall (a :: k). TypeRep a -> TypeRep k
typeRepKind = undefined
toApp :: SomeTypeRep -> SomeTypeRep -> Maybe SomeTypeRep
toApp (SomeTypeRep f) (SomeTypeRep a)
| TypeFun arg res <- typeRepKind f
, Just HRefl <- arg `eqTypeRep` typeRepKind a
= Just $ SomeTypeRep (TypeApp f a)
toApp _ _ = Nothing
```8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13214Orphan instances in Backpack signatures don't work2019-07-07T18:23:09ZEdward Z. YangOrphan instances in Backpack signatures don't work```
unit p where
signature A where
instance Show (a -> b)
module B where
import A
f = show (\x -> x)
```
There are probably other problems too but here's the start.
<details><summary>Trac metadata</summa...```
unit p where
signature A where
instance Show (a -> b)
module B where
import A
f = show (\x -> x)
```
There are probably other problems too but here's the start.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Orphan instances in Backpack signatures don't work","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"ezyang"},"version":"8.1","keywords":["backpack"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\nunit p where\r\n signature A where\r\n instance Show (a -> b)\r\n module B where\r\n import A\r\n f = show (\\x -> x)\r\n}}}\r\n\r\nThere are probably other problems too but here's the start.","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Edward Z. YangEdward Z. Yanghttps://gitlab.haskell.org/ghc/ghc/-/issues/13249Default signature check can be quite onerous2019-07-07T18:22:49ZBen GamariDefault signature check can be quite onerousThe `bytes` library currently doesn't compile with GHC `master` due to the new check of default signatures (7363d5380e600e2ef868a069d5df6857d9e5c17e, #12918). Consider this example,
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE Defau...The `bytes` library currently doesn't compile with GHC `master` due to the new check of default signatures (7363d5380e600e2ef868a069d5df6857d9e5c17e, #12918). Consider this example,
```hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DefaultSignatures #-}
module Hi where
import Control.Monad.Trans.Class
class MonadGet m where
type Remaining m :: *
remaining :: m (Remaining m)
default remaining :: (MonadTrans t, MonadGet n, m ~ t n) => m (Remaining (t n))
remaining = lift remaining
```
Patching this up requires a fair amount of hand-holding,
```hs
default remaining :: (MonadTrans t, MonadGet n, m ~ t n, Remaining m ~ Remaining n, Monad n) => m (Remaining m)
```
Yuck.
I suppose this is just how the world works, but I thought I'd leave this here in case anyone had a clever idea for improvement.8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13250Backpack: matching newtype selectors doesn't work2019-07-07T18:22:47ZEdward Z. YangBackpack: matching newtype selectors doesn't work```
unit p where
signature A where
newtype F a = F { mkF :: a }
unit q where
module A where
newtype F a = F { mkF :: a }
unit r where
dependency p[A=q:A]
```
fails with
```
ezyang@sabre:~$ ghc-head --backpac...```
unit p where
signature A where
newtype F a = F { mkF :: a }
unit q where
module A where
newtype F a = F { mkF :: a }
unit r where
dependency p[A=q:A]
```
fails with
```
ezyang@sabre:~$ ghc-head --backpack selector.bkp -dppr-debug
[1 of 3] Processing p
[2 of 3] Processing q
Instantiating q
[1 of 1] Compiling A ( q/A.hs, q/A.o )
[3 of 3] Processing r
Instantiating r
[1 of 1] Including p[A=q:A]
Instantiating p[A=q:A]
[1 of 1] Compiling A[sig] ( p/A.hsig, p/p-HVmFlcYSefiK5n1aDP1v7x/A.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.1.20170123 for x86_64-unknown-linux):
TcIface.find_lbl
missing: mkF{v}
known labels: [mkF{q:A.mkF{v rb}}]
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1166:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1170:37 in ghc:Outputable
pprPanic, called at compiler/iface/TcIface.hs:841:41 in ghc:TcIface
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Backpack: matching newtype selectors doesn't work","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"ezyang"},"version":"8.1","keywords":["backpack"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\nunit p where\r\n signature A where\r\n newtype F a = F { mkF :: a }\r\nunit q where\r\n module A where\r\n newtype F a = F { mkF :: a }\r\nunit r where\r\n dependency p[A=q:A]\r\n}}}\r\n\r\nfails with\r\n\r\n{{{\r\nezyang@sabre:~$ ghc-head --backpack selector.bkp -dppr-debug\r\n[1 of 3] Processing p\r\n[2 of 3] Processing q\r\n Instantiating q\r\n [1 of 1] Compiling A ( q/A.hs, q/A.o )\r\n[3 of 3] Processing r\r\n Instantiating r\r\n [1 of 1] Including p[A=q:A]\r\n Instantiating p[A=q:A]\r\n [1 of 1] Compiling A[sig] ( p/A.hsig, p/p-HVmFlcYSefiK5n1aDP1v7x/A.o )\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.1.20170123 for x86_64-unknown-linux):\r\n\tTcIface.find_lbl\r\n missing: mkF{v}\r\n known labels: [mkF{q:A.mkF{v rb}}]\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1166:58 in ghc:Outputable\r\n callStackDoc, called at compiler/utils/Outputable.hs:1170:37 in ghc:Outputable\r\n pprPanic, called at compiler/iface/TcIface.hs:841:41 in ghc:TcIface\r\n\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Edward Z. YangEdward Z. Yanghttps://gitlab.haskell.org/ghc/ghc/-/issues/13272DeriveAnyClass regression involving a rigid type variable2019-07-07T18:22:39ZRyan ScottDeriveAnyClass regression involving a rigid type variableI was writing up an example to show off how `DeriveAnyClass` has improved since 639e702b6129f501c539b158b982ed8489e3d09c, and wouldn't you know it, the example doesn't actually compile anymore post-639e702b6129f501c539b158b982ed8489e3d09...I was writing up an example to show off how `DeriveAnyClass` has improved since 639e702b6129f501c539b158b982ed8489e3d09c, and wouldn't you know it, the example doesn't actually compile anymore post-639e702b6129f501c539b158b982ed8489e3d09c. Oopsie.
```hs
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module TypeName where
import GHC.Generics
class TypeName a where
typeName :: forall proxy.
proxy a -> String
default typeName :: forall proxy d f.
(Generic a, Rep a ~ D1 d f, Datatype d)
=> proxy a -> String
typeName _ = gtypeName $ from (undefined :: a)
gtypeName :: Datatype d => D1 d f p -> String
gtypeName = datatypeName
data T a = MkT a
deriving (Generic, TypeName)
```
This compiles before that commit. After it, however, it fails with the error:
```
[1 of 1] Compiling TypeName ( Bug.hs, interpreted )
Bug.hs:23:22: error:
• Couldn't match type ‘f’
with ‘C1
('MetaCons "MkT" 'PrefixI 'False)
(S1
('MetaSel
'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy)
(Rec0 a))’
arising from the 'deriving' clause of a data type declaration
‘f’ is a rigid type variable bound by
the deriving clause for ‘TypeName (T a)’ at Bug.hs:14:38
• When deriving the instance for (TypeName (T a))
|
23 | deriving (Generic, TypeName)
| ^^^^^^^^
```
I'm not sure why it's complaining only about `f` and not, say, `d`.8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13292Type checker rejects ambiguous top level declaration.2019-07-07T18:22:35ZjeieaType checker rejects ambiguous top level declaration.It doesn't seem like a serious problem, but I report it anyway.
With stack's project template, I just removed `main` and `someFunc`'s type signature and changed `someFunc`'s definition to `return ()`.
`stack build` worked well, but `sta...It doesn't seem like a serious problem, but I report it anyway.
With stack's project template, I just removed `main` and `someFunc`'s type signature and changed `someFunc`'s definition to `return ()`.
`stack build` worked well, but `stack repl` emitted this error message.
```
D:\ghc-corePrepPgm\app\Main.hs:6:1: warning: [-Wdeferred-type-errors]
• Couldn't match type ‘ghc-prim-0.5.0.0:GHC.Prim.Any’ with ‘IO’
Expected type: IO ()
Actual type: ghc-prim-0.5.0.0:GHC.Prim.Any ()
• In the expression: main
When checking the type of the IO action ‘main’
ghc.EXE: panic! (the 'impossible' happened)
(GHC version 8.0.2 for x86_64-unknown-mingw32):
corePrepPgm
[False] cobox_r1bo = typeError
@ 'VoidRep
@ (Any :: (* -> *)) ~# (IO :: (* -> *))
"D:\\ghc-corePrepPgm\\app\\Main.hs:6:1: error:\n\
\ \\226\\128\\162 Couldn't match type \\226\\128\\152ghc-prim-0.5.0.0:GHC.Prim.Any\\226\\128\\153 with \\226\\128\\152IO\\226\\128\\153\n\
\ Expected type: IO ()\n\
\ Actual type: ghc-prim-0.5.0.0:GHC.Prim.Any ()\n\
\ \\226\\128\\162 In the expression: main\n\
\ When checking the type of the IO action \\226\\128\\152main\\226\\128\\153\n\
\(deferred type error)"#
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Windows |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"panic! (the 'impossible' happened): corePrepPgm","status":"New","operating_system":"Windows","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"It doesn't seem like a serious problem, but I report it anyway.\r\n\r\nWith stack's project template, I just removed `main` and `someFunc`'s type signature and changed `someFunc`'s definition to `return ()`.\r\n`stack build` worked well, but `stack repl` emitted this error message.\r\n\r\n{{{\r\nD:\\ghc-corePrepPgm\\app\\Main.hs:6:1: warning: [-Wdeferred-type-errors]\r\n • Couldn't match type ‘ghc-prim-0.5.0.0:GHC.Prim.Any’ with ‘IO’\r\n Expected type: IO ()\r\n Actual type: ghc-prim-0.5.0.0:GHC.Prim.Any ()\r\n • In the expression: main\r\n When checking the type of the IO action ‘main’\r\nghc.EXE: panic! (the 'impossible' happened)\r\n (GHC version 8.0.2 for x86_64-unknown-mingw32):\r\n corePrepPgm\r\n [False] cobox_r1bo = typeError\r\n @ 'VoidRep\r\n @ (Any :: (* -> *)) ~# (IO :: (* -> *))\r\n \"D:\\\\ghc-corePrepPgm\\\\app\\\\Main.hs:6:1: error:\\n\\\r\n \\ \\\\226\\\\128\\\\162 Couldn't match type \\\\226\\\\128\\\\152ghc-prim-0.5.0.0:GHC.Prim.Any\\\\226\\\\128\\\\153 with \\\\226\\\\128\\\\152IO\\\\226\\\\128\\\\153\\n\\\r\n \\ Expected type: IO ()\\n\\\r\n \\ Actual type: ghc-prim-0.5.0.0:GHC.Prim.Any ()\\n\\\r\n \\ \\\\226\\\\128\\\\162 In the expression: main\\n\\\r\n \\ When checking the type of the IO action \\\\226\\\\128\\\\152main\\\\226\\\\128\\\\153\\n\\\r\n \\(deferred type error)\"#\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13311Audit shady uses of tcSplitSigmaTy2019-07-07T18:22:30ZRyan ScottAudit shady uses of tcSplitSigmaTyWhen fixing #12918, I ended up needing to introduce a helper function called `tcSplitNestedSigmaTys`, which is quite similar to `tcSplitSigmaTy`, except that it attempts to look through as many nested `forall`s as possible. (See the docu...When fixing #12918, I ended up needing to introduce a helper function called `tcSplitNestedSigmaTys`, which is quite similar to `tcSplitSigmaTy`, except that it attempts to look through as many nested `forall`s as possible. (See the documentation for `tcSplitNestedSigmaTys` [here](http://git.haskell.org/ghc.git/blob/611f998fd545b45167170d9e60b7d9147178f0a1:/compiler/typecheck/TcType.hs#l1378)).
In the process, I accidentally discovered a bug! First, consider this program:
```hs
{-# LANGUAGE RankNTypes #-}
module Bug where
class C a where
op :: forall b c. (Monoid b, Monoid c, Eq a) => a -> b -> c
```
This should be (and is) rejected, since we're trying to constrain `a` with `Eq` in `op`, but we don't have `-XConstraintedClassMethods` enabled. But what about this equivalent program?
```hs
{-# LANGUAGE RankNTypes #-}
module Bug where
class C a where
op :: forall b. Monoid b => forall c. Monoid c => Eq a => a -> b -> c
```
By the same logic, this should also be rejected. But in GHC 8.0.2, it wasn't! That's because we were checking for the presence of constrained class variables using `tcSplitSigmaTy`, which only gives you `Monoid b` as the constraint, totally ignoring the bogus constraint inside of `forall c. Monoid c => Eq a => a -> b -> c`.
When I fixed #12918 (a seemingly unrelated task), I ended up replacing that very use of `tcSplitSigmaTy` with `tcSplitNestedSigmaTys`. Now it gives you `(Monoid b, Monoid c, Eq a)` as expected when checking the constraints, and the second program is now rightly rejected on GHC HEAD.
But I fear that there may be many more bogus uses of `tcSplitSigmaTy`. I should go through and try flushing out bugs of a similar caliber, and see if subbing in `tcSplitNestedSigmaTys` fixes these bugs.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Task |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Audit shady uses of tcSplitSigmaTy","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.4.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Task","description":"When fixing #12918, I ended up needing to introduce a helper function called `tcSplitNestedSigmaTys`, which is quite similar to `tcSplitSigmaTy`, except that it attempts to look through as many nested `forall`s as possible. (See the documentation for `tcSplitNestedSigmaTys` [http://git.haskell.org/ghc.git/blob/611f998fd545b45167170d9e60b7d9147178f0a1:/compiler/typecheck/TcType.hs#l1378 here]).\r\n\r\nIn the process, I accidentally discovered a bug! First, consider this program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\nmodule Bug where\r\n\r\nclass C a where\r\n op :: forall b c. (Monoid b, Monoid c, Eq a) => a -> b -> c\r\n}}}\r\n\r\nThis should be (and is) rejected, since we're trying to constrain `a` with `Eq` in `op`, but we don't have `-XConstraintedClassMethods` enabled. But what about this equivalent program?\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\nmodule Bug where\r\n\r\nclass C a where\r\n op :: forall b. Monoid b => forall c. Monoid c => Eq a => a -> b -> c\r\n}}}\r\n\r\nBy the same logic, this should also be rejected. But in GHC 8.0.2, it wasn't! That's because we were checking for the presence of constrained class variables using `tcSplitSigmaTy`, which only gives you `Monoid b` as the constraint, totally ignoring the bogus constraint inside of `forall c. Monoid c => Eq a => a -> b -> c`.\r\n\r\nWhen I fixed #12918 (a seemingly unrelated task), I ended up replacing that very use of `tcSplitSigmaTy` with `tcSplitNestedSigmaTys`. Now it gives you `(Monoid b, Monoid c, Eq a)` as expected when checking the constraints, and the second program is now rightly rejected on GHC HEAD.\r\n\r\nBut I fear that there may be many more bogus uses of `tcSplitSigmaTy`. I should go through and try flushing out bugs of a similar caliber, and see if subbing in `tcSplitNestedSigmaTys` fixes these bugs.","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1Ryan ScottRyan Scotthttps://gitlab.haskell.org/ghc/ghc/-/issues/13320Unfortunate compiler loop when creating type loop (with UndecidableInstances)2019-07-07T18:22:27ZPtivalUnfortunate compiler loop when creating type loop (with UndecidableInstances)I'm afraid this will simply be seen as "that's what happens when you use UndecidableInstances", but I might as well document this issue I had.
Trying to play with a "Trees that Grow" syntax, I encountered an issue when making a mistake,...I'm afraid this will simply be seen as "that's what happens when you use UndecidableInstances", but I might as well document this issue I had.
Trying to play with a "Trees that Grow" syntax, I encountered an issue when making a mistake, that can be boiled down to the following:
```hs
{-# language ConstraintKinds, FlexibleContexts, TypeFamilies, UndecidableInstances #-}
module Loop where
import GHC.Exts (Constraint)
import Test.QuickCheck
type family X_Var ξ
data TermX ξ = Var (X_Var ξ)
type ForallX (φ :: * -> Constraint) ξ = ( φ (X_Var ξ) )
--genTerm :: ForallX Arbitrary ξ => Int -> Gen (TermX ξ)
genTerm 0 = Var <$> arbitrary
genTerm n = Var <$> genTerm (n - 1)
--instance ForallX Arbitrary ξ => Arbitrary (TermX ξ) where
--arbitrary = sized genTerm
```
This code will compile correctly, and generate:
```hs
genTerm :: (X_Var ξ ~ TermX ξ, Arbitrary (TermX ξ), Eq t, Num t) => t -> Gen (TermX ξ)
```
Which is correct (though, not the type I had intended, since my code had a mistake).
Now, if you uncomment the "instance" line only, the compiler will loop.
Adding the commented out type, of course, gives a type error where it's due.
I was just wondering whether this type of error fell within the "loops that should be caught by the compiler".8.2.1David FeuerDavid Feuerhttps://gitlab.haskell.org/ghc/ghc/-/issues/13324Allow PartialTypeSignatures in the instance context of a standalone deriving ...2019-07-07T18:22:26ZRyan ScottAllow PartialTypeSignatures in the instance context of a standalone deriving declarationCurrently, if you try to use a wildcard anywhere in an instance context, it will fail immediately:
```
$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
λ> instance _...Currently, if you try to use a wildcard anywhere in an instance context, it will fail immediately:
```
$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
λ> instance _ => Show (Maybe a)
<interactive>:1:10: error:
Wildcard ‘_’ not allowed
in an instance declaration for ‘Show’
```
But there's one situation where we could lift this restriction: the context of a standalone, derived instance declaration. That is, something like this:
```hs
deriving instance _ => Show (Maybe a)
```
Why? Because GHC already has the machinery needed to infer what the context should be (see [this part](http://git.haskell.org/ghc.git/blob/8a6b8c5fb96472d7c2e2cd1918950dd50f2fef71:/compiler/typecheck/TcDerivInfer.hs#l49) of `TcDerivInfer`), so if a user turned on `PartialTypeSignatures`, GHC could just fill in the wildcard with the inferred constraints.
The implementation won't be //that// easy, however, since we'd also have to watch out for trickery such as:
```hs
deriving instance (C a, _) => C (T a b c)
```
I only mentioned putting wildcards in a derived instance //context//, because I think allowing the use of wildcards elsewhere in the instance head might be too difficult to deal with. I mean, how would you fill in this, for example?
```hs
instance (_ a)
```
This mini-feature has a very practical application: it would allow users to wield the flexibility of `StandaloneDeriving` without having to manually type in the instance context every time. That is, users could type in these instances:
```hs
deriving instance _ => Data (T a b c)
deriving instance _ => Eq (T a b c)
```
Instead of their fully spelled-out, more laborious counterparts. This would be crucial for Template Haskell, as its ability to infer these contexts is quite limited (see #10607 for an example where this cropped up).
Idle thought: could this be generalized to work for the instance context of //any// instance declaration (and not just derived ones)? From an outside perspective, it seems like typechecking other instances would require inferring constraints in a fashion quite similar to that of derived instances. But I am not at all familiar with that part of the typechecker, so I might be totally off here.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Allow PartialTypeSignatures in the instance context of a standalone deriving declaration","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"Currently, if you try to use a wildcard anywhere in an instance context, it will fail immediately:\r\n\r\n{{{\r\n$ ghci\r\nGHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\nλ> instance _ => Show (Maybe a)\r\n\r\n<interactive>:1:10: error:\r\n Wildcard ‘_’ not allowed\r\n in an instance declaration for ‘Show’\r\n}}}\r\n\r\nBut there's one situation where we could lift this restriction: the context of a standalone, derived instance declaration. That is, something like this:\r\n\r\n{{{#!hs\r\nderiving instance _ => Show (Maybe a)\r\n}}}\r\n\r\nWhy? Because GHC already has the machinery needed to infer what the context should be (see [http://git.haskell.org/ghc.git/blob/8a6b8c5fb96472d7c2e2cd1918950dd50f2fef71:/compiler/typecheck/TcDerivInfer.hs#l49 this part] of `TcDerivInfer`), so if a user turned on `PartialTypeSignatures`, GHC could just fill in the wildcard with the inferred constraints.\r\n\r\nThe implementation won't be //that// easy, however, since we'd also have to watch out for trickery such as:\r\n\r\n{{{#!hs\r\nderiving instance (C a, _) => C (T a b c)\r\n}}}\r\n\r\nI only mentioned putting wildcards in a derived instance //context//, because I think allowing the use of wildcards elsewhere in the instance head might be too difficult to deal with. I mean, how would you fill in this, for example?\r\n\r\n{{{#!hs\r\ninstance (_ a)\r\n}}}\r\n\r\nThis mini-feature has a very practical application: it would allow users to wield the flexibility of `StandaloneDeriving` without having to manually type in the instance context every time. That is, users could type in these instances:\r\n\r\n{{{#!hs\r\nderiving instance _ => Data (T a b c)\r\nderiving instance _ => Eq (T a b c)\r\n}}}\r\n\r\nInstead of their fully spelled-out, more laborious counterparts. This would be crucial for Template Haskell, as its ability to infer these contexts is quite limited (see #10607 for an example where this cropped up).\r\n\r\nIdle thought: could this be generalized to work for the instance context of //any// instance declaration (and not just derived ones)? From an outside perspective, it seems like typechecking other instances would require inferring constraints in a fashion quite similar to that of derived instances. But I am not at all familiar with that part of the typechecker, so I might be totally off here.","type_of_failure":"OtherFailure","blocking":[]} -->8.6.1https://gitlab.haskell.org/ghc/ghc/-/issues/13333Typeable regression in GHC HEAD2019-07-07T18:22:24ZRyan ScottTypeable regression in GHC HEADI recently wrote some code while exploring a fix for #13327 that heavily uses poly-kinded `Typeable`. This compiles without issue on GHC 8.0.1 and 8.0.2:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGU...I recently wrote some code while exploring a fix for #13327 that heavily uses poly-kinded `Typeable`. This compiles without issue on GHC 8.0.1 and 8.0.2:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module DataCast where
import Data.Data
import GHC.Exts (Constraint)
data T (phantom :: k) = T
data D (p :: k -> Constraint) (x :: j) where
D :: forall (p :: k -> Constraint) (x :: k). p x => D p x
class Possibly p x where
possibly :: proxy1 p -> proxy2 x -> Maybe (D p x)
dataCast1T :: forall k c t (phantom :: k).
(Typeable k, Typeable t, Typeable phantom, Possibly Data phantom)
=> (forall d. Data d => c (t d))
-> Maybe (c (T phantom))
dataCast1T f = case possibly (Proxy :: Proxy Data) (Proxy :: Proxy phantom) of
Nothing -> Nothing
Just D -> gcast1 f
```
But on GHC HEAD, it barfs this error:
```
$ ~/Software/ghc2/inplace/bin/ghc-stage2 --interactive Bug.hs
GHCi, version 8.1.20170223: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling DataCast ( Bug.hs, interpreted )
Bug.hs:28:29: error:
• Could not deduce (Typeable T) arising from a use of ‘gcast1’
GHC can't yet do polykinded Typeable (T :: * -> *)
from the context: (Typeable k, Typeable t, Typeable phantom,
Possibly Data phantom)
bound by the type signature for:
dataCast1T :: (Typeable k, Typeable t, Typeable phantom,
Possibly Data phantom) =>
(forall d. Data d => c (t d)) -> Maybe (c (T phantom))
at Bug.hs:(22,1)-(25,35)
or from: (k ~ *, (phantom :: k) ~~ (x :: *), Data x)
bound by a pattern with constructor:
D :: forall k (p :: k -> Constraint) (x :: k). p x => D p x,
in a case alternative
at Bug.hs:28:23
• In the expression: gcast1 f
In a case alternative: Just D -> gcast1 f
In the expression:
case possibly (Proxy :: Proxy Data) (Proxy :: Proxy phantom) of
Nothing -> Nothing
Just D -> gcast1 f
|
28 | Just D -> gcast1 f
| ^^^^^^^^
```
That error message itself is hilariously strange, since GHC certainly has the power to do polykinded `Typeable` nowadays.
Marking as high priority since this is a regression—feel free to lower the priority if you disagree.8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13335Non-abstract types also have skolem nature2019-07-07T18:22:23ZEdward Z. YangNon-abstract types also have skolem natureIn #12680, we determined that abstract types from signatures need to be treated like skolem variables.
But it turns out other types from signatures also need to be treated like skolem variables too:
```
{-# LANGUAGE GADTs #-}
unit p wh...In #12680, we determined that abstract types from signatures need to be treated like skolem variables.
But it turns out other types from signatures also need to be treated like skolem variables too:
```
{-# LANGUAGE GADTs #-}
unit p where
signature M1 where
data A = MkA
signature M2 where
data A = MkA
module A where
import qualified M1
import qualified M2
f :: M1.A ~ M2.A => a -> b
f x = x
```
This is bad because these As could be the same thing in the end. I think the real, final fix, is to not test for "skolem abstractness" (as we do now), but just look and see if the Name for the TyCon is a name hole or not. Then we can eliminate skolem abstract completely.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Non-abstract types also have skolem nature","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.2.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.1","keywords":["backpack"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"In #12680, we determined that abstract types from signatures need to be treated like skolem variables.\r\n\r\nBut it turns out other types from signatures also need to be treated like skolem variables too:\r\n\r\n{{{\r\n{-# LANGUAGE GADTs #-}\r\nunit p where\r\n signature M1 where\r\n data A = MkA\r\n signature M2 where\r\n data A = MkA\r\n module A where\r\n import qualified M1\r\n import qualified M2\r\n f :: M1.A ~ M2.A => a -> b\r\n f x = x\r\n}}}\r\n\r\nThis is bad because these As could be the same thing in the end. I think the real, final fix, is to not test for \"skolem abstractness\" (as we do now), but just look and see if the Name for the TyCon is a name hole or not. Then we can eliminate skolem abstract completely.","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13337GHC doesn't think a type is of kind *, despite having evidence for it2019-07-07T18:22:23ZRyan ScottGHC doesn't think a type is of kind *, despite having evidence for itThe easiest way to illustrate this bug is this:
```hs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Data.Kind (Type)
blah :: forall (a :: k). k ~ Type => a -> a
b...The easiest way to illustrate this bug is this:
```hs
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Foo where
import Data.Kind (Type)
blah :: forall (a :: k). k ~ Type => a -> a
blah x = x
```
```
$ ghci Foo.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Foo ( Foo.hs, interpreted )
Foo.hs:8:43: error:
• Expected a type, but ‘a’ has kind ‘k’
• In the type signature:
blah :: forall (a :: k). k ~ Type => a -> a
```
I find this behavior quite surprising, especially since we have evidence that `k ~ Type` in scope!
If the program above looks too contrived, consider a similar program that uses `Typeable`. I want to write something like this:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module Foo where
import Data.Kind (Type)
import Data.Typeable
foo :: forall k (a :: k) proxy. (Typeable k, Typeable a)
=> proxy a -> String
foo _ =
case eqT :: Maybe (k :~: Type) of
Nothing -> "Non-Type kind"
Just Refl ->
case eqT :: Maybe (a :~: Int) of
Nothing -> "Non-Int type"
Just Refl -> "It's an Int!"
```
This exhibits the same problem. Despite the fact that we pattern-matched on a `Refl` of type `k :~: Type`, GHC refuses to consider the possibility that `a :~: Int` is well kinded, even though `(a :: k)`, and we learned from the first `Refl` that `k ~ Type`!
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC doesn't think a type is of kind *, despite having evidence for it","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"The easiest way to illustrate this bug is this:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind (Type)\r\n\r\nblah :: forall (a :: k). k ~ Type => a -> a\r\nblah x = x\r\n}}}\r\n\r\n{{{\r\n$ ghci Foo.hs\r\nGHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Foo ( Foo.hs, interpreted )\r\n\r\nFoo.hs:8:43: error:\r\n • Expected a type, but ‘a’ has kind ‘k’\r\n • In the type signature:\r\n blah :: forall (a :: k). k ~ Type => a -> a\r\n}}}\r\n\r\nI find this behavior quite surprising, especially since we have evidence that `k ~ Type` in scope!\r\n\r\nIf the program above looks too contrived, consider a similar program that uses `Typeable`. I want to write something like this:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeOperators #-}\r\nmodule Foo where\r\n\r\nimport Data.Kind (Type)\r\nimport Data.Typeable\r\n\r\nfoo :: forall k (a :: k) proxy. (Typeable k, Typeable a)\r\n => proxy a -> String\r\nfoo _ =\r\n case eqT :: Maybe (k :~: Type) of\r\n Nothing -> \"Non-Type kind\"\r\n Just Refl ->\r\n case eqT :: Maybe (a :~: Int) of\r\n Nothing -> \"Non-Int type\"\r\n Just Refl -> \"It's an Int!\"\r\n}}}\r\n\r\nThis exhibits the same problem. Despite the fact that we pattern-matched on a `Refl` of type `k :~: Type`, GHC refuses to consider the possibility that `a :~: Int` is well kinded, even though `(a :: k)`, and we learned from the first `Refl` that `k ~ Type`!","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13343Levity polymorphism-related GHC panic: expectJust zonkTcTyVarToVar2019-07-07T18:22:21ZRyan ScottLevity polymorphism-related GHC panic: expectJust zonkTcTyVarToVarReproducible with GHC 8.0.2 and HEAD:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import GHC.Exts
type Bad = forall (v1 :: RuntimeRep) (a1 :: TYPE v). a1
```
```
[1 of 1] Compiling Bug ...Reproducible with GHC 8.0.2 and HEAD:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import GHC.Exts
type Bad = forall (v1 :: RuntimeRep) (a1 :: TYPE v). a1
```
```
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.1.20170223 for x86_64-unknown-linux):
expectJust zonkTcTyVarToVar
CallStack (from HasCallStack):
error, called at compiler/utils/Maybes.hs:53:27 in ghc:Maybes
expectJust, called at compiler/typecheck/TcType.hs:1576:21 in ghc:TcType
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Levity polymorphism-related GHC panic: expectJust zonkTcTyVarToVar","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["LevityPolymorphism"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Reproducible with GHC 8.0.2 and HEAD:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport GHC.Exts\r\n\r\ntype Bad = forall (v1 :: RuntimeRep) (a1 :: TYPE v). a1\r\n}}}\r\n\r\n{{{\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\nghc-stage2: panic! (the 'impossible' happened)\r\n (GHC version 8.1.20170223 for x86_64-unknown-linux):\r\n expectJust zonkTcTyVarToVar\r\nCallStack (from HasCallStack):\r\n error, called at compiler/utils/Maybes.hs:53:27 in ghc:Maybes\r\n expectJust, called at compiler/typecheck/TcType.hs:1576:21 in ghc:TcType\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/13345GHC 8 type checker regression2019-07-07T18:22:20Zandreas.abelGHC 8 type checker regressionGHC 8.0.1/2 needs a type annotation where GHC 7.8 can do without:
```hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses #-}
data T = Var | App T T
data S = S
class Tr a ...GHC 8.0.1/2 needs a type annotation where GHC 7.8 can do without:
```hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses #-}
data T = Var | App T T
data S = S
class Tr a b where
tr :: a -> b
tr = undefined
instance Tr S T where
instance Tr a b => Tr [a] [b] where
test :: [S] -> T
test es = let
-- es' :: [T] -- This type annotation is not needed by ghc-7.8
es' = tr es
in foldl App Var es'
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC 8 type checker regression","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":["annotation","type"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC 8.0.1/2 needs a type annotation where GHC 7.8 can do without:\r\n{{{#!hs\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses #-}\r\n\r\ndata T = Var | App T T\r\ndata S = S\r\n\r\nclass Tr a b where\r\n tr :: a -> b\r\n tr = undefined\r\n \r\ninstance Tr S T where\r\ninstance Tr a b => Tr [a] [b] where\r\n\r\ntest :: [S] -> T\r\ntest es = let\r\n -- es' :: [T] -- This type annotation is not needed by ghc-7.8\r\n es' = tr es\r\n in foldl App Var es'\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13371instance selection too eager2019-07-07T18:22:14Zaavogtinstance selection too eagerI see a regression in 8.0.2: the `g_f'` definition is rejected. The error goes away if I do one of:
- -XNoMonoLocalBinds
- -XNoPolyKinds
- pasting the inferred type of `g_f`
<details><summary>Trac metadata</summary>
| Trac field ...I see a regression in 8.0.2: the `g_f'` definition is rejected. The error goes away if I do one of:
- -XNoMonoLocalBinds
- -XNoPolyKinds
- pasting the inferred type of `g_f`
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"instance selection too eager","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"I see a regression in 8.0.2: the `g_f'` definition is rejected. The error goes away if I do one of:\r\n\r\n * -XNoMonoLocalBinds\r\n\r\n * -XNoPolyKinds\r\n\r\n * pasting the inferred type of `g_f`","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13409Data types with higher-rank kinds are pretty-printed strangely2019-07-07T18:22:00ZRyan ScottData types with higher-rank kinds are pretty-printed strangelyFirst observed in #13399\##13409. If you define this:
```hs
data Foo :: (* -> *) -> (forall k. k -> *)
```
and type `:i Foo` into GHCi, you get this back:
```
type role Foo phantom nominal phantom
data Foo (a :: * -> *) k (c :: k)
```...First observed in #13399\##13409. If you define this:
```hs
data Foo :: (* -> *) -> (forall k. k -> *)
```
and type `:i Foo` into GHCi, you get this back:
```
type role Foo phantom nominal phantom
data Foo (a :: * -> *) k (c :: k)
```
This seems to imply that Foo has three visible type parameters, which isn't true at all!
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Data types with higher-rank kinds are pretty-printed strangely","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"First observed in https://ghc.haskell.org/trac/ghc/ticket/13399#comment:5. If you define this:\r\n\r\n{{{#!hs\r\ndata Foo :: (* -> *) -> (forall k. k -> *)\r\n}}}\r\n\r\nand type `:i Foo` into GHCi, you get this back:\r\n\r\n{{{\r\ntype role Foo phantom nominal phantom\r\ndata Foo (a :: * -> *) k (c :: k)\r\n}}}\r\n\r\nThis seems to imply that Foo has three visible type parameters, which isn't true at all!","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/13415Instance declarations don't recognize named wildcards2019-07-07T18:21:58ZRyan ScottInstance declarations don't recognize named wildcardsWhile exploring a fix for #13324, I was blocked pretty quickly by this limitation: instance declarations don't properly recognize named wildcards. Here is an example to demonstrate:
```hs
{-# LANGUAGE NamedWildCards #-}
module Bug where...While exploring a fix for #13324, I was blocked pretty quickly by this limitation: instance declarations don't properly recognize named wildcards. Here is an example to demonstrate:
```hs
{-# LANGUAGE NamedWildCards #-}
module Bug where
instance _x => Show (Maybe a)
```
```
Bug.hs:4:10: error:
• Illegal constraint: _x (Use ConstraintKinds to permit this)
• In the context: _x
While checking an instance declaration
In the instance declaration for ‘Show (Maybe a)’
|
4 | instance _x => Show (Maybe a)
| ^^^^^^^^^^^^^^^^^^^^
```
GHC doesn't recognize that `_x` is just a type variable, not a named wildcard.
I believe fixing this is just a matter of changing the ASTs for instance declarations to use `LHsSigWcType` instead of `LHsSigType`. Patch incoming.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Instance declarations don't recognize named wildcards","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.4.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"While exploring a fix for #13324, I was blocked pretty quickly by this limitation: instance declarations don't properly recognize named wildcards. Here is an example to demonstrate:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE NamedWildCards #-}\r\nmodule Bug where\r\n\r\ninstance _x => Show (Maybe a)\r\n}}}\r\n\r\n{{{\r\nBug.hs:4:10: error:\r\n • Illegal constraint: _x (Use ConstraintKinds to permit this)\r\n • In the context: _x\r\n While checking an instance declaration\r\n In the instance declaration for ‘Show (Maybe a)’\r\n |\r\n4 | instance _x => Show (Maybe a)\r\n | ^^^^^^^^^^^^^^^^^^^^\r\n}}}\r\n\r\nGHC doesn't recognize that `_x` is just a type variable, not a named wildcard.\r\n\r\nI believe fixing this is just a matter of changing the ASTs for instance declarations to use `LHsSigWcType` instead of `LHsSigType`. Patch incoming.","type_of_failure":"OtherFailure","blocking":[]} -->8.4.1https://gitlab.haskell.org/ghc/ghc/-/issues/13435Segfaults on levity-polymorphic type class2019-07-07T18:21:52ZIcelandjackSegfaults on levity-polymorphic type class```hs
{-# Language FlexibleInstances, TypeFamilies, TypeInType, MagicHash #-}
import Data.Kind
import GHC.Exts
class Shw (a :: TYPE rep) where
shw :: a -> String
instance Int# ~ a => Shw (a :: TYPE IntRep) where
shw a = "I#" ++ sh...```hs
{-# Language FlexibleInstances, TypeFamilies, TypeInType, MagicHash #-}
import Data.Kind
import GHC.Exts
class Shw (a :: TYPE rep) where
shw :: a -> String
instance Int# ~ a => Shw (a :: TYPE IntRep) where
shw a = "I#" ++ show (I# a)
main = putStrLn (shw 3#)
```
induces a segfault
```
$ runghc --version
runghc 8.0.1
$ runghc test.hs
I#Segmentation fault
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Segfaults on levity-polymorphic type class","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{#!hs\r\n{-# Language FlexibleInstances, TypeFamilies, TypeInType, MagicHash #-}\r\n\r\nimport Data.Kind\r\nimport GHC.Exts\r\n\r\nclass Shw (a :: TYPE rep) where\r\n shw :: a -> String\r\n\r\ninstance Int# ~ a => Shw (a :: TYPE IntRep) where\r\n shw a = \"I#\" ++ show (I# a)\r\n\r\nmain = putStrLn (shw 3#)\r\n}}}\r\n\r\ninduces a segfault \r\n\r\n{{{\r\n$ runghc --version\r\nrunghc 8.0.1\r\n$ runghc test.hs\r\nI#Segmentation fault\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13446Deferred type error sneaks in with -fno-defer-type-errors enabled2019-07-07T18:21:49ZRyan ScottDeferred type error sneaks in with -fno-defer-type-errors enabledThis is a very perplexing bug that MitchellSalad discovered and advertised in [this Reddit post](https://www.reddit.com/r/haskell/comments/604mze/deferred_type_errors_without_setting/). Consider this code:
```hs
{-# LANGUAGE ConstraintK...This is a very perplexing bug that MitchellSalad discovered and advertised in [this Reddit post](https://www.reddit.com/r/haskell/comments/604mze/deferred_type_errors_without_setting/). Consider this code:
```hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-defer-type-errors #-}
module Main where
import Data.Coerce (Coercible)
import GHC.Exts (Constraint)
import GHC.TypeLits (Symbol)
data Dict :: Constraint -> * where
Dict :: a => Dict a
infixr 9 :-
newtype a :- b = Sub (a => Dict b)
instance a => Show (a :- b) where
showsPrec d (Sub Dict) = showParen (d > 10) $ showString "Sub Dict"
class Lifting p f where
lifting :: p a :- p (f a)
data Blah a = Blah
newtype J (a :: JType) = J (Blah (J a))
newtype JComparable a = JComparable (J (T (JTy a)))
instance Lifting JReference JComparable where
lifting = Sub 'a'
class (Coercible a (J (JTy a))) => JReference a where
type JTy a :: JType
type T a
= 'Generic ('Iface "java.lang.Comparable") '[a]
data JType = Class Symbol
| Generic JType [JType]
| Iface Symbol
type JObject = J (Class "java.lang.Object")
instance JReference JObject where
type JTy JObject = 'Class "java.lang.Object"
main :: IO ()
main = print (lifting :: JReference JObject :- JReference (JComparable JObject))
```
There are three concerning things about this:
1. Look at the line `lifting = Sub 'a'`. That's obviously bogus, as `Char`s are not `Dict`s! Yet GHC 8.0.2 and HEAD readily typecheck this code without warnings.
1. So now that we seem to have circumvented type safety, what happens if we actually try to //run// code which uses this bogus `Lifting` instance? Something truly bizarre, that's what:
```
$ /opt/ghc/8.0.2/bin/ghci Bug.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Main ( Bug.hs, interpreted )
Ok, modules loaded: Main.
λ> main
*** Exception: Bug.hs:34:17: error:
• Couldn't match expected type ‘Dict (JReference (JComparable a))’
with actual type ‘Char’
• In the first argument of ‘Sub’, namely ‘'a'’
In the expression: Sub 'a'
In an equation for ‘lifting’: lifting = Sub 'a'
• Relevant bindings include
lifting :: JReference a :- JReference (JComparable a)
(bound at Bug.hs:34:3)
(deferred type error)
```
> Somehow, we managed to defer a type mismatch between `Char` and `Dict`. All while `-fno-defer-type-errors` is enabled!
1. Worst of all, this is a regression from GHC 8.0.1, as it will actually detect the type mismatch at compile-time:
```
$ /opt/ghc/8.0.1/bin/ghci Bug.hs
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Main ( Bug.hs, interpreted )
Bug.hs:34:17: error:
• Couldn't match expected type ‘Dict (JReference (JComparable a))’
with actual type ‘Char’
• In the first argument of ‘Sub’, namely ‘'a'’
In the expression: Sub 'a'
In an equation for ‘lifting’: lifting = Sub 'a'
• Relevant bindings include
lifting :: JReference a :- JReference (JComparable a)
(bound at Bug.hs:34:3)
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | MitchellSalad |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Deferred type error sneaks in with -fno-defer-type-errors enabled","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["MitchellSalad"],"type":"Bug","description":"This is a very perplexing bug that MitchellSalad discovered and advertised in [https://www.reddit.com/r/haskell/comments/604mze/deferred_type_errors_without_setting/ this Reddit post]. Consider this code:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE ConstraintKinds #-}\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE FlexibleContexts #-}\r\n{-# LANGUAGE FlexibleInstances #-}\r\n{-# LANGUAGE MultiParamTypeClasses #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeOperators #-}\r\n{-# OPTIONS_GHC -fno-defer-type-errors #-}\r\nmodule Main where\r\n\r\nimport Data.Coerce (Coercible)\r\nimport GHC.Exts (Constraint)\r\nimport GHC.TypeLits (Symbol)\r\n\r\ndata Dict :: Constraint -> * where\r\n Dict :: a => Dict a\r\n\r\ninfixr 9 :-\r\nnewtype a :- b = Sub (a => Dict b)\r\ninstance a => Show (a :- b) where\r\n showsPrec d (Sub Dict) = showParen (d > 10) $ showString \"Sub Dict\"\r\n\r\nclass Lifting p f where\r\n lifting :: p a :- p (f a)\r\n\r\ndata Blah a = Blah\r\n\r\nnewtype J (a :: JType) = J (Blah (J a))\r\nnewtype JComparable a = JComparable (J (T (JTy a)))\r\n\r\ninstance Lifting JReference JComparable where\r\n lifting = Sub 'a'\r\n\r\nclass (Coercible a (J (JTy a))) => JReference a where\r\n type JTy a :: JType\r\n\r\ntype T a\r\n = 'Generic ('Iface \"java.lang.Comparable\") '[a]\r\ndata JType = Class Symbol\r\n | Generic JType [JType]\r\n | Iface Symbol\r\ntype JObject = J (Class \"java.lang.Object\")\r\ninstance JReference JObject where\r\n type JTy JObject = 'Class \"java.lang.Object\"\r\n\r\nmain :: IO ()\r\nmain = print (lifting :: JReference JObject :- JReference (JComparable JObject))\r\n}}}\r\n\r\nThere are three concerning things about this:\r\n\r\n1. Look at the line `lifting = Sub 'a'`. That's obviously bogus, as `Char`s are not `Dict`s! Yet GHC 8.0.2 and HEAD readily typecheck this code without warnings.\r\n2. So now that we seem to have circumvented type safety, what happens if we actually try to //run// code which uses this bogus `Lifting` instance? Something truly bizarre, that's what:\r\n\r\n{{{\r\n$ /opt/ghc/8.0.2/bin/ghci Bug.hs\r\nGHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Main ( Bug.hs, interpreted )\r\nOk, modules loaded: Main.\r\nλ> main\r\n*** Exception: Bug.hs:34:17: error:\r\n • Couldn't match expected type ‘Dict (JReference (JComparable a))’\r\n with actual type ‘Char’\r\n • In the first argument of ‘Sub’, namely ‘'a'’\r\n In the expression: Sub 'a'\r\n In an equation for ‘lifting’: lifting = Sub 'a'\r\n • Relevant bindings include\r\n lifting :: JReference a :- JReference (JComparable a)\r\n (bound at Bug.hs:34:3)\r\n(deferred type error)\r\n}}}\r\n\r\n Somehow, we managed to defer a type mismatch between `Char` and `Dict`. All while `-fno-defer-type-errors` is enabled!\r\n3. Worst of all, this is a regression from GHC 8.0.1, as it will actually detect the type mismatch at compile-time:\r\n\r\n{{{\r\n$ /opt/ghc/8.0.1/bin/ghci Bug.hs\r\nGHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Main ( Bug.hs, interpreted )\r\n\r\nBug.hs:34:17: error:\r\n • Couldn't match expected type ‘Dict (JReference (JComparable a))’\r\n with actual type ‘Char’\r\n • In the first argument of ‘Sub’, namely ‘'a'’\r\n In the expression: Sub 'a'\r\n In an equation for ‘lifting’: lifting = Sub 'a'\r\n • Relevant bindings include\r\n lifting :: JReference a :- JReference (JComparable a)\r\n (bound at Bug.hs:34:3)\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.2.1https://gitlab.haskell.org/ghc/ghc/-/issues/13458Panic with unsafeCoerce and -dcore-lint2019-07-07T18:21:46ZDavid FeuerPanic with unsafeCoerce and -dcore-lint```hs
{-# LANGUAGE MagicHash, TypeInType, ScopedTypeVariables #-}
module UIOST where
import GHC.Exts
import Data.Kind
import Unsafe.Coerce
unsafeCoerce' :: forall (r :: RuntimeRep)
(a :: TYPE r) (b :: TYPE r).
...```hs
{-# LANGUAGE MagicHash, TypeInType, ScopedTypeVariables #-}
module UIOST where
import GHC.Exts
import Data.Kind
import Unsafe.Coerce
unsafeCoerce' :: forall (r :: RuntimeRep)
(a :: TYPE r) (b :: TYPE r).
a -> b
unsafeCoerce' = unsafeCoerce id
```
Compiling this with optimization and `-dcore-lint` produces a panic:
```
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.1.20170308 for x86_64-unknown-linux):
runtimeRepPrimRep
typePrimRep (a_aW7 :: TYPE r_aW6)
r_aW6
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1191:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1195:37 in ghc:Outputable
pprPanic, called at compiler/simplStg/RepType.hs:360:5 in ghc:RepType
```
Using `unsafeCoerce# id` produces the panic without optimization. I have not been able to reproduce the problem without `-dcore-lint`.8.2.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.dev