The pipeline phase a certain Pass
is supposed to happen in.
- base: Lean.Compiler.LCNF.Phase
Here we still carry most of the original type information, most of the dependent portion is already (partially) erased though.
- mono: Lean.Compiler.LCNF.Phase
In this phase polymorphism has been eliminated.
- impure: Lean.Compiler.LCNF.Phase
In this phase impure stuff such as RC or efficient BaseIO transformations happen.
Instances For
Equations
- Lean.Compiler.LCNF.instInhabitedPhase = { default := Lean.Compiler.LCNF.Phase.base }
The state managed by the CompilerM
Monad
.
- lctx : Lean.Compiler.LCNF.LCtx
A
LocalContext
to store local declarations from let binders and other constructs in as we move throughExpr
s. - nextIdx : Nat
Next auxiliary variable suffix
Instances For
Equations
- Lean.Compiler.LCNF.CompilerM.instInhabitedState = { default := { lctx := default, nextIdx := default } }
- phase : Lean.Compiler.LCNF.Phase
- config : Lean.Compiler.LCNF.ConfigOptions
Instances For
Equations
- Lean.Compiler.LCNF.CompilerM.instInhabitedContext = { default := { phase := default, config := default } }
Equations
Instances For
Equations
- Lean.Compiler.LCNF.instMonadCompilerM = Monad.mk
Equations
- Lean.Compiler.LCNF.withPhase phase x = withReader (fun (ctx : Lean.Compiler.LCNF.CompilerM.Context) => { phase := phase, config := ctx.config }) x
Instances For
Equations
- Lean.Compiler.LCNF.getPhase = do let __do_lift ← read pure __do_lift.phase
Instances For
Equations
- Lean.Compiler.LCNF.inBasePhase = do let __do_lift ← Lean.Compiler.LCNF.getPhase pure (match __do_lift with | Lean.Compiler.LCNF.Phase.base => true | x => false)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Compiler.LCNF.findParam? fvarId = do let __do_lift ← get pure __do_lift.lctx.params[fvarId]?
Instances For
Equations
- Lean.Compiler.LCNF.findLetDecl? fvarId = do let __do_lift ← get pure __do_lift.lctx.letDecls[fvarId]?
Instances For
Equations
- Lean.Compiler.LCNF.findFunDecl? fvarId = do let __do_lift ← get pure __do_lift.lctx.funDecls[fvarId]?
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- (Lean.Compiler.LCNF.Arg.fvar fvarId).isConstructorApp = Lean.Compiler.LCNF.isConstructorApp fvarId
- arg.isConstructorApp = pure false
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Compiler.LCNF.modifyLCtx f = modify fun (s : Lean.Compiler.LCNF.CompilerM.State) => { lctx := f s.lctx, nextIdx := s.nextIdx }
Instances For
Equations
- Lean.Compiler.LCNF.eraseLetDecl decl = Lean.Compiler.LCNF.modifyLCtx fun (lctx : Lean.Compiler.LCNF.LCtx) => lctx.eraseLetDecl decl
Instances For
Equations
- Lean.Compiler.LCNF.eraseFunDecl decl recursive = Lean.Compiler.LCNF.modifyLCtx fun (lctx : Lean.Compiler.LCNF.LCtx) => lctx.eraseFunDecl decl recursive
Instances For
Equations
- Lean.Compiler.LCNF.eraseCode code = Lean.Compiler.LCNF.modifyLCtx fun (lctx : Lean.Compiler.LCNF.LCtx) => Lean.Compiler.LCNF.LCtx.eraseCode code lctx
Instances For
Equations
- Lean.Compiler.LCNF.eraseParam param = Lean.Compiler.LCNF.modifyLCtx fun (lctx : Lean.Compiler.LCNF.LCtx) => lctx.eraseParam param
Instances For
Equations
- Lean.Compiler.LCNF.eraseParams params = Lean.Compiler.LCNF.modifyLCtx fun (lctx : Lean.Compiler.LCNF.LCtx) => lctx.eraseParams params
Instances For
Equations
- Lean.Compiler.LCNF.eraseCodeDecl (Lean.Compiler.LCNF.CodeDecl.let decl_2) = Lean.Compiler.LCNF.eraseLetDecl decl_2
- Lean.Compiler.LCNF.eraseCodeDecl (Lean.Compiler.LCNF.CodeDecl.jp decl_2) = Lean.Compiler.LCNF.eraseFunDecl decl_2
- Lean.Compiler.LCNF.eraseCodeDecl (Lean.Compiler.LCNF.CodeDecl.fun decl_2) = Lean.Compiler.LCNF.eraseFunDecl decl_2
Instances For
Erase all free variables occurring in decls
from the local context.
Equations
- Lean.Compiler.LCNF.eraseCodeDecls decls = Array.forM (fun (decl : Lean.Compiler.LCNF.CodeDecl) => Lean.Compiler.LCNF.eraseCodeDecl decl) decls
Instances For
Equations
- Lean.Compiler.LCNF.eraseDecl decl = do Lean.Compiler.LCNF.eraseParams decl.params Lean.Compiler.LCNF.eraseCode decl.value
Instances For
Equations
- decl.erase = Lean.Compiler.LCNF.eraseDecl decl
Instances For
A free variable substitution.
We use these substitutions when inlining definitions and "internalizing" LCNF code into CompilerM
.
During the internalization process, we ensure all free variables in the LCNF code do not collide with existing ones
at the CompilerM
local context.
Remark: in LCNF, (computationally relevant) data is in A-normal form, but this is not the case for types and type formers.
So, when inlining we often want to replace a free variable with a type or type former.
The substitution contains entries fvarId ↦ e
s.t., e
is a valid LCNF argument. That is,
it is a free variable, a type (or type former), or lcErased
.
Check.lean
contains a substitution validator.
Instances For
Result type for normFVar
and normFVarImp
.
- fvar: Lean.FVarId → Lean.Compiler.LCNF.NormFVarResult
New free variable.
- erased: Lean.Compiler.LCNF.NormFVarResult
Free variable has been erased. This can happen when instantiating polymorphic code with computationally irrelant stuff.
Instances For
Equations
- Lean.Compiler.LCNF.instInhabitedNormFVarResult = { default := Lean.Compiler.LCNF.NormFVarResult.fvar default }
Interface for monads that have a free substitutions.
- getSubst : m Lean.Compiler.LCNF.FVarSubst
Instances
Equations
- Lean.Compiler.LCNF.instMonadFVarSubstOfMonadLift m n = { getSubst := liftM Lean.Compiler.LCNF.getSubst }
- modifySubst : (Lean.Compiler.LCNF.FVarSubst → Lean.Compiler.LCNF.FVarSubst) → m Unit
Instances
Equations
- One or more equations did not get rendered due to their size.
Add the entry fvarId ↦ fvarId'
to the free variable substitution.
Equations
- Lean.Compiler.LCNF.addFVarSubst fvarId fvarId' = Lean.Compiler.LCNF.modifySubst fun (s : Lean.Compiler.LCNF.FVarSubst) => Std.HashMap.insert s fvarId (Lean.Expr.fvar fvarId')
Instances For
Add the substitution fvarId ↦ e
, e
must be a valid LCNF argument.
That is, it must be a free variable, type (or type former), or lcErased
.
See Check.lean
for the free variable substitution checker.
Equations
- Lean.Compiler.LCNF.addSubst fvarId e = Lean.Compiler.LCNF.modifySubst fun (s : Lean.Compiler.LCNF.FVarSubst) => Std.HashMap.insert s fvarId e
Instances For
Normalize the given free variable.
See normExprImp
for documentation on the translator
parameter.
This function is meant to be used in contexts where the input free-variable is computationally relevant.
This function panics if the substitution is mapping fvarId
to an expression that is not another free variable.
That is, it is not a type (or type former), nor lcErased
. Recall that a valid FVarSubst
contains only
expressions that are free variables, lcErased
, or type formers.
Equations
- Lean.Compiler.LCNF.normFVar fvarId = do let __do_lift ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normFVarImp __do_lift fvarId t)
Instances For
Replace the free variables in e
using the given substitution.
If translator = true
, then we assume the free variables occurring in the range of the substitution are in another
local context. For example, translator = true
during internalization where we are making sure all free variables
in a given expression are replaced with new ones that do not collide with the ones in the current local context.
If translator = false
, we assume the substitution contains free variable replacements in the same local context,
and given entries such as x₁ ↦ x₂
, x₂ ↦ x₃
, ..., xₙ₋₁ ↦ xₙ
, and the expression f x₁ x₂
, we want the resulting
expression to be f xₙ xₙ
. We use this setting, for example, in the simplifier.
Equations
- Lean.Compiler.LCNF.normExpr e = do let __do_lift ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normExprImp __do_lift e t)
Instances For
Replace the free variables in arg
using the given substitution.
See normExprImp
Equations
- Lean.Compiler.LCNF.normArg arg = do let __do_lift ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normArgImp __do_lift arg t)
Instances For
Replace the free variables in e
using the given substitution.
See normExprImp
Equations
- Lean.Compiler.LCNF.normLetValue e = do let __do_lift ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normLetValueImp __do_lift e t)
Instances For
Replace the free variables in e
using the given substitution.
If translator = true
, then we assume the free variables occurring in the range of the substitution are in another
local context. For example, translator = true
during internalization where we are making sure all free variables
in a given expression are replaced with new ones that do not collide with the ones in the current local context.
If translator = false
, we assume the substitution contains free variable replacements in the same local context,
and given entries such as x₁ ↦ x₂
, x₂ ↦ x₃
, ..., xₙ₋₁ ↦ xₙ
, and the expression f x₁ x₂
, we want the resulting
expression to be f xₙ xₙ
. We use this setting, for example, in the simplifier.
Equations
- Lean.Compiler.LCNF.normExprCore s e translator = Lean.Compiler.LCNF.normExprImp s e translator
Instances For
Normalize the given arguments using the current substitution.
Equations
- Lean.Compiler.LCNF.normArgs args = do let __do_lift ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normArgsImp __do_lift args t)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Compiler.LCNF.ensureNotAnonymous binderName baseName = if binderName.isAnonymous = true then Lean.Compiler.LCNF.mkFreshBinderName baseName else pure binderName
Instances For
Helper functions for creating LCNF local declarations.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Compiler.LCNF.mkReturnErased = do let auxDecl ← Lean.Compiler.LCNF.mkLetDeclErased pure (Lean.Compiler.LCNF.Code.let auxDecl (Lean.Compiler.LCNF.Code.return auxDecl.fvarId))
Instances For
Equations
- decl.updateValue value = decl.update decl.type value
Instances For
Equations
- Lean.Compiler.LCNF.FunDeclCore.update' decl type value = Lean.Compiler.LCNF.FunDeclCore.update decl type decl.params value
Instances For
Equations
- Lean.Compiler.LCNF.FunDeclCore.updateValue decl value = Lean.Compiler.LCNF.FunDeclCore.update decl decl.type decl.params value
Instances For
Equations
- Lean.Compiler.LCNF.normParam p = do let __do_lift ← Lean.Compiler.LCNF.normExpr p.type liftM (p.update __do_lift)
Instances For
Equations
- Lean.Compiler.LCNF.normParams ps = ps.mapMonoM Lean.Compiler.LCNF.normParam
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- Lean.Compiler.LCNF.instMonadFVarSubstNormalizerM = { getSubst := read }
If result
is .fvar fvarId
, then return x fvarId
. Otherwise, it is .erased
,
and method returns let _x.i := .erased; return _x.i
.
Equations
Instances For
Equations
- Lean.Compiler.LCNF.normFunDecl decl = do let __do_lift ← Lean.Compiler.LCNF.getSubst liftM (Lean.Compiler.LCNF.normFunDeclImp decl __do_lift)
Instances For
Similar to internalize
, but does not refresh FVarId
s.
Equations
- Lean.Compiler.LCNF.normCode code = do let __do_lift ← Lean.Compiler.LCNF.getSubst liftM (Lean.Compiler.LCNF.normCodeImp code __do_lift)
Instances For
Equations
- Lean.Compiler.LCNF.replaceExprFVars e s translator = ReaderT.run (Lean.Compiler.LCNF.normExpr e) s
Instances For
Equations
- Lean.Compiler.LCNF.replaceFVars code s translator = ReaderT.run (Lean.Compiler.LCNF.normCode code) s
Instances For
Instances For
Equations
- Lean.Compiler.LCNF.mkAuxParam type borrow = do let __do_lift ← Lean.Compiler.LCNF.mkFreshBinderName `_y Lean.Compiler.LCNF.mkParam __do_lift type borrow
Instances For
Equations
- Lean.Compiler.LCNF.getConfig = do let __do_lift ← read pure __do_lift.config
Instances For
Equations
- x.run s phase = do let __do_lift ← Lean.getOptions (x { phase := phase, config := Lean.Compiler.LCNF.toConfigOptions __do_lift }).run' s