[GHC] #12972: Missed specialisation opportunity with phantom type class parameter?

GHC ghc-devs at haskell.org
Wed Jan 11 15:08:18 UTC 2017


#12972: Missed specialisation opportunity with phantom type class parameter?
-------------------------------------+-------------------------------------
        Reporter:  mpickering        |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
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 simonpj):

 Matthew: this is a rather odd case.   Look at `test4`.   We have a Wanted
 constraint `[W] Phantom x0 Int`, where `x0` is a unification variable.
 But what is `x0`?  We can use functional dependencies to get TWO derived
 constraints:

 1. From the given `[G] Phantom x Int`, we get `[D] x0 ~ x`.
 2. From the top-level `instance Phantom Char Int`, we get `[D] x0 ~ Char`.

 GHC chooses one of these arbitrarily.  If it chooses (2) we unify `x0 :=
 Int`, and solve the constraint from the top-level instance.  The given
 constraint is not used.  We get nice efficient code.

 But if it chooses (2) it'll unify `x0 := x`, and solve the wanted
 constraint from the given one, which is passed as a paramter to `test4`.
 That's less efficient.

 But you set up this situation, by providing two places to solve the
 constraint: from the passed-in givens, or from a top level instance.  Just
 give a simpler type signature `test4 :: Int`.

 It's bit similar with `test3`.  Again there are two ways to solve the
 wanted constraint: from the top-level instance or from the passed-in
 given.

 I'm not inclined to lose sleep over all this, unless you have a compelling
 use-case.

 ---------

 danharaj: I think you are describing an entirely different problem.  Could
 you make a reproducible test case?

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


More information about the ghc-tickets mailing list