Fix impredicativity (again)
authorSimon Peyton Jones <simonpj@microsoft.com>
Sun, 25 Sep 2016 14:50:18 +0000 (15:50 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 30 Sep 2016 11:53:27 +0000 (12:53 +0100)
commitb612da667fe8fa5277fc78e972a86d4b35f98364
tree814c66b0dfb9e218d25f21f1d84617088c151987
parent3012c431e466c55fccff0dd916987a9478cb1ae3
Fix impredicativity (again)

This patch fixes Trac #12616.

Dignosis.  In TcUnify.tc_sub_type_ds we were going to some trouble to
support co- and contra-variance even for impredicative types.  With
-XImpredicativeTYpes, this allowed a unification variable to be
unified with a polytype (probably wrongly) and that caused later
trouble in the constraint solver, where -XImpredicativeTypes was /not/
on.  In effect, -XImpredicativeTypes can't be switched on locally.

Why did we want ImpredicativeTypes locally?  Because the program
generated by GND for a higher-rank method involved impredicative
instantation of 'coerce':
      op = coerce op   -- where op has a higher rank type
See Note [Newtype-deriving instances] in TcGenDeriv.

Cure.

1.  It is ghastly to rely on ImpredicativeTypes (a 100% flaky
    feature) to instantiate coerce polymorphically.  Happily we
    now have Visible Type Application, so I've used that instead
    which should be solid and reliable.

2.  I deleted the code in tc_sub_type_ds that allows the constraint
    solver to "look through" a unification variable to find a
    polytype.  That used to be essential in the days of ReturnTv,
    but it's utterly unreliable and should be consigned to the dustbin
    of history.  (We have ExpType now for the essential uses.)

Tests involving ImpredicativeTypes are affected, but I'm not worried
about them... it's advertised as a feature you can't rely on, and
I want to reform it outright.
24 files changed:
compiler/hsSyn/HsUtils.hs
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcGenDeriv.hs
compiler/typecheck/TcUnify.hs
testsuite/tests/boxy/Base1.hs
testsuite/tests/boxy/T2193.hs
testsuite/tests/boxy/all.T
testsuite/tests/deriving/should_compile/T12616.hs [new file with mode: 0644]
testsuite/tests/deriving/should_compile/all.T
testsuite/tests/deriving/should_fail/T4846.stderr
testsuite/tests/typecheck/should_compile/T11319.hs
testsuite/tests/typecheck/should_compile/T12644.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/all.T
testsuite/tests/typecheck/should_compile/tc211.hs
testsuite/tests/typecheck/should_compile/tc211.stderr
testsuite/tests/typecheck/should_fail/T10619.stderr
testsuite/tests/typecheck/should_fail/T2846b.stderr
testsuite/tests/typecheck/should_fail/T8428.stderr
testsuite/tests/typecheck/should_fail/all.T
testsuite/tests/typecheck/should_fail/tcfail016.stderr
testsuite/tests/typecheck/should_fail/tcfail165.hs
testsuite/tests/typecheck/should_fail/tcfail165.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/tcfail174.hs
testsuite/tests/typecheck/should_fail/tcfail174.stderr