2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section{@VarSet@: Variable sets}
8 VarSet, IdSet, GenIdSet, TyVarSet, GenTyVarSet, IdOrTyVarSet,
9 emptyVarSet, unitVarSet, mkVarSet,
11 elemVarSet, varSetElems,
12 unionVarSet, unionVarSets,
13 intersectVarSet, intersectsVarSet,
14 isEmptyVarSet, delVarSet,
15 minusVarSet, foldVarSet, filterVarSet,
16 lookupVarSet, mapVarSet,
21 #include "HsVersions.h"
23 import Var ( Var, Id, GenId, TyVar, GenTyVar, IdOrTyVar, setVarUnique )
24 import Unique ( Uniquable(..), incrUnique )
29 %************************************************************************
31 \subsection{@VarSet@s}
33 %************************************************************************
36 type VarSet fs ft = UniqSet (Var fs ft)
37 type IdSet = UniqSet Id
38 type GenIdSet flexi = UniqSet (GenId flexi)
39 type TyVarSet = UniqSet TyVar
40 type GenTyVarSet flexi = UniqSet (GenTyVar flexi)
41 type IdOrTyVarSet = UniqSet IdOrTyVar
43 emptyVarSet :: VarSet fs ft
44 intersectVarSet :: VarSet fs ft -> VarSet fs ft -> VarSet fs ft
45 intersectsVarSet:: VarSet fs ft -> VarSet fs ft -> Bool -- True if non-empty intersection
46 unionVarSet :: VarSet fs ft -> VarSet fs ft -> VarSet fs ft
47 unionVarSets :: [VarSet fs ft] -> VarSet fs ft
48 varSetElems :: VarSet fs ft -> [Var fs ft]
49 unitVarSet :: Var fs ft -> VarSet fs ft
50 extendVarSet :: VarSet fs ft -> Var fs ft -> VarSet fs ft
51 elemVarSet :: Var fs ft -> VarSet fs ft -> Bool
52 delVarSet :: VarSet fs ft -> Var fs ft -> VarSet fs ft
53 minusVarSet :: VarSet fs ft -> VarSet fs ft -> VarSet fs ft
54 isEmptyVarSet :: VarSet fs ft -> Bool
55 mkVarSet :: [Var fs ft] -> VarSet fs ft
56 foldVarSet :: (Var fs ft -> a -> a) -> a -> VarSet fs ft -> a
57 lookupVarSet :: VarSet fs ft -> Var fs ft -> Maybe (Var fs ft)
58 -- Returns the set element, which may be
59 -- (==) to the argument, but not the same as
60 mapVarSet :: (Var fs ft -> Var fs ft) -> VarSet fs ft -> VarSet fs ft
61 filterVarSet :: (Var fs ft -> Bool) -> VarSet fs ft -> VarSet fs ft
63 emptyVarSet = emptyUniqSet
64 unitVarSet = unitUniqSet
65 extendVarSet = addOneToUniqSet
66 intersectVarSet = intersectUniqSets
67 intersectsVarSet s1 s2 = not (isEmptyVarSet (s1 `intersectVarSet` s2))
68 unionVarSet = unionUniqSets
69 unionVarSets = unionManyUniqSets
70 varSetElems = uniqSetToList
71 elemVarSet = elementOfUniqSet
72 minusVarSet = minusUniqSet
73 delVarSet = delOneFromUniqSet
74 isEmptyVarSet = isEmptyUniqSet
76 foldVarSet = foldUniqSet
77 lookupVarSet = lookupUniqSet
78 mapVarSet = mapUniqSet
79 filterVarSet = filterUniqSet
83 uniqAway :: VarSet fs ft -> Var fs ft -> Var fs ft
84 -- Give the Var a new unique, different to any in the VarSet
86 = try 1 (incrUnique (getUnique var))
88 try n uniq | uniq `elemUniqSet_Directly` set = try ((n+1)::Int) (incrUnique uniq)
89 | otherwise = {- pprTrace "uniqAway:" (ppr n <+> text "tries") -}