X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FUniqSet.lhs;h=5216e14bb30192d88c506748446662990a065ace;hb=26741ec416bae2c502ef00a2ba0e79050a32cb67;hp=6882e683e2e6f701b8514aff7fe424c9994a3384;hpb=6c381e873e222417d9a67aeec77b9555eca7b7a8;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/UniqSet.lhs b/ghc/compiler/utils/UniqSet.lhs index 6882e68..5216e14 100644 --- a/ghc/compiler/utils/UniqSet.lhs +++ b/ghc/compiler/utils/UniqSet.lhs @@ -5,31 +5,34 @@ Based on @UniqFMs@ (as you would expect). -Basically, the things need to be in class @NamedThing@. +Basically, the things need to be in class @Uniquable@. \begin{code} #include "HsVersions.h" module UniqSet ( - UniqSet(..), -- abstract type: NOT + SYN_IE(UniqSet), -- abstract type: NOT - mkUniqSet, uniqSetToList, emptyUniqSet, singletonUniqSet, + mkUniqSet, uniqSetToList, emptyUniqSet, unitUniqSet, + addOneToUniqSet, unionUniqSets, unionManyUniqSets, minusUniqSet, elementOfUniqSet, mapUniqSet, intersectUniqSets, isEmptyUniqSet ) where -CHK_Ubiq() -- debugging consistency check +IMP_Ubiq(){-uitous-} -import Maybes ( maybeToBool, Maybe ) +import Maybes ( maybeToBool ) import UniqFM import Unique ( Unique ) -import Outputable ( Outputable(..), NamedThing(..), ExportFlag ) import SrcLoc ( SrcLoc ) -import Pretty ( Pretty(..), PrettyRep ) +import Pretty ( SYN_IE(Pretty), PrettyRep ) import PprStyle ( PprStyle ) import Util ( Ord3(..) ) +import {-hide from mkdependHS-} + RnHsSyn ( RnName ) -- specialising only + #if ! OMIT_NATIVE_CODEGEN #define IF_NCG(a) a #else @@ -43,7 +46,7 @@ import Util ( Ord3(..) ) %* * %************************************************************************ -We use @UniqFM@, with a (@getItsUnique@-able) @Unique@ as ``key'' +We use @UniqFM@, with a (@uniqueOf@-able) @Unique@ as ``key'' and the thing itself as the ``value'' (for later retrieval). \begin{code} @@ -55,15 +58,18 @@ type UniqSet a = UniqFM a emptyUniqSet :: UniqSet a emptyUniqSet = MkUniqSet emptyUFM -singletonUniqSet :: NamedThing a => a -> UniqSet a -singletonUniqSet x = MkUniqSet (singletonUFM x x) +unitUniqSet :: Uniquable a => a -> UniqSet a +unitUniqSet x = MkUniqSet (unitUFM x x) uniqSetToList :: UniqSet a -> [a] uniqSetToList (MkUniqSet set) = eltsUFM set -mkUniqSet :: NamedThing a => [a] -> UniqSet a +mkUniqSet :: Uniquable a => [a] -> UniqSet a mkUniqSet xs = MkUniqSet (listToUFM [ (x, x) | x <- xs]) +addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a +addOneToUniqSet set x = set `unionUniqSets` unitUniqSet x + unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a unionUniqSets (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (plusUFM set1 set2) @@ -79,13 +85,13 @@ minusUniqSet (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (minusUFM set1 set2) intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a intersectUniqSets (MkUniqSet set1) (MkUniqSet set2) = MkUniqSet (intersectUFM set1 set2) -elementOfUniqSet :: NamedThing a => a -> UniqSet a -> Bool +elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool elementOfUniqSet x (MkUniqSet set) = maybeToBool (lookupUFM set x) isEmptyUniqSet :: UniqSet a -> Bool isEmptyUniqSet (MkUniqSet set) = isNullUFM set {-SLOW: sizeUFM set == 0-} -mapUniqSet :: NamedThing b => (a -> b) -> UniqSet a -> UniqSet b +mapUniqSet :: Uniquable b => (a -> b) -> UniqSet a -> UniqSet b mapUniqSet f (MkUniqSet set) = MkUniqSet (listToUFM [ let mapped_thing = f thing @@ -94,52 +100,22 @@ mapUniqSet f (MkUniqSet set) | thing <- eltsUFM set ]) \end{code} -%************************************************************************ -%* * -\subsection{The @IdSet@ and @TyVarSet@ specialisations for sets of Ids/TyVars} -%* * -%************************************************************************ - -@IdSet@ is a specialised version, optimised for sets of Ids. - \begin{code} ---type NameSet = UniqSet Name ---type GenTyVarSet flexi = UniqSet (GenTyVar flexi) ---type GenIdSet ty = UniqSet (GenId ty) - -#if ! OMIT_NATIVE_CODEGEN ---type RegSet = UniqSet Reg -#endif - -#if 0 #if __GLASGOW_HASKELL__ {-# SPECIALIZE - singletonUniqSet :: GenId ty -> GenIdSet ty, - GenTyVar flexi -> GenTyVarSet flexi, - Name -> NameSet - IF_NCG(COMMA Reg -> RegSet) + addOneToUniqSet :: UniqSet Unique -> Unique -> UniqSet Unique #-} - {-# SPECIALIZE - mkUniqSet :: [GenId ty] -> GenIdSet ty, - [GenTyVar flexi] -> GenTyVarSet flexi, - [Name] -> NameSet - IF_NCG(COMMA [Reg] -> RegSet) + elementOfUniqSet :: RnName -> UniqSet RnName -> Bool + , Unique -> UniqSet Unique -> Bool #-} - {-# SPECIALIZE - elementOfUniqSet :: GenId ty -> GenIdSet ty -> Bool, - GenTyVar flexi -> GenTyVarSet flexi -> Bool, - Name -> NameSet -> Bool - IF_NCG(COMMA Reg -> RegSet -> Bool) + mkUniqSet :: [RnName] -> UniqSet RnName #-} {-# SPECIALIZE - mapUniqSet :: (GenId ty -> GenId ty) -> GenIdSet ty -> GenIdSet ty, - (GenTyVar flexi -> GenTyVar flexi) -> GenTyVarSet flexi -> GenTyVarSet flexi, - (Name -> Name) -> NameSet -> NameSet - IF_NCG(COMMA (Reg -> Reg) -> RegSet -> RegSet) + unitUniqSet :: RnName -> UniqSet RnName + , Unique -> UniqSet Unique #-} #endif -#endif \end{code}