Instances in no-evidence implications
authorSimon Peyton Jones <simonpj@microsoft.com>
Fri, 22 Jun 2018 10:27:47 +0000 (11:27 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 22 Jun 2018 10:37:15 +0000 (11:37 +0100)
commit32eb41994f7448caf5fb6b06ed0678d79d029deb
treef93234d879b5480cce1c4afa682d70cf4e2445b7
parent50a35e59034c8616ce5b0fcd3ca2b1757273a552
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.
compiler/typecheck/TcCanonical.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
testsuite/tests/quantified-constraints/T15290.hs [new file with mode: 0644]
testsuite/tests/quantified-constraints/T15290a.hs [new file with mode: 0644]
testsuite/tests/quantified-constraints/T15290a.stderr [new file with mode: 0644]
testsuite/tests/quantified-constraints/all.T
testsuite/tests/typecheck/should_fail/TcCoercibleFail.stderr