[commit: ghc] master: Fix #14875 by introducing PprPrec, and using it (21e1a00)

git at git.haskell.org git at git.haskell.org
Mon May 14 02:52:28 UTC 2018


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/21e1a00c0ccf3072ccc04cd1acfc541c141189d2/ghc

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

commit 21e1a00c0ccf3072ccc04cd1acfc541c141189d2
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Sun May 13 18:36:23 2018 -0400

    Fix #14875 by introducing PprPrec, and using it
    
    Trying to determine when to insert parentheses during TH
    conversion is a bit of a mess. There is an assortment of functions
    that try to detect this, such as:
    
    * `hsExprNeedsParens`
    * `isCompoundHsType`
    * `hsPatNeedsParens`
    * `isCompoundPat`
    * etc.
    
    To make things worse, each of them have slightly different semantics.
    Plus, they don't work well in the presence of explicit type
    signatures, as #14875 demonstrates.
    
    All of these problems can be alleviated with the use of an explicit
    precedence argument (much like what `showsPrec` currently does). To
    accomplish this, I introduce a new `PprPrec` data type, and define
    standard predences for things like function application, infix
    operators, function arrows, and explicit type signatures (that last
    one is new). I then added `PprPrec` arguments to the various
    `-NeedsParens` functions, and use them to make smarter decisions
    about when things need to be parenthesized.
    
    A nice side effect is that functions like `isCompoundHsType` are
    now completely unneeded, since they're simply aliases for
    `hsTypeNeedsParens appPrec`. As a result, I did a bit of refactoring
    to remove these sorts of functions. I also did a pass over various
    utility functions in GHC for constructing AST forms and used more
    appropriate precedences where convenient.
    
    Along the way, I also ripped out the existing `TyPrec`
    data type (which was tailor-made for pretty-printing `Type`s) and
    replaced it with `PprPrec` for consistency.
    
    Test Plan: make test TEST=T14875
    
    Reviewers: alanz, goldfire, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #14875
    
    Differential Revision: https://phabricator.haskell.org/D4688


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

21e1a00c0ccf3072ccc04cd1acfc541c141189d2
 compiler/basicTypes/BasicTypes.hs                  |  57 +++----
 compiler/hsSyn/Convert.hs                          |  42 +++---
 compiler/hsSyn/HsDecls.hs                          |   7 +-
 compiler/hsSyn/HsExpr.hs                           | 128 ++++++++++------
 compiler/hsSyn/HsLit.hs                            |  57 +++----
 compiler/hsSyn/HsPat.hs                            | 165 ++++++++-------------
 compiler/hsSyn/HsTypes.hs                          |  54 ++++---
 compiler/hsSyn/HsUtils.hs                          |  28 ++--
 compiler/iface/IfaceSyn.hs                         |   2 +-
 compiler/iface/IfaceType.hs                        | 126 ++++++++--------
 compiler/typecheck/TcGenDeriv.hs                   |   7 +-
 compiler/types/TyCoRep.hs                          |  37 ++---
 compiler/types/Type.hs                             |   2 +-
 .../template-haskell/Language/Haskell/TH/Ppr.hs    |  19 ++-
 .../tests/deriving/should_compile/T14682.stderr    |   4 +-
 testsuite/tests/th/T14875.hs                       |  14 ++
 testsuite/tests/th/T14875.stderr                   |  24 +++
 testsuite/tests/th/all.T                           |   1 +
 18 files changed, 417 insertions(+), 357 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 21e1a00c0ccf3072ccc04cd1acfc541c141189d2


More information about the ghc-commits mailing list