[commit: ghc] wip/T13633, wip/non-det-ci: Expression/command ambiguity resolution (e61f6e3)

git at git.haskell.org git at git.haskell.org
Sun Feb 24 20:54:52 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branches: wip/T13633,wip/non-det-ci
Link       : http://ghc.haskell.org/trac/ghc/changeset/e61f6e35e2fffb1e82e9559852481010fe84d8d3/ghc

>---------------------------------------------------------------

commit e61f6e35e2fffb1e82e9559852481010fe84d8d3
Author: Vladislav Zavialov <vlad.z.4096 at gmail.com>
Date:   Fri Feb 1 20:03:54 2019 +0300

    Expression/command ambiguity resolution
    
    This patch removes 'HsArrApp' and 'HsArrForm' from 'HsExpr' by
    introducing a new ambiguity resolution system in the parser.
    
    Problem: there are places in the grammar where we do not know whether we
    are parsing an expression or a command:
    
    	proc x -> do { (stuff) -< x }   -- 'stuff' is an expression
    	proc x -> do { (stuff) }        -- 'stuff' is a command
    
    Until we encounter arrow syntax (-<) we don't know whether to parse
    'stuff' as an expression or a command.
    
    The old solution was to parse as HsExpr always, and rejig later:
    
    	checkCommand :: LHsExpr GhcPs -> P (LHsCmd GhcPs)
    
    This meant polluting 'HsExpr' with command-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 by panicking.
    
    We fix this abstraction leak by parsing into an intermediate
    representation, 'ExpCmd':
    
    	data ExpCmdG b where
    	  ExpG :: ExpCmdG HsExpr
    	  CmdG :: ExpCmdG HsCmd
    
    	type ExpCmd = forall b. ExpCmdG b -> PV (Located (b GhcPs))
    
    	checkExp :: ExpCmd -> PV (LHsExpr GhcPs)
    	checkCmd :: ExpCmd -> PV (LHsCmd GhcPs)
    	checkExp f = f ExpG  -- interpret as an expression
    	checkCmd f = f CmdG  -- interpret as a command
    
    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/command ambiguity.
    
    Future work: apply the same principles to the expression/pattern
    ambiguity.


>---------------------------------------------------------------

e61f6e35e2fffb1e82e9559852481010fe84d8d3
 compiler/deSugar/DsExpr.hs                |   2 -
 compiler/hieFile/HieAst.hs                |   8 -
 compiler/hsSyn/HsExpr.hs                  |  50 ---
 compiler/hsSyn/HsUtils.hs                 |   5 +
 compiler/parser/Parser.y                  | 476 ++++++++++++++--------
 compiler/parser/RdrHsSyn.hs               | 628 ++++++++++++++++++++++++------
 compiler/rename/RnExpr.hs                 |  12 -
 compiler/typecheck/TcRnTypes.hs           |   2 -
 hadrian/src/Settings/Builders/Happy.hs    |   2 +-
 mk/config.mk.in                           |   3 +-
 testsuite/tests/ghci/scripts/T8959.stderr |  42 +-
 11 files changed, 881 insertions(+), 349 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc e61f6e35e2fffb1e82e9559852481010fe84d8d3


More information about the ghc-commits mailing list