Equations
Equations
- Lean.Meta.SynthInstance.hasInferTCGoalsRLAttribute env constName = Lean.TagAttribute.hasTag Lean.Meta.SynthInstance.inferTCGoalsRLAttr env constName
- mvar : Lean.Expr
- key : Lean.Expr
- mctx : Lean.MetavarContext
- currInstanceIdx : Nat
Equations
- Lean.Meta.SynthInstance.instInhabitedGeneratorNode = { default := { mvar := default, key := default, mctx := default, instances := default, currInstanceIdx := default } }
- mvar : Lean.Expr
- key : Lean.Expr
- mctx : Lean.MetavarContext
- size : Nat
Equations
- Lean.Meta.SynthInstance.instInhabitedConsumerNode = { default := { mvar := default, key := default, mctx := default, subgoals := default, size := default } }
Equations
- Lean.Meta.SynthInstance.Waiter.isRoot _fun_discr = match _fun_discr with | Lean.Meta.SynthInstance.Waiter.consumerNode a => false | Lean.Meta.SynthInstance.Waiter.root => true
- nextIdx : Nat
- lmap : Std.HashMap Lean.MVarId Lean.Level
- emap : Std.HashMap Lean.MVarId Lean.Expr
Equations
- Lean.Meta.SynthInstance.mkTableKey mctx e = StateT.run' (Lean.Meta.SynthInstance.MkTableKey.normExpr e mctx) { nextIdx := 0, lmap := ∅, emap := ∅ }
- result : Lean.Meta.AbstractMVarsResult
- resultType : Lean.Expr
- size : Nat
Equations
- Lean.Meta.SynthInstance.instInhabitedAnswer = { default := { result := default, resultType := default, size := default } }
- waiters : Array Lean.Meta.SynthInstance.Waiter
- answers : Array Lean.Meta.SynthInstance.Answer
- result? : Option Lean.Meta.AbstractMVarsResult
- generatorStack : Array Lean.Meta.SynthInstance.GeneratorNode
- resumeStack : Array (Lean.Meta.SynthInstance.ConsumerNode × Lean.Meta.SynthInstance.Answer)
- tableEntries : Std.HashMap Lean.Expr Lean.Meta.SynthInstance.TableEntry
Equations
- Lean.Meta.SynthInstance.checkMaxHeartbeats = do let a ← read liftM (Lean.Core.checkMaxHeartbeatsCore "typeclass" `synthInstance.maxHeartbeats a.maxHeartbeats)
Equations
Equations
- Lean.Meta.SynthInstance.instInhabitedSynthM = { default := fun x x => default }
Return globals and locals instances that may unify with type
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.
Create a new generator node for mvar
and add waiter
as its waiter.
key
must be mkTableKey mctx mvarType
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.SynthInstance.findEntry? key = do let a ← get pure (Std.HashMap.find? a.tableEntries key)
Equations
- One or more equations did not get rendered due to their size.
Create a key
for the goal associated with the given metavariable.
That is, we create a key for the type of the metavariable.
We must instantiate assigned metavariables before we invoke mkTableKey
.
Equations
- One or more equations did not get rendered due to their size.
getSubgoals lctx localInsts xs inst
creates the subgoals for the instance inst
.
The subgoals are in the context of the free variables xs
, and
(lctx, localInsts)
is the local context and instances before we added the free variables to it.
This extra complication is required because
1- We want all metavariables created by synthInstance
to share the same local context.
2- We want to ensure that applications such as mvar xs
are higher order patterns.
The method getGoals
create a new metavariable for each parameter of inst
.
For example, suppose the type of inst
is forall (x_1 : A_1) ... (x_n : A_n), B x_1 ... x_n
.
Then, we create the metavariables ?m_i : forall xs, A_i
, and return the subset of these
metavariables that are instance implicit arguments, and the expressions:
- inst (?m_1 xs) ... (?m_n xs)
(aka instVal
)
- B (?m_1 xs) ... (?m_n xs)
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.
Try to synthesize metavariable mvar
using the instance inst
.
Remark: mctx
contains mvar
.
If it succeeds, the result is a new updated metavariable context and a new list of subgoals.
A subgoal is created for each instance implicit parameter of inst
.
Equations
- Lean.Meta.SynthInstance.tryResolve mctx mvar inst = Lean.traceCtx `Meta.synthInstance.tryResolve (Lean.Meta.withMCtx mctx (liftM (Lean.Meta.SynthInstance.tryResolveCore mvar inst)))
Assign a precomputed answer to mvar
.
If it succeeds, the result is a new updated metavariable context and a new list of subgoals.
Equations
- One or more equations did not get rendered due to their size.
Move waiters that are waiting for the given answer to the resume stack.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.SynthInstance.isNewAnswer oldAnswers answer = Array.all oldAnswers (fun oldAnswer => oldAnswer.resultType != answer.resultType) 0 (Array.size oldAnswers)
Create a new answer after cNode
resolved all subgoals.
That is, cNode.subgoals == []
.
And then, store it in the tabled entries map, and wakeup waiters.
Equations
- One or more equations did not get rendered due to their size.
Process the next subgoal in the given consumer node.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.SynthInstance.getTop = do let a ← get pure (Array.back a.generatorStack)
Equations
- One or more equations did not get rendered due to their size.
Try the next instance in the node on the top of the generator stack.
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.
Given (cNode, answer)
on the top of the resume stack, continue execution by using answer
to solve the
next subgoal.
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.Meta.SynthInstance.getResult = do let a ← get pure a.result?
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.
Return LOption.some r
if succeeded, LOption.none
if it failed, and LOption.undef
if
instance cannot be synthesized right now because type
contains metavariables.
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.