[GHC] #9693: Reloading GHCi with Template Haskell names can panic GHC

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: GHC Blocked By: | rejects valid program Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- First, load the following program into GHCi. '''Fun.hs''' {{{#!hs module Fun where import Language.Haskell.TH stuff = do -- let x = mkName "X" x <- newName "X" sequence $ [dataD (return []) x [] [ normalC x [] ] []] }}} '''thbug.hs''' {{{#!hs {-# LANGUAGE TemplateHaskell #-} import Fun stuff }}} Then comment out the newName, un comment the mkName and reload GHCi. {{{ ghc: panic! (the 'impossible' happened) (GHC version 7.8.3 for x86_64-apple-darwin): kcLookupKind APromotionErr RecDataConPE Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} It is important to note this is a valid program, if you then close GHCi and start it again with the modified file, it will load correctly. Reloading after attempting to compile the newName version will cause a panic. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: GHC | Blocked By: rejects valid program | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by goldfire): * status: new => infoneeded Comment: I can't reproduce this problem. When I load your original files (that is, with `newName`, not `mkName`), I get this: {{{ Duplicate exact Name ‘X’ Probable cause: you used a unique Template Haskell name (NameU), perhaps via newName, but bound it multiple times If that's it, then -ddump-splices might be useful }}} The error seems reasonable to me: the name is bound both as a type and as a data constructor. I'm also on GHC 7.8.3 on a Mac. Can you try again to reproduce the problem? Maybe your GHCi state had something else going on... perhaps a `ghci.conf` file? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template | Version: 7.8.3 Haskell | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: GHC | Related Tickets: rejects valid program | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * status: infoneeded => new * component: Compiler => Template Haskell Comment: I am able to reproduce with 7.8.3 and recent HEAD, on Linux, following these steps: * ghci thbug.hs * ignore the error * comment out the newName, uncomment the mkName in Fun.hs * :r This is the result: {{{ $ ghc-7.9.20141108 --interactive thbug.hs GHCi, version 7.9.20141108: http://www.haskell.org/ghc/ :? for help [1 of 2] Compiling Fun ( Fun.hs, interpreted ) [2 of 2] Compiling Main ( thbug.hs, interpreted ) thbug.hs:4:1: Duplicate exact Name ‘X’ Probable cause: you used a unique Template Haskell name (NameU), perhaps via newName, but bound it multiple times If that's it, then -ddump-splices might be useful Failed, modules loaded: Fun. ... Comment out the newName, uncomment the mkName in Fun.hs. ... *Fun> :r [1 of 2] Compiling Fun ( Fun.hs, interpreted ) [2 of 2] Compiling Main ( thbug.hs, interpreted ) ghc: panic! (the 'impossible' happened) (GHC version 7.9.20141108 for x86_64-unknown-linux): kcLookupKind APromotionErr RecDataConPE }}} So the first 'duplicate exact name X' error leaves GHCi in some inconsistent state. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * priority: normal => high Comment: Still reproducible with HEAD. The first error (that you should ignore) is now: {{{ thbug.hs:4:1: error: Same exact name in multiple name-spaces: type constructor or class ‘X’, declared at: thbug.hs:4:1 data constructor ‘X’, declared at: thbug.hs:4:1 Probable cause: you bound a unique Template Haskell name (NameU), perhaps via newName, in different name-spaces. If that's it, then -ddump-splices might be useful }}} And the panic: {{{ ghc: panic! (the 'impossible' happened) (GHC version 7.11.20151213 for x86_64-unknown-linux): kcLookupKind APromotionErr RecDataConPE }}} Panics are bad, raising priority. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: goldfire (added) Comment: Cc'ing Richard, who is our (very busy) Template Haskell czar. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bollmann): upon a quick look at the code the initial error message is thrown in module `rename/RnEnv.hs` by function `lookupExactOcc_either`. But I'm unsure why this leaves `ghci` in an inconsistent state afterwards. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Still reproducible on HEAD, but you'll need a different `Fun.hs`: {{{#!hs module Fun where import Language.Haskell.TH stuff = do -- let x = mkName "X" x <- newName "X" sequence $ [dataD (return []) x [] Nothing [ normalC x [] ] []] }}} And you'll get a slightly different error message: {{{ λ> :r [1 of 2] Compiling Fun ( Fun.hs, interpreted ) [2 of 2] Compiling Main ( thbug.hs, interpreted ) ghc: panic! (the 'impossible' happened) (GHC version 8.1.20161010 for x86_64-unknown-linux): kcLookupTcTyCon APromotionErr RecDataConPE Call stack: CallStack (from HasCallStack): prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1076:58 in ghc:Outputable callStackDoc, called at compiler/utils/Outputable.hs:1080:37 in ghc:Outputable pprPanic, called at compiler/typecheck/TcHsType.hs:1656:27 in ghc:TcHsType Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: (none) Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mgsloan): Is this still an issue? I cannot reproduce it with latest GHC master. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: (none) Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Indeed, it looks like this was fixed! In that case, we should add a regression test for this in GHC's test suite. mgsloan, do you want to pick up this task? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: (none) Type: bug | Status: new Priority: high | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mgsloan): @RyanGIScott Sure! It was interesting figuring out a good way to test issues that only reproduce due to reload. The approach I've taken seems pretty clean to me and might be useful for other such recompilation / reload tests. https://phabricator.haskell.org/D4926 It turns out that there is indeed still some funky statefulness going on. Fresh load of the modified version works fine, whereas reload after modification yields ` Data constructor ‘X’ used as a type constructor`. Nice that it's not a panic, but not correct and indicates some spooky statefulness. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9693: Reloading GHCi with Template Haskell names can panic GHC
-------------------------------------+-------------------------------------
Reporter: maxs | Owner: (none)
Type: bug | Status: new
Priority: high | Milestone:
Component: Template Haskell | Version: 7.8.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC rejects | Unknown/Multiple
valid program | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#9693: Reloading GHCi with Template Haskell names can panic GHC -------------------------------------+------------------------------------- Reporter: maxs | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * priority: high => normal -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9693#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC