summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorBartosz Nitka <niteria@gmail.com>2016-06-30 08:20:41 -0700
committerBartosz Nitka <niteria@gmail.com>2016-06-30 10:22:41 -0700
commit480e0661fb45395610d6b4a7c586a580d30d8df4 (patch)
treecc4a0effeaa3a46ea370496fb2a2143448b168f6 /compiler/utils
parentb6b20a5074ad7d712b4d8448043fc25e4c7bcdaa (diff)
downloadhaskell-480e0661fb45395610d6b4a7c586a580d30d8df4.tar.gz
Remove ufmToList
This documents nondeterminism in code generation and removes the nondeterministic ufmToList function. In the future someone will have to use nonDetUFMToList (with proper explanation) or pprUFMWithKeys.
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/UniqDFM.hs4
-rw-r--r--compiler/utils/UniqFM.hs18
2 files changed, 16 insertions, 6 deletions
diff --git a/compiler/utils/UniqDFM.hs b/compiler/utils/UniqDFM.hs
index 8ed1451eea..bbf6bb0bd8 100644
--- a/compiler/utils/UniqDFM.hs
+++ b/compiler/utils/UniqDFM.hs
@@ -66,7 +66,7 @@ import qualified Data.IntMap as M
import Data.Data
import Data.List (sortBy)
import Data.Function (on)
-import UniqFM (UniqFM, listToUFM_Directly, ufmToList, ufmToIntMap)
+import UniqFM (UniqFM, listToUFM_Directly, nonDetUFMToList, ufmToIntMap)
-- Note [Deterministic UniqFM]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -372,7 +372,7 @@ instance Monoid (UniqDFM a) where
-- This should not be used in commited code, provided for convenience to
-- make ad-hoc conversions when developing
alwaysUnsafeUfmToUdfm :: UniqFM elt -> UniqDFM elt
-alwaysUnsafeUfmToUdfm = listToUDFM_Directly . ufmToList
+alwaysUnsafeUfmToUdfm = listToUDFM_Directly . nonDetUFMToList
-- Output-ery
diff --git a/compiler/utils/UniqFM.hs b/compiler/utils/UniqFM.hs
index f9832d5455..261dd1c622 100644
--- a/compiler/utils/UniqFM.hs
+++ b/compiler/utils/UniqFM.hs
@@ -64,8 +64,8 @@ module UniqFM (
lookupWithDefaultUFM, lookupWithDefaultUFM_Directly,
nonDetEltsUFM, eltsUFM, nonDetKeysUFM,
ufmToSet_Directly,
- nonDetUFMToList, ufmToList, ufmToIntMap,
- pprUniqFM, pprUFM, pluralUFM
+ nonDetUFMToList, ufmToIntMap,
+ pprUniqFM, pprUFM, pprUFMWithKeys, pluralUFM
) where
import Unique ( Uniquable(..), Unique, getKey )
@@ -184,7 +184,6 @@ lookupWithDefaultUFM_Directly
:: UniqFM elt -> elt -> Unique -> elt
eltsUFM :: UniqFM elt -> [elt]
ufmToSet_Directly :: UniqFM elt -> S.IntSet
-ufmToList :: UniqFM elt -> [(Unique, elt)]
{-
************************************************************************
@@ -286,7 +285,6 @@ lookupWithDefaultUFM (UFM m) v k = M.findWithDefault v (getKey $ getUnique k) m
lookupWithDefaultUFM_Directly (UFM m) v u = M.findWithDefault v (getKey u) m
eltsUFM (UFM m) = M.elems m
ufmToSet_Directly (UFM m) = M.keysSet m
-ufmToList (UFM m) = map (\(k, v) -> (getUnique k, v)) $ M.toList m
anyUFM :: (elt -> Bool) -> UniqFM elt -> Bool
anyUFM p (UFM m) = M.fold ((||) . p) False m
@@ -357,6 +355,18 @@ pprUFM :: UniqFM a -- ^ The things to be pretty printed
-- printed
pprUFM ufm pp = pp (nonDetEltsUFM 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
+-- nonDetUFMToList.
+pprUFMWithKeys
+ :: UniqFM a -- ^ The things to be pretty printed
+ -> ([(Unique, a)] -> SDoc) -- ^ The pretty printing function to use on the elements
+ -> SDoc -- ^ 'SDoc' where the things have been pretty
+ -- printed
+pprUFMWithKeys ufm pp = pp (nonDetUFMToList 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