File: .lake/packages/lean4/src/lean/Lean/Meta/Instances.lean

full_name: Lean.Meta.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Instances._hyg.6
code: register_builtin_option synthInstance.checkSynthOrder : Bool := {
  defValue := true
  descr := "check that instances do not introduce metavariable in non-out-params"
}
goal: IO (Lean.Option Bool)

full_name: Lean.Meta.synthInstance.checkSynthOrder
code: register_builtin_option synthInstance.checkSynthOrder : Bool := {
  defValue := true
  descr := "check that instances do not introduce metavariable in non-out-params"
}
goal: Lean.Option Bool

full_name: Lean.Meta.InstanceKey
code: abbrev InstanceKey 
goal: Type

full_name: Lean.Meta.InstanceEntry.attrKind
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Lean.AttributeKind

full_name: Lean.Meta.InstanceEntry.synthOrder
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Array Nat

full_name: Lean.Meta.InstanceEntry.val
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Lean.Expr

full_name: Lean.Meta.InstanceEntry.priority
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Nat

full_name: Lean.Meta.instInhabitedInstanceEntry
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Inhabited Lean.Meta.InstanceEntry

full_name: Lean.Meta.InstanceEntry.globalName?
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Option Lean.Name

full_name: Lean.Meta.InstanceEntry.keys
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Array Lean.Meta.InstanceKey

full_name: Lean.Meta.InstanceEntry
code: structure InstanceEntry where
  keys        : Array InstanceKey
  val         : Expr
  priority    : Nat
  globalName? : Option Name := none
  /-- The order in which the instance's arguments are to be synthesized. -/
  synthOrder  : Array Nat
  /-
  We store the attribute kind to be able to implement the API `getInstanceAttrKind`.
  TODO: add better support for retrieving the `attrKind` of any attribute.
  The current implementation here works only for instances, but it is good enough for unblocking the
  implementation of `to_additive`.
  -/
  attrKind    : AttributeKind
  deriving Inhabited
goal: Type

full_name: Lean.Meta.instBEqInstanceEntry
code: instance : BEq InstanceEntry 
goal: BEq Lean.Meta.InstanceEntry

full_name: Lean.Meta.instToFormatInstanceEntry
code: instance : ToFormat InstanceEntry 
goal: Lean.ToFormat Lean.Meta.InstanceEntry

full_name: Lean.Meta.InstanceTree
code: abbrev InstanceTree 
goal: Type

full_name: Lean.Meta.Instances.erased
code: structure Instances where
  discrTree     : InstanceTree := DiscrTree.empty
  instanceNames : PHashMap Name InstanceEntry := {}
  erased        : PHashSet Name := {}
  deriving Inhabited
goal: Lean.PHashSet Lean.Name

full_name: Lean.Meta.instInhabitedInstances
code: structure Instances where
  discrTree     : InstanceTree := DiscrTree.empty
  instanceNames : PHashMap Name InstanceEntry := {}
  erased        : PHashSet Name := {}
  deriving Inhabited
goal: Inhabited Lean.Meta.Instances

full_name: Lean.Meta.Instances
code: structure Instances where
  discrTree     : InstanceTree := DiscrTree.empty
  instanceNames : PHashMap Name InstanceEntry := {}
  erased        : PHashSet Name := {}
  deriving Inhabited
goal: Type

full_name: Lean.Meta.Instances.discrTree
code: structure Instances where
  discrTree     : InstanceTree := DiscrTree.empty
  instanceNames : PHashMap Name InstanceEntry := {}
  erased        : PHashSet Name := {}
  deriving Inhabited
goal: Lean.Meta.InstanceTree

full_name: Lean.Meta.Instances.instanceNames
code: structure Instances where
  discrTree     : InstanceTree := DiscrTree.empty
  instanceNames : PHashMap Name InstanceEntry := {}
  erased        : PHashSet Name := {}
  deriving Inhabited
goal: Lean.PHashMap Lean.Name Lean.Meta.InstanceEntry

full_name: Lean.Meta.tcDtConfig
code: /-- Configuration for the discrimination tree module -/
def tcDtConfig : WhnfCoreConfig 
goal: Lean.Meta.WhnfCoreConfig

full_name: Lean.Meta.addInstanceEntry
code: def addInstanceEntry (d : Instances) (e : InstanceEntry) : Instances 
goal: Lean.Meta.Instances

full_name: Lean.Meta.Instances.eraseCore
code: def Instances.eraseCore (d : Instances) (declName : Name) : Instances 
goal: Lean.Meta.Instances

full_name: Lean.Meta.Instances.erase
code: def Instances.erase [Monad m] [MonadError m] (d : Instances) (declName : Name) : m Instances 
goal: m Lean.Meta.Instances

full_name: Lean.Meta.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Instances._hyg.394
code: builtin_initialize instanceExtension : SimpleScopedEnvExtension InstanceEntry Instances ←
  registerSimpleScopedEnvExtension {
    initial  := {}
    addEntry := addInstanceEntry
  }
goal: IO (Lean.SimpleScopedEnvExtension Lean.Meta.InstanceEntry Lean.Meta.Instances)

full_name: Lean.Meta.instanceExtension
code: builtin_initialize instanceExtension : SimpleScopedEnvExtension InstanceEntry Instances ←
  registerSimpleScopedEnvExtension {
    initial  := {}
    addEntry := addInstanceEntry
  }
goal: Lean.SimpleScopedEnvExtension Lean.Meta.InstanceEntry Lean.Meta.Instances

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Instances.0.Lean.Meta.mkInstanceKey
code: private def mkInstanceKey (e : Expr) : MetaM (Array InstanceKey) 
goal: Lean.MetaM (Array Lean.Meta.InstanceKey)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Instances.0.Lean.Meta.computeSynthOrder.getSemiOutParamPositionsOf
code: /--
Compute the order the arguments of `inst` should by synthesized.

The synthesization order makes sure that all mvars in non-out-params of the
subgoals are assigned before we try to synthesize it.  Otherwise it goes left
to right.

For example:
  - `[Add α] [Zero α] : Foo α` returns `[0, 1]`
  - `[Mul A] [Mul B] [MulHomClass F A B] : FunLike F A B` returns `[2, 0, 1]`
    (because A B are out-params and are only filled in once we synthesize 2)

(The type of `inst` must not contain mvars.)
-/
private partial def computeSynthOrder (inst : Expr) : MetaM (Array Nat) 
goal: Lean.MetaM (Array Nat)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Instances.0.Lean.Meta.computeSynthOrder.assignMVarsIn
code: /--
Compute the order the arguments of `inst` should by synthesized.

The synthesization order makes sure that all mvars in non-out-params of the
subgoals are assigned before we try to synthesize it.  Otherwise it goes left
to right.

For example:
  - `[Add α] [Zero α] : Foo α` returns `[0, 1]`
  - `[Mul A] [Mul B] [MulHomClass F A B] : FunLike F A B` returns `[2, 0, 1]`
    (because A B are out-params and are only filled in once we synthesize 2)

(The type of `inst` must not contain mvars.)
-/
private partial def computeSynthOrder (inst : Expr) : MetaM (Array Nat) 
goal: Lean.MetaM Unit

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Meta.Instances.0.Lean.Meta.computeSynthOrder
code: /--
Compute the order the arguments of `inst` should by synthesized.

The synthesization order makes sure that all mvars in non-out-params of the
subgoals are assigned before we try to synthesize it.  Otherwise it goes left
to right.

For example:
  - `[Add α] [Zero α] : Foo α` returns `[0, 1]`
  - `[Mul A] [Mul B] [MulHomClass F A B] : FunLike F A B` returns `[2, 0, 1]`
    (because A B are out-params and are only filled in once we synthesize 2)

(The type of `inst` must not contain mvars.)
-/
private partial def computeSynthOrder (inst : Expr) : MetaM (Array Nat) 
goal: Lean.MetaM (Array Nat)

full_name: Lean.Meta.addInstance
code: def addInstance (declName : Name) (attrKind : AttributeKind) (prio : Nat) : MetaM Unit 
goal: Lean.MetaM Unit

full_name: Lean.Meta.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Instances._hyg.2556
code: builtin_initialize
  registerBuiltinAttribute {
    name  := `instance
    descr := "type class instance"
    add   := fun declName stx attrKind => do
      let prio ← getAttrParamOptPrio stx[1]
      discard <| addInstance declName attrKind prio |>.run {} {}
    erase := fun declName => do
      let s := instanceExtension.getState (← getEnv)
      let s ← s.erase declName
      modifyEnv fun env => instanceExtension.modifyState env fun _ => s
  }
goal: IO Unit

full_name: Lean.Meta.getGlobalInstancesIndex
code: def getGlobalInstancesIndex : CoreM (DiscrTree InstanceEntry) 
goal: Lean.CoreM (Lean.Meta.DiscrTree Lean.Meta.InstanceEntry)

full_name: Lean.Meta.getErasedInstances
code: def getErasedInstances : CoreM (PHashSet Name) 
goal: Lean.CoreM (Lean.PHashSet Lean.Name)

full_name: Lean.Meta.isInstanceCore
code: def isInstanceCore (env : Environment) (declName : Name) : Bool 
goal: Bool

full_name: Lean.Meta.isInstance
code: def isInstance (declName : Name) : CoreM Bool 
goal: Lean.CoreM Bool

full_name: Lean.Meta.getInstancePriority?
code: def getInstancePriority? (declName : Name) : CoreM (Option Nat) 
goal: Lean.CoreM (Option Nat)

full_name: Lean.Meta.getInstanceAttrKind?
code: def getInstanceAttrKind? (declName : Name) : CoreM (Option AttributeKind) 
goal: Lean.CoreM (Option Lean.AttributeKind)

full_name: Lean.Meta.DefaultInstanceEntry.instanceName
code: structure DefaultInstanceEntry where
  className    : Name
  instanceName : Name
  priority     : Nat
goal: Lean.Name

full_name: Lean.Meta.DefaultInstanceEntry.priority
code: structure DefaultInstanceEntry where
  className    : Name
  instanceName : Name
  priority     : Nat
goal: Nat

full_name: Lean.Meta.DefaultInstanceEntry.className
code: structure DefaultInstanceEntry where
  className    : Name
  instanceName : Name
  priority     : Nat
goal: Lean.Name

full_name: Lean.Meta.DefaultInstanceEntry
code: structure DefaultInstanceEntry where
  className    : Name
  instanceName : Name
  priority     : Nat
goal: Type

full_name: Lean.Meta.PrioritySet
code: abbrev PrioritySet 
goal: Type

full_name: Lean.Meta.instInhabitedDefaultInstances
code: structure DefaultInstances where
  defaultInstances : NameMap (List (Name × Nat)) := {}
  priorities       : PrioritySet := {}
  deriving Inhabited
goal: Inhabited Lean.Meta.DefaultInstances

full_name: Lean.Meta.DefaultInstances
code: structure DefaultInstances where
  defaultInstances : NameMap (List (Name × Nat)) := {}
  priorities       : PrioritySet := {}
  deriving Inhabited
goal: Type

full_name: Lean.Meta.DefaultInstances.defaultInstances
code: structure DefaultInstances where
  defaultInstances : NameMap (List (Name × Nat)) := {}
  priorities       : PrioritySet := {}
  deriving Inhabited
goal: Lean.NameMap (List (Lean.Name × Nat))

full_name: Lean.Meta.DefaultInstances.priorities
code: structure DefaultInstances where
  defaultInstances : NameMap (List (Name × Nat)) := {}
  priorities       : PrioritySet := {}
  deriving Inhabited
goal: Lean.Meta.PrioritySet

full_name: Lean.Meta.addDefaultInstanceEntry
code: def addDefaultInstanceEntry (d : DefaultInstances) (e : DefaultInstanceEntry) : DefaultInstances 
goal: Lean.Meta.DefaultInstances

full_name: Lean.Meta.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Instances._hyg.3161
code: builtin_initialize defaultInstanceExtension : SimplePersistentEnvExtension DefaultInstanceEntry DefaultInstances ←
  registerSimplePersistentEnvExtension {
    addEntryFn    := addDefaultInstanceEntry
    addImportedFn := fun es => (mkStateFromImportedEntries addDefaultInstanceEntry {} es)
  }
goal: IO (Lean.SimplePersistentEnvExtension Lean.Meta.DefaultInstanceEntry Lean.Meta.DefaultInstances)

full_name: Lean.Meta.defaultInstanceExtension
code: builtin_initialize defaultInstanceExtension : SimplePersistentEnvExtension DefaultInstanceEntry DefaultInstances ←
  registerSimplePersistentEnvExtension {
    addEntryFn    := addDefaultInstanceEntry
    addImportedFn := fun es => (mkStateFromImportedEntries addDefaultInstanceEntry {} es)
  }
goal: Lean.SimplePersistentEnvExtension Lean.Meta.DefaultInstanceEntry Lean.Meta.DefaultInstances

full_name: Lean.Meta.addDefaultInstance
code: def addDefaultInstance (declName : Name) (prio : Nat := 0) : MetaM Unit 
goal: Lean.MetaM Unit

full_name: Lean.Meta.initFn._@..lake.packages.lean4.src.lean.Lean.Meta.Instances._hyg.3506
code: builtin_initialize
  registerBuiltinAttribute {
    name  := `default_instance
    descr := "type class default instance"
    add   := fun declName stx kind => do
      let prio ← getAttrParamOptPrio stx[1]
      unless kind == AttributeKind.global do throwError "invalid attribute 'default_instance', must be global"
      discard <| addDefaultInstance declName prio |>.run {} {}
  }
  registerTraceClass `Meta.synthOrder
goal: IO Unit

full_name: Lean.Meta.getDefaultInstancesPriorities
code: def getDefaultInstancesPriorities [Monad m] [MonadEnv m] : m PrioritySet 
goal: m Lean.Meta.PrioritySet

full_name: Lean.Meta.getDefaultInstances
code: def getDefaultInstances [Monad m] [MonadEnv m] (className : Name) : m (List (Name × Nat)) 
goal: m (List (Lean.Name × Nat))