Visible dependent quantification
authorRyan Scott <ryan.gl.scott@gmail.com>
Tue, 18 Dec 2018 01:54:36 +0000 (20:54 -0500)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Fri, 1 Mar 2019 21:26:02 +0000 (16:26 -0500)
commitc26d299dc422f43b8c37da4b26da2067eedcbae8
tree517d7b87043152bee667485e186314d19b55cfba
parentf838809f1e73c20bc70926fe98e735297572ac60
Visible dependent quantification

This implements GHC proposal 35
(https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0035-forall-arrow.rst)
by adding the ability to write kinds with
visible dependent quantification (VDQ).

Most of the work for supporting VDQ was actually done _before_ this
patch. That is, GHC has been able to reason about kinds with VDQ for
some time, but it lacked the ability to let programmers directly
write these kinds in the source syntax. This patch is primarly about
exposing this ability, by:

* Changing `HsForAllTy` to add an additional field of type
  `ForallVisFlag` to distinguish between invisible `forall`s (i.e,
  with dots) and visible `forall`s (i.e., with arrows)
* Changing `Parser.y` accordingly

The rest of the patch mostly concerns adding validity checking to
ensure that VDQ is never used in the type of a term (as permitting
this would require full-spectrum dependent types). This is
accomplished by:

* Adding a `vdqAllowed` predicate to `TcValidity`.
* Introducing `splitLHsSigmaTyInvis`, a variant of `splitLHsSigmaTy`
  that only splits invisible `forall`s. This function is used in
  certain places (e.g., in instance declarations) to ensure that GHC
  doesn't try to split visible `forall`s (e.g., if it tried splitting
  `instance forall a -> Show (Blah a)`, then GHC would mistakenly
  allow that declaration!)

This also updates Template Haskell by introducing a new `ForallVisT`
constructor to `Type`.

Fixes #16326. Also fixes #15658 by documenting this feature in the
users' guide.
64 files changed:
compiler/basicTypes/Var.hs
compiler/deSugar/DsMeta.hs
compiler/hieFile/HieAst.hs
compiler/hsSyn/Convert.hs
compiler/hsSyn/HsDecls.hs
compiler/hsSyn/HsTypes.hs
compiler/hsSyn/HsUtils.hs
compiler/iface/IfaceType.hs
compiler/parser/Parser.y
compiler/parser/RdrHsSyn.hs
compiler/prelude/THNames.hs
compiler/prelude/TysWiredIn.hs
compiler/rename/RnTypes.hs
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcRnDriver.hs
compiler/typecheck/TcSigs.hs
compiler/typecheck/TcSplice.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcValidity.hs
compiler/types/TyCoRep.hs
compiler/types/Type.hs
docs/users_guide/8.10.1-notes.rst
docs/users_guide/glasgow_exts.rst
docs/users_guide/index.rst
libraries/template-haskell/Language/Haskell/TH/Lib.hs
libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
libraries/template-haskell/Language/Haskell/TH/Ppr.hs
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
libraries/template-haskell/changelog.md
testsuite/tests/dependent/should_compile/T16326_Compile1.hs [new file with mode: 0644]
testsuite/tests/dependent/should_compile/T16326_Compile2.hs [new file with mode: 0644]
testsuite/tests/dependent/should_compile/all.T
testsuite/tests/dependent/should_fail/T15859.stderr
testsuite/tests/dependent/should_fail/T16326_Fail1.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail1.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail10.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail10.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail11.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail11.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail12.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail12.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail2.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail2.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail3.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail3.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail4.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail4.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail5.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail5.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail6.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail6.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail7.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail7.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail8.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail8.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail9.hs [new file with mode: 0644]
testsuite/tests/dependent/should_fail/T16326_Fail9.stderr [new file with mode: 0644]
testsuite/tests/dependent/should_fail/all.T
testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
testsuite/tests/th/T16326_TH.hs [new file with mode: 0644]
testsuite/tests/th/T16326_TH.stderr [new file with mode: 0644]
testsuite/tests/th/all.T
utils/haddock