ghc-8.4.1.20180329: The GHC API

Safe HaskellNone
LanguageHaskell2010

VarEnv

Contents

Synopsis

Var, Id and TyVar environments (maps)

type VarEnv elt = UniqFM elt Source #

Variable Environment

type IdEnv elt = VarEnv elt Source #

Identifier Environment

type TyVarEnv elt = VarEnv elt Source #

Type Variable Environment

type CoVarEnv elt = VarEnv elt Source #

Coercion Variable Environment

type TyCoVarEnv elt = VarEnv elt Source #

Type or Coercion Variable Environment

Manipulating these environments

mkVarEnv :: [(Var, a)] -> VarEnv a 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 #

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 #

alterVarEnv :: (Maybe a -> Maybe a) -> VarEnv a -> Var -> VarEnv 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 #

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

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

Deterministic Var environments (maps)

type DVarEnv elt = UniqDFM elt Source #

Deterministic Variable Environment

type DIdEnv elt = DVarEnv elt Source #

Deterministic Identifier Environment

type DTyVarEnv elt = DVarEnv elt Source #

Deterministic Type Variable Environment

Manipulating these environments

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

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

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

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

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

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

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

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

The InScopeSet type

data InScopeSet Source #

A set of variables that are in scope at some point "Secrets of the Glasgow Haskell Compiler inliner" Section 3.2 provides the motivation for this abstraction.

Instances
Outputable InScopeSet Source # 
Instance details

Defined in VarEnv

Operations on InScopeSets

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.

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.

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

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

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

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]

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