[GHC] #13984: Panic when using a TH splice in a do bind pattern
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1-rc3 Keywords: panic | Operating System: Unknown/Multiple template-haskell | Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When compiling this file with HEAD (f656fba19d0cefe05643ddea35d080ea332a6584): {{{#!hs {-# LANGUAGE TemplateHaskell #-} module Panic where import Language.Haskell.TH expr :: IO Exp expr = runQ $ do name <- newName "foo" [| do $(varP name) <- pure (); pure () |] }}} I get this message: {{{ [1 of 1] Compiling Panic ( Panic.hs, Panic.o ) ghc-stage2: panic! (the 'impossible' happened) (GHC version 8.3.20170713 for x86_64-unknown-linux): isIrrefutableHsPat: $(varP name) Call stack: CallStack (from HasCallStack): prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable pprPanic, called at compiler/hsSyn/HsPat.hs:643:15 in ghc:HsPat Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} It compiles normally with GHC 8.2.1-rc2 (20170507). The bug exists in rc3 (20170704). I am unable to perform a more precise bisect. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mbieleck): The bug was probably introduced by 2fcb5c5c3f6c5a5936eeb5dc07b476e5737f12ad. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: AaronFriel (added) Comment: Aaron, as the author of that patch, what are your thoughts? The problem is that `isIrrefutableHsPat` has as an invariant that it should be called //after// the renamer (see [http://git.haskell.org/ghc.git/blob/f656fba19d0cefe05643ddea35d080ea332a6584... here]), but your patch calls `isIrrefutableHsPat` directly from the renamer. Do you think it's sensible to have `isIrrefutableHsPat` return `False` for all Template Haskell splices? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mbieleck): Replying to [comment:2 RyanGlScott]:
`isIrrefutableHsPat` has as an invariant that it should be called //after// the renamer (see [http://git.haskell.org/ghc.git/blob/f656fba19d0cefe05643ddea35d080ea332a6584... here]), but your patch calls `isIrrefutableHsPat` directly from the renamer.
I think the comment you mentioned
Both should be gotten rid of by renamer before isIrrefutablePat is called
may be wrong. The comment [http://git.haskell.org/ghc.git/blob/f656fba19d0cefe05643ddea35d080ea332a6584... here] says:
This is the result of splicing a splice. It is produced by the renamer and consumed by the typechecker. It lives only between the two.
(this is not directly related to the issue, just stumbled upon this while trying to fix this) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * priority: normal => high Comment: Certainly, I think that comment's claim needs to be removed (or at least tempered), since `isIrrefutableHsPat` is clearly being used in more places than it was originally designed for nowadays. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * milestone: => 8.2.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): I think it's reasonable to do the conservative thing here and just return `False` for splices for now. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3766 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch * differential: => Phab:D3766 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.2.1-rc3 Resolution: | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3766 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"36e8bcba08446dbc4e7532ef9db5517c13977bf9/ghc" 36e8bcba/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="36e8bcba08446dbc4e7532ef9db5517c13977bf9" HsPat: Assume that no spliced patterns are irrefutable This is a conservative assumption which will limit some uses of spliced patterns, but it fixes #13984. Test Plan: Validate Reviewers: RyanGlScott, AaronFriel, austin Reviewed By: RyanGlScott Subscribers: rwbarton, thomie GHC Trac Issues: #13984 Differential Revision: https://phabricator.haskell.org/D3766 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13984: Panic when using a TH splice in a do bind pattern -------------------------------------+------------------------------------- Reporter: mbieleck | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 8.2.1-rc3 Resolution: fixed | Keywords: panic | template-haskell Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3766 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: Merged to `ghc-8.2` with b45d1277ada4b5ce30d5cfa188fb020f4806d9ea. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13984#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC