diff options
author | Bartosz Nitka <niteria@gmail.com> | 2017-04-17 12:50:10 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-04-17 20:34:40 -0400 |
commit | c87584f167ae6aee7b75d6ee4a39586b291543a0 (patch) | |
tree | 6f5c3d2dfa0399d25cb09fdf4f9a8442c08d55a1 | |
parent | f58176fe731e0412a04239be620443d63f067adf (diff) | |
download | haskell-c87584f167ae6aee7b75d6ee4a39586b291543a0.tar.gz |
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
-rw-r--r-- | compiler/basicTypes/VarSet.hs | 6 | ||||
-rw-r--r-- | compiler/typecheck/TcSimplify.hs | 2 | ||||
-rw-r--r-- | compiler/typecheck/TcType.hs | 2 | ||||
-rw-r--r-- | compiler/utils/UniqDFM.hs | 2 | ||||
-rw-r--r-- | 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 8877f64080..e4f0d25dfb 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 e5f3fe97cc..2822985f54 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 c76647cfa7..ab2f8430d8 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 9f81e4dca6..17f2747f83 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 4e8c7ed97f..eef545eedd 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 |