Fix solving of implicit parameter constraints
authorSimon Peyton Jones <simonpj@microsoft.com>
Mon, 25 Sep 2017 10:06:34 +0000 (11:06 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Mon, 25 Sep 2017 13:01:20 +0000 (14:01 +0100)
commitabed9bf5008baf6b3e84251fe4d07de80c532ead
treeacb9f6fdacd2aa70e8e5b6c04f30ad3487688148
parent1b476ab55be6c2c553988cc63d8e0c5473136275
Fix solving of implicit parameter constraints

Trac #14218 showed that we were not solving implicit-parameter
constraints correctly.  In particular,

- A tuple constraint could "hide" an implicit-parameter wanted
  constraint, and that in turn could that we solved it from the
  wrong implicit-parameter binding.

- As a special case the HasCallStack constraint (which is just
  short for (IP "callStack" CallStack), was getting mis-solved.

The big change is to arrange that, in TcSMonad.findDict when looking
for a dictionary, either when looking for a matching inert or solved
dictionary, we fail for

  - Tuples that are hiding implicit parameters
    See Note [Tuples hiding implicit parameters]

  - HasCallStack constraints where we have not yet pushed
    on the call-site info
    See Note [Solving CallStack constraints]

I also did a little refactoring

* Move naturallyCoherentClass from Class to TcInteract, its sole
  use site.  Class.hs seems like the wrong place.  (And I also
  do not understand the reason that we need the eq/Coercible/
  Typable stuff in this predicate, but I'll tackle that separately.)

* Move the code that pushes call-site info onto a call stack
  from the "interact" part to the "canonicalise" part of the solver.
compiler/typecheck/TcCanonical.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcType.hs
compiler/types/Class.hs
testsuite/tests/typecheck/should_run/T14218.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/T14218.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/all.T