GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2022-01-29T16:06:57Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/10946Typed hole inside typed Template Haskell bracket causes panic2022-01-29T16:06:57ZJan Stolarekjan.stolarek@ed.ac.ukTyped hole inside typed Template Haskell bracket causes panicWhen I say:
```hs
m :: a -> a
m x = $$([||_||])
```
I get:
```
T10946.hs:47:13:ghc: panic! (the 'impossible' happened)
(GHC version 7.10.1 for x86_64-unknown-linux):
No skolem info: a_apJ[sk]
```
This happens both with GHC ...When I say:
```hs
m :: a -> a
m x = $$([||_||])
```
I get:
```
T10946.hs:47:13:ghc: panic! (the 'impossible' happened)
(GHC version 7.10.1 for x86_64-unknown-linux):
No skolem info: a_apJ[sk]
```
This happens both with GHC 7.10.1 and latest HEAD (e2b579e8d77357e8b36f57d15daead101586ac8e).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ---------------- |
| Version | 7.10.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Template Haskell |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Typed hole inside typed Template Haskell bracket causes panic","status":"New","operating_system":"","component":"Template Haskell","related":[],"milestone":"8.0.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["goldfire"],"type":"Bug","description":"When I say:\r\n\r\n{{{#!hs\r\nm :: a -> a\r\nm x = $$([||_||])\r\n}}}\r\nI get:\r\n{{{\r\nT10946.hs:47:13:ghc: panic! (the 'impossible' happened)\r\n (GHC version 7.10.1 for x86_64-unknown-linux):\r\n No skolem info: a_apJ[sk]\r\n}}}\r\nThis happens both with GHC 7.10.1 and latest HEAD (e2b579e8d77357e8b36f57d15daead101586ac8e).","type_of_failure":"OtherFailure","blocking":[]} -->8.10.2https://gitlab.haskell.org/ghc/ghc/-/issues/15437Internal error when applying a scoped type variable inside a typed expression...2023-08-11T11:04:21ZdminuosoInternal error when applying a scoped type variable inside a typed expression quotation```hs
{-# LANGUAGE TemplateHaskell #-}
import TestMod
f :: Int
f = $$(foo)
main :: IO ()
main = main
```
```hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module TestMod wh...```hs
{-# LANGUAGE TemplateHaskell #-}
import TestMod
f :: Int
f = $$(foo)
main :: IO ()
main = main
```
```hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module TestMod where
import Language.Haskell.TH.Syntax (Q, TExp)
get :: forall a. Int
get = 1
foo :: forall a. Q (TExp Int)
foo = [|| get @a ||]
```
```
Test.hs:6:8: error:
• The exact Name ‘a’ is not in scope
Probable cause: you used a unique Template Haskell name (NameU),
perhaps via newName, but did not bind it
If that's it, then -ddump-splices might be useful
• In the result of the splice:
$foo
To see what the splice expanded to, use -ddump-splices
In the Template Haskell splice $$(foo)
In the expression: $$(foo)
|
6 | f = $$(foo)
| ^^^
Test.hs:6:8: error:
• GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [r3Kl :-> Identifier[f::Int, TopLevelLet [] True],
r3PI :-> Identifier[main::IO (), TopLevelLet [r3PI :-> main] True]]
• In the type ‘a’
In the expression: get @a
In the result of the splice:
$foo
To see what the splice expanded to, use -ddump-splices
|
6 | f = $$(foo)
|
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.4.3 |
| 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":"Internal error when applying a scoped type variable inside a typed expression quotation","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{#!hs\r\n{-# LANGUAGE TemplateHaskell #-}\r\n\r\nimport TestMod\r\n\r\nf :: Int\r\nf = $$(foo)\r\n\r\nmain :: IO ()\r\nmain = main\r\n}}}\r\n\r\n{{{#!hs\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TemplateHaskell #-}\r\n{-# LANGUAGE TypeApplications #-}\r\n\r\nmodule TestMod where\r\n\r\nimport Language.Haskell.TH.Syntax (Q, TExp)\r\n\r\nget :: forall a. Int\r\nget = 1\r\n\r\nfoo :: forall a. Q (TExp Int)\r\nfoo = [|| get @a ||]\r\n}}}\r\n\r\n{{{\r\nTest.hs:6:8: error:\r\n • The exact Name ‘a’ is not in scope\r\n Probable cause: you used a unique Template Haskell name (NameU),\r\n perhaps via newName, but did not bind it\r\n If that's it, then -ddump-splices might be useful\r\n • In the result of the splice:\r\n $foo\r\n To see what the splice expanded to, use -ddump-splices\r\n In the Template Haskell splice $$(foo)\r\n In the expression: $$(foo)\r\n |\r\n6 | f = $$(foo)\r\n | ^^^\r\n\r\nTest.hs:6:8: error:\r\n • GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [r3Kl :-> Identifier[f::Int, TopLevelLet [] True],\r\n r3PI :-> Identifier[main::IO (), TopLevelLet [r3PI :-> main] True]]\r\n • In the type ‘a’\r\n In the expression: get @a\r\n In the result of the splice:\r\n $foo\r\n To see what the splice expanded to, use -ddump-splices\r\n |\r\n6 | f = $$(foo)\r\n |\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.10.2https://gitlab.haskell.org/ghc/ghc/-/issues/17252Mangled reified GADT record selector2020-07-01T14:36:13ZRichard Eisenbergrae@richarde.devMangled reified GADT record selectorFrom @RyanGlScott (originally https://gitlab.haskell.org/ghc/ghc/issues/16980#note_222424, but unrelated to that ticket):
Consider this program:
```haskell
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
impo...From @RyanGlScott (originally https://gitlab.haskell.org/ghc/ghc/issues/16980#note_222424, but unrelated to that ticket):
Consider this program:
```haskell
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH
$([d| data T b where
MkT :: { unT :: a } -> T a
|])
$(return [])
main :: IO ()
main = putStrLn $(reify 'unT >>= stringE . pprint)
```
If you run this, you'll get a surprising answer:
```
$ /opt/ghc/8.8.1/bin/runghc Bug.hs
Main.unT :: forall (a_0 :: *) . Main.T b_1 -> b_1
```
The reported type is `forall a. T b -> b`, which is completely bogus! Even stranger is that if I load this module into GHCi and *then* reify it:
```
$ /opt/ghc/8.8.1/bin/ghci Bug.hs -XTemplateHaskell
GHCi, version 8.8.1: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Main ( Bug.hs, interpreted )
Ok, one module loaded.
λ> import Language.Haskell.TH
λ> putStrLn $(reify 'unT >>= stringE . pprint)
Main.unT :: forall (a_0 :: *) . Main.T a_0 -> a_0
```
Then the reported type is `forall a. T a -> a`, as expected. I can't help but wonder if this is another case of metavariables leaking through when they shouldn't.8.10.2https://gitlab.haskell.org/ghc/ghc/-/issues/17305Data family instances aren't eta-reduced correctly2020-12-14T13:50:30ZRyan ScottData family instances aren't eta-reduced correctly(I originally discovered this when debugging #17296/!1877, but this doesn't rely on !1877 to reproduce.)
Take this code:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where
impo...(I originally discovered this when debugging #17296/!1877, but this doesn't rely on !1877 to reproduce.)
Take this code:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where
import Data.Kind
import Language.Haskell.TH hiding (Type)
import System.IO
data family Foo a
data instance Foo :: Type -> Type where
MkFoo :: Foo a
$(do i <- reify ''Foo
runIO $ hPutStrLn stderr $ pprint i
pure [])
```
And compile it with a `devel2`-flavoured compiler. (I'm on commit d0924b153b093a925c9e721f2540f3dfd6c278ae.) You'll get the following panic:
```
$ ~/Software/ghc3/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o, Bug.dyn_o )
Bug.hs:1:1: error:
Exception when trying to run compile-time code:
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.9.0.20191003:
zipEqual: unequal lists:zipTyEnv
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Code: do i <- reify ''Foo
runIO $ hPutStrLn stderr $ pprint i
pure []
|
1 | {-# LANGUAGE GADTs #-}
| ^
```8.10.2https://gitlab.haskell.org/ghc/ghc/-/issues/17688Template Haskell gets confused around visible dependent quantification2020-02-25T01:01:53ZRichard Eisenbergrae@richarde.devTemplate Haskell gets confused around visible dependent quantificationIf I say
```hs
$( do ty <- [d| {-# SPECIALISE id :: forall a -> a -> a #-} |]
runIO $ print ty
return [] )
```
I see
```
[PragmaD (SpecialiseP GHC.Base.id (ForallT [PlainTV a_6989586621679025225] [] (AppT (AppT ArrowT (Var...If I say
```hs
$( do ty <- [d| {-# SPECIALISE id :: forall a -> a -> a #-} |]
runIO $ print ty
return [] )
```
I see
```
[PragmaD (SpecialiseP GHC.Base.id (ForallT [PlainTV a_6989586621679025225] [] (AppT (AppT ArrowT (VarT a_6989586621679025225)) (VarT a_6989586621679025225))) Nothing AllPhases)]
```
Note that the output has a normal `ForallT`, not a `ForallVisT`.
This is because `splitLHsForAllTy` is used (within `splitLHsSigmaTy`). I conjecture that most uses of `splitLHsForAllTy` are wrong. Instead, callers should use `splitLHsForAllTyInvis`, which distinguishes between visible and invisible dependent quantification. Indeed, perhaps `splitLHsForAllTy` should be deleted, entirely.
Tagging @RyanGlScott, who knows both about VDQ and TH, happily.8.10.2https://gitlab.haskell.org/ghc/ghc/-/issues/18097$(tupE [ [|x|] ]) /= Unit x2021-04-07T15:59:53Zaavogt$(tupE [ [|x|] ]) /= Unit x## Summary
Today in #haskell http://tunes.org/~nef/logs/haskell/20.04.24
```
11:12:58 <mniip> ghc-prim:GHC.Tuple.Unit{(w) tc 42} versus ghc-prim:GHC.Tuple.Unit{tc rdRN}
11:14:39 <mniip> (w) indicating the wired in id (likely the name ...## Summary
Today in #haskell http://tunes.org/~nef/logs/haskell/20.04.24
```
11:12:58 <mniip> ghc-prim:GHC.Tuple.Unit{(w) tc 42} versus ghc-prim:GHC.Tuple.Unit{tc rdRN}
11:14:39 <mniip> (w) indicating the wired in id (likely the name from the type sig)
11:22:10 <mniip> looks like a TH/renamer bug
```
## Steps to reproduce
```haskell
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import GHC.Tuple
main = case $( tupE [ [| "ok" |] ] ) of Unit x -> putStrLn x
{-
runghc -dppr-debug unit.hs
unit.hs:5:41: error:
• Couldn't match expected type ‘ghc-prim:GHC.Tuple.Unit{(w) tc 42}
(ghc-prim:GHC.Types.[]{(w) tc 3Q}
ghc-prim:GHC.Types.Char{(w) tc 3g})’
with actual type ‘ghc-prim:GHC.Tuple.Unit{tc rIJ}
base:GHC.Base.String{tc rf1}’
NB: ‘ghc-prim:GHC.Tuple.Unit{tc rIJ}’ is defined in ‘GHC.Tuple’
‘ghc-prim:GHC.Tuple.Unit{(w) tc 42}’ is defined in ‘GHC.Tuple’
• In the pattern: ghc-prim:GHC.Tuple.Unit{d rIK} (x{v a2dg})
In a case alternative:
{unit.hs:5:41-46}
ghc-prim:GHC.Tuple.Unit{d rIK} (x{v a2dg})
-> {unit.hs:5:51-60}
base:System.IO.putStrLn{v rt9}
{unit.hs:5:60}
x{v a2dg}
In the expression:
{unit.hs:5:8-60}
case
{unit.hs:5:13-36}
(Unit {unit.hs:5:16-34}
"ok")
of {
{unit.hs:5:41-46}
ghc-prim:GHC.Tuple.Unit{d rIK} (x{v a2dg})
-> {unit.hs:5:51-60}
base:System.IO.putStrLn{v rt9}
{unit.hs:5:60}
x{v a2dg} }
• Relevant bindings include
main:Main.main{v rOW} :: ghc-prim:GHC.Types.IO{tc 31Q}
ghc-prim:GHC.Tuple.(){(w) tc 40}
(bound at unit.hs:5:1)
|
5 | main = case $( tupE [ [| "ok" |] ] ) of Unit x -> putStrLn x
|
-}
```
## Expected behavior
It should print "ok"
## Environment
* GHC version used: 8.10.1
Optional:
* Operating System:
* System Architecture:8.10.2