[GHC] #14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty-printed

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Take this file: {{{#!hs {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -ddump-splices #-} module Bug where import Language.Haskell.TH $([d| f :: (forall a. a) -> Int f _ = undefined |]) }}} In GHC 8.2.2, `-ddump-splices` behaves as you'd expect: {{{ $ /opt/ghc/8.2.2/bin/ghci Bug.hs GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:(8,3)-(9,24): Splicing declarations [d| f_a1zL :: (forall a_a1zM. a_a1zM) -> Int f_a1zL _ = undefined |] ======> f_a49Z :: (forall a_a4a0. a_a4a0) -> Int f_a49Z _ = undefined Ok, one module loaded. }}} But in GHC 8.4.1-alpha (and HEAD), the GHC pretty-printer incorrectly leaves off the parentheses around the type `(forall a. a)`: {{{ $ /opt/ghc/8.4.1/bin/ghci Bug.hs GHCi, version 8.4.0.20171222: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Bug.hs:(8,3)-(9,24): Splicing declarations [d| f_a1EF :: (forall a_a1EG. a_a1EG) -> Int f_a1EF _ = undefined |] ======> f_a4ap :: forall a_a4aq. a_a4aq -> Int f_a4ap _ = undefined Ok, one module loaded. }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): This regression was caused by commit 3b23f680c2b1f80b693eb8896fb21e4bbf8edc7e (`Remove HsContext from ppr_mono_ty, and remove ppParendHsType`). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I think this will be hard to fix. The problem is that `ppParendHsType` was bad, as `HsSyn` already tracks parentheses. It was silly to have another function guess at where to put more of them. And it often guessed wrong, leading to all sorts of pretty-printer infelicities. On the other hand, Template Haskell does ''not'' track parentheses. And so when GHC converts TH to `HsSyn`, the parentheses aren't inserted and so are not pretty-printed. I see two ways forward: 1. Track parentheses in TH, breaking lots and lots of client code. (Note that this is different than TH's usual churn of adding new constructs, because much code out there that consumes the TH AST will start silently failing in the presence of an unexpected ''old'' construct.) 2. Insert parens when converting TH AST to `HsSyn`. By using precedence rules, etc., it should be possible to do a passable job, but we'll never replicate exactly what the user wrote. I think I favor (2). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Yes to (2) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): (2) is the option I implemented for all the rest of these cases, in `hsSyn/Convert.hs` -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * owner: (none) => RyanGlScott Comment: I will take a crack at (2). Note to myself: we should try to emulate the behavior of the first case of [http://git.haskell.org/ghc.git/blob/fb78b0d22635b1d7ae68385c648b8c407f5562c2... /template-haskell/Language/Haskell/TH/Ppr.hs#l734 pprFunArgType] in the `ArrowT` case of `Convert.cvtTypeKind`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): I just realised this is an 8.4.1 regression. @RyanGlScott, I can take a look if you prefer. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): No worries, I believe I already have the patch implemented. (I'll add you as a reviewer, of course.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4298 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4298 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty-
printed
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: RyanGlScott
Type: bug | Status: patch
Priority: high | Milestone: 8.4.1
Component: GHC API | Version: 8.4.1-alpha1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result | Unknown/Multiple
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4298
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: merge Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4298 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14646: GHC 8.4.1 regression: rank-n types no longer parenthesized when pretty- printed -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: closed Priority: high | Milestone: 8.4.1 Component: GHC API | Version: 8.4.1-alpha1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: th/T14646 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4298 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: merge => closed * testcase: => th/T14646 * resolution: => fixed Comment: This appears to have been merged in b92fb5150bdc6a0a090ecba2927c14e19005116e. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14646#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC