[commit: ghc] master: Use intersect and minus instead of filter (c87584f)
git at git.haskell.org
git at git.haskell.org
Tue Apr 18 00:35:29 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/c87584f167ae6aee7b75d6ee4a39586b291543a0/ghc
>---------------------------------------------------------------
commit c87584f167ae6aee7b75d6ee4a39586b291543a0
Author: Bartosz Nitka <niteria at gmail.com>
Date: Mon Apr 17 12:50:10 2017 -0400
Use intersect and minus instead of filter
These are asymptotically better and convey the intent
a bit better.
Test Plan: ./validate
Reviewers: simonpj, bgamari, austin, goldfire
Reviewed By: bgamari
Subscribers: rwbarton, thomie, simonmar
Differential Revision: https://phabricator.haskell.org/D3455
>---------------------------------------------------------------
c87584f167ae6aee7b75d6ee4a39586b291543a0
compiler/basicTypes/VarSet.hs | 6 +++++-
compiler/typecheck/TcSimplify.hs | 2 +-
compiler/typecheck/TcType.hs | 2 +-
compiler/utils/UniqDFM.hs | 2 +-
compiler/utils/UniqDSet.hs | 7 +++++--
5 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/compiler/basicTypes/VarSet.hs b/compiler/basicTypes/VarSet.hs
index 8877f64..e4f0d25 100644
--- a/compiler/basicTypes/VarSet.hs
+++ b/compiler/basicTypes/VarSet.hs
@@ -32,7 +32,8 @@ module VarSet (
extendDVarSet, extendDVarSetList,
elemDVarSet, dVarSetElems, subDVarSet,
unionDVarSet, unionDVarSets, mapUnionDVarSet,
- intersectDVarSet, intersectsDVarSet, disjointDVarSet,
+ intersectDVarSet, dVarSetIntersectVarSet,
+ intersectsDVarSet, disjointDVarSet,
isEmptyDVarSet, delDVarSet, delDVarSetList,
minusDVarSet, foldDVarSet, filterDVarSet,
dVarSetMinusVarSet, anyDVarSet, allDVarSet,
@@ -259,6 +260,9 @@ mapUnionDVarSet get_set xs = foldr (unionDVarSet . get_set) emptyDVarSet xs
intersectDVarSet :: DVarSet -> DVarSet -> DVarSet
intersectDVarSet = intersectUniqDSets
+dVarSetIntersectVarSet :: DVarSet -> VarSet -> DVarSet
+dVarSetIntersectVarSet = uniqDSetIntersectUniqSet
+
-- | True if empty intersection
disjointDVarSet :: DVarSet -> DVarSet -> Bool
disjointDVarSet s1 s2 = disjointUDFM s1 s2
diff --git a/compiler/typecheck/TcSimplify.hs b/compiler/typecheck/TcSimplify.hs
index e5f3fe9..2822985 100644
--- a/compiler/typecheck/TcSimplify.hs
+++ b/compiler/typecheck/TcSimplify.hs
@@ -956,7 +956,7 @@ decideQuantifiedTyVars mono_tvs name_taus psigs candidates
; let DV {dv_kvs = cand_kvs, dv_tvs = cand_tvs}
= candidateQTyVarsOfTypes $
psig_tys ++ candidates ++ tau_tys
- pick = filterDVarSet (`elemVarSet` grown_tvs)
+ pick = (`dVarSetIntersectVarSet` grown_tvs)
dvs_plus = DV { dv_kvs = pick cand_kvs, dv_tvs = pick cand_tvs }
; mono_tvs <- TcM.zonkTyCoVarsAndFV mono_tvs
diff --git a/compiler/typecheck/TcType.hs b/compiler/typecheck/TcType.hs
index c76647c..ab2f843 100644
--- a/compiler/typecheck/TcType.hs
+++ b/compiler/typecheck/TcType.hs
@@ -1092,7 +1092,7 @@ split_dvs bound dvs ty
kill_bound free
| isEmptyVarSet bound = free
- | otherwise = filterDVarSet (not . (`elemVarSet` bound)) free
+ | otherwise = free `dVarSetMinusVarSet` bound
-- | Like 'splitDepVarsOfType', but over a list of types
candidateQTyVarsOfTypes :: [Type] -> CandidatesQTvs
diff --git a/compiler/utils/UniqDFM.hs b/compiler/utils/UniqDFM.hs
index 9f81e4d..17f2747 100644
--- a/compiler/utils/UniqDFM.hs
+++ b/compiler/utils/UniqDFM.hs
@@ -294,7 +294,7 @@ intersectUDFM (UDFM x i) (UDFM y _j) = UDFM (M.intersection x y) i
-- M.intersection is left biased, that means the result will only have
-- a subset of elements from the left set, so `i` is a good upper bound.
-udfmIntersectUFM :: UniqDFM elt -> UniqFM elt -> UniqDFM elt
+udfmIntersectUFM :: UniqDFM elt1 -> UniqFM elt2 -> UniqDFM elt1
udfmIntersectUFM (UDFM x i) y = UDFM (M.intersection x (ufmToIntMap y)) i
-- M.intersection is left biased, that means the result will only have
-- a subset of elements from the left set, so `i` is a good upper bound.
diff --git a/compiler/utils/UniqDSet.hs b/compiler/utils/UniqDSet.hs
index 4e8c7ed..eef545e 100644
--- a/compiler/utils/UniqDSet.hs
+++ b/compiler/utils/UniqDSet.hs
@@ -20,7 +20,7 @@ module UniqDSet (
addOneToUniqDSet, addListToUniqDSet,
unionUniqDSets, unionManyUniqDSets,
minusUniqDSet, uniqDSetMinusUniqSet,
- intersectUniqDSets,
+ intersectUniqDSets, uniqDSetIntersectUniqSet,
intersectsUniqDSets,
foldUniqDSet,
elementOfUniqDSet,
@@ -69,12 +69,15 @@ unionManyUniqDSets sets = foldr1 unionUniqDSets sets
minusUniqDSet :: UniqDSet a -> UniqDSet a -> UniqDSet a
minusUniqDSet = minusUDFM
-uniqDSetMinusUniqSet :: UniqDSet a -> UniqSet a -> UniqDSet a
+uniqDSetMinusUniqSet :: UniqDSet a -> UniqSet b -> UniqDSet a
uniqDSetMinusUniqSet xs ys = udfmMinusUFM xs (getUniqSet ys)
intersectUniqDSets :: UniqDSet a -> UniqDSet a -> UniqDSet a
intersectUniqDSets = intersectUDFM
+uniqDSetIntersectUniqSet :: UniqDSet a -> UniqSet b -> UniqDSet a
+uniqDSetIntersectUniqSet xs ys = xs `udfmIntersectUFM` getUniqSet ys
+
intersectsUniqDSets :: UniqDSet a -> UniqDSet a -> Bool
intersectsUniqDSets = intersectsUDFM
More information about the ghc-commits
mailing list