[GHC] #10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty`

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #1062, #1176, Differential Revisions: | #7666 -------------------------------------+------------------------------------- GHC has an internal copy of `pretty` in `compiler/utils/Pretty.hs`. Todo: * refactor GHC's copy to make it as similar as possible to `pretty`, without making any real code changes. * apply the bug fixes that `pretty` received to GHC's copy, making sure not to pick up any possible new bugs in the process. According to (1): "There is one situation where the laws for pretty are ambiguous and leave room for choice. GHC decided one way and pretty the other." * Find which law that is, and document the differences. This hopefully allows us to close the following tickets for free: #1062, #1176 and #7666, maybe more. Ideally we could remove GHC's copy altogether, but we're not there yet. GHC's copy uses FastString, which is supposedly needed for performance, whereas pretty uses `String`. (1) https://github.com/haskell/pretty/issues/1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Revisions: #7666 | -------------------------------------+------------------------------------- Changes (by thomie): * owner: => thomie Comment: I have patches. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Revisions: #7666 | -------------------------------------+------------------------------------- Comment (by bgamari): Replying to [comment:1 thomie]:
I have patches. Lovely. Will we be seeing them on Phab soon?
On a related note, I've recently been thinking about error reporting with an eye for making the messages produced by GHC more useful to external tools. I've described one possible approach in ticket:8809#comment:3 which would involve making `Doc` a sort of free functor, allowing the insertion of rich AST objects into the document. Monadic semantics would certain patterns of projecting out these annotations into vanilla documents quite convenient. Unfortunately, the Hughes/Peyton-Jones pretty-printer isn't terribly well- suited for this as you need to know the width of a node's parent during construction. I've been meaning to explore adopting the Wadler/Leijen pretty-printer as Edward Kmett has already [http://hackage.haskell.org/package/wl-pprint-extras-3.5.0.5/docs/Text- PrettyPrint-Free.html demonstrated] that an implementation with annotations along the lines of my proposal is possible. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Revisions: #7666, #8809 | -------------------------------------+------------------------------------- Changes (by thomie): * related: #1062, #1176, #7666 => #1062, #1176, #7666, #8809 Comment: Ok, maybe you want to comment on https://github.com/haskell/pretty/issues/1#issuecomment-78297997, where Trevor Elliott said: "I was hoping to extend the GHC pretty printer with the annotations, to get functionality like in the idris repl. Maybe extending their forked version with the annotations is the right path forward for that work :)" -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: new Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130 #7666, #8809 | -------------------------------------+------------------------------------- Changes (by thomie): * differential: => Phab:D1130 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: new
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions: Phab:D1130
#7666, #8809 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: patch Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Revisions: #7666, #8809 | Phab:D1130, Phab:D1132 -------------------------------------+------------------------------------- Changes (by thomie): * status: new => patch * differential: Phab:D1130 => Phab:D1130, Phab:D1132 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: patch
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions:
#7666, #8809 | Phab:D1130, Phab:D1132
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: patch
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions:
#7666, #8809 | Phab:D1130, Phab:D1132
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: patch
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions:
#7666, #8809 | Phab:D1130, Phab:D1132
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: patch
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions:
#7666, #8809 | Phab:D1130, Phab:D1132
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: patch Priority: normal | Milestone: 7.12.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Revisions: #7666, #8809 | Phab:D1130, Phab:D1132 -------------------------------------+------------------------------------- Comment (by thomie): There is 1 commit left for parity with pretty-1.1.2.0. I have not landed it yet, because I haven't been able to measure the supposed space/time improvement yet. The other 2 commits described below seem to suggest this commit doesn't actually work: "Pretty: improving the space/time performance of vcat, hsep, hcat" There are 2 commits left for parity with pretty-1.1.2.1. I have not landed them yet, because they seem to cause more allocation in the compiler (see discussion in https://github.com/haskell/pretty/pull/9): "Resolve foldr-strictness stack overflow bug" "Special-case reduce for horiz/vert" The commits are here: https://github.com/thomie/ghc/commits/pretty -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and
`libraries/pretty`
-------------------------------------+-------------------------------------
Reporter: thomie | Owner: thomie
Type: task | Status: patch
Priority: normal | Milestone: 7.12.1
Component: Compiler | Version: 7.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #1062, #1176, | Differential Revisions:
#7666, #8809 | Phab:D1130, Phab:D1132
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Rev(s): Phab:D1130, #7666, #8809 | Phab:D1132 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.1 => 8.2.1 Comment: It seems unlikely that this is going to happen for 8.0. Punting to 8.2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: thomie Type: task | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Rev(s): Phab:D1130, #7666, #8809 | Phab:D1132 Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: patch => closed * resolution: => fixed * milestone: 8.2.1 => 8.0.1 Comment: This is pretty much done. For parity with pretty-1.1.2.1 the following two commits would also be needed. I did not land them, because they seem to cause more allocation in the compiler (see discussion in https://github.com/haskell/pretty/pull/9): * "Resolve foldr-strictness stack overflow bug" * "Special-case reduce for horiz/vert" The commits are here: https://github.com/thomie/ghc/commits/pretty -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:23 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: task | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Rev(s): Phab:D1130, #7666, #8809 | Phab:D1132 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: closed => new * owner: thomie => * resolution: fixed => Comment: Re-opening, because we'd really like to start using the real `pretty` library for GHC. It just needs someone to finish the work Thomas started! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:24 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: task | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Rev(s): Phab:D1130, #7666, #8809 | Phab:D1132 Wiki Page: | -------------------------------------+------------------------------------- Comment (by niteria): I've made some notes about this for my convenience: https://github.com/niteria/notes/blob/master/PrettyPrintingGHC.md#problems, it summarizes some issues around this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:25 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: task | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Rev(s): Phab:D1130, #7666, #8809 | Phab:D1132 Wiki Page: | -------------------------------------+------------------------------------- Changes (by michalt): * cc: michalt (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:26 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10735: Smooth out the differences between `compiler/utils/Pretty.hs` and `libraries/pretty` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: task | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #1062, #1176, | Differential Rev(s): Phab:D1130, #7666, #8809 | Phab:D1132 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Note that adinapoli has been doing some great work on this: https://github.com/haskell/pretty/pull/43. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10735#comment:27 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC