GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2021-05-17T16:05:16Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/9975RecordWildcards and PatternSynonyms cause impossible bug2021-05-17T16:05:16ZgamegoblinRecordWildcards and PatternSynonyms cause impossible bugWhen using RecordWildcards with PatternSynonyms, I have found a way to cause this bug:
```
$ /usr/local/bin/ghc-7.10.0.20141222 test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
ghc: panic! (the 'impossible' happened)
(...When using RecordWildcards with PatternSynonyms, I have found a way to cause this bug:
```
$ /usr/local/bin/ghc-7.10.0.20141222 test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
ghc: panic! (the 'impossible' happened)
(GHC version 7.10.0.20141222 for x86_64-apple-darwin):
find_tycon
Test
[Test defined at test.hs:6:9,
Test parent:Test defined at test.hs:4:13]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
Here is the full code that causes it:
```hs
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE PatternSynonyms #-}
data Test = Test { x :: Int }
pattern Test wat = Test { x = wat }
```
If you remove `RecordWildCards`, the bug does not happen.7.10.1https://gitlab.haskell.org/ghc/ghc/-/issues/9900Support pattern synonyms in GHCi2019-07-07T18:38:34ZGergő ÉrdiSupport pattern synonyms in GHCiPattern synonyms are not parsed in GHCi:
```
λ» :set -XPatternSynonyms
λ» pattern P x = x
<interactive>:5:1: parse error on input ‘pattern’
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
|...Pattern synonyms are not parsed in GHCi:
```
λ» :set -XPatternSynonyms
λ» pattern P x = x
<interactive>:5:1: parse error on input ‘pattern’
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 7.8.3 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | GHCi |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | #7253, #8749 |
| Blocking | |
| CC | hvr |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Support pattern synonyms in GHCi","status":"New","operating_system":"","component":"GHCi","related":[7253,8749],"milestone":"7.10.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"cactus"},"version":"7.8.3","keywords":["PatternSynonyms"],"differentials":[],"test_case":"","architecture":"","cc":["hvr"],"type":"FeatureRequest","description":"Pattern synonyms are not parsed in GHCi:\r\n\r\n{{{\r\nλ» :set -XPatternSynonyms \r\nλ» pattern P x = x\r\n\r\n<interactive>:5:1: parse error on input ‘pattern’\r\n\r\n}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->7.10.1Gergő ÉrdiGergő Érdihttps://gitlab.haskell.org/ghc/ghc/-/issues/9889Pattern synonym does not work in top-level pattern bind2019-07-07T18:38:37ZRichard Eisenbergrae@richarde.devPattern synonym does not work in top-level pattern bindWhen I say
```
{-# LANGUAGE PatternSynonyms #-}
pattern Id x = x
Id x = True
```
I get
```
Not in scope: data constructor ‘Id’
```
This happens with both 7.8.3 and HEAD.When I say
```
{-# LANGUAGE PatternSynonyms #-}
pattern Id x = x
Id x = True
```
I get
```
Not in scope: data constructor ‘Id’
```
This happens with both 7.8.3 and HEAD.7.10.1Gergő ÉrdiGergő Érdihttps://gitlab.haskell.org/ghc/ghc/-/issues/9783Pattern synonym matcher is unnecessarily strict on unboxed continuations2019-07-07T18:39:03ZGergő ÉrdiPattern synonym matcher is unnecessarily strict on unboxed continuationsAs discovered while investigating #9732, if you have something like
```
{-# LANGUAGE PatternSynonyms, MagicHash #-}
import GHC.Base
pattern P = True
f :: Bool -> Int#
f P = 42#
```
`f` is compiled into
```
Main.f :: GHC.Types.Bool -...As discovered while investigating #9732, if you have something like
```
{-# LANGUAGE PatternSynonyms, MagicHash #-}
import GHC.Base
pattern P = True
f :: Bool -> Int#
f P = 42#
```
`f` is compiled into
```
Main.f :: GHC.Types.Bool -> GHC.Prim.Int#
[LclIdX, Str=DmdType]
Main.f =
letrec {
f_apU :: GHC.Types.Bool -> GHC.Prim.Int#
[LclId, Str=DmdType]
f_apU =
\ (ds_dq1 :: GHC.Types.Bool) ->
break<2>()
let {
fail_dq2 :: GHC.Prim.Void# -> GHC.Prim.Int#
[LclId, Str=DmdType]
fail_dq2 =
\ (ds_dq3 [OS=OneShot] :: GHC.Prim.Void#) ->
Control.Exception.Base.patError
@ GHC.Prim.Int# "unboxed.hs:7:1-9|function f"# } in
case fail_dq2 GHC.Prim.void# of wild_00 { __DEFAULT ->
(case break<1>() 42 of wild_00 { __DEFAULT ->
Main.$mP @ GHC.Prim.Int# ds_dq1 wild_00
})
wild_00
}; } in
f_apU
```
Note how `fail_dq2` is applied on `void#` _before_ the pattern match, meaning the following expression:
```
I# (f True)
```
will fail with
```
*** Exception: unboxed.hs:7:1-9: Non-exhaustive patterns in function f
```
This is because the the type of `P`'s matcher, instantiated for its use in `f`, is
```
$mP :: Bool -> Int# -> Int# -> Int#
```
so of course it is strict both on the success and the failure continuation.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 7.8.3 |
| 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":"Pattern synonym matcher is unnecessarily strict on unboxed continuations","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"7.10.1","resolution":"Unresolved","owner":{"tag":"OwnedBy","contents":"cactus"},"version":"7.8.3","keywords":["pattern","synonyms"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"As discovered while investigating #9732, if you have something like\r\n\r\n{{{\r\n{-# LANGUAGE PatternSynonyms, MagicHash #-}\r\nimport GHC.Base\r\n\r\npattern P = True\r\n\r\nf :: Bool -> Int#\r\nf P = 42#\r\n}}}\r\n\r\n`f` is compiled into\r\n\r\n{{{\r\nMain.f :: GHC.Types.Bool -> GHC.Prim.Int#\r\n[LclIdX, Str=DmdType]\r\nMain.f =\r\n letrec {\r\n f_apU :: GHC.Types.Bool -> GHC.Prim.Int#\r\n [LclId, Str=DmdType]\r\n f_apU =\r\n \\ (ds_dq1 :: GHC.Types.Bool) ->\r\n break<2>()\r\n let {\r\n fail_dq2 :: GHC.Prim.Void# -> GHC.Prim.Int#\r\n [LclId, Str=DmdType]\r\n fail_dq2 =\r\n \\ (ds_dq3 [OS=OneShot] :: GHC.Prim.Void#) ->\r\n Control.Exception.Base.patError\r\n @ GHC.Prim.Int# \"unboxed.hs:7:1-9|function f\"# } in\r\n case fail_dq2 GHC.Prim.void# of wild_00 { __DEFAULT ->\r\n (case break<1>() 42 of wild_00 { __DEFAULT ->\r\n Main.$mP @ GHC.Prim.Int# ds_dq1 wild_00\r\n })\r\n wild_00\r\n }; } in\r\n f_apU\r\n}}}\r\n\r\nNote how `fail_dq2` is applied on `void#` _before_ the pattern match, meaning the following expression:\r\n\r\n{{{\r\nI# (f True)\r\n}}}\r\n\r\nwill fail with\r\n\r\n{{{\r\n*** Exception: unboxed.hs:7:1-9: Non-exhaustive patterns in function f\r\n}}}\r\n\r\nThis is because the the type of `P`'s matcher, instantiated for its use in `f`, is\r\n\r\n{{{\r\n$mP :: Bool -> Int# -> Int# -> Int#\r\n}}}\r\n\r\nso of course it is strict both on the success and the failure continuation.","type_of_failure":"OtherFailure","blocking":[]} -->7.10.1Gergő ÉrdiGergő Érdi