[GHC] #10603: Output of -ddump-splices is parenthesized incorrectly

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: | Owner: RyanGlScott | Status: new Type: bug | Milestone: Priority: normal | Version: 7.10.1 Component: Template | Operating System: Unknown/Multiple Haskell | Type of failure: Other Keywords: | Blocked By: Architecture: | Related Tickets: Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Sometimes, Template Haskell splices lack necessary parentheses. Minimal example: {{{ $ ghci -XTemplateHaskell -ddump-splices GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help λ> :t $([| case Just 'a' of Just a -> Just ((\x -> x) a) |]) <interactive>:1:3-53: Splicing expression [| case Just 'a' of { Just a_avZ -> Just ((\ x_aw0 -> x_aw0) a_avZ) } |] ======> case Just 'a' of { Just a_a3wI -> Just (\ x_a3wJ -> x_a3wJ a_a3wI) } $([| case Just 'a' of Just a -> Just ((\x -> x) a) |]) :: Maybe Char }}} The suspect part is {{{case Just 'a' of { Just a_a3wI -> Just (\ x_a3wJ -> x_a3wJ a_a3wI) } }}}, which should be {{{case Just 'a' of { Just a_a3wI -> Just ((\ x_a3wJ -> x_a3wJ) a_a3wI) } }}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by goldfire): * keywords: => newcomer Comment: This is indeed a bug, but straightforward to fix. The code is all in `libraries/template-haskell/Language/Haskell/TH/Ppr.hs`. Anyone want to submit a patch? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by dnusbaum): * owner: => dnusbaum Comment: I am new to GHC development, and this looks like a good first bug for me, so I'll work on a patch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): Hooray! Let me know if I can be of help. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: D1114 -------------------------------------+------------------------------------- Changes (by rodlogic): * status: new => patch * differential: => D1114 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: D1114 -------------------------------------+------------------------------------- Comment (by rodlogic): Sorry @dnusbaum, I had my nose around this issue, which was a problem pretty printing the HsSyn AST and not TH AST. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: patch Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10703 | Differential Revisions: Phab:D1114 -------------------------------------+------------------------------------- Changes (by thomie): * differential: D1114 => Phab:D1114 * related: => #10703 * milestone: => 7.12.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: patch Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10703 | Differential Revisions: Phab:D1114 -------------------------------------+------------------------------------- Comment (by osa1): Just to keep this ticket updated: There are some other, related problems with GHC printing that made it to the testsuite. Example: https://github.com/ghc/ghc/blob/5ff4daddd9bc8f424d8f71fb01ebbbae9d608cdf/tes... this is not a valid syntax. (needs a paren around the function) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10703 | Differential Rev(s): Phab:D1114 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.1 => 8.2.1 Comment: This hasn't yet been merged and likely won't make 8.0. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: patch Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10703 | Differential Rev(s): Phab:D1114 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * milestone: 8.2.1 => 8.0.1 Comment: This whole ticket is just symptomatic of a broader issue. As Richard says: "The problem is that HsExpr is intended to be parsed Haskell source. Printing should thus be a breeze: the programmer had to insert all the necessary parens, so we just spit back out what the programmer said. "However, splicing in TH also produces HsExpr. Because it's not programmer-specified, the parentheses are unnecessary here, because no parser will ever look at it. But here we do want parentheses. "We could try to get the HsExpr pretty-printer to be smarter about all of this. But I think that's barking up the wrong tree -- ideally, the HsExprpretty-printer should be very dumb about parentheses. (Indeed, I believe that ppr_expr should never recur into pprParendExpr. But that's more than we need to accomplish today.) "Instead, I think a better approach is to have the Convert module add HsPar nodes. By doing this, we make it more possible that printing HsExpr will be exactly what the programmer wrote, while still getting valid output from TH." And in `HsExpr` we find {{{ HsSyn records exactly where the user put parens, with HsPar. So generally speaking we print without adding any parens. However, some code is internally generated, and in some places parens are absolutely required; so for these places we use pprParendExpr (but don't print double parens of course). For operator applications we don't add parens, because the operator fixities should do the job, except in debug mode (-dppr-debug) so we can see the structure of the parse tree. }}} I like Richard's proposed solution. Let's do that rather than making an ad-hoc fix for this particular example. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10603: Output of -ddump-splices is parenthesized incorrectly
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: dnusbaum
Type: bug | Status: patch
Priority: normal | Milestone: 8.0.1
Component: Template Haskell | Version: 7.10.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Other | Test Case:
Blocked By: | Blocking:
Related Tickets: #10703 | Differential Rev(s): Phab:D1114
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10603: Output of -ddump-splices is parenthesized incorrectly
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: dnusbaum
Type: bug | Status: patch
Priority: normal | Milestone: 8.0.1
Component: Template Haskell | Version: 7.10.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Other | Test Case:
Blocked By: | Blocking:
Related Tickets: #10703 | Differential Rev(s): Phab:D1114
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10603: Output of -ddump-splices is parenthesized incorrectly -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: dnusbaum Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: 7.10.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10703 | Differential Rev(s): Phab:D1114 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10603#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC