[GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
39 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
           Reporter:  goldfire       |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:  8.6.1
          Component:  Compiler       |           Version:  8.4.3
           Keywords:                 |  Operating System:  Unknown/Multiple
  QuantifiedConstraints              |
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 I wanted to see if we're ready to put `join` into `Monad`. So I typed this
 in:

 {{{#!hs
 {-# LANGUAGE QuantifiedConstraints, StandaloneDeriving,
 GeneralizedNewtypeDeriving #-}

 module Bug where

 import Prelude hiding ( Monad(..) )
 import Data.Coerce ( Coercible )

 class Monad m where
   (>>=) :: m a -> (a -> m b) -> m b
   join  :: m (m a) -> m a

 newtype StateT s m a = StateT { runStateT :: s -> m (s, a) }

 instance Monad m => Monad (StateT s m) where
   ma >>= fmb = StateT $ \s -> runStateT ma s >>= \(s1, a) -> runStateT
 (fmb a) s1
   join ssa = StateT $ \s -> runStateT ssa s >>= \(s, sa) -> runStateT sa s

 newtype IntStateT m a = IntStateT { runIntStateT :: StateT Int m a }

 deriving instance (Monad m, forall p q. Coercible p q => Coercible (m p)
 (m q)) => Monad (IntStateT m)

 }}}

 This looks like it should be accepted. But I get

 {{{
 ghc-stage2: panic! (the 'impossible' happened)
   (GHC version 8.5.20180617 for x86_64-apple-darwin):
         addTcEvBind NoEvBindsVar
   [G] df_a67k
     = \ (@ p_a62C) (@ q_a62D) (v_B1 :: Coercible p_a62C q_a62D) ->
         coercible_sel
           @ *
           @ (m_a64Z[ssk:1] p_a62C)
           @ (m_a64Z[ssk:1] q_a62D)
           (df_a651 @ p_a62C @ q_a62D v_B1)
   a67c
   Call stack:
       CallStack (from HasCallStack):
         callStackDoc, called at compiler/utils/Outputable.hs:1164:37 in
 ghc:Outputable
         pprPanic, called at compiler/typecheck/TcRnMonad.hs:1404:5 in
 ghc:TcRnMonad
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
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 goldfire):

 Simpler test case:

 {{{#!hs
 {-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving,
 QuantifiedConstraints #-}

 module Bug where

 import Data.Coerce

 class C m where
   join :: m (m a) -> m a

 newtype T m a = MkT (m a)

 deriving instance (C m, forall p q. Coercible p q => Coercible (m p) (m
 q)) => C (T m)
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
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 goldfire):

 This is blocking #9123.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by goldfire):

 * blocking:   => 9123


--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Good grief.  At first I thought the problem was simple, but now I realise
 there is more to it than that.

 Here is a minimised version that crashes
 {{{
 {-# LANGUAGE TypeApplications, ImpredicativeTypes, ScopedTypeVariables,
              QuantifiedConstraints, StandaloneDeriving,
 GeneralizedNewtypeDeriving #-}

 module T15290 where

 import Prelude hiding ( Monad(..) )
 import Data.Coerce ( Coercible, coerce )

 class Monad m where
   join  :: m (m a) -> m a

 newtype StateT s m a = StateT { runStateT :: s -> m (s, a) }

 newtype IntStateT m a = IntStateT { runIntStateT :: StateT Int m a }

 instance (Monad m, forall p q. Coercible p q => Coercible (m p) (m q))
       => Monad (IntStateT m) where

     join = coerce
           @(forall a. StateT Int m (StateT Int m a) -> StateT Int m a)
           @(forall a. IntStateT m (IntStateT m a)   -> IntStateT m a)
           join
 }}}
 The `deriving` mechanism tries to instantiate `coerce` at a polymorphic
 type,
 a form of impredicative polymorphism, so it's on thin ice.  And in fact
 the ice breaks.

 The call to `coerce` gives rise to
 {{{
 Coercible (forall a. blah1) (forall a. blah2)
 }}}
 and that soon simplifies to the implication constraint (because
 of the forall)
 {{{
 forall a <no-ev>. m (Int, IntStateT m a) ~R# m (Int, StateT Int m a)
 }}}
 But, becuase this constraint is under a forall, inside a type, we have
 to prove it ''without computing any term evidence''.  Hence the `<no-ev>`,
 meaning I can't generate any term-level evidence bindings.

 Alas, I ''must'' generate a term-level evidence binding, to instantiate
 the quantified constraint.   Currently GHC crashes, but I suppose it
 should instead decline to consult given quantified constraints if it's
 in a context where evidence bindings are not allowed.
 I don't see any way out here.

 All this arises from a sneaky attempt to use impredicative polymorphism.
 Maybe instead the derviing mechansim should generate
 {{{
     join = (coerce
            @(StateT Int m (StateT Int m a) -> StateT Int m a)
            @(IntStateT m (IntStateT m a)   -> IntStateT m a)
            join) :: forall a. IntStateT m (IntStateT m a)   -> IntStateT m
 a
 }}}
 and use ordinary predicative instantiation for `coerce`. And
 indeed that works fine right now.   It'll mean a bit more work for
 the `deriving` mechanism, but not much.

 Richard and Ryan may want to comment.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 I don't think your workaround is sufficient to avoid the issue. Consider
 what would happen if we had a variant of `join` with this type signature:

 {{{#!hs
 join  :: (forall b. b -> a) -> m (m a) -> m a
 }}}

 If we plug that in to our proposed scheme:

 {{{#!hs
 {-# LANGUAGE TypeApplications, ImpredicativeTypes, ScopedTypeVariables,
              QuantifiedConstraints, StandaloneDeriving,
 GeneralizedNewtypeDeriving #-}

 module T15290 where

 import Prelude hiding ( Monad(..) )
 import Data.Coerce ( Coercible, coerce )

 class Monad m where
   join  :: (forall b. b -> a) -> m (m a) -> m a

 newtype StateT s m a = StateT { runStateT :: s -> m (s, a) }

 instance Monad m => Monad (StateT s m) where

 newtype IntStateT m a = IntStateT { runIntStateT :: StateT Int m a }

 instance (Monad m, forall p q. Coercible p q => Coercible (m p) (m q))
       => Monad (IntStateT m) where

     join = coerce
           @((forall b. b -> a) -> StateT Int m (StateT Int m a) -> StateT
 Int m a)
           @((forall b. b -> a) -> IntStateT m (IntStateT m a)   ->
 IntStateT m a)
           join :: forall a. (forall b. b -> a) -> IntStateT m (IntStateT m
 a) -> IntStateT m a
 }}}

 Then that, too, will panic:

 {{{
 $ /opt/ghc/head/bin/ghc Bug.hs
 [1 of 1] Compiling T15290           ( Bug.hs, Bug.o )
 ghc: panic! (the 'impossible' happened)
   (GHC version 8.5.20180616 for x86_64-unknown-linux):
         addTcEvBind NoEvBindsVar
   [G] df_a1pg
     = \ (@ p_aW5) (@ q_aW6) (v_B1 :: Coercible p_aW5 q_aW6) ->
         coercible_sel
           @ *
           @ (m_a1nx[ssk:1] p_aW5)
           @ (m_a1nx[ssk:1] q_aW6)
           (df_a1nz @ p_aW5 @ q_aW6 v_B1)
   a1og
   Call stack:
       CallStack (from HasCallStack):
         callStackDoc, called at compiler/utils/Outputable.hs:1164:37 in
 ghc:Outputable
         pprPanic, called at compiler/typecheck/TcRnMonad.hs:1404:5 in
 ghc:TcRnMonad
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Yes, I agree.  I'll stop the panic (by refraining from using quantified
 constraints if I have no place to put the evidence) but that will make GHC
 reject `deriving` for
 * A higher rank method
 * That makes essential use of a quantified constraint
 * Under a forall

 I don't see how to avoid that restriction.   If anyone else does, please
 say so!

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Wait, you're saying that deriving classes with methods that use higher-
 rank types will no longer work? If so, that is going to break enormous
 swaths of code both in the wild and in the test suite (see
 [http://git.haskell.org/ghc.git/blob/3048a87a3f2ef97d9f6559064d7a32ec7566542b:/testsuite/tests/deriving/should_compile/T8631.hs#l14
 here] for one example).

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 > Wait, you're saying that deriving classes with methods that use higher-
 rank types will no longer work?

 No, I am not saying that (see the second bullet).  It's just that if you
 can't ''simultaneously'' exploit impredicative instantiation of `coerce`
 and quantified constraints.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Ah, my apologies. I interpreted that list of bullet points as three
 separate criteria under which `deriving` would fail, not as a list of
 three conditions which must simultaneously hold.

 In that case, I feel much better about this idea (if this really is the
 only way forward). I've always thought that derived instance methods
 should use `InstanceSigs`, and this gives us a good excuse to do so. (And
 I think certain folks, possibly from Iceland, will find that more
 aesthetically pleasing to look at in `-ddump-deriv` output.)

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 You could use `InstanceSigs`; or just an expression type signature as I
 have done.

 And incidentally you can them omit the second type argument to `coerce`,
 which is perhaps nice.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 To be clear: are you working on the change to `deriving` alongside the
 typechecker changes? Or should I implement the `deriving` bits?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:12>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Could you do the `deriving` bits?  Thanks!

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:13>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 See also #14883, which is very similar

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:14>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Hm, I've hit a roadblock when trying to switch over to the scheme proposed
 in comment:5. Consider this code:

 {{{#!hs
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE ImpredicativeTypes #-}
 {-# LANGUAGE KindSignatures #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE TypeApplications #-}
 {-# OPTIONS_GHC -ddump-deriv #-}
 module Bug where

 import Data.Coerce

 class C a where
   c :: Int -> forall b. b -> a

 instance C Int where
   c _ _ = 42

 newtype Age = MkAge Int

 -- This is what
 --
 --   deriving instance C Age
 --
 -- would generate:
 instance C Age where
   c = coerce @(             Int -> forall b. b -> a)
              c :: forall a. Int -> forall b. b -> a
 }}}

 This fails to typecheck:

 {{{
 $ /opt/ghc/8.4.3/bin/ghc Bug.hs
 [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

 Bug.hs:26:7: error:
     • Couldn't match representation of type ‘forall b2. b2 -> a’
                                with that of ‘b1 -> a’
         arising from a use of ‘coerce’
     • In the expression:
           coerce @(Int -> forall b. b -> a) c ::
             forall a. Int -> forall b. b -> a
       In an equation for ‘c’:
           c = coerce @(Int -> forall b. b -> a) c ::
                 forall a. Int -> forall b. b -> a
       In the instance declaration for ‘C Age’
    |
 26 |   c = coerce @(             Int -> forall b. b -> a)
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
 }}}

 The same error occurs if I use `InstanceSigs`.

 Any ideas on how to make this work?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:15>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by goldfire):

 The current behavior was introduced in
 b612da667fe8fa5277fc78e972a86d4b35f98364

 That commit fixes some impredicativity bug but also rewrites GND to use
 type application. However, the change to GND also has it work with
 polytypes instead of its previous behavior, using monotypes. It sounds
 like we want to go to the previous behavior.

 As for Ryan's question: try passing both type arguments to `coerce`. As
 explained in the visible type application paper, type signatures on
 expressions are ''deeply skolemized'', which is causing havoc for you
 here. I think including the second type parameter to `coerce` will solve
 the problem.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 Thanks Richard, that did indeed solve that problem.

 On the other hand, I seem to have hit an even trickier problem. For
 context: this is the entirety of my patch at the moment:

 {{{#!diff
 diff --git a/compiler/typecheck/TcGenDeriv.hs
 b/compiler/typecheck/TcGenDeriv.hs
 index b944520..1f1cba2 100644
 --- a/compiler/typecheck/TcGenDeriv.hs
 +++ b/compiler/typecheck/TcGenDeriv.hs
 @@ -1668,13 +1668,16 @@ gen_Newtype_binds loc cls inst_tvs inst_tys rhs_ty
                                            [] rhs_expr]
        where
          Pair from_ty to_ty = mkCoerceClassMethEqn cls inst_tvs inst_tys
 rhs_ty meth_id
 +        (_, _, from_tau) = tcSplitSigmaTy from_ty
 +        (_, _, to_tau)   = tcSplitSigmaTy to_ty

          meth_RDR = getRdrName meth_id

          rhs_expr = nlHsVar (getRdrName coerceId)
 -                                      `nlHsAppType` from_ty
 -                                      `nlHsAppType` to_ty
 -                                      `nlHsApp`     nlHsVar meth_RDR
 +                                      `nlHsAppType`     from_tau
 +                                      `nlHsAppType`     to_tau
 +                                      `nlHsApp`         nlHsVar meth_RDR
 +                                      `nlExprWithTySig` to_ty

      mk_atf_inst :: TyCon -> TcM FamInst
      mk_atf_inst fam_tc = do
 }}}

 i.e., drop the `forall`s from each of the types inside the explicit type
 applications, and put an explicit type signature (with `forall`s) on the
 whole expression.

 Now here's the kicker: if you try that patch on this program:

 {{{#!hs
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE TypeApplications #-}
 {-# OPTIONS_GHC -ddump-deriv #-}
 module Bug where

 import Data.Coerce

 class Foo a where
   bar :: a -> Maybe b

 instance Foo Int where
   bar _ = Nothing

 newtype Age = MkAge Int
   deriving Foo
 }}}

 Then it no longer typechecks:

 {{{
 $ inplace/bin/ghc-stage2 --interactive ../Bug2.hs
 GHCi, version 8.7.20180621: http://www.haskell.org/ghc/  :? for help
 Loaded GHCi configuration from /home/rgscott/.ghci
 [1 of 1] Compiling Bug              ( ../Bug2.hs, interpreted )

 ==================== Derived instances ====================
 Derived class instances:
   instance Bug.Foo Bug.Age where
     Bug.bar
       = GHC.Prim.coerce
           @(GHC.Types.Int -> GHC.Maybe.Maybe b_a1AR)
           @(Bug.Age -> GHC.Maybe.Maybe b_a1AR)
           Bug.bar ::
           forall (b_a1AR :: TYPE GHC.Types.LiftedRep).
           Bug.Age -> GHC.Maybe.Maybe b_a1AR


 Derived type family instances:



 ../Bug2.hs:16:12: error:
     • Couldn't match type ‘b1’ with ‘b’
       ‘b1’ is a rigid type variable bound by
         an expression type signature:
           forall b1. Age -> Maybe b1
         at ../Bug2.hs:16:12-14
       ‘b’ is a rigid type variable bound by
         the type signature for:
           bar :: forall b. Age -> Maybe b
         at ../Bug2.hs:16:12-14
       Expected type: Age -> Maybe b1
         Actual type: Age -> Maybe b
     • In the expression:
           coerce @(Int -> Maybe b) @(Age -> Maybe b) bar ::
             forall (b :: TYPE GHC.Types.LiftedRep). Age -> Maybe b
       In an equation for ‘bar’:
           bar
             = coerce @(Int -> Maybe b) @(Age -> Maybe b) bar ::
                 forall (b :: TYPE GHC.Types.LiftedRep). Age -> Maybe b
       When typechecking the code for ‘bar’
         in a derived instance for ‘Foo Age’:
         To see the code I am typechecking, use -ddump-deriv
       In the instance declaration for ‘Foo Age’
     • Relevant bindings include
         bar :: Age -> Maybe b (bound at ../Bug2.hs:16:12)
    |
 16 |   deriving Foo
    |            ^^^
 }}}

 For the life of me, I can't figure out why this shouldn't typecheck.
 What's even stranger, if I take the code that GHC's giving me and paste it
 back into the source:

 {{{#!hs
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE TypeApplications #-}
 {-# OPTIONS_GHC -ddump-deriv #-}
 module Bug where

 import Data.Coerce

 class Foo a where
   bar :: a -> Maybe b

 instance Foo Int where
   bar _ = Nothing

 newtype Age = MkAge Int
   -- deriving Foo

 instance Foo Age where
   bar = coerce @(Int -> Maybe b)
                @(Age -> Maybe b)
                bar :: forall b. Age -> Maybe b
 }}}

 Then it typechecks again!

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:17>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Simon Peyton Jones <simonpj@…>):

 In [changeset:"32eb41994f7448caf5fb6b06ed0678d79d029deb/ghc" 32eb419/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="32eb41994f7448caf5fb6b06ed0678d79d029deb"
 Instances in no-evidence implications

 Trac #15290 showed that it's possible that we might attempt to use a
 quantified constraint to solve an equality in a situation where we
 don't have anywhere to put the evidence bindings.  This made GHC crash.

 This patch stops the crash, but still rejects the pogram.  See
 Note [Instances in no-evidence implications] in TcInteract.

 Finding this bug revealed another lurking bug:

 * An infelicity in the treatment of superclasses -- we were expanding
   them locally at the leaves, rather than at their binding site; see
   (3a) in Note [The superclass story].

   As a consequence, TcRnTypes.superclassesMightHelp must look inside
   implications.

 In more detail:

 * Stop the crash, by making TcInteract.chooseInstance test for
   the no-evidence-bindings case.  In that case we simply don't
   use the instance.  This entailed a slight change to the type
   of chooseInstance.

 * Make TcSMonad.getPendingScDicts (now renamed getPendingGivenScs)
   return only Givens from the /current level/; and make
   TcRnTypes.superClassesMightHelp look inside implications.

 * Refactor the simpl_loop and superclass-expansion stuff in
   TcSimplify.  The logic is much easier to understand now, and
   has less duplication.
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:18>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:  quantified-
                                     |  constraints/T15290, T15290a
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by simonpj):

 * testcase:   => quantified-constraints/T15290, T15290a


--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:19>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#15290: QuantifiedConstraints: panic "addTcEvBind NoEvBindsVar"
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:  quantified-
                                     |  constraints/T15290, T15290a
      Blocked By:                    |             Blocking:  9123, 14883
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 To make things more outrageous, if I manually freshen the type variable
 binders in `to_ty` in comment:17 (using `freshTyVarBndrs`), //then// it
 works. Quite mysterious.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15290#comment:20>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
12