[commit: ghc] master: More compact Outputable instance for `Uniq(D)Set` (17e771e)

git at git.haskell.org git at git.haskell.org
Sat Nov 17 12:53:06 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/17e771e17e2374f50f39948955e583760f28351f/ghc

>---------------------------------------------------------------

commit 17e771e17e2374f50f39948955e583760f28351f
Author: Sebastian Graf <sebastian.graf at kit.edu>
Date:   Sat Nov 17 12:31:29 2018 +0100

    More compact Outputable instance for `Uniq(D)Set`
    
    Summary:
    Until now, `UniqSet` and `UniqDSet` inherited their `Outputable`
    instances from `UniqFM` and `UniqDFM`.
    
    That made for verbose and redundant output. This patch rectifies
    that by pretty-printing these sets in common math notation.
    E.g., previously, we would render `UniqSet`s like this:
    
        [s2fE :-> x_s2fE, s2fF :-> y_s2fF, s2fG :-> z_s2fG, s2fH :-> g_s2fH]
    
    Now, they're are printed like this:
    
        {x_s2fE, y_s2fF, z_s2fG, g_s2fH}
    
    Reviewers: simonpj, bgamari, AndreasK, dfeuer, osa1
    
    Reviewed By: osa1
    
    Subscribers: osa1, rwbarton, carter
    
    GHC Trac Issues: #15879
    
    Differential Revision: https://phabricator.haskell.org/D5315


>---------------------------------------------------------------

17e771e17e2374f50f39948955e583760f28351f
 compiler/utils/UniqDSet.hs | 2 +-
 compiler/utils/UniqSet.hs  | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/compiler/utils/UniqDSet.hs b/compiler/utils/UniqDSet.hs
index 4be437c..92d924e 100644
--- a/compiler/utils/UniqDSet.hs
+++ b/compiler/utils/UniqDSet.hs
@@ -133,4 +133,4 @@ instance Outputable a => Outputable (UniqDSet a) where
   ppr = pprUniqDSet ppr
 
 pprUniqDSet :: (a -> SDoc) -> UniqDSet a -> SDoc
-pprUniqDSet f (UniqDSet s) = pprUniqDFM f s
+pprUniqDSet f = braces . pprWithCommas f . uniqDSetToList
diff --git a/compiler/utils/UniqSet.hs b/compiler/utils/UniqSet.hs
index be600a0..82b5e9f 100644
--- a/compiler/utils/UniqSet.hs
+++ b/compiler/utils/UniqSet.hs
@@ -191,4 +191,6 @@ instance Outputable a => Outputable (UniqSet a) where
     ppr = pprUniqSet ppr
 
 pprUniqSet :: (a -> SDoc) -> UniqSet a -> SDoc
-pprUniqSet f (UniqSet s) = pprUniqFM f s
+-- It's OK to use nonDetUFMToList here because we only use it for
+-- pretty-printing.
+pprUniqSet f = braces . pprWithCommas f . nonDetEltsUniqSet



More information about the ghc-commits mailing list