summaryrefslogtreecommitdiff
path: root/compiler/parser
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@richarde.dev>2019-09-25 12:28:40 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-03 12:17:30 -0400
commit6655ec734a51eda91273585d8d8e3d5d308a6628 (patch)
tree1f23c2d5e338b214add96b32899f303a7fcf3fc7 /compiler/parser
parent67bf734c6c118aa7caa06875f253defe8b7dd271 (diff)
downloadhaskell-6655ec734a51eda91273585d8d8e3d5d308a6628.tar.gz
Improve documentation around empty tuples/lists
This patch also changes the way we handle empty lists, simplifying them somewhat. See Note [Empty lists]. Previously, we had to special-case empty lists in the type-checker. Now no more! Finally, this patch improves some documentation around the ir_inst field used in the type-checker. This breaks a test case, but I really think the problem is #17251, not really related to this patch. Test case: typecheck/should_compile/T13680
Diffstat (limited to 'compiler/parser')
-rw-r--r--compiler/parser/Parser.y8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index 21737b46e6..997f497510 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -259,6 +259,8 @@ from the Haskell98 data constructor for a tuple. Shift resolves in
favor of sysdcon, which is good because a tuple section will get rejected
if -XTupleSections is not specified.
+See also Note [ExplicitTuple] in GHC.Hs.Expr.
+
-------------------------------------------------------------------------------
state 408 contains 1 shift/reduce conflicts.
@@ -2934,6 +2936,9 @@ texp :: { ECP }
amms (mkHsViewPatPV (comb2 $1 $>) $1 $3) [mu AnnRarrow $2] }
-- Always at least one comma or bar.
+-- Though this can parse just commas (without any expressions), it won't
+-- in practice, because (,,,) is parsed as a name. See Note [ExplicitTuple]
+-- in GHC.Hs.Expr.
tup_exprs :: { forall b. DisambECP b => PV ([AddAnn],SumOrTuple b) }
: texp commas_tup_tail
{ runECP_PV $1 >>= \ $1 ->
@@ -2978,6 +2983,7 @@ tup_tail :: { forall b. DisambECP b => PV [Located (Maybe (Located b))] }
-- The rules below are little bit contorted to keep lexps left-recursive while
-- avoiding another shift/reduce-conflict.
+-- Never empty.
list :: { forall b. DisambECP b => SrcSpan -> PV (Located b) }
: texp { \loc -> runECP_PV $1 >>= \ $1 ->
mkHsExplicitListPV loc [$1] }
@@ -3399,6 +3405,7 @@ con_list : con { sL1 $1 [$1] }
| con ',' con_list {% addAnnotation (gl $1) AnnComma (gl $2) >>
return (sLL $1 $> ($1 : unLoc $3)) }
+-- See Note [ExplicitTuple] in GHC.Hs.Expr
sysdcon_nolist :: { Located DataCon } -- Wired in data constructors
: '(' ')' {% ams (sLL $1 $> unitDataCon) [mop $1,mcp $2] }
| '(' commas ')' {% ams (sLL $1 $> $ tupleDataCon Boxed (snd $2 + 1))
@@ -3407,6 +3414,7 @@ sysdcon_nolist :: { Located DataCon } -- Wired in data constructors
| '(#' commas '#)' {% ams (sLL $1 $> $ tupleDataCon Unboxed (snd $2 + 1))
(mo $1:mc $3:(mcommas (fst $2))) }
+-- See Note [Empty lists] in GHC.Hs.Expr
sysdcon :: { Located DataCon }
: sysdcon_nolist { $1 }
| '[' ']' {% ams (sLL $1 $> nilDataCon) [mos $1,mcs $2] }