Fix TcLevel manipulation in TcDerivInfer.simplifyDeriv
authorSimon Peyton Jones <simonpj@microsoft.com>
Mon, 25 Jun 2018 16:42:57 +0000 (17:42 +0100)
committerBen Gamari <ben@smart-cactus.org>
Wed, 27 Jun 2018 21:07:56 +0000 (17:07 -0400)
commit145f7c663e6df4ecfa848c0e2e478454cf9fb1d9
treeb8d426e115699d1936a2e77a913596f306783f4f
parent7e19610c925c45ade589b573a7e1c247cd8265ef
Fix TcLevel manipulation in TcDerivInfer.simplifyDeriv

The level numbers we were getting simply didn't obey the
invariant (ImplicInv) in TcType
   Note [TcLevel and untouchable type variables]

That leads to chaos. Easy to fix.  I improved the documentation.

I also added an assertion in TcSimplify that checks that
level numbers go up by 1 as we dive inside implications, so
that we catch the problem at source rather than than through
its obscure consequences.

That in turn showed up that TcRules was also generating
constraints that didn't obey (ImplicInv), so I fixed that too.
I have no idea what consequences were lurking behing that
bug, but anyway now it's fixed.  Hooray.

(cherry picked from commit 261dd83cacec71edd551e9c581d05285c9ea3226)
compiler/typecheck/TcDerivInfer.hs
compiler/typecheck/TcRules.hs
compiler/typecheck/TcSimplify.hs
testsuite/tests/quantified-constraints/T15290b.hs [new file with mode: 0644]
testsuite/tests/quantified-constraints/T15290b.stderr [new file with mode: 0644]
testsuite/tests/quantified-constraints/all.T