[GHC] #14875: -ddump-splices pretty-printing oddities with case statements

GHC ghc-devs at haskell.org
Mon May 14 02:52:21 UTC 2018


#14875: -ddump-splices pretty-printing oddities with case statements
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.2.2
      Resolution:  fixed             |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Debugging         |  Unknown/Multiple
  information is incorrect           |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4688
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ben Gamari <ben@…>):

 In [changeset:"21e1a00c0ccf3072ccc04cd1acfc541c141189d2/ghc"
 21e1a00c/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="21e1a00c0ccf3072ccc04cd1acfc541c141189d2"
 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
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14875#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list