[Git][ghc/ghc][wip/pat-builder-tagless] Pattern/expression ambiguity resolution

Vladislav Zavialov gitlab at gitlab.haskell.org
Mon Apr 29 13:39:19 UTC 2019



Vladislav Zavialov pushed to branch wip/pat-builder-tagless at Glasgow Haskell Compiler / GHC


Commits:
0a18bd64 by Vladislav Zavialov at 2019-04-29T13:37:00Z
Pattern/expression ambiguity resolution

This patch removes 'EWildPat', 'EAsPat', 'EViewPat', and 'ELazyPat'
from 'HsExpr' by using the ambiguity resolution system introduced
earlier for the command/expression ambiguity.

Problem: there are places in the grammar where we do not know whether we
are parsing an expression or a pattern, for example:

	do { Con a b <- x } -- 'Con a b' is a pattern
	do { Con a b }      -- 'Con a b' is an expression

Until we encounter binding syntax (<-) we don't know whether to parse
'Con a b' as an expression or a pattern.

The old solution was to parse as HsExpr always, and rejig later:

	checkPattern :: LHsExpr GhcPs -> P (LPat GhcPs)

This meant polluting 'HsExpr' with pattern-related constructors. In
other words, limitations of the parser were affecting the AST, and all
other code (the renamer, the typechecker) had to deal with these extra
constructors.

We fix this abstraction leak by parsing into an overloaded
representation:

	class DisambECP b where ...
	newtype ECP = ECP { runECP_PV :: forall b. DisambECP b => PV (Located b) }

See Note [Ambiguous syntactic categories] for details.

Now the intricacies of parsing have no effect on the hsSyn AST when it
comes to the expression/pattern ambiguity.

- - - - -


30 changed files:

- compiler/deSugar/DsExpr.hs
- compiler/hieFile/HieAst.hs
- compiler/hsSyn/HsExpr.hs
- compiler/hsSyn/HsExtension.hs
- compiler/parser/Lexer.x
- compiler/parser/Parser.y
- compiler/parser/RdrHsSyn.hs
- compiler/rename/RnExpr.hs
- compiler/typecheck/TcRnTypes.hs
- testsuite/tests/parser/should_fail/InfixAppPatErr.stderr
- testsuite/tests/parser/should_fail/T984.stderr
- testsuite/tests/parser/should_fail/all.T
- + testsuite/tests/parser/should_fail/cmdFail001.hs
- + testsuite/tests/parser/should_fail/cmdFail001.stderr
- + testsuite/tests/parser/should_fail/cmdFail002.hs
- + testsuite/tests/parser/should_fail/cmdFail002.stderr
- + testsuite/tests/parser/should_fail/cmdFail003.hs
- + testsuite/tests/parser/should_fail/cmdFail003.stderr
- + testsuite/tests/parser/should_fail/cmdFail004.hs
- + testsuite/tests/parser/should_fail/cmdFail004.stderr
- + testsuite/tests/parser/should_fail/cmdFail005.hs
- + testsuite/tests/parser/should_fail/cmdFail005.stderr
- + testsuite/tests/parser/should_fail/cmdFail006.hs
- + testsuite/tests/parser/should_fail/cmdFail006.stderr
- + testsuite/tests/parser/should_fail/cmdFail007.hs
- + testsuite/tests/parser/should_fail/cmdFail007.stderr
- + testsuite/tests/parser/should_fail/cmdFail008.hs
- + testsuite/tests/parser/should_fail/cmdFail008.stderr
- + testsuite/tests/parser/should_fail/cmdFail009.hs
- + testsuite/tests/parser/should_fail/cmdFail009.stderr


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/0a18bd64ce54ea1c787366e3d38fc2f1a333f58c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/0a18bd64ce54ea1c787366e3d38fc2f1a333f58c
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190429/dc4e6c9c/attachment.html>


More information about the ghc-commits mailing list