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 x
returnstrue
ifx
is a variable that is not inC
.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 : FVarIdSet
Set of already visited free variables.
Free variables that must become new parameters of the code being specialized.
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
- Lean.Compiler.LCNF.Closure.markVisited fvarId = modify fun (s : Lean.Compiler.LCNF.Closure.State) => { visited := s.visited.insert fvarId, params := s.params, decls := s.decls }
Instances For
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.