ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Utils.FV

Contents

- Deterministic free vars computations
- Running the computations
  - Manipulating those computations

Description

Utilities for efficiently and deterministically computing free variables.

Synopsis

- type FV = InterestingVarFun -> VarSet -> VarAcc -> VarAcc
- type InterestingVarFun = Var -> Bool
- fvVarList :: FV -> [Var]
- fvVarSet :: FV -> VarSet
- fvDVarSet :: FV -> DVarSet
- unitFV :: Id -> FV
- emptyFV :: FV
- mkFVs :: [Var] -> FV
- unionFV :: FV -> FV -> FV
- unionsFV :: [FV] -> FV
- delFV :: Var -> FV -> FV
- delFVs :: VarSet -> FV -> FV
- filterFV :: InterestingVarFun -> FV -> FV
- mapUnionFV :: (a -> FV) -> [a] -> FV
- fvDVarSetSome :: InterestingVarFun -> FV -> DVarSet

# Deterministic free vars computations

type FV = InterestingVarFun -> VarSet -> VarAcc -> VarAcc #

type InterestingVarFun = Var -> Bool #

Predicate on possible free variables: returns `True` iff the variable is interesting

# Running the computations

fvVarList :: FV -> [Var] #

Run a free variable computation, returning a list of distinct free variables in deterministic order.

fvVarSet :: FV -> VarSet #

Run a free variable computation, returning a non-deterministic set of free variables. Don't use if the set will be later converted to a list and the order of that list will impact the generated code.

fvDVarSet :: FV -> DVarSet #

Run a free variable computation, returning a deterministic set of free variables. Note that this is just a wrapper around the version that returns a deterministic list. If you need a list you should use `fvVarList`.

## Manipulating those computations

unitFV :: Id -> FV #

Add a variable - when free, to the returned free variables. Ignores duplicates and respects the filtering function.

emptyFV :: FV #

Return no free variables.

mkFVs :: [Var] -> FV #

Add multiple variables - when free, to the returned free variables. Ignores duplicates and respects the filtering function.

unionFV :: FV -> FV -> FV #

Union two free variable computations.

unionsFV :: [FV] -> FV #

Union many free variable computations.

delFV :: Var -> FV -> FV #

Mark the variable as not free by putting it in scope.

delFVs :: VarSet -> FV -> FV #

Mark many free variables as not free.

filterFV :: InterestingVarFun -> FV -> FV #

Filter a free variable computation.

mapUnionFV :: (a -> FV) -> [a] -> FV #

Map a free variable computation over a list and union the results.

fvDVarSetSome :: InterestingVarFun -> FV -> DVarSet #