Stop inferring over-polymorphic kinds
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 21 Feb 2019 15:27:17 +0000 (15:27 +0000)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Sat, 9 Mar 2019 07:07:53 +0000 (02:07 -0500)
commit1f5cc9dc8aeeafa439d6d12c3c4565ada524b926
treea83c219447dc397524535f408368437422178cba
parent2762f94dc27cc065dded7755f99c66cba26683dd
Stop inferring over-polymorphic kinds

Before this patch GHC was trying to be too clever
(Trac #16344); it succeeded in kind-checking this
polymorphic-recursive declaration

    data T ka (a::ka) b
      = MkT (T Type           Int   Bool)
            (T (Type -> Type) Maybe Bool)

As Note [No polymorphic recursion] discusses, the "solution" was
horribly fragile.  So this patch deletes the key lines in
TcHsType, and a wodge of supporting stuff in the renamer.

There were two regressions, both the same: a closed type family
decl like this (T12785b) does not have a CUSK:
  type family Payload (n :: Peano) (s :: HTree n x) where
    Payload Z (Point a) = a
    Payload (S n) (a `Branch` stru) = a

To kind-check the equations we need a dependent kind for
Payload, and we don't get that any more.  Solution: make it
a CUSK by giving the result kind -- probably a good thing anyway.

The other case (T12442) was very similar: a close type family
declaration without a CUSK.
20 files changed:
compiler/deSugar/DsMeta.hs
compiler/hieFile/HieAst.hs
compiler/hsSyn/HsTypes.hs
compiler/rename/RnSource.hs
compiler/rename/RnTypes.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcTyClsDecls.hs
testsuite/tests/dependent/should_compile/T12442.hs
testsuite/tests/dependent/should_compile/T16326_Compile1.hs
testsuite/tests/dependent/should_compile/T16344b.hs [new file with mode: 0644]
testsuite/tests/dependent/should_compile/all.T
testsuite/tests/dependent/should_fail/T16344.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16344.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16344a.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16344a.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/all.T
testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
testsuite/tests/parser/should_compile/T14189.stderr
testsuite/tests/typecheck/should_fail/T12785b.hs
utils/haddock