File: .lake/packages/lean4/src/lean/Lean/Compiler/LCNF/Specialize.lean

full_name: Lean.Compiler.LCNF.Specialize.Cache
code: abbrev Cache 
goal: Type

full_name: Lean.Compiler.LCNF.Specialize.CacheEntry.key
code: structure CacheEntry where
  key : Expr
  declName : Name
  deriving Inhabited
goal: Lean.Expr

full_name: Lean.Compiler.LCNF.Specialize.CacheEntry.declName
code: structure CacheEntry where
  key : Expr
  declName : Name
  deriving Inhabited
goal: Lean.Name

full_name: Lean.Compiler.LCNF.Specialize.CacheEntry
code: structure CacheEntry where
  key : Expr
  declName : Name
  deriving Inhabited
goal: Type

full_name: Lean.Compiler.LCNF.Specialize.instInhabitedCacheEntry
code: structure CacheEntry where
  key : Expr
  declName : Name
  deriving Inhabited
goal: Inhabited Lean.Compiler.LCNF.Specialize.CacheEntry

full_name: Lean.Compiler.LCNF.Specialize.addEntry
code: def addEntry (cache : Cache) (e : CacheEntry) : Cache 
goal: Lean.Compiler.LCNF.Specialize.Cache

full_name: Lean.Compiler.LCNF.Specialize.specCacheExt
code: builtin_initialize specCacheExt : SimplePersistentEnvExtension CacheEntry Cache ←
  registerSimplePersistentEnvExtension {
    addEntryFn    := addEntry
    addImportedFn := fun es => (mkStateFromImportedEntries addEntry {} es).switch
  }
goal: Lean.SimplePersistentEnvExtension Lean.Compiler.LCNF.Specialize.CacheEntry Lean.Compiler.LCNF.Specialize.Cache

full_name: Lean.Compiler.LCNF.Specialize.initFn._@..lake.packages.lean4.src.lean.Lean.Compiler.LCNF.Specialize._hyg.50
code: builtin_initialize specCacheExt : SimplePersistentEnvExtension CacheEntry Cache ←
  registerSimplePersistentEnvExtension {
    addEntryFn    := addEntry
    addImportedFn := fun es => (mkStateFromImportedEntries addEntry {} es).switch
  }
goal: IO (Lean.SimplePersistentEnvExtension Lean.Compiler.LCNF.Specialize.CacheEntry Lean.Compiler.LCNF.Specialize.Cache)

full_name: Lean.Compiler.LCNF.Specialize.cacheSpec
code: def cacheSpec (key : Expr) (declName : Name) : CoreM Unit 
goal: Lean.CoreM Unit

full_name: Lean.Compiler.LCNF.Specialize.findSpecCache?
code: def findSpecCache? (key : Expr) : CoreM (Option Name) 
goal: Lean.CoreM (Option Lean.Name)

full_name: Lean.Compiler.LCNF.Specialize.Context.ground
code: structure Context where
  /--
  Set of free variables in scope. The "collector" uses this information when collecting
  dependencies for code specialization.
  -/
  scope  : FVarIdSet := {}
  /--
  Set of let-declarations in scope that do not depend on parameters.
  -/
  ground : FVarIdSet := {}
  /--
  Name of the declaration being processed
  -/
  declName : Name
goal: Lean.FVarIdSet

full_name: Lean.Compiler.LCNF.Specialize.Context.scope
code: structure Context where
  /--
  Set of free variables in scope. The "collector" uses this information when collecting
  dependencies for code specialization.
  -/
  scope  : FVarIdSet := {}
  /--
  Set of let-declarations in scope that do not depend on parameters.
  -/
  ground : FVarIdSet := {}
  /--
  Name of the declaration being processed
  -/
  declName : Name
goal: Lean.FVarIdSet

full_name: Lean.Compiler.LCNF.Specialize.Context
code: structure Context where
  /--
  Set of free variables in scope. The "collector" uses this information when collecting
  dependencies for code specialization.
  -/
  scope  : FVarIdSet := {}
  /--
  Set of let-declarations in scope that do not depend on parameters.
  -/
  ground : FVarIdSet := {}
  /--
  Name of the declaration being processed
  -/
  declName : Name
goal: Type

full_name: Lean.Compiler.LCNF.Specialize.Context.declName
code: structure Context where
  /--
  Set of free variables in scope. The "collector" uses this information when collecting
  dependencies for code specialization.
  -/
  scope  : FVarIdSet := {}
  /--
  Set of let-declarations in scope that do not depend on parameters.
  -/
  ground : FVarIdSet := {}
  /--
  Name of the declaration being processed
  -/
  declName : Name
goal: Lean.Name

full_name: Lean.Compiler.LCNF.Specialize.State
code: structure State where
  decls : Array Decl := #[]
goal: Type

full_name: Lean.Compiler.LCNF.Specialize.State.decls
code: structure State where
  decls : Array Decl := #[]
goal: Array Lean.Compiler.LCNF.Decl

full_name: Lean.Compiler.LCNF.Specialize.SpecializeM
code: abbrev SpecializeM 
goal: Type

full_name: Lean.Compiler.LCNF.Specialize.instMonadScopeSpecializeM
code: instance : MonadScope SpecializeM 
goal: Lean.Compiler.LCNF.MonadScope Lean.Compiler.LCNF.Specialize.SpecializeM

full_name: Lean.Compiler.LCNF.Specialize.isGround
code: /--
Return `true` if `e` is a ground term. That is,
it contains only free variables tagged as ground
-/
def isGround [TraverseFVar α] (e : α) : SpecializeM Bool 
goal: Lean.Compiler.LCNF.Specialize.SpecializeM Bool

full_name: Lean.Compiler.LCNF.Specialize.withLetDecl
code: @[inline] def withLetDecl (decl : LetDecl) (x : SpecializeM α) : SpecializeM α 
goal: Lean.Compiler.LCNF.Specialize.SpecializeM α

full_name: Lean.Compiler.LCNF.Specialize.Collector.collect
code: /--
Given the specialization mask `paramsInfo` and the arguments `args`,
collect their dependencies, and return an array `mask` of size `paramsInfo.size` s.t.
- `mask[i] = some args[i]` if `paramsInfo[i] != .other`
- `mask[i] = none`, otherwise.
That is, `mask` contains only the arguments that are contributing to the code specialization.
We use this information to compute a "key" to uniquely identify the code specialization, and
creating the specialized code.
-/
def collect (paramsInfo : Array SpecParamInfo) (args : Array Arg) : SpecializeM (Array (Option Arg) × Array Param × Array CodeDecl) 
goal: Lean.Compiler.LCNF.Specialize.SpecializeM
  (Array (Option Lean.Compiler.LCNF.Arg) × Array Lean.Compiler.LCNF.Param × Array Lean.Compiler.LCNF.CodeDecl)

full_name: Lean.Compiler.LCNF.Specialize.shouldSpecialize
code: /--
Return `true` if it is worth using arguments `args` for specialization given the parameter specialization information.
-/
def shouldSpecialize (paramsInfo : Array SpecParamInfo) (args : Array Arg) : SpecializeM Bool 
goal: Lean.Compiler.LCNF.Specialize.SpecializeM Bool

full_name: Lean.Compiler.LCNF.Specialize.expandCodeDecls
code: /--
Convert the given declarations into `Expr`, and "zeta-reduce" them into body.
This function is used to compute the key that uniquely identifies an code specialization.
-/
def expandCodeDecls (decls : Array CodeDecl) (body : LetValue) : CompilerM Expr 
goal: Lean.Compiler.LCNF.CompilerM Lean.Expr

full_name: Lean.Compiler.LCNF.Specialize.expandCodeDecls.go
code: /--
Convert the given declarations into `Expr`, and "zeta-reduce" them into body.
This function is used to compute the key that uniquely identifies an code specialization.
-/
def expandCodeDecls (decls : Array CodeDecl) (body : LetValue) : CompilerM Expr 
goal: Lean.Expr

full_name: Lean.Compiler.LCNF.Specialize.mkKey
code: /--
Create the "key" that uniquely identifies a code specialization.
`params` and `decls` are the declarations collected by the `collect` function above.
The result contains the list of universe level parameter names the key that `params`, `decls`, and `body` depends on.
We use this information to create the new auxiliary declaration and resulting application.
-/
def mkKey (params : Array Param) (decls : Array CodeDecl) (body : LetValue) : CompilerM (Expr × List Name) 
goal: Lean.Compiler.LCNF.CompilerM (Lean.Expr × List Lean.Name)

full_name: Lean.Compiler.LCNF.Specialize.mkSpecDecl.go
code: /--
Specialize `decl` using
- `us`: the universe level used to instantiate `decl.name`
- `argMask`: arguments that are being used to specialize the declaration.
- `params`: new parameters that arguments in `argMask` depend on.
- `decls`: local declarations that arguments in `argMask` depend on.
- `levelParamsNew`: the universe level parameters for the new declaration.
-/
def mkSpecDecl (decl : Decl) (us : List Level) (argMask : Array (Option Arg)) (params : Array Param) (decls : Array CodeDecl) (levelParamsNew : List Name) : SpecializeM Decl 
goal: Lean.Compiler.LCNF.Internalize.InternalizeM Lean.Compiler.LCNF.Decl

full_name: Lean.Compiler.LCNF.Specialize.mkSpecDecl
code: /--
Specialize `decl` using
- `us`: the universe level used to instantiate `decl.name`
- `argMask`: arguments that are being used to specialize the declaration.
- `params`: new parameters that arguments in `argMask` depend on.
- `decls`: local declarations that arguments in `argMask` depend on.
- `levelParamsNew`: the universe level parameters for the new declaration.
-/
def mkSpecDecl (decl : Decl) (us : List Level) (argMask : Array (Option Arg)) (params : Array Param) (decls : Array CodeDecl) (levelParamsNew : List Name) : SpecializeM Decl 
goal: Lean.Compiler.LCNF.Specialize.SpecializeM Lean.Compiler.LCNF.Decl

full_name: Lean.Compiler.LCNF.Specialize.getRemainingArgs
code: /--
Given the specialization mask `paramsInfo` and the arguments `args`,
return the arguments that have not been considered for specialization.
-/
def getRemainingArgs (paramsInfo : Array SpecParamInfo) (args : Array Arg) : Array Arg 
goal: Array Lean.Compiler.LCNF.Arg

full_name: Lean.Compiler.LCNF.Specialize.main
code: def main (decl : Decl) : SpecializeM Decl 
goal: Lean.Compiler.LCNF.Specialize.SpecializeM Lean.Compiler.LCNF.Decl

full_name: Lean.Compiler.LCNF.Decl.specialize
code: partial def Decl.specialize (decl : Decl) : CompilerM (Array Decl) 
goal: Lean.Compiler.LCNF.CompilerM (Array Lean.Compiler.LCNF.Decl)

full_name: Lean.Compiler.LCNF.specialize
code: def specialize : Pass 
goal: Lean.Compiler.LCNF.Pass

full_name: Lean.Compiler.LCNF.initFn._@..lake.packages.lean4.src.lean.Lean.Compiler.LCNF.Specialize._hyg.4216
code: builtin_initialize
  registerTraceClass `Compiler.specialize (inherited := true)
  registerTraceClass `Compiler.specialize.candidate
  registerTraceClass `Compiler.specialize.step
goal: IO Unit