Panic with -O and representation polymorphism
The following file, found during investigation of #22715 (closed), causes a panic in master with -O
module M where
import GHC.Exts (TYPE)
f :: forall r (a :: TYPE r). () -> a
f x = f x
[g@g-work:~/haskell/ghc/_build]$ ./stage1/bin/ghc -O M
[1 of 1] Compiling M ( M.hs, M.o ) [Source file changed]
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.7.20230103:
typeKind
forall {r :: RuntimeRep} {a :: TYPE r}. a
[r_sH5, a_sH6]
a_sH6 :: TYPE r_sH5
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:189:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Type.hs:2575:18 in ghc:GHC.Core.Type
typeKind, called at compiler/GHC/Core/Type.hs:2623:48 in ghc:GHC.Core.Type
typeTypeOrConstraint, called at compiler/GHC/Core/Type.hs:1363:48 in ghc:GHC.Core.Type
chooseFunTyFlag, called at compiler/GHC/Core/Type.hs:1348:10 in ghc:GHC.Core.Type
CallStack (from HasCallStack):
panic, called at compiler/GHC/Utils/Error.hs:454:29 in ghc:GHC.Utils.Error
GHC 9.4 fails Lint
*** Core Lint errors : in result of Worker Wrapper binds ***
M.hs:6:1: warning:
Variable escape in forall:
tyvar: r_sEE
type: forall {a :: TYPE r_sEE}. a
kind: TYPE r_sEE
In the type of a binder: $wf_sEI
In the type ‘(# #) -> forall {r :: RuntimeRep} {a :: TYPE r}. a’