Documentation

Lean.Compiler.LCNF.CompilerM

inductive Lean.Compiler.LCNF.Phase :
Type

The pipeline phase a certain Pass is supposed to happen in.

Instances For
    • A LocalContext to store local declarations from let binders and other constructs in as we move through Exprs.

    • Next auxiliary variable suffix

      nextIdx : Nat

    The state managed by the CompilerM Monad.

    Instances For
      @[inline]
      Equations
      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
      • 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
      • One or more equations did not get rendered due to their size.

      Erase all free variables occurring in decls from the local context.

      Equations
      @[inline]

      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.

      Equations
      class Lean.Compiler.LCNF.MonadFVarSubst (m : TypeType) (translator : outParam Bool) :
      Type

      Interface for monads that have a free substitutions.

      Instances
        instance Lean.Compiler.LCNF.instMonadFVarSubst {t : Bool} (m : TypeType) (n : TypeType) [inst : MonadLift m n] [inst : Lean.Compiler.LCNF.MonadFVarSubst m t] :
        Equations
        @[inline]
        def Lean.Compiler.LCNF.addFVarSubst {m : TypeType} [inst : Lean.Compiler.LCNF.MonadFVarSubstState m] (fvarId : Lean.FVarId) (fvarId' : Lean.FVarId) :

        Add the entry fvarId ↦ fvarId' to the free variable substitution.

        Equations
        @[inline]

        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
        @[inline]
        def Lean.Compiler.LCNF.normFVar {m : TypeType} {t : Bool} [inst : Lean.Compiler.LCNF.MonadFVarSubst m t] [inst : Monad m] (fvarId : Lean.FVarId) :

        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
        @[inline]
        def Lean.Compiler.LCNF.normExpr {m : TypeType} {t : Bool} [inst : Lean.Compiler.LCNF.MonadFVarSubst m t] [inst : Monad m] (e : Lean.Expr) :

        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
        def Lean.Compiler.LCNF.normExprs {m : TypeType} {t : Bool} [inst : Lean.Compiler.LCNF.MonadFVarSubst m t] [inst : Monad m] (es : Array Lean.Expr) :

        Normalize the given expressions using the current substitution.

        Equations
        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

        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.
        @[implementedBy _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateParamImp]
        @[implementedBy _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateLetDeclImp]
        @[implementedBy _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateFunDeclImp]
        Equations
        • Lean.Compiler.LCNF.instMonadFVarSubstNormalizerM = { getSubst := read }
        @[inline]
        Equations
        @[inline]

        Similar to internalize, but does not refresh FVarIds.

        Equations

        Create a fresh local context and internalize the given decls.

        Equations
        • One or more equations did not get rendered due to their size.
        Equations