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

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.FVs

Contents

- Free variables of expressions and binding groups
- Selective free variables of expressions
- Free variables of Rules, Vars and Ids
- Orphan names
- Core syntax tree annotation with free variables

Description

A module concerned with finding the free variables of an expression.

Synopsis

- exprFreeVars :: CoreExpr -> VarSet
- exprsFreeVars :: [CoreExpr] -> VarSet
- exprFreeVarsDSet :: CoreExpr -> DVarSet
- exprFreeVarsList :: CoreExpr -> [Var]
- exprsFreeVarsList :: [CoreExpr] -> [Var]
- exprFreeIds :: CoreExpr -> IdSet
- exprsFreeIds :: [CoreExpr] -> IdSet
- exprFreeIdsDSet :: CoreExpr -> DIdSet
- exprsFreeIdsDSet :: [CoreExpr] -> DIdSet
- exprFreeIdsList :: CoreExpr -> [Id]
- exprsFreeIdsList :: [CoreExpr] -> [Id]
- bindFreeVars :: CoreBind -> VarSet
- type InterestingVarFun = Var -> Bool
- exprSomeFreeVars :: InterestingVarFun -> CoreExpr -> VarSet
- exprsSomeFreeVars :: InterestingVarFun -> [CoreExpr] -> VarSet
- exprSomeFreeVarsList :: InterestingVarFun -> CoreExpr -> [Var]
- exprsSomeFreeVarsList :: InterestingVarFun -> [CoreExpr] -> [Var]
- varTypeTyCoVars :: Var -> TyCoVarSet
- varTypeTyCoFVs :: Var -> FV
- idUnfoldingVars :: Id -> VarSet
- idFreeVars :: Id -> VarSet
- dIdFreeVars :: Id -> DVarSet
- bndrRuleAndUnfoldingVarsDSet :: Id -> DVarSet
- bndrRuleAndUnfoldingIds :: Id -> IdSet
- idFVs :: Id -> FV
- idRuleVars :: Id -> VarSet
- stableUnfoldingVars :: Unfolding -> Maybe VarSet
- ruleFreeVars :: CoreRule -> VarSet
- rulesFreeVars :: [CoreRule] -> VarSet
- rulesFreeVarsDSet :: [CoreRule] -> DVarSet
- mkRuleInfo :: [CoreRule] -> RuleInfo
- ruleLhsFreeIds :: CoreRule -> VarSet
- ruleLhsFreeIdsList :: CoreRule -> [Var]
- ruleRhsFreeVars :: CoreRule -> VarSet
- rulesRhsFreeIds :: [CoreRule] -> VarSet
- exprFVs :: CoreExpr -> FV
- orphNamesOfType :: Type -> NameSet
- orphNamesOfTypes :: [Type] -> NameSet
- orphNamesOfCo :: Coercion -> NameSet
- orphNamesOfCoCon :: forall (br :: BranchFlag). CoAxiom br -> NameSet
- orphNamesOfAxiomLHS :: forall (br :: BranchFlag). CoAxiom br -> NameSet
- exprsOrphNames :: [CoreExpr] -> NameSet
- type FVAnn = DVarSet
- type CoreExprWithFVs = AnnExpr Id FVAnn
- type CoreExprWithFVs' = AnnExpr' Id FVAnn
- type CoreBindWithFVs = AnnBind Id FVAnn
- type CoreAltWithFVs = AnnAlt Id FVAnn
- freeVars :: CoreExpr -> CoreExprWithFVs
- freeVarsBind :: CoreBind -> DVarSet -> (CoreBindWithFVs, DVarSet)
- freeVarsOf :: CoreExprWithFVs -> DIdSet
- freeVarsOfAnn :: FVAnn -> DIdSet

# Free variables of expressions and binding groups

exprFreeVars :: CoreExpr -> VarSet #

Find all locally-defined free Ids or type variables in an expression returning a non-deterministic set.

exprsFreeVars :: [CoreExpr] -> VarSet #

Find all locally-defined free Ids or type variables in several expressions returning a non-deterministic set.

exprFreeVarsDSet :: CoreExpr -> DVarSet #

Find all locally-defined free Ids or type variables in an expression returning a deterministic set.

exprFreeVarsList :: CoreExpr -> [Var] #

Find all locally-defined free Ids or type variables in an expression returning a deterministically ordered list.

exprsFreeVarsList :: [CoreExpr] -> [Var] #

Find all locally-defined free Ids or type variables in several expressions returning a deterministically ordered list.

exprFreeIds :: CoreExpr -> IdSet #

Find all locally-defined free Ids in an expression

exprsFreeIds :: [CoreExpr] -> IdSet #

exprFreeIdsDSet :: CoreExpr -> DIdSet #

Find all locally-defined free Ids in an expression returning a deterministic set.

exprsFreeIdsDSet :: [CoreExpr] -> DIdSet #

Find all locally-defined free Ids in several expressions returning a deterministic set.

exprFreeIdsList :: CoreExpr -> [Id] #

Find all locally-defined free Ids in an expression returning a deterministically ordered list.

exprsFreeIdsList :: [CoreExpr] -> [Id] #

Find all locally-defined free Ids in several expressions returning a deterministically ordered list.

bindFreeVars :: CoreBind -> VarSet #

Find all locally defined free Ids in a binding group

# Selective free variables of expressions

type InterestingVarFun = Var -> Bool #

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

exprSomeFreeVars #

Arguments

:: InterestingVarFun | Says which `Var`s are interesting
-> CoreExpr |
-> VarSet |

Finds free variables in an expression selected by a predicate

exprsSomeFreeVars :: InterestingVarFun -> [CoreExpr] -> VarSet #

Finds free variables in several expressions selected by a predicate

exprSomeFreeVarsList #

Arguments

:: InterestingVarFun | Says which `Var`s are interesting
-> CoreExpr |
-> [Var] |

Finds free variables in an expression selected by a predicate returning a deterministically ordered list.

exprsSomeFreeVarsList :: InterestingVarFun -> [CoreExpr] -> [Var] #

Finds free variables in several expressions selected by a predicate returning a deterministically ordered list.

# Free variables of Rules, Vars and Ids

varTypeTyCoVars :: Var -> TyCoVarSet #

varTypeTyCoFVs :: Var -> FV #

idUnfoldingVars :: Id -> VarSet #

idFreeVars :: Id -> VarSet #

dIdFreeVars :: Id -> DVarSet #

bndrRuleAndUnfoldingVarsDSet :: Id -> DVarSet #

bndrRuleAndUnfoldingIds :: Id -> IdSet #

idFVs :: Id -> FV #

idRuleVars :: Id -> VarSet #

stableUnfoldingVars :: Unfolding -> Maybe VarSet #

ruleFreeVars :: CoreRule -> VarSet #

Those variables free in the both the left right hand sides of a rule returned as a non-deterministic set

rulesFreeVars :: [CoreRule] -> VarSet #

Those variables free in both the left right hand sides of several rules

rulesFreeVarsDSet :: [CoreRule] -> DVarSet #

Those variables free in the both the left right hand sides of rules returned as a deterministic set

mkRuleInfo :: [CoreRule] -> RuleInfo #

Make a `RuleInfo` containing a number of `CoreRule`s, suitable for putting into an `IdInfo`

ruleLhsFreeIds :: CoreRule -> VarSet #

This finds all locally-defined free Ids on the left hand side of a rule and returns them as a non-deterministic set

ruleLhsFreeIdsList :: CoreRule -> [Var] #

This finds all locally-defined free Ids on the left hand side of a rule and returns them as a deterministically ordered list

ruleRhsFreeVars :: CoreRule -> VarSet #

Those variables free in the right hand side of a rule returned as a non-deterministic set

rulesRhsFreeIds :: [CoreRule] -> VarSet #

Those locally-defined free `Id`s in the right hand side of several rules returned as a non-deterministic set

exprFVs :: CoreExpr -> FV #

Find all locally-defined free Ids or type variables in an expression returning a composable FV computation. See Note [FV naming conventions] in GHC.Utils.FV for why export it.

# Orphan names

orphNamesOfType :: Type -> NameSet #

orphNamesOfTypes :: [Type] -> NameSet #

orphNamesOfCo :: Coercion -> NameSet #

orphNamesOfCoCon :: forall (br :: BranchFlag). CoAxiom br -> NameSet #

orphNamesOfAxiomLHS :: forall (br :: BranchFlag). CoAxiom br -> NameSet #

`orphNamesOfAxiomLHS` collects the names of the concrete types and type constructors that make up the LHS of a type family instance, including the family name itself.

For instance, given `type family Foo a b`: `type instance Foo (F (G (H a))) b = ...` would yield [Foo,F,G,H]

Used (via orphNamesOfFamInst) in the implementation of ":info" in GHCi. and when determining orphan-hood for a FamInst or module

exprsOrphNames :: [CoreExpr] -> NameSet #

Finds the free external names of several expressions: see `exprOrphNames` for details

# Core syntax tree annotation with free variables

type FVAnn = DVarSet #

type CoreExprWithFVs = AnnExpr Id FVAnn #

Every node in an expression annotated with its (non-global) free variables, both Ids and TyVars, and type. NB: see Note [The FVAnn invariant]

type CoreExprWithFVs' = AnnExpr' Id FVAnn #

type CoreBindWithFVs = AnnBind Id FVAnn #

Every node in a binding group annotated with its (non-global) free variables, both Ids and TyVars, and type.

type CoreAltWithFVs = AnnAlt Id FVAnn #

Every node in an expression annotated with its (non-global) free variables, both Ids and TyVars, and type.

freeVars :: CoreExpr -> CoreExprWithFVs #

Annotate a `CoreExpr` with its (non-global) free type and value variables at every tree node.

freeVarsBind :: CoreBind -> DVarSet -> (CoreBindWithFVs, DVarSet) #

freeVarsOf :: CoreExprWithFVs -> DIdSet #

Inverse function to `freeVars`

freeVarsOfAnn :: FVAnn -> DIdSet #

Extract the vars reported in a FVAnn