Fix floating of equalities
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 21 Dec 2017 14:13:54 +0000 (14:13 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Thu, 21 Dec 2017 14:14:21 +0000 (14:14 +0000)
commitf5cf9d1a1b198edc929e1fa96c6d841d182fe766
tree21f9daccb8a46e0f5b06ab820861a842cecd91b3
parenta492af06d3264530d134584f22ffb726a16c78ec
Fix floating of equalities

This rather subtle patch fixes Trac #14584.  The problem was
that we'd allowed a coercion, bound in a nested scope, to escape
into an outer scope.

The main changes are

* TcSimplify.floatEqualities takes more care when floating
  equalities to make sure we don't float one out that mentions
  a locally-bound coercion.
  See Note [What prevents a constraint from floating]

* TcSimplify.emitResidualConstraints (which emits the residual
  constraints in simplifyInfer) now avoids burying the constraints
  for escaping CoVars inside the implication constraint.

* Since I had do to this stuff with CoVars, I moved the
  fancy footwork about not quantifying over CoVars from
  TcMType.quantifyTyVars to its caller
  TcSimplify.decideQuantifiedTyVars.  I think its other
  callers don't need to worry about all this CoVar stuff.

This turned out to be surprisigly tricky, and took me a solid
day to get right.  I think the result is reasonably neat, though,
and well documented with Notes.
compiler/typecheck/TcMType.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
testsuite/tests/indexed-types/should_fail/T13877.stderr
testsuite/tests/partial-sigs/should_fail/T14584.hs [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/T14584.stderr [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/T14584a.hs [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/T14584a.stderr [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/all.T
testsuite/tests/typecheck/should_fail/VtaFail.stderr