diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-05-21 12:01:06 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-06-09 08:06:24 -0400 |
commit | 72c7fe9a1e147dfeaf043f6d591d724a126cce45 (patch) | |
tree | 89c4eb7ba14900e32a6b48c7e73ececcc0b1a4d4 /testsuite/tests/ghc-api | |
parent | 9b607671b9158c60470b2bd57804a7684d3ea33f (diff) | |
download | haskell-72c7fe9a1e147dfeaf043f6d591d724a126cce45.tar.gz |
Make GADT constructors adhere to the forall-or-nothing rule properly
Issue #18191 revealed that the types of GADT constructors don't quite
adhere to the `forall`-or-nothing rule. This patch serves to clean up
this sad state of affairs somewhat. The main change is not in the
code itself, but in the documentation, as this patch introduces two
sections to the GHC User's Guide:
* A "Formal syntax for GADTs" section that presents a BNF-style
grammar for what is and isn't allowed in GADT constructor types.
This mostly exists to codify GHC's existing behavior, but it also
imposes a new restriction that addresses #18191: the outermost
`forall` and/or context in a GADT constructor is not allowed to be
surrounded by parentheses. Doing so would make these
`forall`s/contexts nested, and GADTs do not support nested
`forall`s/contexts at present.
* A "`forall`-or-nothing rule" section that describes exactly what
the `forall`-or-nothing rule is all about. Surprisingly, there was
no mention of this anywhere in the User's Guide up until now!
To adhere the new specification in the "Formal syntax for GADTs"
section of the User's Guide, the following code changes were made:
* A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced.
This is very much like `splitLHsSigmaTy`, except that it avoids
splitting apart any parentheses, which can be syntactically
significant for GADT types. See
`Note [No nested foralls or contexts in GADT constructors]` in
`GHC.Hs.Type`.
* `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was
introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return
it when given a prefix GADT constructor. Unlike `ConDeclGADT`,
`ConDeclGADTPrefixPs` does not split the GADT type into its argument
and result types, as this cannot be done until after the type is
renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why
this is the case).
* `GHC.Renamer.Module.rnConDecl` now has an additional case for
`ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into
its `forall`s, context, argument types, and result type, and
(2) checks for nested `forall`s/contexts. Step (2) used to be
performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather
than the renamer, but now the relevant code from the typechecker
can simply be deleted.
One nice side effect of this change is that we are able to give a
more accurate error message for GADT constructors that use visible
dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`),
which improves the stderr in the `T16326_Fail6` test case.
Fixes #18191. Bumps the Haddock submodule.
Diffstat (limited to 'testsuite/tests/ghc-api')
-rw-r--r-- | testsuite/tests/ghc-api/annotations/T10399.stdout | 60 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/annotations/Test10399.hs | 6 |
2 files changed, 29 insertions, 37 deletions
diff --git a/testsuite/tests/ghc-api/annotations/T10399.stdout b/testsuite/tests/ghc-api/annotations/T10399.stdout index a71abc4139..7588393264 100644 --- a/testsuite/tests/ghc-api/annotations/T10399.stdout +++ b/testsuite/tests/ghc-api/annotations/T10399.stdout @@ -34,9 +34,9 @@ ((Test10399.hs:12:30,AnnComma), [Test10399.hs:12:30]), ((Test10399.hs:12:31-32,AnnCloseP), [Test10399.hs:12:32]), ((Test10399.hs:12:31-32,AnnOpenP), [Test10399.hs:12:31]), -((Test10399.hs:(14,1)-(18,55),AnnData), [Test10399.hs:14:1-4]), -((Test10399.hs:(14,1)-(18,55),AnnSemi), [Test10399.hs:20:1]), -((Test10399.hs:(14,1)-(18,55),AnnWhere), [Test10399.hs:14:21-25]), +((Test10399.hs:(14,1)-(18,53),AnnData), [Test10399.hs:14:1-4]), +((Test10399.hs:(14,1)-(18,53),AnnSemi), [Test10399.hs:20:1]), +((Test10399.hs:(14,1)-(18,53),AnnWhere), [Test10399.hs:14:21-25]), ((Test10399.hs:15:5-64,AnnDcolon), [Test10399.hs:15:11-12]), ((Test10399.hs:15:5-64,AnnSemi), [Test10399.hs:16:5]), ((Test10399.hs:15:14-64,AnnDot), [Test10399.hs:15:23]), @@ -48,37 +48,29 @@ ((Test10399.hs:15:45-46,AnnBang), [Test10399.hs:15:45]), ((Test10399.hs:15:45-46,AnnRarrow), [Test10399.hs:15:48-49]), ((Test10399.hs:15:45-64,AnnRarrow), [Test10399.hs:15:48-49]), -((Test10399.hs:(16,5)-(17,69),AnnCloseP), [Test10399.hs:17:69]), -((Test10399.hs:(16,5)-(17,69),AnnDcolon), [Test10399.hs:16:12-13]), -((Test10399.hs:(16,5)-(17,69),AnnOpenP), [Test10399.hs:16:27]), -((Test10399.hs:(16,5)-(17,69),AnnSemi), [Test10399.hs:18:5]), -((Test10399.hs:(16,15)-(17,69),AnnDot), [Test10399.hs:16:25]), -((Test10399.hs:(16,15)-(17,69),AnnForall), [Test10399.hs:16:15-20]), -((Test10399.hs:(16,27)-(17,69),AnnCloseP), [Test10399.hs:17:69]), -((Test10399.hs:(16,27)-(17,69),AnnOpenP), [Test10399.hs:16:27]), -((Test10399.hs:16:28-43,AnnCloseP), [Test10399.hs:16:43, Test10399.hs:16:43]), -((Test10399.hs:16:28-43,AnnDarrow), [Test10399.hs:16:45-46]), -((Test10399.hs:16:28-43,AnnOpenP), [Test10399.hs:16:28, Test10399.hs:16:28]), -((Test10399.hs:16:30-33,AnnComma), [Test10399.hs:16:34]), -((Test10399.hs:16:48,AnnRarrow), [Test10399.hs:16:50-51]), -((Test10399.hs:(16,48)-(17,68),AnnRarrow), [Test10399.hs:16:50-51]), -((Test10399.hs:16:53-66,AnnRarrow), [Test10399.hs:17:45-46]), -((Test10399.hs:(16,53)-(17,68),AnnRarrow), [Test10399.hs:17:45-46]), -((Test10399.hs:17:48,AnnRarrow), [Test10399.hs:17:50-51]), -((Test10399.hs:17:48-68,AnnRarrow), [Test10399.hs:17:50-51]), -((Test10399.hs:17:66-68,AnnCloseS), [Test10399.hs:17:68]), -((Test10399.hs:17:66-68,AnnOpenS), [Test10399.hs:17:66]), -((Test10399.hs:18:5-55,AnnCloseP), [Test10399.hs:18:55]), -((Test10399.hs:18:5-55,AnnDcolon), [Test10399.hs:18:16-17]), -((Test10399.hs:18:5-55,AnnOpenP), [Test10399.hs:18:19]), -((Test10399.hs:18:19-55,AnnCloseP), [Test10399.hs:18:55]), -((Test10399.hs:18:19-55,AnnOpenP), [Test10399.hs:18:19]), -((Test10399.hs:18:20-54,AnnDot), [Test10399.hs:18:29]), -((Test10399.hs:18:20-54,AnnForall), [Test10399.hs:18:20-25]), -((Test10399.hs:18:31-36,AnnCloseP), [Test10399.hs:18:36]), -((Test10399.hs:18:31-36,AnnOpenP), [Test10399.hs:18:31]), -((Test10399.hs:18:31-36,AnnRarrow), [Test10399.hs:18:38-39]), -((Test10399.hs:18:31-54,AnnRarrow), [Test10399.hs:18:38-39]), +((Test10399.hs:(16,5)-(17,67),AnnDcolon), [Test10399.hs:16:12-13]), +((Test10399.hs:(16,5)-(17,67),AnnSemi), [Test10399.hs:18:5]), +((Test10399.hs:(16,15)-(17,67),AnnDot), [Test10399.hs:16:25]), +((Test10399.hs:(16,15)-(17,67),AnnForall), [Test10399.hs:16:15-20]), +((Test10399.hs:16:27-42,AnnCloseP), [Test10399.hs:16:42, Test10399.hs:16:42]), +((Test10399.hs:16:27-42,AnnDarrow), [Test10399.hs:16:44-45]), +((Test10399.hs:16:27-42,AnnOpenP), [Test10399.hs:16:27, Test10399.hs:16:27]), +((Test10399.hs:16:29-32,AnnComma), [Test10399.hs:16:33]), +((Test10399.hs:16:47,AnnRarrow), [Test10399.hs:16:49-50]), +((Test10399.hs:(16,47)-(17,67),AnnRarrow), [Test10399.hs:16:49-50]), +((Test10399.hs:16:52-65,AnnRarrow), [Test10399.hs:17:44-45]), +((Test10399.hs:(16,52)-(17,67),AnnRarrow), [Test10399.hs:17:44-45]), +((Test10399.hs:17:47,AnnRarrow), [Test10399.hs:17:49-50]), +((Test10399.hs:17:47-67,AnnRarrow), [Test10399.hs:17:49-50]), +((Test10399.hs:17:65-67,AnnCloseS), [Test10399.hs:17:67]), +((Test10399.hs:17:65-67,AnnOpenS), [Test10399.hs:17:65]), +((Test10399.hs:18:5-53,AnnDcolon), [Test10399.hs:18:16-17]), +((Test10399.hs:18:19-53,AnnDot), [Test10399.hs:18:28]), +((Test10399.hs:18:19-53,AnnForall), [Test10399.hs:18:19-24]), +((Test10399.hs:18:30-35,AnnCloseP), [Test10399.hs:18:35]), +((Test10399.hs:18:30-35,AnnOpenP), [Test10399.hs:18:30]), +((Test10399.hs:18:30-35,AnnRarrow), [Test10399.hs:18:37-38]), +((Test10399.hs:18:30-53,AnnRarrow), [Test10399.hs:18:37-38]), ((Test10399.hs:20:1-25,AnnCloseQ), [Test10399.hs:20:24-25]), ((Test10399.hs:20:1-25,AnnOpen), [Test10399.hs:20:1-3]), ((Test10399.hs:20:1-25,AnnSemi), [Test10399.hs:22:1]), diff --git a/testsuite/tests/ghc-api/annotations/Test10399.hs b/testsuite/tests/ghc-api/annotations/Test10399.hs index 6a35712bfd..bb3265000d 100644 --- a/testsuite/tests/ghc-api/annotations/Test10399.hs +++ b/testsuite/tests/ghc-api/annotations/Test10399.hs @@ -13,9 +13,9 @@ mkPoli = mkBila . map ((,,(),,()) <$> P.base <*> P.pos <*> P.form) data MaybeDefault v where SetTo :: forall v . ( Eq v, Show v ) => !v -> MaybeDefault v - SetTo4 :: forall v a. (( Eq v, Show v ) => v -> MaybeDefault v - -> a -> MaybeDefault [a]) - TestParens :: (forall v . (Eq v) -> MaybeDefault v) + SetTo4 :: forall v a. ( Eq v, Show v ) => v -> MaybeDefault v + -> a -> MaybeDefault [a] + TestParens :: forall v . (Eq v) -> MaybeDefault v [t| Map.Map T.Text $tc |] |