{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module GHC.Cmm.Dataflow.Label
( Label
, LabelMap
, LabelSet
, FactBase
, lookupFact
, mkHooplLabel
) where
import GHC.Prelude
import GHC.Utils.Outputable
import GHC.Cmm.Dataflow.Collections
import GHC.Types.Unique (Uniquable(..))
import GHC.Data.TrieMap
newtype Label = Label { Label -> Int
lblToUnique :: Int }
deriving (Label -> Label -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Label -> Label -> Bool
$c/= :: Label -> Label -> Bool
== :: Label -> Label -> Bool
$c== :: Label -> Label -> Bool
Eq, Eq Label
Label -> Label -> Bool
Label -> Label -> Ordering
Label -> Label -> Label
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Label -> Label -> Label
$cmin :: Label -> Label -> Label
max :: Label -> Label -> Label
$cmax :: Label -> Label -> Label
>= :: Label -> Label -> Bool
$c>= :: Label -> Label -> Bool
> :: Label -> Label -> Bool
$c> :: Label -> Label -> Bool
<= :: Label -> Label -> Bool
$c<= :: Label -> Label -> Bool
< :: Label -> Label -> Bool
$c< :: Label -> Label -> Bool
compare :: Label -> Label -> Ordering
$ccompare :: Label -> Label -> Ordering
Ord)
mkHooplLabel :: Int -> Label
mkHooplLabel :: Int -> Label
mkHooplLabel = Int -> Label
Label
instance Show Label where
show :: Label -> String
show (Label Int
n) = String
"L" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
n
instance Uniquable Label where
getUnique :: Label -> Unique
getUnique Label
label = forall a. Uniquable a => a -> Unique
getUnique (Label -> Int
lblToUnique Label
label)
instance Outputable Label where
ppr :: Label -> SDoc
ppr Label
label = forall a. Outputable a => a -> SDoc
ppr (forall a. Uniquable a => a -> Unique
getUnique Label
label)
instance OutputableP env Label where
pdoc :: env -> Label -> SDoc
pdoc env
_ Label
l = forall a. Outputable a => a -> SDoc
ppr Label
l
newtype LabelSet = LS UniqueSet deriving (LabelSet -> LabelSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LabelSet -> LabelSet -> Bool
$c/= :: LabelSet -> LabelSet -> Bool
== :: LabelSet -> LabelSet -> Bool
$c== :: LabelSet -> LabelSet -> Bool
Eq, Eq LabelSet
LabelSet -> LabelSet -> Bool
LabelSet -> LabelSet -> Ordering
LabelSet -> LabelSet -> LabelSet
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LabelSet -> LabelSet -> LabelSet
$cmin :: LabelSet -> LabelSet -> LabelSet
max :: LabelSet -> LabelSet -> LabelSet
$cmax :: LabelSet -> LabelSet -> LabelSet
>= :: LabelSet -> LabelSet -> Bool
$c>= :: LabelSet -> LabelSet -> Bool
> :: LabelSet -> LabelSet -> Bool
$c> :: LabelSet -> LabelSet -> Bool
<= :: LabelSet -> LabelSet -> Bool
$c<= :: LabelSet -> LabelSet -> Bool
< :: LabelSet -> LabelSet -> Bool
$c< :: LabelSet -> LabelSet -> Bool
compare :: LabelSet -> LabelSet -> Ordering
$ccompare :: LabelSet -> LabelSet -> Ordering
Ord, Int -> LabelSet -> ShowS
[LabelSet] -> ShowS
LabelSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LabelSet] -> ShowS
$cshowList :: [LabelSet] -> ShowS
show :: LabelSet -> String
$cshow :: LabelSet -> String
showsPrec :: Int -> LabelSet -> ShowS
$cshowsPrec :: Int -> LabelSet -> ShowS
Show, Semigroup LabelSet
LabelSet
[LabelSet] -> LabelSet
LabelSet -> LabelSet -> LabelSet
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [LabelSet] -> LabelSet
$cmconcat :: [LabelSet] -> LabelSet
mappend :: LabelSet -> LabelSet -> LabelSet
$cmappend :: LabelSet -> LabelSet -> LabelSet
mempty :: LabelSet
$cmempty :: LabelSet
Monoid, NonEmpty LabelSet -> LabelSet
LabelSet -> LabelSet -> LabelSet
forall b. Integral b => b -> LabelSet -> LabelSet
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> LabelSet -> LabelSet
$cstimes :: forall b. Integral b => b -> LabelSet -> LabelSet
sconcat :: NonEmpty LabelSet -> LabelSet
$csconcat :: NonEmpty LabelSet -> LabelSet
<> :: LabelSet -> LabelSet -> LabelSet
$c<> :: LabelSet -> LabelSet -> LabelSet
Semigroup)
instance IsSet LabelSet where
type ElemOf LabelSet = Label
setNull :: LabelSet -> Bool
setNull (LS UniqueSet
s) = forall set. IsSet set => set -> Bool
setNull UniqueSet
s
setSize :: LabelSet -> Int
setSize (LS UniqueSet
s) = forall set. IsSet set => set -> Int
setSize UniqueSet
s
setMember :: ElemOf LabelSet -> LabelSet -> Bool
setMember (Label Int
k) (LS UniqueSet
s) = forall set. IsSet set => ElemOf set -> set -> Bool
setMember Int
k UniqueSet
s
setEmpty :: LabelSet
setEmpty = UniqueSet -> LabelSet
LS forall set. IsSet set => set
setEmpty
setSingleton :: ElemOf LabelSet -> LabelSet
setSingleton (Label Int
k) = UniqueSet -> LabelSet
LS (forall set. IsSet set => ElemOf set -> set
setSingleton Int
k)
setInsert :: ElemOf LabelSet -> LabelSet -> LabelSet
setInsert (Label Int
k) (LS UniqueSet
s) = UniqueSet -> LabelSet
LS (forall set. IsSet set => ElemOf set -> set -> set
setInsert Int
k UniqueSet
s)
setDelete :: ElemOf LabelSet -> LabelSet -> LabelSet
setDelete (Label Int
k) (LS UniqueSet
s) = UniqueSet -> LabelSet
LS (forall set. IsSet set => ElemOf set -> set -> set
setDelete Int
k UniqueSet
s)
setUnion :: LabelSet -> LabelSet -> LabelSet
setUnion (LS UniqueSet
x) (LS UniqueSet
y) = UniqueSet -> LabelSet
LS (forall set. IsSet set => set -> set -> set
setUnion UniqueSet
x UniqueSet
y)
setDifference :: LabelSet -> LabelSet -> LabelSet
setDifference (LS UniqueSet
x) (LS UniqueSet
y) = UniqueSet -> LabelSet
LS (forall set. IsSet set => set -> set -> set
setDifference UniqueSet
x UniqueSet
y)
setIntersection :: LabelSet -> LabelSet -> LabelSet
setIntersection (LS UniqueSet
x) (LS UniqueSet
y) = UniqueSet -> LabelSet
LS (forall set. IsSet set => set -> set -> set
setIntersection UniqueSet
x UniqueSet
y)
setIsSubsetOf :: LabelSet -> LabelSet -> Bool
setIsSubsetOf (LS UniqueSet
x) (LS UniqueSet
y) = forall set. IsSet set => set -> set -> Bool
setIsSubsetOf UniqueSet
x UniqueSet
y
setFilter :: (ElemOf LabelSet -> Bool) -> LabelSet -> LabelSet
setFilter ElemOf LabelSet -> Bool
f (LS UniqueSet
s) = UniqueSet -> LabelSet
LS (forall set. IsSet set => (ElemOf set -> Bool) -> set -> set
setFilter (ElemOf LabelSet -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Label
mkHooplLabel) UniqueSet
s)
setFoldl :: forall b. (b -> ElemOf LabelSet -> b) -> b -> LabelSet -> b
setFoldl b -> ElemOf LabelSet -> b
k b
z (LS UniqueSet
s) = forall set b. IsSet set => (b -> ElemOf set -> b) -> b -> set -> b
setFoldl (\b
a ElemOf UniqueSet
v -> b -> ElemOf LabelSet -> b
k b
a (Int -> Label
mkHooplLabel ElemOf UniqueSet
v)) b
z UniqueSet
s
setFoldr :: forall b. (ElemOf LabelSet -> b -> b) -> b -> LabelSet -> b
setFoldr ElemOf LabelSet -> b -> b
k b
z (LS UniqueSet
s) = forall set b. IsSet set => (ElemOf set -> b -> b) -> b -> set -> b
setFoldr (\ElemOf UniqueSet
v b
a -> ElemOf LabelSet -> b -> b
k (Int -> Label
mkHooplLabel ElemOf UniqueSet
v) b
a) b
z UniqueSet
s
setElems :: LabelSet -> [ElemOf LabelSet]
setElems (LS UniqueSet
s) = forall a b. (a -> b) -> [a] -> [b]
map Int -> Label
mkHooplLabel (forall set. IsSet set => set -> [ElemOf set]
setElems UniqueSet
s)
setFromList :: [ElemOf LabelSet] -> LabelSet
setFromList [ElemOf LabelSet]
ks = UniqueSet -> LabelSet
LS (forall set. IsSet set => [ElemOf set] -> set
setFromList (forall a b. (a -> b) -> [a] -> [b]
map Label -> Int
lblToUnique [ElemOf LabelSet]
ks))
newtype LabelMap v = LM (UniqueMap v)
deriving (LabelMap v -> LabelMap v -> Bool
forall v. Eq v => LabelMap v -> LabelMap v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LabelMap v -> LabelMap v -> Bool
$c/= :: forall v. Eq v => LabelMap v -> LabelMap v -> Bool
== :: LabelMap v -> LabelMap v -> Bool
$c== :: forall v. Eq v => LabelMap v -> LabelMap v -> Bool
Eq, LabelMap v -> LabelMap v -> Bool
LabelMap v -> LabelMap v -> Ordering
LabelMap v -> LabelMap v -> LabelMap v
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {v}. Ord v => Eq (LabelMap v)
forall v. Ord v => LabelMap v -> LabelMap v -> Bool
forall v. Ord v => LabelMap v -> LabelMap v -> Ordering
forall v. Ord v => LabelMap v -> LabelMap v -> LabelMap v
min :: LabelMap v -> LabelMap v -> LabelMap v
$cmin :: forall v. Ord v => LabelMap v -> LabelMap v -> LabelMap v
max :: LabelMap v -> LabelMap v -> LabelMap v
$cmax :: forall v. Ord v => LabelMap v -> LabelMap v -> LabelMap v
>= :: LabelMap v -> LabelMap v -> Bool
$c>= :: forall v. Ord v => LabelMap v -> LabelMap v -> Bool
> :: LabelMap v -> LabelMap v -> Bool
$c> :: forall v. Ord v => LabelMap v -> LabelMap v -> Bool
<= :: LabelMap v -> LabelMap v -> Bool
$c<= :: forall v. Ord v => LabelMap v -> LabelMap v -> Bool
< :: LabelMap v -> LabelMap v -> Bool
$c< :: forall v. Ord v => LabelMap v -> LabelMap v -> Bool
compare :: LabelMap v -> LabelMap v -> Ordering
$ccompare :: forall v. Ord v => LabelMap v -> LabelMap v -> Ordering
Ord, Int -> LabelMap v -> ShowS
forall v. Show v => Int -> LabelMap v -> ShowS
forall v. Show v => [LabelMap v] -> ShowS
forall v. Show v => LabelMap v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LabelMap v] -> ShowS
$cshowList :: forall v. Show v => [LabelMap v] -> ShowS
show :: LabelMap v -> String
$cshow :: forall v. Show v => LabelMap v -> String
showsPrec :: Int -> LabelMap v -> ShowS
$cshowsPrec :: forall v. Show v => Int -> LabelMap v -> ShowS
Show, forall a b. a -> LabelMap b -> LabelMap a
forall a b. (a -> b) -> LabelMap a -> LabelMap b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> LabelMap b -> LabelMap a
$c<$ :: forall a b. a -> LabelMap b -> LabelMap a
fmap :: forall a b. (a -> b) -> LabelMap a -> LabelMap b
$cfmap :: forall a b. (a -> b) -> LabelMap a -> LabelMap b
Functor, forall a. Eq a => a -> LabelMap a -> Bool
forall a. Num a => LabelMap a -> a
forall a. Ord a => LabelMap a -> a
forall m. Monoid m => LabelMap m -> m
forall a. LabelMap a -> Bool
forall a. LabelMap a -> Int
forall a. LabelMap a -> [a]
forall a. (a -> a -> a) -> LabelMap a -> a
forall m a. Monoid m => (a -> m) -> LabelMap a -> m
forall b a. (b -> a -> b) -> b -> LabelMap a -> b
forall a b. (a -> b -> b) -> b -> LabelMap a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => LabelMap a -> a
$cproduct :: forall a. Num a => LabelMap a -> a
sum :: forall a. Num a => LabelMap a -> a
$csum :: forall a. Num a => LabelMap a -> a
minimum :: forall a. Ord a => LabelMap a -> a
$cminimum :: forall a. Ord a => LabelMap a -> a
maximum :: forall a. Ord a => LabelMap a -> a
$cmaximum :: forall a. Ord a => LabelMap a -> a
elem :: forall a. Eq a => a -> LabelMap a -> Bool
$celem :: forall a. Eq a => a -> LabelMap a -> Bool
length :: forall a. LabelMap a -> Int
$clength :: forall a. LabelMap a -> Int
null :: forall a. LabelMap a -> Bool
$cnull :: forall a. LabelMap a -> Bool
toList :: forall a. LabelMap a -> [a]
$ctoList :: forall a. LabelMap a -> [a]
foldl1 :: forall a. (a -> a -> a) -> LabelMap a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> LabelMap a -> a
foldr1 :: forall a. (a -> a -> a) -> LabelMap a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> LabelMap a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> LabelMap a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> LabelMap a -> b
foldl :: forall b a. (b -> a -> b) -> b -> LabelMap a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> LabelMap a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> LabelMap a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> LabelMap a -> b
foldr :: forall a b. (a -> b -> b) -> b -> LabelMap a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> LabelMap a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> LabelMap a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> LabelMap a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> LabelMap a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> LabelMap a -> m
fold :: forall m. Monoid m => LabelMap m -> m
$cfold :: forall m. Monoid m => LabelMap m -> m
Foldable, Functor LabelMap
Foldable LabelMap
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => LabelMap (m a) -> m (LabelMap a)
forall (f :: * -> *) a.
Applicative f =>
LabelMap (f a) -> f (LabelMap a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LabelMap a -> m (LabelMap b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LabelMap a -> f (LabelMap b)
sequence :: forall (m :: * -> *) a. Monad m => LabelMap (m a) -> m (LabelMap a)
$csequence :: forall (m :: * -> *) a. Monad m => LabelMap (m a) -> m (LabelMap a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LabelMap a -> m (LabelMap b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> LabelMap a -> m (LabelMap b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
LabelMap (f a) -> f (LabelMap a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
LabelMap (f a) -> f (LabelMap a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LabelMap a -> f (LabelMap b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> LabelMap a -> f (LabelMap b)
Traversable)
instance IsMap LabelMap where
type KeyOf LabelMap = Label
mapNull :: forall a. LabelMap a -> Bool
mapNull (LM UniqueMap a
m) = forall (map :: * -> *) a. IsMap map => map a -> Bool
mapNull UniqueMap a
m
mapSize :: forall a. LabelMap a -> Int
mapSize (LM UniqueMap a
m) = forall (map :: * -> *) a. IsMap map => map a -> Int
mapSize UniqueMap a
m
mapMember :: forall a. KeyOf LabelMap -> LabelMap a -> Bool
mapMember (Label Int
k) (LM UniqueMap a
m) = forall (map :: * -> *) a. IsMap map => KeyOf map -> map a -> Bool
mapMember Int
k UniqueMap a
m
mapLookup :: forall a. KeyOf LabelMap -> LabelMap a -> Maybe a
mapLookup (Label Int
k) (LM UniqueMap a
m) = forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup Int
k UniqueMap a
m
mapFindWithDefault :: forall a. a -> KeyOf LabelMap -> LabelMap a -> a
mapFindWithDefault a
def (Label Int
k) (LM UniqueMap a
m) = forall (map :: * -> *) a. IsMap map => a -> KeyOf map -> map a -> a
mapFindWithDefault a
def Int
k UniqueMap a
m
mapEmpty :: forall a. LabelMap a
mapEmpty = forall v. UniqueMap v -> LabelMap v
LM forall (map :: * -> *) a. IsMap map => map a
mapEmpty
mapSingleton :: forall a. KeyOf LabelMap -> a -> LabelMap a
mapSingleton (Label Int
k) a
v = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a. IsMap map => KeyOf map -> a -> map a
mapSingleton Int
k a
v)
mapInsert :: forall a. KeyOf LabelMap -> a -> LabelMap a -> LabelMap a
mapInsert (Label Int
k) a
v (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> a -> map a -> map a
mapInsert Int
k a
v UniqueMap a
m)
mapInsertWith :: forall a.
(a -> a -> a) -> KeyOf LabelMap -> a -> LabelMap a -> LabelMap a
mapInsertWith a -> a -> a
f (Label Int
k) a
v (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(a -> a -> a) -> KeyOf map -> a -> map a -> map a
mapInsertWith a -> a -> a
f Int
k a
v UniqueMap a
m)
mapDelete :: forall a. KeyOf LabelMap -> LabelMap a -> LabelMap a
mapDelete (Label Int
k) (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a. IsMap map => KeyOf map -> map a -> map a
mapDelete Int
k UniqueMap a
m)
mapAlter :: forall a.
(Maybe a -> Maybe a) -> KeyOf LabelMap -> LabelMap a -> LabelMap a
mapAlter Maybe a -> Maybe a
f (Label Int
k) (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(Maybe a -> Maybe a) -> KeyOf map -> map a -> map a
mapAlter Maybe a -> Maybe a
f Int
k UniqueMap a
m)
mapAdjust :: forall a. (a -> a) -> KeyOf LabelMap -> LabelMap a -> LabelMap a
mapAdjust a -> a
f (Label Int
k) (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(a -> a) -> KeyOf map -> map a -> map a
mapAdjust a -> a
f Int
k UniqueMap a
m)
mapUnion :: forall a. LabelMap a -> LabelMap a -> LabelMap a
mapUnion (LM UniqueMap a
x) (LM UniqueMap a
y) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a. IsMap map => map a -> map a -> map a
mapUnion UniqueMap a
x UniqueMap a
y)
mapUnionWithKey :: forall a.
(KeyOf LabelMap -> a -> a -> a)
-> LabelMap a -> LabelMap a -> LabelMap a
mapUnionWithKey KeyOf LabelMap -> a -> a -> a
f (LM UniqueMap a
x) (LM UniqueMap a
y) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(KeyOf map -> a -> a -> a) -> map a -> map a -> map a
mapUnionWithKey (KeyOf LabelMap -> a -> a -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Label
mkHooplLabel) UniqueMap a
x UniqueMap a
y)
mapDifference :: forall a. LabelMap a -> LabelMap a -> LabelMap a
mapDifference (LM UniqueMap a
x) (LM UniqueMap a
y) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a. IsMap map => map a -> map a -> map a
mapDifference UniqueMap a
x UniqueMap a
y)
mapIntersection :: forall a. LabelMap a -> LabelMap a -> LabelMap a
mapIntersection (LM UniqueMap a
x) (LM UniqueMap a
y) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a. IsMap map => map a -> map a -> map a
mapIntersection UniqueMap a
x UniqueMap a
y)
mapIsSubmapOf :: forall v. Eq v => LabelMap v -> LabelMap v -> Bool
mapIsSubmapOf (LM UniqueMap a
x) (LM UniqueMap a
y) = forall (map :: * -> *) a.
(IsMap map, Eq a) =>
map a -> map a -> Bool
mapIsSubmapOf UniqueMap a
x UniqueMap a
y
mapMap :: forall a b. (a -> b) -> LabelMap a -> LabelMap b
mapMap a -> b
f (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a b. IsMap map => (a -> b) -> map a -> map b
mapMap a -> b
f UniqueMap a
m)
mapMapWithKey :: forall a b. (KeyOf LabelMap -> a -> b) -> LabelMap a -> LabelMap b
mapMapWithKey KeyOf LabelMap -> a -> b
f (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a b.
IsMap map =>
(KeyOf map -> a -> b) -> map a -> map b
mapMapWithKey (KeyOf LabelMap -> a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Label
mkHooplLabel) UniqueMap a
m)
mapFoldl :: forall b a. (b -> a -> b) -> b -> LabelMap a -> b
mapFoldl b -> a -> b
k b
z (LM UniqueMap a
m) = forall (map :: * -> *) b a.
IsMap map =>
(b -> a -> b) -> b -> map a -> b
mapFoldl b -> a -> b
k b
z UniqueMap a
m
mapFoldr :: forall a b. (a -> b -> b) -> b -> LabelMap a -> b
mapFoldr a -> b -> b
k b
z (LM UniqueMap a
m) = forall (map :: * -> *) a b.
IsMap map =>
(a -> b -> b) -> b -> map a -> b
mapFoldr a -> b -> b
k b
z UniqueMap a
m
mapFoldlWithKey :: forall b a. (b -> KeyOf LabelMap -> a -> b) -> b -> LabelMap a -> b
mapFoldlWithKey b -> KeyOf LabelMap -> a -> b
k b
z (LM UniqueMap a
m) =
forall (map :: * -> *) b a.
IsMap map =>
(b -> KeyOf map -> a -> b) -> b -> map a -> b
mapFoldlWithKey (\b
a KeyOf UniqueMap
v -> b -> KeyOf LabelMap -> a -> b
k b
a (Int -> Label
mkHooplLabel KeyOf UniqueMap
v)) b
z UniqueMap a
m
mapFoldMapWithKey :: forall m a.
Monoid m =>
(KeyOf LabelMap -> a -> m) -> LabelMap a -> m
mapFoldMapWithKey KeyOf LabelMap -> a -> m
f (LM UniqueMap a
m) = forall (map :: * -> *) m a.
(IsMap map, Monoid m) =>
(KeyOf map -> a -> m) -> map a -> m
mapFoldMapWithKey (\KeyOf UniqueMap
k a
v -> KeyOf LabelMap -> a -> m
f (Int -> Label
mkHooplLabel KeyOf UniqueMap
k) a
v) UniqueMap a
m
{-# INLINEABLE mapFilter #-}
mapFilter :: forall a. (a -> Bool) -> LabelMap a -> LabelMap a
mapFilter a -> Bool
f (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(a -> Bool) -> map a -> map a
mapFilter a -> Bool
f UniqueMap a
m)
{-# INLINEABLE mapFilterWithKey #-}
mapFilterWithKey :: forall a. (KeyOf LabelMap -> a -> Bool) -> LabelMap a -> LabelMap a
mapFilterWithKey KeyOf LabelMap -> a -> Bool
f (LM UniqueMap a
m) = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(KeyOf map -> a -> Bool) -> map a -> map a
mapFilterWithKey (KeyOf LabelMap -> a -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Label
mkHooplLabel) UniqueMap a
m)
mapElems :: forall a. LabelMap a -> [a]
mapElems (LM UniqueMap a
m) = forall (map :: * -> *) a. IsMap map => map a -> [a]
mapElems UniqueMap a
m
mapKeys :: forall a. LabelMap a -> [KeyOf LabelMap]
mapKeys (LM UniqueMap a
m) = forall a b. (a -> b) -> [a] -> [b]
map Int -> Label
mkHooplLabel (forall (map :: * -> *) a. IsMap map => map a -> [KeyOf map]
mapKeys UniqueMap a
m)
{-# INLINEABLE mapToList #-}
mapToList :: forall a. LabelMap a -> [(KeyOf LabelMap, a)]
mapToList (LM UniqueMap a
m) = [(Int -> Label
mkHooplLabel Int
k, a
v) | (Int
k, a
v) <- forall (map :: * -> *) a. IsMap map => map a -> [(KeyOf map, a)]
mapToList UniqueMap a
m]
mapFromList :: forall a. [(KeyOf LabelMap, a)] -> LabelMap a
mapFromList [(KeyOf LabelMap, a)]
assocs = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a. IsMap map => [(KeyOf map, a)] -> map a
mapFromList [(Label -> Int
lblToUnique Label
k, a
v) | (Label
k, a
v) <- [(KeyOf LabelMap, a)]
assocs])
mapFromListWith :: forall a. (a -> a -> a) -> [(KeyOf LabelMap, a)] -> LabelMap a
mapFromListWith a -> a -> a
f [(KeyOf LabelMap, a)]
assocs = forall v. UniqueMap v -> LabelMap v
LM (forall (map :: * -> *) a.
IsMap map =>
(a -> a -> a) -> [(KeyOf map, a)] -> map a
mapFromListWith a -> a -> a
f [(Label -> Int
lblToUnique Label
k, a
v) | (Label
k, a
v) <- [(KeyOf LabelMap, a)]
assocs])
instance Outputable LabelSet where
ppr :: LabelSet -> SDoc
ppr = forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall set. IsSet set => set -> [ElemOf set]
setElems
instance Outputable a => Outputable (LabelMap a) where
ppr :: LabelMap a -> SDoc
ppr = forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (map :: * -> *) a. IsMap map => map a -> [(KeyOf map, a)]
mapToList
instance OutputableP env a => OutputableP env (LabelMap a) where
pdoc :: env -> LabelMap a -> SDoc
pdoc env
env = forall env a. OutputableP env a => env -> a -> SDoc
pdoc env
env forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (map :: * -> *) a. IsMap map => map a -> [(KeyOf map, a)]
mapToList
instance TrieMap LabelMap where
type Key LabelMap = Label
emptyTM :: forall a. LabelMap a
emptyTM = forall (map :: * -> *) a. IsMap map => map a
mapEmpty
lookupTM :: forall b. Key LabelMap -> LabelMap b -> Maybe b
lookupTM Key LabelMap
k LabelMap b
m = forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup Key LabelMap
k LabelMap b
m
alterTM :: forall b. Key LabelMap -> XT b -> LabelMap b -> LabelMap b
alterTM Key LabelMap
k XT b
f LabelMap b
m = forall (map :: * -> *) a.
IsMap map =>
(Maybe a -> Maybe a) -> KeyOf map -> map a -> map a
mapAlter XT b
f Key LabelMap
k LabelMap b
m
foldTM :: forall a b. (a -> b -> b) -> LabelMap a -> b -> b
foldTM a -> b -> b
k LabelMap a
m b
z = forall (map :: * -> *) a b.
IsMap map =>
(a -> b -> b) -> b -> map a -> b
mapFoldr a -> b -> b
k b
z LabelMap a
m
filterTM :: forall a. (a -> Bool) -> LabelMap a -> LabelMap a
filterTM a -> Bool
f LabelMap a
m = forall (map :: * -> *) a.
IsMap map =>
(a -> Bool) -> map a -> map a
mapFilter a -> Bool
f LabelMap a
m
type FactBase f = LabelMap f
lookupFact :: Label -> FactBase f -> Maybe f
lookupFact :: forall f. Label -> FactBase f -> Maybe f
lookupFact = forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup