summaryrefslogtreecommitdiff
path: root/compiler/utils/Pretty.hs
Commit message (Collapse)AuthorAgeFilesLines
* Modules: Utils and Data (#13009)Sylvain Henry2020-04-261-1105/+0
| | | | | | | Update Haddock submodule Metric Increase: haddock.compiler
* Add PlainPanic for throwing exceptions without depending on pprintMichael Sloan2019-05-241-4/+1
| | | | | | | | | | | | | | | | | | | | | This commit splits out a subset of GhcException which do not depend on pretty printing (SDoc), as a new datatype called PlainGhcException. These exceptions can be caught as GhcException, because 'fromException' will convert them. The motivation for this change is that that the Panic module transitively depends on many modules, primarily due to pretty printing code. It's on the order of about 130 modules. This large set of dependencies has a few implications: 1. To avoid cycles / use of boot files, these dependencies cannot throw GhcException. 2. There are some utility modules that use UnboxedTuples and also use `panic`. This means that when loading GHC into GHCi, about 130 additional modules would need to be compiled instead of interpreted. Splitting the non-pprint exception throwing into a new module resolves this issue. See #13101
* Update Trac ticket URLs to point to GitLabRyan Scott2019-03-151-2/+2
| | | | | This moves all URL references to Trac tickets to their corresponding GitLab counterparts.
* Stomp a few typos and grammarosGabor Greif2018-12-171-1/+1
| | | | Also use 'id'
* Rename literal constructorsSylvain Henry2018-11-221-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | In a previous patch we replaced some built-in literal constructors (MachInt, MachWord, etc.) with a single LitNumber constructor. In this patch we replace the `Mach` prefix of the remaining constructors with `Lit` for consistency (e.g., LitChar, LitLabel, etc.). Sadly the name `LitString` was already taken for a kind of FastString and it would become misleading to have both `LitStr` (literal constructor renamed after `MachStr`) and `LitString` (FastString variant). Hence this patch renames the FastString variant `PtrString` (which is more accurate) and the literal string constructor now uses the least surprising `LitString` name. Both `Literal` and `LitString/PtrString` have recently seen breaking changes so doing this kind of renaming now shouldn't harm much. Reviewers: hvr, goldfire, bgamari, simonmar, jrtc27, tdammers Subscribers: tdammers, rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4881
* Refactor LitStringSylvain Henry2018-05-131-38/+36
| | | | | | | | | | | | | | | | | | Refactor LitString so that the string length is computed at most once and then stored. Also remove strlen and memcmp wrappers (it seems like they were a workaround for a very old GCC when using -fvia-C). Bumps haddock submodule. Reviewers: bgamari, dfeuer, nickkuk Reviewed By: bgamari, nickkuk Subscribers: nickkuk, dfeuer, thomie, carter Differential Revision: https://phabricator.haskell.org/D4630
* Implement -dword-hex-literalsAndrew Martin2018-03-191-1/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | Provide flag for showing showing Word# and Word64# as hexadecimal when dumping GHC core. The only affects Word, not Int, and it prefixes the hexadecimal with enough zeroes to make the total character count a power of two. For example: - 0x0C0C instead of 0xC0C - 0x00BA00BA instead of 0xBA00BA This also affects the presentation of Word# and Word64# in GHC's error messages. It is not expected that the flag will be used for this, but it is a side-effect worth noting. Test Plan: none Reviewers: bgamari, simonpj Reviewed By: simonpj Subscribers: simonpj, mpickering, rwbarton, thomie, carter, andrewthad GHC Trac Issues: #14872 Differential Revision: https://phabricator.haskell.org/D4465
* Make layLeft and reduceDoc stricter (#7258)Tobias Dammers2017-10-251-6/+6
| | | | | | | | | | | | | | Making the pretty-printer based assembly output stricter in strategically chosen locations produces a minor performance improvement when compiling large derived Read instance (on the order of 5-10%). Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4111
* compiler: introduce custom "GhcPrelude" PreludeHerbert Valerio Riedel2017-09-191-1/+2
| | | | | | | | | | | | | | | | | | This switches the compiler/ component to get compiled with -XNoImplicitPrelude and a `import GhcPrelude` is inserted in all modules. This is motivated by the upcoming "Prelude" re-export of `Semigroup((<>))` which would cause lots of name clashes in every modulewhich imports also `Outputable` Reviewers: austin, goldfire, bgamari, alanz, simonmar Reviewed By: bgamari Subscribers: goldfire, rwbarton, thomie, mpickering, bgamari Differential Revision: https://phabricator.haskell.org/D3989
* Spelling fixes in comments [ci skip]Gabor Greif2017-01-181-1/+1
|
* cleanup: drop 11 years old performance hackSergei Trofimovich2016-09-041-8/+2
| | | | | | | | | | | The 'return () >>' hack was added in commit commit ac88f113abdec1edbffb6d2f97323e81f82908e7 Date: Tue Jul 26 12:14:03 2005 +0000 Nowadays it has no effect on generated Core on -O1/-O2 and slightly bloats Core on -O0. Signed-off-by: Sergei Trofimovich <siarheit@google.com>
* Pretty: remove a harmful $! (#12227)Thomas Miedema2016-07-171-1/+44
| | | | | | | | | | | | | | | | | This is backport of [1] for GHC's copy of Pretty. See Note [Differences between libraries/pretty and compiler/utils/Pretty.hs]. [1] http://git.haskell.org/packages/pretty.git/commit/bbe9270c5f849a5bb74c9166a5f4202cfb0dba22 https://github.com/haskell/pretty/issues/32 https://github.com/haskell/pretty/pull/35 Reviewers: bgamari, austin Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D2397 GHC Trac Issues: #12227
* Pretty: delete really old changelogThomas Miedema2016-07-111-154/+20
| | | | | | | This changelog is very incomplete, and basically useless. I'm removing it, because it made it harder to compare this copy of `Pretty.hs` with the copy in `libraries/pretty` (from which a similar changelog was deleted some time ago).
* Fix inconsistent pretty-printing of type familiesMichał Sośnicki2015-11-181-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | After the changes, the three functions used to print type families were identical, so they are refactored into one. Original RHSs of data instance declarations are recreated and printed in user error messages. RHSs containing representation TyCons are printed in the Coercion Axioms section in a typechecker dump. Add vbar to the list of SDocs exported by Outputable. Replace all text "|" docs with it. Fixes #10839 Reviewers: goldfire, jstolarek, austin, bgamari Reviewed By: jstolarek Subscribers: jstolarek, thomie Differential Revision: https://phabricator.haskell.org/D1441 GHC Trac Issues: #10839
* Pretty: improving the space/time performance of vcat, hsep, hcat (#10735)Thomas Miedema2015-08-121-3/+16
| | | | | | | | | | | | | | | | | | | | | | | After 5d57087e314bd484dbe14958f9b422be3ac6641a ("Pretty: fix a broken invariant"), T3294 showed 50% more max_bytes_used (#3294). After this commit, max_bytes_used is back to what it was before, and the test passes again. This is a backport of a bug fix by Benedikt Huber (#2393), from commit 1e50748beaa4bd2281d323b18ea51c786bba04a1 in the pretty library. From https://mail.haskell.org/pipermail/libraries/2008-June/009991.html: vcat (hsep,cat) is implemented in an unneccessarily strict way. We only get some output after all of vcat's arguments are evaluated and checked against being Empty. This can be improved by only checking the right argument of foldr against being Empty, and then applying an Empty-filter on the resulting Doc. Space improvement is obvious. The microbenchmark (code.haskell.org/~bhuber/Text/PrettyPrint/ HughesPJPerfCheck.hs) suggests that the improvements in time are remarkable too.
* Pretty: show rational as is (#10735)Thomas Miedema2015-08-121-3/+1
| | | | | | | | | | Following libraries/pretty. I'm not sure why it converted to Double before. This function isn't used by GHC itself. It is exported from these two places: * compiler/utils/Outputable * libraries/template-haskell/Language/Haskell/TH/PprLib.hs
* Pretty: fix a broken invariant (#10735)Thomas Miedema2015-08-121-4/+14
| | | | | | | | | This is a backport of a bug fix from 6cfbd0444981c074bae10a3cf72733bcb8597bef in libraries/pretty: Fix a broken invariant Patch from #694, for the problem "empty is an identity for <> and $$" is currently broken by eg. isEmpty (empty<>empty)"
* Pretty: fix potential bad formatting of error message (#10735)Thomas Miedema2015-08-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a backport of a bug fix by Benedikt Huber for the same problem in the pretty library (#1337), from commit 8d8866a8379c2fe8108ef034893c59e06d5e752f. The original explanation for the fix is attached below. Ticket #1776 originally reported an infinite loop when printing error message. This promptly got fixed in: commit 2d52ee06786e5caf0c2d65a4b4bb7c45c6493190 Author: simonpj@microsoft.com <unknown> Date: Thu Mar 1 11:45:13 2007 +0000 Do not go into an infinite loop when pretty-printer finds a negative indent (Trac #1176) SPJ reports in the ticket: "So infinite loop is fixed, but the bad formatting remains. I've added a test, tcfail177." tcfail177 however hasn't triggered the formatting problem for years (as Ian reported in c9e0e6067a47c574d9ff3721afe58e30ca1be3e4). This patch updates the test to a version that at least still failed with ghc-7.0 (from #1776#comment:7). ------------------- From https://mail.haskell.org/pipermail/libraries/2008-June/010013.html, by Benedikt Huber: Concerning ticket #1337, we have to change the formal specification of fill (it doesn't match the implementation): -- Current Specification: -- fill [] = empty -- fill [p] = p -- fill (p1:p2:ps) = oneLiner p1 <#> nest (length p1) -- (fill (oneLiner p2 : ps)) -- `union` -- p1 $$ fill ps Problem 1: We want to `unnest' the second argument of (p1 $$ fill ps), but not the first one In the definition above we have e.g. > getSecondLayout $ > fillDef False [text "a", text "b", text "a"] >> text "ab"; nilabove; nest -1; text "a"; empty >> |ab| >> |.a| Problem 2: The overlapping $$ should only be used for those layouts of p1 which aren't one liners (otherwise violating the invariant "Left union arg has shorter first line"). I suggest the following specification (i believe it almost matches the current implementation, modulo [fillNB: fix bug #1337] (see below): -- Revised Specification: -- fill g docs = fill' 0 docs -- gap g = if g then 1 else 0 -- fill' n [] = [] -- fill' n [p] = [p] -- fill' n (p1:p2:ps) = -- oneLiner p1 <g> (fill' (n+length p1+gap g) (oneLiner p2 : ps)) -- `union` -- (p1 $*$ nest (-n) (fill' g ps)) -- -- $*$ is defined for layouts (One-Layout Documents) as -- -- layout1 $*$ layout2 | isOneLiner layout1 = layout1 $+$ layout2 -- | otherwise = layout1 $$ layout2 I've also implemented the specification in HughesPJQuickCheck.hs, and checked them against the patched pretty printer. Concerning Bug #1337: ~~~~~~~~~~~~~~~~~~~~~ If the above formal specification is fine, it is easy to fix: elide the nests of (oneLiner p2) [see attached patch, record bug #1337]. > PrettyPrint(0) $ ./Bug1337 > ....ab > ...c The (long) explanation follows below. <snip/> =========================================================== Explanation of Bug #1337: Consider > fcat [ nest 1 $ text "a", nest 2 $ text "b", text "c"] --> expected: (nest 1; text "a"; text "b"; nest -3; "c") --> actual : (nest 1; text "a"; text "b"; nest -5; "c") Reduction: === (nest 1; text a) <> (fill (-2) (p2:ps)) ==> (nest 2 (text "b") $+$ text "c") ==> (nest 2 (text "b")) `nilabove` (nest (-3) (text "c")) ==> (nest 1; text a; text b; nest -5 c) The problem is that if we decide to layout (p1:p2:ps) as | p1 p2 | ps (call it layout A), then we want to have > (p1 <> p2) $+$ ps. But following law <n6> this means that > fcat_A [p1:nest k p2:ps] is equivalent to > fcat_A [p1,p2,ps] so the nest of p2 has to be removed. This is somewhat similar to bug #667, but easier to fix from a semantic point of view: p1,p2 and ps are distinct layouts - we only have to preserve the individual layouts, and no combinations of them.
* Pretty: bugfix fillNB (#10735)Thomas Miedema2015-08-121-0/+1
| | | | | | | | | | | | | | | | | | | | This is a backport of a bug fix by Benedikt Huber (#2393), from commit 1e50748beaa4bd2281d323b18ea51c786bba04a1 in the pretty library. From https://mail.haskell.org/pipermail/libraries/2008-June/009991.html: Law <l1> states that > sep (ps++[empty]++qs) = sep (ps ++ qs) > ...ditto hsep, hcat, vcat, fill... In the current implementation, this fails for the paragraph fill variants. > render' $ fsep [ text "c", text "c",empty, text "c", text "b"] > where render' = renderStyle (Style PageMode 7 1.4) >> c c c >> b
* Pretty: use replicate for spaces and multi_ch (#10735)Thomas Miedema2015-08-051-8/+3
| | | | | Similar changes were made to pretty in commit 7575ab16430c876eaa1451b02465b6b103b3a519.
* Pretty: mimic pretty API more closely (#10735)Thomas Miedema2015-08-051-41/+59
| | | | Refactoring only. Nothing much to see here.
* Pretty: use BangPatterns instead of manual unboxing Ints (#10735)Thomas Miedema2015-08-051-80/+88
| | | | | | | Follow same style as libraries/pretty, although some of it is pretty archaic, and could be improved with BangPatterns: * `get w _ | w == 0 && False = undefined` * `mkNest k _ | k `seq` False = undefined`
* Pretty: Args of NilAbove/TextBeside/Nest/Union are always RDocs (#10735)Thomas Miedema2015-08-051-8/+5
| | | | Just following libraries/pretty.
* Pretty: kill code that has been dead since 1997 (#10735)Thomas Miedema2015-08-051-21/+4
|
* Pretty: remove superfluous parenthesis (#10735)Thomas Miedema2015-08-051-9/+9
|
* Pretty: improve error messages (#10735)Thomas Miedema2015-08-051-14/+37
| | | | Again, following libraries/pretty.
* Pretty: rename variables to the ones used by libraries/pretty (#10735)Thomas Miedema2015-08-051-39/+39
|
* Pretty: reformat using style from libraries/pretty (#10735)Thomas Miedema2015-08-051-374/+442
| | | | | | | | | This commit copies the code structure (what goes where), whitespace layout and comments from libraries/pretty/src/Text/PrettyPrint/HughesPJ.hs, with the intention to be able to later more easily compare the two files, and port bug fixes. I'm sorry this messes up git blame history, but there's no other way.
* Typos in error messages and in commentsGabor Greif2015-04-101-1/+1
|
* compiler: de-lhs utils/Austin Seipp2014-12-031-0/+1024
Signed-off-by: Austin Seipp <austin@well-typed.com>