ghc-9.6.3: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Types.Var.Env

Contents

- Var, Id and TyVar environments (maps)
  - Manipulating these environments
- Deterministic Var environments (maps)
  - Manipulating these environments
- The InScopeSet type
  - Operations on InScopeSets
- The RnEnv2 type
  - Operations on RnEnv2s
- TidyEnv and its operation

Synopsis

- type VarEnv elt = UniqFM Var elt
- type IdEnv elt = UniqFM Id elt
- type TyVarEnv elt = UniqFM Var elt
- type CoVarEnv elt = UniqFM CoVar elt
- type TyCoVarEnv elt = UniqFM TyCoVar elt
- emptyVarEnv :: VarEnv a
- unitVarEnv :: Var -> a -> VarEnv a
- mkVarEnv :: [(Var, a)] -> VarEnv a
- mkVarEnv_Directly :: [(Unique, a)] -> VarEnv a
- elemVarEnv :: Var -> VarEnv a -> Bool
- disjointVarEnv :: VarEnv a -> VarEnv a -> Bool
- anyVarEnv :: (elt -> Bool) -> UniqFM key elt -> Bool
- extendVarEnv :: VarEnv a -> Var -> a -> VarEnv a
- extendVarEnv_C :: (a -> a -> a) -> VarEnv a -> Var -> a -> VarEnv a
- extendVarEnv_Acc :: (a -> b -> b) -> (a -> b) -> VarEnv b -> Var -> a -> VarEnv b
- extendVarEnvList :: VarEnv a -> [(Var, a)] -> VarEnv a
- plusVarEnv :: VarEnv a -> VarEnv a -> VarEnv a
- plusVarEnv_C :: (a -> a -> a) -> VarEnv a -> VarEnv a -> VarEnv a
- plusVarEnv_CD :: (a -> a -> a) -> VarEnv a -> a -> VarEnv a -> a -> VarEnv a
- plusMaybeVarEnv_C :: (a -> a -> Maybe a) -> VarEnv a -> VarEnv a -> VarEnv a
- plusVarEnvList :: [VarEnv a] -> VarEnv a
- alterVarEnv :: (Maybe a -> Maybe a) -> VarEnv a -> Var -> VarEnv a
- delVarEnvList :: VarEnv a -> [Var] -> VarEnv a
- delVarEnv :: VarEnv a -> Var -> VarEnv a
- minusVarEnv :: VarEnv a -> VarEnv b -> VarEnv a
- lookupVarEnv :: VarEnv a -> Var -> Maybe a
- lookupVarEnv_NF :: VarEnv a -> Var -> a
- lookupWithDefaultVarEnv :: VarEnv a -> a -> Var -> a
- lookupVarEnv_Directly :: VarEnv a -> Unique -> Maybe a
- mapVarEnv :: (a -> b) -> VarEnv a -> VarEnv b
- zipVarEnv :: [Var] -> [a] -> VarEnv a
- modifyVarEnv :: (a -> a) -> VarEnv a -> Var -> VarEnv a
- modifyVarEnv_Directly :: (a -> a) -> UniqFM key a -> Unique -> UniqFM key a
- isEmptyVarEnv :: VarEnv a -> Bool
- elemVarEnvByKey :: Unique -> VarEnv a -> Bool
- filterVarEnv :: (a -> Bool) -> VarEnv a -> VarEnv a
- restrictVarEnv :: VarEnv a -> VarSet -> VarEnv a
- partitionVarEnv :: (a -> Bool) -> VarEnv a -> (VarEnv a, VarEnv a)
- varEnvDomain :: VarEnv elt -> UnVarSet
- type DVarEnv elt = UniqDFM Var elt
- type DIdEnv elt = UniqDFM Var elt
- type DTyVarEnv elt = UniqDFM TyVar elt
- emptyDVarEnv :: DVarEnv a
- mkDVarEnv :: [(Var, a)] -> DVarEnv a
- dVarEnvElts :: DVarEnv a -> [a]
- extendDVarEnv :: DVarEnv a -> Var -> a -> DVarEnv a
- extendDVarEnv_C :: (a -> a -> a) -> DVarEnv a -> Var -> a -> DVarEnv a
- extendDVarEnvList :: DVarEnv a -> [(Var, a)] -> DVarEnv a
- lookupDVarEnv :: DVarEnv a -> Var -> Maybe a
- elemDVarEnv :: Var -> DVarEnv a -> Bool
- isEmptyDVarEnv :: DVarEnv a -> Bool
- foldDVarEnv :: (a -> b -> b) -> b -> DVarEnv a -> b
- nonDetStrictFoldDVarEnv :: (a -> b -> b) -> b -> DVarEnv a -> b
- mapDVarEnv :: (a -> b) -> DVarEnv a -> DVarEnv b
- filterDVarEnv :: (a -> Bool) -> DVarEnv a -> DVarEnv a
- modifyDVarEnv :: (a -> a) -> DVarEnv a -> Var -> DVarEnv a
- alterDVarEnv :: (Maybe a -> Maybe a) -> DVarEnv a -> Var -> DVarEnv a
- plusDVarEnv :: DVarEnv a -> DVarEnv a -> DVarEnv a
- plusDVarEnv_C :: (a -> a -> a) -> DVarEnv a -> DVarEnv a -> DVarEnv a
- unitDVarEnv :: Var -> a -> DVarEnv a
- delDVarEnv :: DVarEnv a -> Var -> DVarEnv a
- delDVarEnvList :: DVarEnv a -> [Var] -> DVarEnv a
- minusDVarEnv :: DVarEnv a -> DVarEnv a' -> DVarEnv a
- partitionDVarEnv :: (a -> Bool) -> DVarEnv a -> (DVarEnv a, DVarEnv a)
- anyDVarEnv :: (a -> Bool) -> DVarEnv a -> Bool
- newtype InScopeSet = InScope VarSet
- emptyInScopeSet :: InScopeSet
- mkInScopeSet :: VarSet -> InScopeSet
- mkInScopeSetList :: [Var] -> InScopeSet
- delInScopeSet :: InScopeSet -> Var -> InScopeSet
- extendInScopeSet :: InScopeSet -> Var -> InScopeSet
- extendInScopeSetList :: InScopeSet -> [Var] -> InScopeSet
- extendInScopeSetSet :: InScopeSet -> VarSet -> InScopeSet
- getInScopeVars :: InScopeSet -> VarSet
- lookupInScope :: InScopeSet -> Var -> Maybe Var
- lookupInScope_Directly :: InScopeSet -> Unique -> Maybe Var
- unionInScope :: InScopeSet -> InScopeSet -> InScopeSet
- elemInScopeSet :: Var -> InScopeSet -> Bool
- uniqAway :: InScopeSet -> Var -> Var
- varSetInScope :: VarSet -> InScopeSet -> Bool
- unsafeGetFreshLocalUnique :: InScopeSet -> Unique
- data RnEnv2
- mkRnEnv2 :: InScopeSet -> RnEnv2
- rnBndr2 :: RnEnv2 -> Var -> Var -> RnEnv2
- rnBndrs2 :: RnEnv2 -> [Var] -> [Var] -> RnEnv2
- rnBndr2_var :: RnEnv2 -> Var -> Var -> (RnEnv2, Var)
- rnOccL :: RnEnv2 -> Var -> Var
- rnOccR :: RnEnv2 -> Var -> Var
- inRnEnvL :: RnEnv2 -> Var -> Bool
- inRnEnvR :: RnEnv2 -> Var -> Bool
- anyInRnEnvR :: RnEnv2 -> VarSet -> Bool
- rnOccL_maybe :: RnEnv2 -> Var -> Maybe Var
- rnOccR_maybe :: RnEnv2 -> Var -> Maybe Var
- rnBndrL :: RnEnv2 -> Var -> (RnEnv2, Var)
- rnBndrR :: RnEnv2 -> Var -> (RnEnv2, Var)
- nukeRnEnvL :: RnEnv2 -> RnEnv2
- nukeRnEnvR :: RnEnv2 -> RnEnv2
- rnSwap :: RnEnv2 -> RnEnv2
- delBndrL :: RnEnv2 -> Var -> RnEnv2
- delBndrR :: RnEnv2 -> Var -> RnEnv2
- delBndrsL :: RnEnv2 -> [Var] -> RnEnv2
- delBndrsR :: RnEnv2 -> [Var] -> RnEnv2
- extendRnInScopeSetList :: RnEnv2 -> [Var] -> RnEnv2
- rnEtaL :: RnEnv2 -> Var -> (RnEnv2, Var)
- rnEtaR :: RnEnv2 -> Var -> (RnEnv2, Var)
- rnInScope :: Var -> RnEnv2 -> Bool
- rnInScopeSet :: RnEnv2 -> InScopeSet
- lookupRnInScope :: RnEnv2 -> Var -> Var
- rnEnvL :: RnEnv2 -> VarEnv Var
- rnEnvR :: RnEnv2 -> VarEnv Var
- type TidyEnv = (TidyOccEnv, VarEnv Var)
- emptyTidyEnv :: TidyEnv
- mkEmptyTidyEnv :: TidyOccEnv -> TidyEnv
- delTidyEnvList :: TidyEnv -> [Var] -> TidyEnv

# Var, Id and TyVar environments (maps)

type VarEnv elt = UniqFM Var elt Source #

Variable Environment

type IdEnv elt = UniqFM Id elt Source #

Identifier Environment

type TyVarEnv elt = UniqFM Var elt Source #

Type Variable Environment

type CoVarEnv elt = UniqFM CoVar elt Source #

Coercion Variable Environment

type TyCoVarEnv elt = UniqFM TyCoVar elt Source #

Type or Coercion Variable Environment

## Manipulating these environments

emptyVarEnv :: VarEnv a Source #

unitVarEnv :: Var -> a -> VarEnv a Source #

mkVarEnv :: [(Var, a)] -> VarEnv a Source #

mkVarEnv_Directly :: [(Unique, a)] -> VarEnv a Source #

elemVarEnv :: Var -> VarEnv a -> Bool Source #

disjointVarEnv :: VarEnv a -> VarEnv a -> Bool Source #

anyVarEnv :: (elt -> Bool) -> UniqFM key elt -> Bool Source #

extendVarEnv :: VarEnv a -> Var -> a -> VarEnv a Source #

extendVarEnv_C :: (a -> a -> a) -> VarEnv a -> Var -> a -> VarEnv a Source #

extendVarEnv_Acc :: (a -> b -> b) -> (a -> b) -> VarEnv b -> Var -> a -> VarEnv b Source #

extendVarEnvList :: VarEnv a -> [(Var, a)] -> VarEnv a Source #

plusVarEnv :: VarEnv a -> VarEnv a -> VarEnv a Source #

plusVarEnv_C :: (a -> a -> a) -> VarEnv a -> VarEnv a -> VarEnv a Source #

plusVarEnv_CD :: (a -> a -> a) -> VarEnv a -> a -> VarEnv a -> a -> VarEnv a Source #

plusMaybeVarEnv_C :: (a -> a -> Maybe a) -> VarEnv a -> VarEnv a -> VarEnv a Source #

plusVarEnvList :: [VarEnv a] -> VarEnv a Source #

alterVarEnv :: (Maybe a -> Maybe a) -> VarEnv a -> Var -> VarEnv a Source #

delVarEnvList :: VarEnv a -> [Var] -> VarEnv a Source #

delVarEnv :: VarEnv a -> Var -> VarEnv a Source #

minusVarEnv :: VarEnv a -> VarEnv b -> VarEnv a Source #

lookupVarEnv :: VarEnv a -> Var -> Maybe a Source #

lookupVarEnv_NF :: VarEnv a -> Var -> a Source #

lookupWithDefaultVarEnv :: VarEnv a -> a -> Var -> a Source #

lookupVarEnv_Directly :: VarEnv a -> Unique -> Maybe a Source #

mapVarEnv :: (a -> b) -> VarEnv a -> VarEnv b Source #

zipVarEnv :: [Var] -> [a] -> VarEnv a Source #

modifyVarEnv :: (a -> a) -> VarEnv a -> Var -> VarEnv a Source #

modifyVarEnv_Directly :: (a -> a) -> UniqFM key a -> Unique -> UniqFM key a Source #

isEmptyVarEnv :: VarEnv a -> Bool Source #

elemVarEnvByKey :: Unique -> VarEnv a -> Bool Source #

filterVarEnv :: (a -> Bool) -> VarEnv a -> VarEnv a Source #

restrictVarEnv :: VarEnv a -> VarSet -> VarEnv a Source #

Only keep variables contained in the VarSet

partitionVarEnv :: (a -> Bool) -> VarEnv a -> (VarEnv a, VarEnv a) Source #

varEnvDomain :: VarEnv elt -> UnVarSet Source #

# Deterministic Var environments (maps)

type DVarEnv elt = UniqDFM Var elt Source #

Deterministic Variable Environment

type DIdEnv elt = UniqDFM Var elt Source #

Deterministic Identifier Environment Sadly not always indexed by Id, but it is in the common case.

type DTyVarEnv elt = UniqDFM TyVar elt Source #

Deterministic Type Variable Environment

## Manipulating these environments

emptyDVarEnv :: DVarEnv a Source #

mkDVarEnv :: [(Var, a)] -> DVarEnv a Source #

dVarEnvElts :: DVarEnv a -> [a] Source #

extendDVarEnv :: DVarEnv a -> Var -> a -> DVarEnv a Source #

extendDVarEnv_C :: (a -> a -> a) -> DVarEnv a -> Var -> a -> DVarEnv a Source #

extendDVarEnvList :: DVarEnv a -> [(Var, a)] -> DVarEnv a Source #

lookupDVarEnv :: DVarEnv a -> Var -> Maybe a Source #

elemDVarEnv :: Var -> DVarEnv a -> Bool Source #

isEmptyDVarEnv :: DVarEnv a -> Bool Source #

foldDVarEnv :: (a -> b -> b) -> b -> DVarEnv a -> b Source #

nonDetStrictFoldDVarEnv :: (a -> b -> b) -> b -> DVarEnv a -> b Source #

mapDVarEnv :: (a -> b) -> DVarEnv a -> DVarEnv b Source #

filterDVarEnv :: (a -> Bool) -> DVarEnv a -> DVarEnv a Source #

modifyDVarEnv :: (a -> a) -> DVarEnv a -> Var -> DVarEnv a Source #

alterDVarEnv :: (Maybe a -> Maybe a) -> DVarEnv a -> Var -> DVarEnv a Source #

plusDVarEnv :: DVarEnv a -> DVarEnv a -> DVarEnv a Source #

plusDVarEnv_C :: (a -> a -> a) -> DVarEnv a -> DVarEnv a -> DVarEnv a Source #

unitDVarEnv :: Var -> a -> DVarEnv a Source #

delDVarEnv :: DVarEnv a -> Var -> DVarEnv a Source #

delDVarEnvList :: DVarEnv a -> [Var] -> DVarEnv a Source #

minusDVarEnv :: DVarEnv a -> DVarEnv a' -> DVarEnv a Source #

partitionDVarEnv :: (a -> Bool) -> DVarEnv a -> (DVarEnv a, DVarEnv a) Source #

anyDVarEnv :: (a -> Bool) -> DVarEnv a -> Bool Source #

# The InScopeSet type

newtype InScopeSet Source #

A set of variables that are in scope at some point.

Note that this is a superset of the variables that are currently in scope. See Note [The InScopeSet invariant].

"Secrets of the Glasgow Haskell Compiler inliner" Section 3.2 provides the motivation for this abstraction.

Constructors

InScope VarSet |

#### Instances

Instances details

Outputable InScopeSet Source # |
Instance details Defined in GHC.Types.Var.Env Methods ppr :: InScopeSet -> SDoc Source #

## Operations on InScopeSets

emptyInScopeSet :: InScopeSet Source #

mkInScopeSet :: VarSet -> InScopeSet Source #

mkInScopeSetList :: [Var] -> InScopeSet Source #

delInScopeSet :: InScopeSet -> Var -> InScopeSet Source #

extendInScopeSet :: InScopeSet -> Var -> InScopeSet Source #

extendInScopeSetList :: InScopeSet -> [Var] -> InScopeSet Source #

extendInScopeSetSet :: InScopeSet -> VarSet -> InScopeSet Source #

getInScopeVars :: InScopeSet -> VarSet Source #

lookupInScope :: InScopeSet -> Var -> Maybe Var Source #

Look up a variable the `InScopeSet`. This lets you map from the variable's identity (unique) to its full value.

lookupInScope_Directly :: InScopeSet -> Unique -> Maybe Var Source #

unionInScope :: InScopeSet -> InScopeSet -> InScopeSet Source #

elemInScopeSet :: Var -> InScopeSet -> Bool Source #

uniqAway :: InScopeSet -> Var -> Var Source #

`uniqAway in_scope v` finds a unique that is not used in the in-scope set, and gives that to v. See Note [Local uniques] and Note [The InScopeSet invariant].

varSetInScope :: VarSet -> InScopeSet -> Bool Source #

unsafeGetFreshLocalUnique :: InScopeSet -> Unique Source #

`unsafeGetFreshUnique in_scope` finds a unique that is not in-scope in the given `InScopeSet`. This must be used very carefully since one can very easily introduce non-unique `Unique`s this way. See Note [Local uniques].

# The RnEnv2 type

data RnEnv2 Source #

Rename Environment 2

When we are comparing (or matching) types or terms, we are faced with "going under" corresponding binders. E.g. when comparing:

    \x. e1     ~   \y. e2

Basically we want to rename [`x` -> `y`] or [`y` -> `x`], but there are lots of things we must be careful of. In particular, `x` might be free in `e2`, or y in `e1`. So the idea is that we come up with a fresh binder that is free in neither, and rename `x` and `y` respectively. That means we must maintain:

1. A renaming for the left-hand expression
2. A renaming for the right-hand expressions
3. An in-scope set

Furthermore, when matching, we want to be able to have an 'occurs check', to prevent:

    \x. f   ~   \y. y

matching with [`f` -> `y`]. So for each expression we want to know that set of locally-bound variables. That is precisely the domain of the mappings 1. and 2., but we must ensure that we always extend the mappings as we go in.

All of this information is bundled up in the `RnEnv2`

## Operations on RnEnv2s

mkRnEnv2 :: InScopeSet -> RnEnv2 Source #

rnBndr2 :: RnEnv2 -> Var -> Var -> RnEnv2 Source #

`rnBndr2 env bL bR` goes under a binder `bL` in the Left term, and binder `bR` in the Right term. It finds a new binder, `new_b`, and returns an environment mapping `bL -> new_b` and `bR -> new_b`

rnBndrs2 :: RnEnv2 -> [Var] -> [Var] -> RnEnv2 Source #

Applies `rnBndr2` to several variables: the two variable lists must be of equal length

rnBndr2_var :: RnEnv2 -> Var -> Var -> (RnEnv2, Var) Source #

Similar to `rnBndr2` but returns the new variable as well as the new environment

rnOccL :: RnEnv2 -> Var -> Var Source #

Look up the renaming of an occurrence in the left or right term

rnOccR :: RnEnv2 -> Var -> Var Source #

Look up the renaming of an occurrence in the left or right term

inRnEnvL :: RnEnv2 -> Var -> Bool Source #

Tells whether a variable is locally bound

inRnEnvR :: RnEnv2 -> Var -> Bool Source #

Tells whether a variable is locally bound

anyInRnEnvR :: RnEnv2 -> VarSet -> Bool Source #

`anyInRnEnvR env set` == `any (inRnEnvR rn_env) (toList set)` but lazy in the second argument if the right side of the env is empty.

rnOccL_maybe :: RnEnv2 -> Var -> Maybe Var Source #

Look up the renaming of an occurrence in the left or right term

rnOccR_maybe :: RnEnv2 -> Var -> Maybe Var Source #

Look up the renaming of an occurrence in the left or right term

rnBndrL :: RnEnv2 -> Var -> (RnEnv2, Var) Source #

Similar to `rnBndr2` but used when there's a binder on the left side only.

rnBndrR :: RnEnv2 -> Var -> (RnEnv2, Var) Source #

Similar to `rnBndr2` but used when there's a binder on the right side only.

nukeRnEnvL :: RnEnv2 -> RnEnv2 Source #

Wipe the left or right side renaming

nukeRnEnvR :: RnEnv2 -> RnEnv2 Source #

Wipe the left or right side renaming

rnSwap :: RnEnv2 -> RnEnv2 Source #

swap the meaning of left and right

delBndrL :: RnEnv2 -> Var -> RnEnv2 Source #

delBndrR :: RnEnv2 -> Var -> RnEnv2 Source #

delBndrsL :: RnEnv2 -> [Var] -> RnEnv2 Source #

delBndrsR :: RnEnv2 -> [Var] -> RnEnv2 Source #

extendRnInScopeSetList :: RnEnv2 -> [Var] -> RnEnv2 Source #

rnEtaL :: RnEnv2 -> Var -> (RnEnv2, Var) Source #

Similar to `rnBndrL` but used for eta expansion See Note [Eta expansion]

rnEtaR :: RnEnv2 -> Var -> (RnEnv2, Var) Source #

Similar to `rnBndr2` but used for eta expansion See Note [Eta expansion]

rnInScope :: Var -> RnEnv2 -> Bool Source #

rnInScopeSet :: RnEnv2 -> InScopeSet Source #

lookupRnInScope :: RnEnv2 -> Var -> Var Source #

rnEnvL :: RnEnv2 -> VarEnv Var Source #

Retrieve the left mapping

rnEnvR :: RnEnv2 -> VarEnv Var Source #

Retrieve the right mapping

# TidyEnv and its operation

type TidyEnv = (TidyOccEnv, VarEnv Var) Source #

Tidy Environment

When tidying up print names, we keep a mapping of in-scope occ-names (the `TidyOccEnv`) and a Var-to-Var of the current renamings

emptyTidyEnv :: TidyEnv Source #

mkEmptyTidyEnv :: TidyOccEnv -> TidyEnv Source #

delTidyEnvList :: TidyEnv -> [Var] -> TidyEnv Source #