diff options
author | David Feuer <david.feuer@gmail.com> | 2017-08-28 23:28:08 -0400 |
---|---|---|
committer | David Feuer <David.Feuer@gmail.com> | 2017-08-28 23:31:36 -0400 |
commit | 29da01e0a023eea4bbbfd69dd5d854db721233e6 (patch) | |
tree | d73f43acf46cf6242efaae9f834056a43cf3b079 /utils | |
parent | 682e8e6e01cd9c96378692656649094ad44c35a7 (diff) | |
download | haskell-29da01e0a023eea4bbbfd69dd5d854db721233e6.tar.gz |
Make parsed AST dump output lazily
Previously, `showAstData` produced a `String`. That `String` would
then be converted to a `Doc` using `text` to implement
`-ddump-parsed-ast`. But rendering `text` calculates the length
of the `String` before doing anything else. Since the AST can be
very large, this was bad: the whole dump string (potentially hundreds
of millions of `Char`s) was accumulated in memory.
Now, `showAstData` produces a `Doc` directly, which seems to work
a lot better. As an extra bonus, the code is simpler and cleaner.
The formatting has changed a bit, as the previous ad hoc approach
didn't really match the pretty printer too well. If someone cares
enough to request adjustments, we can surely make them.
Reviewers: austin, bgamari, mpickering, alanz
Reviewed By: bgamari
Subscribers: mpickering, rwbarton, thomie
GHC Trac Issues: #14161
Differential Revision: https://phabricator.haskell.org/D3894
Diffstat (limited to 'utils')
-rw-r--r-- | utils/check-ppr/Main.hs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/utils/check-ppr/Main.hs b/utils/check-ppr/Main.hs index 2fd44b2be0..a5aeee2f1d 100644 --- a/utils/check-ppr/Main.hs +++ b/utils/check-ppr/Main.hs @@ -31,7 +31,8 @@ testOneFile :: FilePath -> String -> IO () testOneFile libdir fileName = do p <- parseOneFile libdir fileName let - origAst = showAstData BlankSrcSpan (pm_parsed_source p) + origAst = showSDoc unsafeGlobalDynFlags + $ showAstData BlankSrcSpan (pm_parsed_source p) pped = pragmas ++ "\n" ++ pp (pm_parsed_source p) anns = pm_annotations p pragmas = getPragmas anns @@ -45,7 +46,9 @@ testOneFile libdir fileName = do p' <- parseOneFile libdir newFile - let newAstStr = showAstData BlankSrcSpan (pm_parsed_source p') + let newAstStr :: String + newAstStr = showSDoc unsafeGlobalDynFlags + $ showAstData BlankSrcSpan (pm_parsed_source p') writeFile newAstFile newAstStr if origAst == newAstStr |