Dependency collector for code specialization and lambda lifting. #
During code specialization and lambda lifting, we have code C
containing free variables. These free variables
are in a scope, and we say we are computing C
's closure.
This module is used to compute the closure.
- inScope : Lean.FVarId → Bool
inScope x
returnstrue
ifx
is a variable that is not inC
. - abstract : Lean.FVarId → Bool
If
abstract x
returnstrue
, we convertx
into a closure parameter. Otherwise, we collect the dependencies in thelet
/fun
-declaration too, and include the declaration in the closure. Remark: the lambda lifting pass abstracts alllet
/fun
-declarations.
Instances For
State for the ClosureM
monad.
- visited : Lean.FVarIdSet
Set of already visited free variables.
- params : Array Lean.Compiler.LCNF.Param
Free variables that must become new parameters of the code being specialized.
- decls : Array Lean.Compiler.LCNF.CodeDecl
Let-declarations and local function declarations that are going to be "copied" to the code being processed. For example, when this module is used in the code specializer, the let-declarations often contain the instance values. In the current specialization heuristic all let-declarations are ground values (i.e., they do not contain free-variables). However, local function declarations may contain free variables.
All customers of this module try to avoid work duplication. If a let-declaration is a ground value, it most likely will be computed during compilation time, and work duplication is not an issue.
Instances For
Monad for implementing the dependency collector.
Equations
Instances For
Mark a free variable as already visited. We perform a topological sort over the dependencies.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Collect dependencies in parameters. We need this because parameters may contain other type parameters.
Collect dependencies in the given code. We need this function to be able to collect dependencies in a local function declaration.
Collect dependencies of a local function declaration.
Process the given free variable. If it has not already been visited and is in scope, we collect its dependencies.
Collect dependencies of the given expression.
Equations
- One or more equations did not get rendered due to their size.