[GHC] #12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened)

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- While compiling `Repro.hs` with `HEAD` I get this: {{{ $ ~/local/ghc-inaccessible-right-side/inplace/bin/ghc-stage2 Repro.hs [1 of 1] Compiling Repro ( Repro.hs, Repro.o ) Repro.hs:22:35: warning: [-Woverlapping-patterns] Pattern match has inaccessible right hand side In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) (GHC version 8.1.20161209 for x86_64-unknown-linux): unused Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} It doesn't reproduce on 7.10.2. I'm 90% sure it reproduces on 8.0.2 (I have a branch with some unrelated patches). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by niteria): * Attachment "Repro.hs" added. Repro.hs -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by niteria): {{{ diff --git a/compiler/hsSyn/HsExpr.hs b/compiler/hsSyn/HsExpr.hs index 78ee4e0..4422ec7 100644 --- a/compiler/hsSyn/HsExpr.hs +++ b/compiler/hsSyn/HsExpr.hs @@ -2389,7 +2389,7 @@ matchSeparator LambdaExpr = text "->" matchSeparator ProcExpr = text "->" matchSeparator PatBindRhs = text "=" matchSeparator (StmtCtxt _) = text "<-" -matchSeparator RecUpd = panic "unused" +matchSeparator RecUpd = text "{" matchSeparator ThPatSplice = panic "unused" matchSeparator ThPatQuote = panic "unused" matchSeparator PatSyn = panic "unused" }}} makes the panic go away, but the error isn't very nice: {{{ [1 of 1] Compiling Repro ( Repro.hs, Repro.o ) Repro.hs:22:35: warning: [-Woverlapping-patterns] Pattern match has inaccessible right hand side In a record-update construct: BFields ds_dFp { ... }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): It is unfortunate the compiler doesn't throw a type error earlier. The warning comes from the desugaring of the record update so it would still be difficult for users to act upon. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ocharles): I think I'm running into the same bug. A super minimal example is: {{{ go = case [] of (a:b) -> a {b = a} }}} Do we think this is the same bug? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): I think it very well might be the same bug, considering the form of the panic is identical to how niteria originally reported it: {{{ $ ghci -fdefer-type-errors Bug.hsGHCi, 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 ) Bug.hs:3:16: warning: [-Woverlapping-patterns] Pattern match is redundant In a case alternative: (_ : _) -> ... Bug.hs:3:25: warning: [-Wdeferred-out-of-scope-variables] Variable not in scope: a :: A Bug.hs:3:25: warning: [-Woverlapping-patterns] Pattern match is redundant In a record-update construct:ghc: panic! (the 'impossible' happened) (GHC version 8.0.2 for x86_64-unknown-linux): unused }}} Also reproducible on GHC HEAD. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: => mpickering -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): I will get to this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3065, Wiki Page: | Phab:D3064 -------------------------------------+------------------------------------- Changes (by mpickering): * differential: => Phab:D3065, Phab:D3064 Comment: There was actually a bug in the PM checker which was causing this bug to show up. Here is a simpler reproduction. Essentially the checker was seeing that `[]` was not consistent with `(_:_)` and thus for any nested pattern matches the initial uncovered set was empty which caused all patterns to be reported as redundant. {{{ module T12957 where data A = N | A { b :: Bool } f = case [] of (_:_) -> case () of a -> undefined }}} However, it was also good to add the case to `matchSeparator` as these matches are printed when `-ddump-ec-trace` is used. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3065, Wiki Page: | Phab:D3064 -------------------------------------+------------------------------------- Comment (by mpickering): Actually, there are two different problems here the original report is different from the case that ocharles reported and I fixed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3065, Wiki Page: | Phab:D3064 -------------------------------------+------------------------------------- Comment (by mpickering): In the original ticket, the record update gets desugared to something like {{{#!hs case emptyA of BFields _ -> BFields [a] _ -> error "Non-exhaustive patterns..." }}} GHC then warns that the first branch is inaccessible, which is true as the type of `emptyA` means that the value has to be either `EmptyFields` or `AFields`. At run-time, evaluating `f ()` causes a run-time error. So, is there anything here to fix apart from the panic? Usually warnings which affect incomplete pattern match warnings are only turned on by `-Wincomplete-record-updates`. This is however, a warning about inaccessibility/redundancy rather than incompleteness. What do you expect to happen niteria? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened)
-------------------------------------+-------------------------------------
Reporter: niteria | Owner: mpickering
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version:
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3065,
Wiki Page: | Phab:D3064
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened) -------------------------------------+------------------------------------- Reporter: niteria | Owner: mpickering Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3065, Wiki Page: | Phab:D3064 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * version: => 8.1 * resolution: => fixed * milestone: => 8.2.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12957#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12957: In a record-update construct:ghc-stage2: panic! (the 'impossible' happened)
-------------------------------------+-------------------------------------
Reporter: niteria | Owner: mpickering
Type: bug | Status: closed
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 8.1
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3065,
Wiki Page: | Phab:D3064
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC