Standalone kind signatures (#16794)

Implements GHC Proposal #54: .../ghc-proposals/blob/master/proposals/0054-kind-signatures.rst

With this patch, a type constructor can now be given an explicit
standalone kind signature:

  {-# LANGUAGE StandaloneKindSignatures #-}
  type Functor :: (Type -> Type) -> Constraint
  class Functor f where
    fmap :: (a -> b) -> f a -> f b

This is a replacement for CUSKs (complete user-specified
kind signatures), which are now scheduled for deprecation.

User-facing changes
-------------------

* A new extension flag has been added, -XStandaloneKindSignatures, which
  implies -XNoCUSKs.

* There is a new syntactic construct, a standalone kind signature:

    type <name> :: <kind>

  Declarations of data types, classes, data families, type families, and
  type synonyms may be accompanied by a standalone kind signature.

* A standalone kind signature enables polymorphic recursion in types,
  just like a function type signature enables polymorphic recursion in
  terms. This obviates the need for CUSKs.

* TemplateHaskell AST has been extended with 'KiSigD' to represent
  standalone kind signatures.

* GHCi :info command now prints the kind signature of type constructors:

    ghci> :info Functor
    type Functor :: (Type -> Type) -> Constraint
    ...

Limitations
-----------

* 'forall'-bound type variables of a standalone kind signature do not
  scope over the declaration body, even if the -XScopedTypeVariables is
  enabled. See #16635 and #16734.

* Wildcards are not allowed in standalone kind signatures, as partial
  signatures do not allow for polymorphic recursion.

* Associated types may not be given an explicit standalone kind
  signature. Instead, they are assumed to have a CUSK if the parent class
  has a standalone kind signature and regardless of the -XCUSKs flag.

* Standalone kind signatures do not support multiple names at the moment:

    type T1, T2 :: Type -> Type   -- rejected
    type T1 = Maybe
    type T2 = Either String

  See #16754.

* Creative use of equality constraints in standalone kind signatures may
  lead to GHC panics:

    type C :: forall (a :: Type) -> a ~ Int => Constraint
    class C a where
      f :: C a => a -> Int

  See #16758.

Implementation notes
--------------------

* The heart of this patch is the 'kcDeclHeader' function, which is used to
  kind-check a declaration header against its standalone kind signature.
  It does so in two rounds:

    1. check user-written binders
    2. instantiate invisible binders a la 'checkExpectedKind'

* 'kcTyClGroup' now partitions declarations into declarations with a
  standalone kind signature or a CUSK (kinded_decls) and declarations
  without either (kindless_decls):

    * 'kinded_decls' are kind-checked with 'checkInitialKinds'
    * 'kindless_decls' are kind-checked with 'getInitialKinds'

* DerivInfo has been extended with a new field:

    di_scoped_tvs :: ![(Name,TyVar)]

  These variables must be added to the context in case the deriving clause
  references tcTyConScopedTyVars. See #16731.
21 jobs for master in 427 minutes and 21 seconds (queued for 5 seconds)
Status Job ID Name Coverage
  Lint
passed #164734
lint
lint-linters

00:00:23

passed #164737
lint
lint-submods-branch

00:00:29

passed #164735
lint
lint-testsuite

00:00:23

passed #164736
lint
typecheck-testsuite

00:00:21

 
  Build
passed #164739
x86_64-linux
hadrian-ghc-in-ghci

00:21:14

passed #164741
x86_64-linux
release-x86_64-linux-deb9-dwarf

02:07:38

passed #164740
x86_64-linux
validate-x86_64-linux-deb9-debug

03:29:26

passed #164738
x86_64-linux
validate-x86_64-linux-deb9-hadrian

02:32:24

 
  Full Build
failed #164743
aarch64-linux allowed to fail
validate-aarch64-linux-deb9

00:12:04

passed #164744
x86_64-linux
validate-i386-linux-deb9

01:06:06

failed #164742
x86_64-darwin
validate-x86_64-darwin

00:45:02

passed #164745
x86_64-linux
validate-x86_64-linux-deb9-integer-simple

01:54:50

passed #164746
x86_64-linux
validate-x86_64-linux-deb9-unreg

02:07:54

passed #164747
x86_64-linux
validate-x86_64-linux-fedora27

01:57:10

failed #164749
x86_64-windows allowed to fail
validate-x86_64-windows

00:36:56

failed #164748
x86_64-windows allowed to fail
validate-x86_64-windows-hadrian

03:05:44

 
  Cleanup
failed #164750
x86_64-darwin
cleanup-darwin

00:00:06

 
  Packaging
skipped #164751
x86_64-linux allowed to fail
doc-tarball
 
  Testing
skipped #164752
x86_64-linux allowed to fail manual
hackage
skipped #164753
x86_64-linux
perf-nofib
 
  Deploy
skipped #164754
x86_64-linux allowed to fail
pages
 
Name Stage Failure
failed
validate-x86_64-windows-hadrian Full Build
junit.xml: found 1 matching files                  
WARNING: Failed to load system CertPool:crypto/x509: system root pool is not available on Windows
Uploading artifacts to coordinator... ok
id=164748 responseStatus=201 Created token=89RqccxJ
Uploading artifacts...
Runtime platform
arch=amd64 os=windows pid=2736 revision=1f513601 version=11.10.1
junit.xml: found 1 matching files

WARNING: Failed to load system CertPool:crypto/x509: system root pool is not available on Windows
Uploading artifacts to coordinator... ok
id=164748 responseStatus=201 Created token=89RqccxJ
ERROR: Job failed: exit status 1
failed
cleanup-darwin Cleanup
Using Shell executor...
Running on hippogrif-lumbering...
Reinitialized existing Git repository in /Users/ghcbuilder/builds/_kpDUkXG/0/ghc/ghc/.git/
Fetching changes...
From https://gitlab.haskell.org/ghc/ghc
* [new branch] wip/T14998 -> origin/wip/T14998
Checking out 0b5eede9 as master...
fatal: Cannot lstat 'testsuite/tests/typecheck/should_compile/T12923.run/': No such file or directory
ERROR: Job failed: exit status 1
failed
validate-x86_64-darwin Full Build
Runtime platform                                    arch=amd64 os=darwin pid=67024 revision=ac2a293c version=11.11.2
WARNING: ghc-*.tar.xz: no matching files
WARNING: junit.xml: no matching files
ERROR: No files to upload
Uploading artifacts...
Runtime platform
arch=amd64 os=darwin pid=67026 revision=ac2a293c version=11.11.2
WARNING: junit.xml: no matching files
ERROR: No files to upload
ERROR: Job failed: exit status 1
failed
validate-x86_64-windows Full Build
Runtime platform                                    arch=amd64 os=windows pid=4068 revision=1f513601 version=11.10.1
WARNING: ghc-*.tar.xz: no matching files
WARNING: junit.xml: no matching files
ERROR: No files to upload
Uploading artifacts...
Runtime platform
arch=amd64 os=windows pid=5740 revision=1f513601 version=11.10.1
WARNING: junit.xml: no matching files
ERROR: No files to upload
ERROR: Job failed: exit status 2
failed
validate-aarch64-linux-deb9 Full Build
$ cp -Rf $HOME/.cabal cabal-cache
Uploading artifacts...
WARNING: ghc-*.tar.xz: no matching files
WARNING: junit.xml: no matching files
ERROR: No files to upload
Uploading artifacts...
WARNING: junit.xml: no matching files
ERROR: No files to upload
ERROR: Job failed: exit code 1