summaryrefslogtreecommitdiff
path: root/compiler/utils/UniqFM.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils/UniqFM.hs')
-rw-r--r--compiler/utils/UniqFM.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/utils/UniqFM.hs b/compiler/utils/UniqFM.hs
index 8214f1704b..71a092b28e 100644
--- a/compiler/utils/UniqFM.hs
+++ b/compiler/utils/UniqFM.hs
@@ -55,6 +55,7 @@ module UniqFM (
intersectUFM,
intersectUFM_C,
disjointUFM,
+ equalKeysUFM,
nonDetFoldUFM, foldUFM, nonDetFoldUFM_Directly,
anyUFM, allUFM, seqEltsUFM,
mapUFM, mapUFM_Directly,
@@ -76,6 +77,11 @@ import Outputable
import Data.List (foldl')
import qualified Data.IntMap as M
+#if MIN_VERSION_containers(0,5,9)
+import qualified Data.IntMap.Merge.Lazy as M
+import Control.Applicative (Const (..))
+import qualified Data.Monoid as Mon
+#endif
import qualified Data.IntSet as S
import Data.Typeable
import Data.Data
@@ -339,6 +345,17 @@ nonDetUFMToList (UFM m) = map (\(k, v) -> (getUnique k, v)) $ M.toList m
ufmToIntMap :: UniqFM elt -> M.IntMap elt
ufmToIntMap (UFM m) = m
+-- Determines whether two 'UniqFm's contain the same keys.
+equalKeysUFM :: UniqFM a -> UniqFM b -> Bool
+#if MIN_VERSION_containers(0,5,9)
+equalKeysUFM (UFM m1) (UFM m2) = Mon.getAll $ getConst $
+ M.mergeA (M.traverseMissing (\_ _ -> Const (Mon.All False)))
+ (M.traverseMissing (\_ _ -> Const (Mon.All False)))
+ (M.zipWithAMatched (\_ _ _ -> Const (Mon.All True))) m1 m2
+#else
+equalKeysUFM (UFM m1) (UFM m2) = M.keys m1 == M.keys m2
+#endif
+
-- Instances
#if __GLASGOW_HASKELL__ > 710