{-# LANGUAGE BangPatterns #-}
module FV (
FV, InterestingVarFun,
fvVarListVarSet, fvVarList, fvVarSet, fvDVarSet,
unitFV,
emptyFV,
mkFVs,
unionFV,
unionsFV,
delFV,
delFVs,
filterFV,
mapUnionFV,
) where
import GhcPrelude
import Var
import VarSet
type InterestingVarFun = Var -> Bool
type FV = InterestingVarFun
-> VarSet
-> ([Var], VarSet)
-> ([Var], VarSet)
fvVarListVarSet :: FV -> ([Var], VarSet)
fvVarListVarSet :: FV -> ([Var], VarSet)
fvVarListVarSet fv :: FV
fv = FV
fv (Bool -> Var -> Bool
forall a b. a -> b -> a
const Bool
True) VarSet
emptyVarSet ([], VarSet
emptyVarSet)
fvVarList :: FV -> [Var]
fvVarList :: FV -> [Var]
fvVarList = ([Var], VarSet) -> [Var]
forall a b. (a, b) -> a
fst (([Var], VarSet) -> [Var])
-> (FV -> ([Var], VarSet)) -> FV -> [Var]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FV -> ([Var], VarSet)
fvVarListVarSet
fvDVarSet :: FV -> DVarSet
fvDVarSet :: FV -> DVarSet
fvDVarSet = [Var] -> DVarSet
mkDVarSet ([Var] -> DVarSet) -> (FV -> [Var]) -> FV -> DVarSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Var], VarSet) -> [Var]
forall a b. (a, b) -> a
fst (([Var], VarSet) -> [Var])
-> (FV -> ([Var], VarSet)) -> FV -> [Var]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FV -> ([Var], VarSet)
fvVarListVarSet
fvVarSet :: FV -> VarSet
fvVarSet :: FV -> VarSet
fvVarSet = ([Var], VarSet) -> VarSet
forall a b. (a, b) -> b
snd (([Var], VarSet) -> VarSet)
-> (FV -> ([Var], VarSet)) -> FV -> VarSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FV -> ([Var], VarSet)
fvVarListVarSet
unitFV :: Id -> FV
unitFV :: Var -> FV
unitFV var :: Var
var fv_cand :: Var -> Bool
fv_cand in_scope :: VarSet
in_scope acc :: ([Var], VarSet)
acc@(have :: [Var]
have, haveSet :: VarSet
haveSet)
| Var
var Var -> VarSet -> Bool
`elemVarSet` VarSet
in_scope = ([Var], VarSet)
acc
| Var
var Var -> VarSet -> Bool
`elemVarSet` VarSet
haveSet = ([Var], VarSet)
acc
| Var -> Bool
fv_cand Var
var = (Var
varVar -> [Var] -> [Var]
forall a. a -> [a] -> [a]
:[Var]
have, VarSet -> Var -> VarSet
extendVarSet VarSet
haveSet Var
var)
| Bool
otherwise = ([Var], VarSet)
acc
{-# INLINE unitFV #-}
emptyFV :: FV
emptyFV :: FV
emptyFV _ _ acc :: ([Var], VarSet)
acc = ([Var], VarSet)
acc
{-# INLINE emptyFV #-}
unionFV :: FV -> FV -> FV
unionFV :: FV -> FV -> FV
unionFV fv1 :: FV
fv1 fv2 :: FV
fv2 fv_cand :: Var -> Bool
fv_cand in_scope :: VarSet
in_scope acc :: ([Var], VarSet)
acc =
FV
fv1 Var -> Bool
fv_cand VarSet
in_scope (([Var], VarSet) -> ([Var], VarSet))
-> ([Var], VarSet) -> ([Var], VarSet)
forall a b. (a -> b) -> a -> b
$! FV
fv2 Var -> Bool
fv_cand VarSet
in_scope (([Var], VarSet) -> ([Var], VarSet))
-> ([Var], VarSet) -> ([Var], VarSet)
forall a b. (a -> b) -> a -> b
$! ([Var], VarSet)
acc
{-# INLINE unionFV #-}
delFV :: Var -> FV -> FV
delFV :: Var -> FV -> FV
delFV var :: Var
var fv :: FV
fv fv_cand :: Var -> Bool
fv_cand !VarSet
in_scope acc :: ([Var], VarSet)
acc =
FV
fv Var -> Bool
fv_cand (VarSet -> Var -> VarSet
extendVarSet VarSet
in_scope Var
var) ([Var], VarSet)
acc
{-# INLINE delFV #-}
delFVs :: VarSet -> FV -> FV
delFVs :: VarSet -> FV -> FV
delFVs vars :: VarSet
vars fv :: FV
fv fv_cand :: Var -> Bool
fv_cand !VarSet
in_scope acc :: ([Var], VarSet)
acc =
FV
fv Var -> Bool
fv_cand (VarSet
in_scope VarSet -> VarSet -> VarSet
`unionVarSet` VarSet
vars) ([Var], VarSet)
acc
{-# INLINE delFVs #-}
filterFV :: InterestingVarFun -> FV -> FV
filterFV :: (Var -> Bool) -> FV -> FV
filterFV fv_cand2 :: Var -> Bool
fv_cand2 fv :: FV
fv fv_cand1 :: Var -> Bool
fv_cand1 in_scope :: VarSet
in_scope acc :: ([Var], VarSet)
acc =
FV
fv (\v :: Var
v -> Var -> Bool
fv_cand1 Var
v Bool -> Bool -> Bool
&& Var -> Bool
fv_cand2 Var
v) VarSet
in_scope ([Var], VarSet)
acc
{-# INLINE filterFV #-}
mapUnionFV :: (a -> FV) -> [a] -> FV
mapUnionFV :: (a -> FV) -> [a] -> FV
mapUnionFV _f :: a -> FV
_f [] _fv_cand :: Var -> Bool
_fv_cand _in_scope :: VarSet
_in_scope acc :: ([Var], VarSet)
acc = ([Var], VarSet)
acc
mapUnionFV f :: a -> FV
f (a :: a
a:as :: [a]
as) fv_cand :: Var -> Bool
fv_cand in_scope :: VarSet
in_scope acc :: ([Var], VarSet)
acc =
(a -> FV) -> [a] -> FV
forall a. (a -> FV) -> [a] -> FV
mapUnionFV a -> FV
f [a]
as Var -> Bool
fv_cand VarSet
in_scope (([Var], VarSet) -> ([Var], VarSet))
-> ([Var], VarSet) -> ([Var], VarSet)
forall a b. (a -> b) -> a -> b
$! a -> FV
f a
a Var -> Bool
fv_cand VarSet
in_scope (([Var], VarSet) -> ([Var], VarSet))
-> ([Var], VarSet) -> ([Var], VarSet)
forall a b. (a -> b) -> a -> b
$! ([Var], VarSet)
acc
{-# INLINABLE mapUnionFV #-}
unionsFV :: [FV] -> FV
unionsFV :: [FV] -> FV
unionsFV fvs :: [FV]
fvs fv_cand :: Var -> Bool
fv_cand in_scope :: VarSet
in_scope acc :: ([Var], VarSet)
acc = (FV -> FV) -> [FV] -> FV
forall a. (a -> FV) -> [a] -> FV
mapUnionFV FV -> FV
forall a. a -> a
id [FV]
fvs Var -> Bool
fv_cand VarSet
in_scope ([Var], VarSet)
acc
{-# INLINE unionsFV #-}
mkFVs :: [Var] -> FV
mkFVs :: [Var] -> FV
mkFVs vars :: [Var]
vars fv_cand :: Var -> Bool
fv_cand in_scope :: VarSet
in_scope acc :: ([Var], VarSet)
acc =
(Var -> FV) -> [Var] -> FV
forall a. (a -> FV) -> [a] -> FV
mapUnionFV Var -> FV
unitFV [Var]
vars Var -> Bool
fv_cand VarSet
in_scope ([Var], VarSet)
acc
{-# INLINE mkFVs #-}