{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

-}

{-# LANGUAGE CPP #-}

module GHC.Core.TyCon.Set (
        -- * TyCons set type
        TyConSet,

        -- ** Manipulating these sets
        emptyTyConSet, unitTyConSet, mkTyConSet, unionTyConSet, unionTyConSets,
        minusTyConSet, elemTyConSet, extendTyConSet, extendTyConSetList,
        delFromTyConSet, delListFromTyConSet, isEmptyTyConSet, filterTyConSet,
        intersectsTyConSet, disjointTyConSet, intersectTyConSet,
        nameSetAny, nameSetAll
    ) where

#include "HsVersions.h"

import GHC.Prelude

import GHC.Types.Unique.Set
import GHC.Core.TyCon (TyCon)

type TyConSet = UniqSet TyCon

emptyTyConSet       :: TyConSet
unitTyConSet        :: TyCon -> TyConSet
extendTyConSetList   :: TyConSet -> [TyCon] -> TyConSet
extendTyConSet    :: TyConSet -> TyCon -> TyConSet
mkTyConSet          :: [TyCon] -> TyConSet
unionTyConSet      :: TyConSet -> TyConSet -> TyConSet
unionTyConSets  :: [TyConSet] -> TyConSet
minusTyConSet       :: TyConSet -> TyConSet -> TyConSet
elemTyConSet        :: TyCon -> TyConSet -> Bool
isEmptyTyConSet     :: TyConSet -> Bool
delFromTyConSet     :: TyConSet -> TyCon -> TyConSet
delListFromTyConSet :: TyConSet -> [TyCon] -> TyConSet
filterTyConSet      :: (TyCon -> Bool) -> TyConSet -> TyConSet
intersectTyConSet   :: TyConSet -> TyConSet -> TyConSet
intersectsTyConSet  :: TyConSet -> TyConSet -> Bool
-- ^ True if there is a non-empty intersection.
-- @s1 `intersectsTyConSet` s2@ doesn't compute @s2@ if @s1@ is empty
disjointTyConSet    :: TyConSet -> TyConSet -> Bool

isEmptyTyConSet :: TyConSet -> Bool
isEmptyTyConSet    = TyConSet -> Bool
forall a. UniqSet a -> Bool
isEmptyUniqSet
emptyTyConSet :: TyConSet
emptyTyConSet      = TyConSet
forall a. UniqSet a
emptyUniqSet
unitTyConSet :: TyCon -> TyConSet
unitTyConSet       = TyCon -> TyConSet
forall a. Uniquable a => a -> UniqSet a
unitUniqSet
mkTyConSet :: [TyCon] -> TyConSet
mkTyConSet         = [TyCon] -> TyConSet
forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet
extendTyConSetList :: TyConSet -> [TyCon] -> TyConSet
extendTyConSetList = TyConSet -> [TyCon] -> TyConSet
forall a. Uniquable a => UniqSet a -> [a] -> UniqSet a
addListToUniqSet
extendTyConSet :: TyConSet -> TyCon -> TyConSet
extendTyConSet     = TyConSet -> TyCon -> TyConSet
forall a. Uniquable a => UniqSet a -> a -> UniqSet a
addOneToUniqSet
unionTyConSet :: TyConSet -> TyConSet -> TyConSet
unionTyConSet      = TyConSet -> TyConSet -> TyConSet
forall a. UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets
unionTyConSets :: [TyConSet] -> TyConSet
unionTyConSets     = [TyConSet] -> TyConSet
forall a. [UniqSet a] -> UniqSet a
unionManyUniqSets
minusTyConSet :: TyConSet -> TyConSet -> TyConSet
minusTyConSet      = TyConSet -> TyConSet -> TyConSet
forall a. UniqSet a -> UniqSet a -> UniqSet a
minusUniqSet
elemTyConSet :: TyCon -> TyConSet -> Bool
elemTyConSet       = TyCon -> TyConSet -> Bool
forall a. Uniquable a => a -> UniqSet a -> Bool
elementOfUniqSet
delFromTyConSet :: TyConSet -> TyCon -> TyConSet
delFromTyConSet    = TyConSet -> TyCon -> TyConSet
forall a. Uniquable a => UniqSet a -> a -> UniqSet a
delOneFromUniqSet
filterTyConSet :: (TyCon -> Bool) -> TyConSet -> TyConSet
filterTyConSet     = (TyCon -> Bool) -> TyConSet -> TyConSet
forall a. (a -> Bool) -> UniqSet a -> UniqSet a
filterUniqSet
intersectTyConSet :: TyConSet -> TyConSet -> TyConSet
intersectTyConSet  = TyConSet -> TyConSet -> TyConSet
forall a. UniqSet a -> UniqSet a -> UniqSet a
intersectUniqSets
disjointTyConSet :: TyConSet -> TyConSet -> Bool
disjointTyConSet   = TyConSet -> TyConSet -> Bool
forall a. UniqSet a -> UniqSet a -> Bool
disjointUniqSets


delListFromTyConSet :: TyConSet -> [TyCon] -> TyConSet
delListFromTyConSet TyConSet
set [TyCon]
ns = (TyConSet -> TyCon -> TyConSet) -> TyConSet -> [TyCon] -> TyConSet
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' TyConSet -> TyCon -> TyConSet
delFromTyConSet TyConSet
set [TyCon]
ns

intersectsTyConSet :: TyConSet -> TyConSet -> Bool
intersectsTyConSet TyConSet
s1 TyConSet
s2 = Bool -> Bool
not (TyConSet -> Bool
isEmptyTyConSet (TyConSet
s1 TyConSet -> TyConSet -> TyConSet
`intersectTyConSet` TyConSet
s2))

nameSetAny :: (TyCon -> Bool) -> TyConSet -> Bool
nameSetAny :: (TyCon -> Bool) -> TyConSet -> Bool
nameSetAny = (TyCon -> Bool) -> TyConSet -> Bool
forall a. (a -> Bool) -> UniqSet a -> Bool
uniqSetAny

nameSetAll :: (TyCon -> Bool) -> TyConSet -> Bool
nameSetAll :: (TyCon -> Bool) -> TyConSet -> Bool
nameSetAll = (TyCon -> Bool) -> TyConSet -> Bool
forall a. (a -> Bool) -> UniqSet a -> Bool
uniqSetAll