Instances in no-evidence implications
authorSimon Peyton Jones <simonpj@microsoft.com>
Fri, 22 Jun 2018 10:27:47 +0000 (11:27 +0100)
committerBen Gamari <ben@smart-cactus.org>
Wed, 27 Jun 2018 21:07:55 +0000 (17:07 -0400)
commit61adfbe6f9926daf06031b7da2522f73addf75dc
treee7963c553b4a09255f180d7cdbe6ca5091842601
parent867e861ba06f6cbc2e0c303e79b1ce928477ff90
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.

(cherry picked from commit 32eb41994f7448caf5fb6b06ed0678d79d029deb)
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