{-# LANGUAGE CPP #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module GHC.Types.Name.Set (
NameSet,
emptyNameSet, unitNameSet, mkNameSet, unionNameSet, unionNameSets,
minusNameSet, elemNameSet, extendNameSet, extendNameSetList,
delFromNameSet, delListFromNameSet, isEmptyNameSet, filterNameSet,
intersectsNameSet, disjointNameSet, intersectNameSet,
nameSetAny, nameSetAll, nameSetElemsStable,
FreeVars,
isEmptyFVs, emptyFVs, plusFVs, plusFV,
mkFVs, addOneFV, unitFV, delFV, delFVs,
intersectFVs,
Defs, Uses, DefUse, DefUses,
emptyDUs, usesOnly, mkDUs, plusDU,
findUses, duDefs, duUses, allUses,
NonCaffySet(..)
) where
#include "HsVersions.h"
import GHC.Prelude
import GHC.Types.Name
import GHC.Data.OrdList
import GHC.Types.Unique.Set
import Data.List (sortBy)
type NameSet = UniqSet Name
emptyNameSet :: NameSet
unitNameSet :: Name -> NameSet
extendNameSetList :: NameSet -> [Name] -> NameSet
extendNameSet :: NameSet -> Name -> NameSet
mkNameSet :: [Name] -> NameSet
unionNameSet :: NameSet -> NameSet -> NameSet
unionNameSets :: [NameSet] -> NameSet
minusNameSet :: NameSet -> NameSet -> NameSet
elemNameSet :: Name -> NameSet -> Bool
isEmptyNameSet :: NameSet -> Bool
delFromNameSet :: NameSet -> Name -> NameSet
delListFromNameSet :: NameSet -> [Name] -> NameSet
filterNameSet :: (Name -> Bool) -> NameSet -> NameSet
intersectNameSet :: NameSet -> NameSet -> NameSet
intersectsNameSet :: NameSet -> NameSet -> Bool
disjointNameSet :: NameSet -> NameSet -> Bool
isEmptyNameSet :: NameSet -> Bool
isEmptyNameSet = forall a. UniqSet a -> Bool
isEmptyUniqSet
emptyNameSet :: NameSet
emptyNameSet = forall a. UniqSet a
emptyUniqSet
unitNameSet :: Name -> NameSet
unitNameSet = forall a. Uniquable a => a -> UniqSet a
unitUniqSet
mkNameSet :: [Name] -> NameSet
mkNameSet = forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet
extendNameSetList :: NameSet -> [Name] -> NameSet
extendNameSetList = forall a. Uniquable a => UniqSet a -> [a] -> UniqSet a
addListToUniqSet
extendNameSet :: NameSet -> Name -> NameSet
extendNameSet = forall a. Uniquable a => UniqSet a -> a -> UniqSet a
addOneToUniqSet
unionNameSet :: NameSet -> NameSet -> NameSet
unionNameSet = forall a. UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets
unionNameSets :: [NameSet] -> NameSet
unionNameSets = forall a. [UniqSet a] -> UniqSet a
unionManyUniqSets
minusNameSet :: NameSet -> NameSet -> NameSet
minusNameSet = forall a. UniqSet a -> UniqSet a -> UniqSet a
minusUniqSet
elemNameSet :: Name -> NameSet -> Bool
elemNameSet = forall a. Uniquable a => a -> UniqSet a -> Bool
elementOfUniqSet
delFromNameSet :: NameSet -> Name -> NameSet
delFromNameSet = forall a. Uniquable a => UniqSet a -> a -> UniqSet a
delOneFromUniqSet
filterNameSet :: (Name -> Bool) -> NameSet -> NameSet
filterNameSet = forall a. (a -> Bool) -> UniqSet a -> UniqSet a
filterUniqSet
intersectNameSet :: NameSet -> NameSet -> NameSet
intersectNameSet = forall a. UniqSet a -> UniqSet a -> UniqSet a
intersectUniqSets
disjointNameSet :: NameSet -> NameSet -> Bool
disjointNameSet = forall a. UniqSet a -> UniqSet a -> Bool
disjointUniqSets
delListFromNameSet :: NameSet -> [Name] -> NameSet
delListFromNameSet NameSet
set [Name]
ns = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' NameSet -> Name -> NameSet
delFromNameSet NameSet
set [Name]
ns
intersectsNameSet :: NameSet -> NameSet -> Bool
intersectsNameSet NameSet
s1 NameSet
s2 = Bool -> Bool
not (NameSet
s1 NameSet -> NameSet -> Bool
`disjointNameSet` NameSet
s2)
nameSetAny :: (Name -> Bool) -> NameSet -> Bool
nameSetAny :: (Name -> Bool) -> NameSet -> Bool
nameSetAny = forall a. (a -> Bool) -> UniqSet a -> Bool
uniqSetAny
nameSetAll :: (Name -> Bool) -> NameSet -> Bool
nameSetAll :: (Name -> Bool) -> NameSet -> Bool
nameSetAll = forall a. (a -> Bool) -> UniqSet a -> Bool
uniqSetAll
nameSetElemsStable :: NameSet -> [Name]
nameSetElemsStable :: NameSet -> [Name]
nameSetElemsStable NameSet
ns =
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy Name -> Name -> Ordering
stableNameCmp forall a b. (a -> b) -> a -> b
$ forall elt. UniqSet elt -> [elt]
nonDetEltsUniqSet NameSet
ns
type FreeVars = NameSet
plusFV :: FreeVars -> FreeVars -> FreeVars
addOneFV :: FreeVars -> Name -> FreeVars
unitFV :: Name -> FreeVars
emptyFVs :: FreeVars
plusFVs :: [FreeVars] -> FreeVars
mkFVs :: [Name] -> FreeVars
delFV :: Name -> FreeVars -> FreeVars
delFVs :: [Name] -> FreeVars -> FreeVars
intersectFVs :: FreeVars -> FreeVars -> FreeVars
isEmptyFVs :: NameSet -> Bool
isEmptyFVs :: NameSet -> Bool
isEmptyFVs = NameSet -> Bool
isEmptyNameSet
emptyFVs :: NameSet
emptyFVs = NameSet
emptyNameSet
plusFVs :: [NameSet] -> NameSet
plusFVs = [NameSet] -> NameSet
unionNameSets
plusFV :: NameSet -> NameSet -> NameSet
plusFV = NameSet -> NameSet -> NameSet
unionNameSet
mkFVs :: [Name] -> NameSet
mkFVs = [Name] -> NameSet
mkNameSet
addOneFV :: NameSet -> Name -> NameSet
addOneFV = NameSet -> Name -> NameSet
extendNameSet
unitFV :: Name -> NameSet
unitFV = Name -> NameSet
unitNameSet
delFV :: Name -> NameSet -> NameSet
delFV Name
n NameSet
s = NameSet -> Name -> NameSet
delFromNameSet NameSet
s Name
n
delFVs :: [Name] -> NameSet -> NameSet
delFVs [Name]
ns NameSet
s = NameSet -> [Name] -> NameSet
delListFromNameSet NameSet
s [Name]
ns
intersectFVs :: NameSet -> NameSet -> NameSet
intersectFVs = NameSet -> NameSet -> NameSet
intersectNameSet
type Defs = NameSet
type Uses = NameSet
type DefUse = (Maybe Defs, Uses)
type DefUses = OrdList DefUse
emptyDUs :: DefUses
emptyDUs :: DefUses
emptyDUs = forall a. OrdList a
nilOL
usesOnly :: Uses -> DefUses
usesOnly :: NameSet -> DefUses
usesOnly NameSet
uses = forall a. a -> OrdList a
unitOL (forall a. Maybe a
Nothing, NameSet
uses)
mkDUs :: [(Defs,Uses)] -> DefUses
mkDUs :: [(NameSet, NameSet)] -> DefUses
mkDUs [(NameSet, NameSet)]
pairs = forall a. [a] -> OrdList a
toOL [(forall a. a -> Maybe a
Just NameSet
defs, NameSet
uses) | (NameSet
defs,NameSet
uses) <- [(NameSet, NameSet)]
pairs]
plusDU :: DefUses -> DefUses -> DefUses
plusDU :: DefUses -> DefUses -> DefUses
plusDU = forall a. OrdList a -> OrdList a -> OrdList a
appOL
duDefs :: DefUses -> Defs
duDefs :: DefUses -> NameSet
duDefs DefUses
dus = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {b}. (Maybe NameSet, b) -> NameSet -> NameSet
get NameSet
emptyNameSet DefUses
dus
where
get :: (Maybe NameSet, b) -> NameSet -> NameSet
get (Maybe NameSet
Nothing, b
_u1) NameSet
d2 = NameSet
d2
get (Just NameSet
d1, b
_u1) NameSet
d2 = NameSet
d1 NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
d2
allUses :: DefUses -> Uses
allUses :: DefUses -> NameSet
allUses DefUses
dus = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {a}. (a, NameSet) -> NameSet -> NameSet
get NameSet
emptyNameSet DefUses
dus
where
get :: (a, NameSet) -> NameSet -> NameSet
get (a
_d1, NameSet
u1) NameSet
u2 = NameSet
u1 NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
u2
duUses :: DefUses -> Uses
duUses :: DefUses -> NameSet
duUses DefUses
dus = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr DefUse -> NameSet -> NameSet
get NameSet
emptyNameSet DefUses
dus
where
get :: DefUse -> NameSet -> NameSet
get (Maybe NameSet
Nothing, NameSet
rhs_uses) NameSet
uses = NameSet
rhs_uses NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
uses
get (Just NameSet
defs, NameSet
rhs_uses) NameSet
uses = (NameSet
rhs_uses NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
uses)
NameSet -> NameSet -> NameSet
`minusNameSet` NameSet
defs
findUses :: DefUses -> Uses -> Uses
findUses :: DefUses -> NameSet -> NameSet
findUses DefUses
dus NameSet
uses
= forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr DefUse -> NameSet -> NameSet
get NameSet
uses DefUses
dus
where
get :: DefUse -> NameSet -> NameSet
get (Maybe NameSet
Nothing, NameSet
rhs_uses) NameSet
uses
= NameSet
rhs_uses NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
uses
get (Just NameSet
defs, NameSet
rhs_uses) NameSet
uses
| NameSet
defs NameSet -> NameSet -> Bool
`intersectsNameSet` NameSet
uses
Bool -> Bool -> Bool
|| (Name -> Bool) -> NameSet -> Bool
nameSetAny (OccName -> Bool
startsWithUnderscore forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName) NameSet
defs
= NameSet
rhs_uses NameSet -> NameSet -> NameSet
`unionNameSet` NameSet
uses
| Bool
otherwise
= NameSet
uses
newtype NonCaffySet = NonCaffySet NameSet
deriving (NonEmpty NonCaffySet -> NonCaffySet
NonCaffySet -> NonCaffySet -> NonCaffySet
forall b. Integral b => b -> NonCaffySet -> NonCaffySet
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> NonCaffySet -> NonCaffySet
$cstimes :: forall b. Integral b => b -> NonCaffySet -> NonCaffySet
sconcat :: NonEmpty NonCaffySet -> NonCaffySet
$csconcat :: NonEmpty NonCaffySet -> NonCaffySet
<> :: NonCaffySet -> NonCaffySet -> NonCaffySet
$c<> :: NonCaffySet -> NonCaffySet -> NonCaffySet
Semigroup, Semigroup NonCaffySet
NonCaffySet
[NonCaffySet] -> NonCaffySet
NonCaffySet -> NonCaffySet -> NonCaffySet
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [NonCaffySet] -> NonCaffySet
$cmconcat :: [NonCaffySet] -> NonCaffySet
mappend :: NonCaffySet -> NonCaffySet -> NonCaffySet
$cmappend :: NonCaffySet -> NonCaffySet -> NonCaffySet
mempty :: NonCaffySet
$cmempty :: NonCaffySet
Monoid)