VarSet.lhs 3.83 KB
Newer Older
1
%
Simon Marlow's avatar
Simon Marlow committed
2
% (c) The University of Glasgow 2006
3 4 5 6
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%

\begin{code}
Ian Lynagh's avatar
Ian Lynagh committed
7 8 9 10 11 12 13
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
--     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details

14
module VarSet (
batterseapower's avatar
batterseapower committed
15
        -- * Var, Id and TyVar set types
16
	VarSet, IdSet, TyVarSet, CoVarSet,
batterseapower's avatar
batterseapower committed
17 18
	
	-- ** Manipulating these sets
19
	emptyVarSet, unitVarSet, mkVarSet,
20
	extendVarSet, extendVarSetList, extendVarSet_C,
21
	elemVarSet, varSetElems, subVarSet,
22
	unionVarSet, unionVarSets,
23
	intersectVarSet, intersectsVarSet, disjointVarSet,
24
	isEmptyVarSet, delVarSet, delVarSetList, delVarSetByKey,
25
	minusVarSet, foldVarSet, filterVarSet, fixVarSet,
26 27
	lookupVarSet, mapVarSet, sizeVarSet, seqVarSet,
	elemVarSetByKey
28 29 30 31
    ) where

#include "HsVersions.h"

32
import Var      ( Var, TyVar, CoVar, Id )
Simon Marlow's avatar
Simon Marlow committed
33
import Unique
34 35 36 37 38 39 40 41 42 43
import UniqSet
\end{code}

%************************************************************************
%*									*
\subsection{@VarSet@s}
%*									*
%************************************************************************

\begin{code}
44 45 46
type VarSet       = UniqSet Var
type IdSet 	  = UniqSet Id
type TyVarSet	  = UniqSet TyVar
47
type CoVarSet     = UniqSet CoVar
48

49 50 51 52 53 54 55
emptyVarSet	:: VarSet
intersectVarSet	:: VarSet -> VarSet -> VarSet
unionVarSet	:: VarSet -> VarSet -> VarSet
unionVarSets	:: [VarSet] -> VarSet
varSetElems	:: VarSet -> [Var]
unitVarSet	:: Var -> VarSet
extendVarSet	:: VarSet -> Var -> VarSet
56
extendVarSetList:: VarSet -> [Var] -> VarSet
57 58
elemVarSet	:: Var -> VarSet -> Bool
delVarSet	:: VarSet -> Var -> VarSet
59
delVarSetList	:: VarSet -> [Var] -> VarSet
60 61 62 63 64
minusVarSet	:: VarSet -> VarSet -> VarSet
isEmptyVarSet	:: VarSet -> Bool
mkVarSet	:: [Var] -> VarSet
foldVarSet	:: (Var -> a -> a) -> a -> VarSet -> a
lookupVarSet	:: VarSet -> Var -> Maybe Var
65 66
			-- Returns the set element, which may be
			-- (==) to the argument, but not the same as
67
mapVarSet 	:: (Var -> Var) -> VarSet -> VarSet
68
sizeVarSet	:: VarSet -> Int
69
filterVarSet	:: (Var -> Bool) -> VarSet -> VarSet
70
extendVarSet_C  :: (Var->Var->Var) -> VarSet -> Var -> VarSet
71 72

delVarSetByKey	:: VarSet -> Unique -> VarSet
73
elemVarSetByKey :: Unique -> VarSet -> Bool
74
fixVarSet       :: (VarSet -> VarSet) -> VarSet -> VarSet
75 76 77 78

emptyVarSet	= emptyUniqSet
unitVarSet	= unitUniqSet
extendVarSet	= addOneToUniqSet
79
extendVarSetList= addListToUniqSet
80
intersectVarSet	= intersectUniqSets
81 82

intersectsVarSet:: VarSet -> VarSet -> Bool 	-- True if non-empty intersection
83
disjointVarSet  :: VarSet -> VarSet -> Bool 	-- True if empty intersection
84
subVarSet	:: VarSet -> VarSet -> Bool	-- True if first arg is subset of second
85 86
	-- (s1 `intersectsVarSet` s2) doesn't compute s2 if s1 is empty; 
	-- ditto disjointVarSet, subVarSet
87

88 89 90 91 92 93
unionVarSet	= unionUniqSets
unionVarSets	= unionManyUniqSets
varSetElems	= uniqSetToList
elemVarSet	= elementOfUniqSet
minusVarSet	= minusUniqSet
delVarSet	= delOneFromUniqSet
94
delVarSetList	= delListFromUniqSet
95 96 97 98 99
isEmptyVarSet	= isEmptyUniqSet
mkVarSet	= mkUniqSet
foldVarSet	= foldUniqSet
lookupVarSet	= lookupUniqSet
mapVarSet	= mapUniqSet
100
sizeVarSet	= sizeUniqSet
101
filterVarSet	= filterUniqSet
102 103
extendVarSet_C = addOneToUniqSet_C
delVarSetByKey	= delOneFromUniqSet_Directly
104
elemVarSetByKey	= elemUniqSet_Directly
105 106
\end{code}

107 108
\begin{code}
-- See comments with type signatures
109 110 111
intersectsVarSet s1 s2 = not (s1 `disjointVarSet` s2)
disjointVarSet   s1 s2 = isEmptyVarSet (s1 `intersectVarSet` s2)
subVarSet        s1 s2 = isEmptyVarSet (s1 `minusVarSet` s2)
112 113 114 115 116 117

-- Iterate f to a fixpoint
fixVarSet f s | new_s `subVarSet` s = s
	      | otherwise	    = fixVarSet f new_s 
	      where
		new_s = f s
118 119
\end{code}

120 121 122 123 124
\begin{code}
seqVarSet :: VarSet -> ()
seqVarSet s = sizeVarSet s `seq` ()
\end{code}