Fix TcLevel manipulation in TcDerivInfer.simplifyDeriv
authorSimon Peyton Jones <simonpj@microsoft.com>
Mon, 25 Jun 2018 16:42:57 +0000 (17:42 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Tue, 26 Jun 2018 11:09:36 +0000 (12:09 +0100)
commit261dd83cacec71edd551e9c581d05285c9ea3226
tree325b904128148fa6f865403b70f4c6e84ac54335
parente53c113dcfeca9ee957722ede3d8b6a2c4c751a1
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.
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