Variable Environment
Moduleghc-9.10.3GHC2021
GHC.Types.Var.Env
- 11 types
- 104 values
- Packageghc-9.10.3
- Exports115
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceEnv.hs
Var, Id and TyVar environments (maps)
5 declarationsIdentifier Environment
Type Variable Environment
Coercion Variable Environment
Type or Coercion Variable Environment
Manipulating these environments
Only keep variables contained in the VarSet
Deterministic Var environments (maps)
3 declarationsDeterministic Variable Environment
Deterministic Identifier Environment Sadly not always indexed by Id, but it is in the common case.
Deterministic Type Variable Environment
Manipulating these environments
The InScopeSet type
1 declarationA 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.
Instances1Outputable
Outputable InScopeSetDefined in ghc-9.10.3 · GHC.Types.Var.Env
Operations on InScopeSets
Look up a variable the InScopeSet. This lets you map from the variable's identity (unique) to its full value.
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].
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 Uniques this way. See Note [Local uniques].
The RnEnv2 type
1 declarationRename 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. e2Basically 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:
A renaming for the left-hand expression
A renaming for the right-hand expressions
An in-scope set
Furthermore, when matching, we want to be able to have an 'occurs check', to prevent:
\x. f ~ \y. ymatching 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 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
Applies rnBndr2 to several variables: the two variable lists must be of equal length
Similar to rnBndr2 but returns the new variable as well as the new environment. Postcondition: the type of the returned Var is that of bR
Look up the renaming of an occurrence in the left or right term
Look up the renaming of an occurrence in the left or right term
Tells whether a variable is locally bound
Tells whether a variable is locally bound
`anyInRnEnvR env set` == `any (inRnEnvR rn_env) (toList set)` but lazy in the second argument if the right side of the env is empty.
Look up the renaming of an occurrence in the left or right term
Look up the renaming of an occurrence in the left or right term
Similar to rnBndr2 but used when there's a binder on the left side only.
Similar to rnBndr2 but used when there's a binder on the right side only.
Wipe the left or right side renaming
Wipe the left or right side renaming
swap the meaning of left and right
Similar to rnBndrL but used for eta expansion See Note [Eta expansion]
Similar to rnBndr2 but used for eta expansion See Note [Eta expansion]
Retrieve the left mapping
Retrieve the right mapping
TidyEnv and its operation
4 declarationsTidy 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