- 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.
The pipeline phase a certain Pass is supposed to happen in.
Instances For
Equations
- Lean.Compiler.LCNF.instInhabitedPhase = { default := Lean.Compiler.LCNF.Phase.base }
A
LocalContextto store local declarations from let binders and other constructs in as we move throughExprs.lctx : Lean.Compiler.LCNF.LCtxNext auxiliary variable suffix
nextIdx : Nat
The state managed by the CompilerM Monad.
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
- Lean.Compiler.LCNF.withPhase phase x = withReader (fun ctx => { phase := phase, config := ctx.config }) x
Equations
- Lean.Compiler.LCNF.getPhase = do let a ← read pure a.phase
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.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Compiler.LCNF.findParam? fvarId = do let a ← get pure (Lean.HashMap.find? a.lctx.params fvarId)
Equations
- Lean.Compiler.LCNF.findLetDecl? fvarId = do let a ← get pure (Lean.HashMap.find? a.lctx.letDecls fvarId)
Equations
- Lean.Compiler.LCNF.findFunDecl? fvarId = do let a ← get pure (Lean.HashMap.find? a.lctx.funDecls fvarId)
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.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Compiler.LCNF.modifyLCtx f = modify fun s => { lctx := f s.lctx, nextIdx := s.nextIdx }
Equations
- Lean.Compiler.LCNF.eraseLetDecl decl = Lean.Compiler.LCNF.modifyLCtx fun lctx => Lean.Compiler.LCNF.LCtx.eraseLetDecl lctx decl
Equations
- Lean.Compiler.LCNF.eraseFunDecl decl recursive = Lean.Compiler.LCNF.modifyLCtx fun lctx => Lean.Compiler.LCNF.LCtx.eraseFunDecl lctx decl recursive
Equations
- Lean.Compiler.LCNF.eraseCode code = Lean.Compiler.LCNF.modifyLCtx fun lctx => Lean.Compiler.LCNF.LCtx.eraseCode code lctx
Equations
- Lean.Compiler.LCNF.eraseParam param = Lean.Compiler.LCNF.modifyLCtx fun lctx => Lean.Compiler.LCNF.LCtx.eraseParam lctx param
Equations
- Lean.Compiler.LCNF.eraseParams params = Lean.Compiler.LCNF.modifyLCtx fun lctx => Lean.Compiler.LCNF.LCtx.eraseParams lctx params
Equations
- One or more equations did not get rendered due to their size.
Erase all free variables occurring in decls from the local context.
Equations
- Lean.Compiler.LCNF.eraseCodeDecls decls = Array.forM (fun decl => Lean.Compiler.LCNF.eraseCodeDecl decl) decls 0 (Array.size decls)
Equations
- Lean.Compiler.LCNF.eraseDecl decl = do Lean.Compiler.LCNF.eraseParams decl.params Lean.Compiler.LCNF.eraseCode decl.value
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.
- getSubst : m Lean.Compiler.LCNF.FVarSubst
Interface for monads that have a free substitutions.
Instances
Equations
- Lean.Compiler.LCNF.instMonadFVarSubst m n = { getSubst := liftM Lean.Compiler.LCNF.getSubst }
- modifySubst : (Lean.Compiler.LCNF.FVarSubst → Lean.Compiler.LCNF.FVarSubst) → m Unit
Instances
Equations
- Lean.Compiler.LCNF.instMonadFVarSubstState m n = { modifySubst := fun f => liftM (Lean.Compiler.LCNF.modifySubst f) }
Add the entry fvarId ↦ fvarId' to the free variable substitution.
Equations
- Lean.Compiler.LCNF.addFVarSubst fvarId fvarId' = Lean.Compiler.LCNF.modifySubst fun s => Lean.HashMap.insert s fvarId (Lean.Expr.fvar fvarId')
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.HashMap.insert s fvarId e
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 a ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normFVarImp a fvarId t)
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 a ← Lean.Compiler.LCNF.getSubst pure (Lean.Compiler.LCNF.normExprImp a e t)
Normalize the given expressions using the current substitution.
Equations
- Lean.Compiler.LCNF.normExprs es = Array.mapMonoM es Lean.Compiler.LCNF.normExpr
Equations
- One or more equations did not get rendered due to their size.
The InternalizeM monad is a translator. It "translates" the free variables
in the input expressions and Code, into new fresh free variables in the
local context.
Equations
- Lean.Compiler.LCNF.Internalize.instMonadFVarSubstInternalizeMTrue = { getSubst := get }
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.
Equations
- One or more equations did not get rendered due to their size.
Refresh free variables ids in code, and store their declarations in the local context.
Equations
Equations
- One or more equations did not get rendered due to their size.
Helper functions for creating LCNF local declarations.
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.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Compiler.LCNF.LetDecl.updateValue decl value = Lean.Compiler.LCNF.LetDecl.update decl decl.type value
Equations
- Lean.Compiler.LCNF.FunDeclCore.update' decl type value = Lean.Compiler.LCNF.FunDeclCore.update decl type decl.params value
Equations
- Lean.Compiler.LCNF.FunDeclCore.updateValue decl value = Lean.Compiler.LCNF.FunDeclCore.update decl decl.type decl.params value
Equations
- Lean.Compiler.LCNF.normParam p = do let a ← Lean.Compiler.LCNF.normExpr p.type liftM (Lean.Compiler.LCNF.Param.update p a)
Equations
- Lean.Compiler.LCNF.normParams ps = Array.mapMonoM ps Lean.Compiler.LCNF.normParam
Equations
- Lean.Compiler.LCNF.normLetDecl decl = do let a ← Lean.Compiler.LCNF.normExpr decl.type let a_1 ← Lean.Compiler.LCNF.normExpr decl.value liftM (Lean.Compiler.LCNF.LetDecl.update decl a a_1)
Equations
Equations
- Lean.Compiler.LCNF.instMonadFVarSubstNormalizerM = { getSubst := read }
Equations
- Lean.Compiler.LCNF.normFunDecl decl = do let a ← Lean.Compiler.LCNF.getSubst liftM (Lean.Compiler.LCNF.normFunDeclImp decl a)
Similar to internalize, but does not refresh FVarIds.
Equations
- Lean.Compiler.LCNF.normCode code = do let a ← Lean.Compiler.LCNF.getSubst liftM (Lean.Compiler.LCNF.normCodeImp code a)
Equations
- Lean.Compiler.LCNF.replaceExprFVars e s translator = ReaderT.run (Lean.Compiler.LCNF.normExpr e) s
Equations
- Lean.Compiler.LCNF.replaceFVars code s translator = ReaderT.run (Lean.Compiler.LCNF.normCode code) s
Equations
- Lean.Compiler.LCNF.mkAuxParam type borrow = do let a ← Lean.Compiler.LCNF.mkFreshBinderName (Lean.Name.mkStr1 "_y") Lean.Compiler.LCNF.mkParam a type borrow
Create a fresh local context and internalize the given decls.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Compiler.LCNF.getConfig = do let a ← read pure a.config
Equations
- Lean.Compiler.LCNF.CompilerM.run x s phase = do let a ← Lean.getOptions StateRefT'.run' (x { phase := phase, config := Lean.Compiler.LCNF.toConfigOptions a }) s