summaryrefslogtreecommitdiff
path: root/compiler/utils/UniqFM.hs
diff options
context:
space:
mode:
authorBartosz Nitka <niteria@gmail.com>2016-04-28 13:32:39 -0700
committerBartosz Nitka <niteria@gmail.com>2016-04-28 13:32:58 -0700
commit3c426b0552dffa82f1663f2eca19188afe247865 (patch)
tree32d68542a516fa67661a6ed285115b9d9d16f3d0 /compiler/utils/UniqFM.hs
parentb0569e881f66c3e987bc1108ad771a706399f5ff (diff)
downloadhaskell-3c426b0552dffa82f1663f2eca19188afe247865.tar.gz
Add uniqSetAny and uniqSetAll and use them
There are couple of places where we do `foldUniqSet` just to compute `any` or `all`. `foldUniqSet` is non-deterministic in the general case and `any` and `all` also read nicer. Test Plan: ./validate Reviewers: simonmar, goldfire, simonpj, bgamari, austin Reviewed By: simonpj Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2156 GHC Trac Issues: #4012
Diffstat (limited to 'compiler/utils/UniqFM.hs')
-rw-r--r--compiler/utils/UniqFM.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/utils/UniqFM.hs b/compiler/utils/UniqFM.hs
index 10cc179910..ed82fee4ec 100644
--- a/compiler/utils/UniqFM.hs
+++ b/compiler/utils/UniqFM.hs
@@ -56,7 +56,7 @@ module UniqFM (
intersectUFM,
intersectUFM_C,
disjointUFM,
- foldUFM, foldUFM_Directly,
+ foldUFM, foldUFM_Directly, anyUFM, allUFM,
mapUFM, mapUFM_Directly,
elemUFM, elemUFM_Directly,
filterUFM, filterUFM_Directly, partitionUFM,
@@ -275,6 +275,8 @@ intersectUFM_C f (UFM x) (UFM y) = UFM (M.intersectionWith f x y)
disjointUFM (UFM x) (UFM y) = M.null (M.intersection x y)
foldUFM k z (UFM m) = M.fold k z m
+
+
foldUFM_Directly k z (UFM m) = M.foldWithKey (k . getUnique) z m
mapUFM f (UFM m) = UFM (M.map f m)
mapUFM_Directly f (UFM m) = UFM (M.mapWithKey (f . getUnique) m)
@@ -298,6 +300,12 @@ 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
+
+allUFM :: (elt -> Bool) -> UniqFM elt -> Bool
+allUFM p (UFM m) = M.fold ((&&) . p) True m
+
ufmToIntMap :: UniqFM elt -> M.IntMap elt
ufmToIntMap (UFM m) = m