Documentation

Lean.Compiler.LCNF.SpecInfo

Each parameter is associated with a SpecParamInfo. This information is used by LCNF/Specialize.lean.

  • fixedInst : SpecParamInfo

    A parameter that is an type class instance (or an arrow that produces a type class instance), and is fixed in recursive declarations. By default, Lean always specializes this kind of argument.

  • fixedHO : SpecParamInfo

    A parameter that is a function and is fixed in recursive declarations. If the user tags a declaration with @[specialize] without specifying which arguments should be specialized, Lean will specialize .fixedHO arguments in addition to .fixedInst.

  • fixedNeutral : SpecParamInfo

    Computationally irrelevant parameters that are fixed in recursive declarations, and there is a fixedInst, fixedHO, or user param that depends on it.

  • user : SpecParamInfo

    An argument that has been specified in the @[specialize] attribute. Lean specializes it even if it is not fixed in recursive declarations. Non-termination can happen, and Lean interrupts it with an error message based on the stack depth.

  • other : SpecParamInfo

    Parameter is not going to be specialized.

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.
      • declName : Name

        The name of the declaration.

      • paramsInfo : Array SpecParamInfo

        Information about which parameters of the declaration qualify for specialization.

      • alreadySpecialized : Bool

        True if declName was already specialized before. This is relevant because we specialize declarations that have already been specialized less aggressively than declarations that have not.

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

          Extension for storing SpecParamInfo for declarations being compiled. Remark: we only store information for declarations that will be specialized.

          Note: fixedNeutral must have forward dependencies.

          The code specializer consider a fixedNeutral parameter during code specialization only if it contains forward dependencies that are tagged as .user, .fixedHO, or .fixedInst. The motivation is to minimize the number of code specializations that have little or no impact on performance. For example, let's consider the function.

          def liftMacroM
              {α : Type} {m : Type → Type}
              [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m]
              [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLiftT IO m] (x : MacroM α) : m α := do
          

          The parameter α does not occur in any local instance, and x is marked as .other since the function is not tagged as [specialize]. There is little value in considering α during code specialization, but if we do many copies of this function will be generated. Recall users may still force the code specializer to take α into account by using [specialize α] (α has .user info), or [specialize x] (α has .fixedNeutral since x is a forward dependency tagged as .user), or [specialize] (α has .fixedNeutral since x is a forward dependency tagged as .fixedHO).

          def Lean.Compiler.LCNF.computeSpecEntries (decls : Array Decl) (autoSpecialize : NameOption (Array Nat)Bool) (alreadySpecialized : Array Bool) :

          Compute specialization information for decls. We assume that decls contains a full SCC of computationally relevant declarations. Furthermore this function takes:

          • autoSpecialize which determines whether we apply "automated" specialization to a decl, that is whether we automatically specialize for all fixedHO parameters. It receives both the name and the array of arguments mentioned in @[specialize] if any.
          • alreadySpecialized which is a mask that says whether a decl is already a specialized declaration itself.
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Compute and save specialization information for decls. Assumes that decls is an SCC of user defined 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
                Instances For
                  def Lean.Compiler.LCNF.isSpecCandidate {m : TypeType} [Monad m] [MonadEnv m] (declName : Name) :
                  Equations
                  Instances For