diff options
author | Bartosz Nitka <niteria@gmail.com> | 2016-04-18 07:32:03 -0700 |
---|---|---|
committer | Bartosz Nitka <niteria@gmail.com> | 2016-04-22 09:09:24 -0700 |
commit | 0f96686b10fd36d479a54c71a6e1753193e85347 (patch) | |
tree | 58a9d65664645e9ae99fa3385d66919acb8fb97a /compiler/utils/UniqFM.hs | |
parent | a9076fc2685b296bf5a32ff978c5eec91f67fd6a (diff) | |
download | haskell-0f96686b10fd36d479a54c71a6e1753193e85347.tar.gz |
Make benign non-determinism in pretty-printing more obvious
This change takes us one step closer to being able to remove
`varSetElemsWellScoped`. The end goal is to make every source
of non-determinism obvious at the source level, so that when
we achieve determinism it doesn't get broken accidentally.
Test Plan: compile GHC
Reviewers: simonmar, goldfire, simonpj, austin, bgamari
Reviewed By: simonpj
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2123
GHC Trac Issues: #4012
Diffstat (limited to 'compiler/utils/UniqFM.hs')
-rw-r--r-- | compiler/utils/UniqFM.hs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/utils/UniqFM.hs b/compiler/utils/UniqFM.hs index 969e1dc10a..3632926d91 100644 --- a/compiler/utils/UniqFM.hs +++ b/compiler/utils/UniqFM.hs @@ -67,7 +67,7 @@ module UniqFM ( eltsUFM, keysUFM, splitUFM, ufmToSet_Directly, ufmToList, - joinUFM, pprUniqFM + joinUFM, pprUniqFM, pprUFM, pluralUFM ) where import Unique ( Uniquable(..), Unique, getKey ) @@ -324,3 +324,21 @@ pprUniqFM ppr_elt ufm = brackets $ fsep $ punctuate comma $ [ ppr uq <+> text ":->" <+> ppr_elt elt | (uq, elt) <- ufmToList ufm ] + +-- | Pretty-print a non-deterministic set. +-- The order of variables is non-deterministic and for pretty-printing that +-- shouldn't be a problem. +-- Having this function helps contain the non-determinism created with +-- eltsUFM. +pprUFM :: ([a] -> SDoc) -- ^ The pretty printing function to use on the elements + -> UniqFM a -- ^ The things to be pretty printed + -> SDoc -- ^ 'SDoc' where the things have been pretty + -- printed +pprUFM pp ufm = pp (eltsUFM ufm) + +-- | Determines the pluralisation suffix appropriate for the length of a set +-- in the same way that plural from Outputable does for lists. +pluralUFM :: UniqFM a -> SDoc +pluralUFM ufm + | sizeUFM ufm == 1 = empty + | otherwise = char 's' |