[GHC] #10384: "Can't splice the polymorphic local variable" check looks dead
 
            #10384: "Can't splice the polymorphic local variable" check looks dead
-------------------------------------+-------------------------------------
              Reporter:  ezyang      |             Owner:
                  Type:  task        |            Status:  new
              Priority:  normal      |         Milestone:
             Component:  Template    |           Version:  7.11
  Haskell                            |  Operating System:  Unknown/Multiple
              Keywords:              |   Type of failure:  None/Unknown
          Architecture:              |        Blocked By:
  Unknown/Multiple                   |   Related Tickets:
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
 While I was looking for TH checks which might want to be checked when
 `Quotes` are enabled ala #10382, I found the "Can't splice the polymorphic
 local variable" check in `checkCrossStageLifting` in `TcExpr`. I thought
 this was a bit odd, because there is another implementation of this very
 function in `RnSplice`.
 So I went ahead and removed this check from the compiler, and it validated
 fine.
 I then went and tried to see if I could tickle the problem. An old mailing
 list suggested the following test program to induce the error:
 {{{
 module TH_polymorphic where
 import Language.Haskell.TH
 import Language.Haskell.TH.Syntax
 -- See https://mail.haskell.org/pipermail/template-
 haskell/2006-April/000552.html
 test2 () = runQ [| foldr f z xs |]
     where (f,z,xs) = undefined
 }}}
 but I get this error:
 {{{
 TH_polymorphic.hs:8:17: error:
     Could not deduce (Lift t0) arising from a use of ‘lift’
     from the context: Quasi m
       bound by the inferred type of test2 :: Quasi m => () -> m Exp
       at TH_polymorphic.hs:(8,1)-(9,30)
     The type variable ‘t0’ is ambiguous
     Note: there are several potential instances:
       instance (Lift a, Lift b) => Lift (Either a b)
         -- Defined in ‘Language.Haskell.TH.Syntax’
       instance Lift a => Lift (Maybe a)
         -- Defined in ‘Language.Haskell.TH.Syntax’
       instance Lift Int16 -- Defined in ‘Language.Haskell.TH.Syntax’
       ...plus 24 others
     In the expression: lift xs
     In the first argument of ‘runQ’, namely
       ‘[| foldr f z xs |]
        pending(rn) [
 
            #10384: "Can't splice the polymorphic local variable" check looks dead -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): I don't think it's dead: * In `RnSplice.checkCrossStageLifting` you'll see that it applies ONLY if the stage is `RnPendingUntyped`, i.e. we are renaming the body of an untyped bracket. It does nothing for typed brackets. So what is happening in `RnSplice` is that we treat `[| ...x...|]` as equivalent to `[| ...(lift x)... |]`, which seems right. But what should happen for ''typed'' splices? Presumably, `[|| ...x....||]` should be equivalent to `[|| ....$(tlift x).... ||]`, where {{{ tlift :: Lift t => t -> TExp t }}} It shouldn't matter if `x` has a polymorphic type, because it'll be instantiated by its context. We might need to whiz up a new `SplicePointName` though. But we don't seem to have `tlift` or anything like it. I'm puzzled. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10384#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
 
            #10384: "Can't splice the polymorphic local variable" check looks dead -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by ezyang): * owner: => ezyang Comment: Looking at the Core of: {{{ {-# LANGUAGE TemplateHaskell, FlexibleInstances, IncoherentInstances #-} module A where import Language.Haskell.TH.Syntax instance Lift a where lift = undefined x = \y -> [|| y ||] }}} we can see that it goes through `Lift`, and then an `unsafeTExpCoerce`, so there's no need for a separate `tlift` typeclass. (`tcTypedBracket` is responsible for typechecking the expression and then coercing it.) But that was enough of a hint to let me figure out how to tickle this case. {{{ {-# LANGUAGE TemplateHaskell, RankNTypes, ScopedTypeVariables #-} module A where x = \(y :: forall a. a -> a) -> [|| y ||] }}} {{{ A.hs:3:37: Can't splice the polymorphic local variable ‘y’ In the Template Haskell quotation [|| y ||] In the expression: [|| y ||] In the expression: \ (y :: forall a. a -> a) -> [|| y ||] }}} I'll add a test-case for it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10384#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
 
            #10384: "Can't splice the polymorphic local variable" check looks dead
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                   Owner:  ezyang
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Template Haskell  |                 Version:  7.11
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang 
 
            #10384: "Can't splice the polymorphic local variable" check looks dead
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                   Owner:  ezyang
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Template Haskell  |                 Version:  7.11
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones 
 
            #10384: "Can't splice the polymorphic local variable" check looks dead
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                   Owner:  ezyang
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Template Haskell  |                 Version:  7.11
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang 
 
            #10384: "Can't splice the polymorphic local variable" check looks dead -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.11 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10384#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
 
            #10384: "Can't splice the polymorphic local variable" check looks dead
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                   Owner:  ezyang
            Type:  task              |                  Status:  closed
        Priority:  normal            |               Milestone:
       Component:  Template Haskell  |                 Version:  7.11
      Resolution:  fixed             |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang 
 
            #10384: "Can't splice the polymorphic local variable" check looks dead -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 7.11 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Edward, I'm confused. The ticket is closed, but all patches seem to have been reverted. What's up? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10384#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
 
            #10384: "Can't splice the polymorphic local variable" check looks dead -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * owner: ezyang => * status: closed => new * resolution: fixed => Comment: I think Edward said in IRC that the template-haskell library needs to be fixed up to build with 7.8 again first, since the commits in this ticket cause it to be built as a boot library and we need to be able to bootstrap with 7.8. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10384#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
 
            #10384: "Can't splice the polymorphic local variable" check looks dead -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * owner: => ezyang -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10384#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
 
            #10384: "Can't splice the polymorphic local variable" check looks dead
-------------------------------------+-------------------------------------
        Reporter:  ezyang            |                   Owner:  ezyang
            Type:  task              |                  Status:  closed
        Priority:  normal            |               Milestone:
       Component:  Template Haskell  |                 Version:  7.11
      Resolution:  fixed             |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Changes (by ezyang):
 * status:  new => closed
 * resolution:   => fixed
Comment:
 Re-committed as:
 {{{
 commit f16ddcee0c64a92ab911a7841a8cf64e3ac671fd
 Author: Edward Z. Yang 
participants (1)
- 
                 GHC GHC