[GHC] #10945: Typed Template Haskell splices broken in HEAD (7.11)
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template | Version: 7.11 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | -------------------------------------+------------------------------------- In the latest HEAD (e2b579e8d77357e8b36f57d15daead101586ac8e) when I say: {{{#!hs $$(return [ SigD (mkName "m") (ForallT [PlainTV (mkName "a")] [] (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))) , FunD (mkName "m") [Clause [VarP (mkName "x")] (NormalB (VarE (mkName "x"))) []] ]) }}} I get: {{{ ghc-stage2: panic! (the 'impossible' happened) (GHC version 7.11.20151007 for x86_64-unknown-linux): runRnSplice $$(return [SigD (mkName "m") (ForallT [PlainTV (mkName "a")] [] (AppT (AppT ArrowT (VarT (mkName "a"))) (VarT (mkName "a")))), FunD (mkName "m") [Clause [VarP (mkName "x")] (NormalB (VarE (mkName "x"))) []]]) }}} This code compiles correctly in GHC 7.10.1. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Changes (by jstolarek): * cc: simonpj (added) Comment: The sequence of calls that leads to this panic goes like this: `TcRnDriver.tc_rn_src_decls` -> `RnSplice.rnTopSpliceDecls` -> `RnSplice.runRnSplice` and in `runRnSplice` we hit `HsTypedSplice` alternative in the case that scrutinizes `splice'`. Looking at git blame I conjecture that this bug was introduced in f46360ed7139ff25741b381647b0a0b6d1000d84 (but would need to bisect to verify), which was a fix for #10047. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by Jan Stolarek <jan.stolarek@…>): In [changeset:"f64f7c36ef9395da1cc7b686aaf1b019204cd0fc/ghc" f64f7c3/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="f64f7c36ef9395da1cc7b686aaf1b019204cd0fc" Tests for #10945 and #10946 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Changes (by jstolarek): * testcase: => th/T10945 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by goldfire): Obviously we shouldn't panic, but the code above looks utterly bogus, for two reasons: 1. According to my understanding, typed splices only work for expressions -- no other contexts allowed. 2. The contents of a typed splice (of type `a`) must be `Q (TExp a)`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by Jan Stolarek <jan.stolarek@…>): In [changeset:"75492e7467ff962f2f2e29e5c8b2c588c94ae8a7/ghc" 75492e7/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="75492e7467ff962f2f2e29e5c8b2c588c94ae8a7" Add typed holes support in Template Haskell. Fixes #10267. Typed holes in typed Template Haskell currently don't work. See #10945 and #10946. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by jstolarek): * owner: => jstolarek -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jstolarek): I initially thought that this bogus code - ie. top-level typed TH splice - should be rejected as a parse error. I spent some time trying to change the parser to reject the code but I couldn't find a good way of doing that. Then I realized that this code should parse: with TH enabled all top-level expressions should really be accepted, including a typed TH splice. After some more thought I believe that the right way of doing this would be to run the typed TH splice and then report a type error in the same way we report a type error here: {{{#!hs {-# LANGUAGE TemplateHaskell #-} module T10945s where import Language.Haskell.TH True }}} {{{ T10945.hs:8:1: Couldn't match type ‘Bool’ with ‘Q [Dec]’ Expected type: DecsQ Actual type: Bool In the expression: True }}} Before investing more time into this I'd like to hear thoughts from other devs. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jstolarek): Oh, I have a nearly-one-line fix. Will post patch later for review. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1344 Wiki Page: | -------------------------------------+------------------------------------- Changes (by jstolarek): * differential: => Phab:D1344 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1344 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Jan Stolarek <jan.stolarek@…>): In [changeset:"1750ebc2e40bab85246717326d3d5c60f132e652/ghc" 1750ebc2/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="1750ebc2e40bab85246717326d3d5c60f132e652" Reject top-level typed TH splices. Fixes #10945 When TemplateHaskell language extension is enabled it is valid to have top-level expressions. Each such expression is treated as a contents of a splice. The problem arises with typed splices. They are not valid at the top level and therefore we should interpret them not as a splice but as a top-level expression (aka. implicit splice). So saying: $$foo is equivalent of: $( $$foo ) This patch makes sure that this is indeed the case. Until now we incorrectly treated typed splices as explicit splices. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: closed Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1344 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => fixed Comment: The test is passing. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: closed Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1344 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"c6ac1e5f25e980c69e36581666210749811ee1c6/ghc" c6ac1e5/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="c6ac1e5f25e980c69e36581666210749811ee1c6" users_guide: TH now partially supports typed holes As requested in #10267. However we still lack support in typed splices. See #10945 and #10946. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10945: Typed Template Haskell splices broken in HEAD (7.11) -------------------------------------+------------------------------------- Reporter: jstolarek | Owner: jstolarek Type: bug | Status: closed Priority: high | Milestone: 8.0.1 Component: Template Haskell | Version: 7.11 Resolution: fixed | Keywords: | TypedTemplateHaskell Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: th/T10945 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1344 Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * keywords: => TypedTemplateHaskell -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10945#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC