Repository navigation
feat: reorder tc subgoals according to out-params - #2174
Conversation
|
!bench |
|
Here are the benchmark results for commit 37d1449. Benchmark Metric Change
============================================
- stdlib type checking 1.3% (227.2 σ) |
| Semi-output parameters influence the order in which arguments to type class | ||
| instances are processed. Lean determines an order where all non-(semi-)output | ||
| parameters to the instance argument have to be figured out before attempting to | ||
| synthesize an argument (that is, they do not contain metavariables). This |
There was a problem hiding this comment.
Just to clarify, this is not strictly true as the inputs to TC synth could already contain mvars (which may or may not make synth get stuck), no? We just don't want class input parameters to... add even more of them.
There was a problem hiding this comment.
Yes, this is indeed a bit tricky to describe. I've added the qualifier "assignable" and an explanation that these mvars are created during TC synthesis.
| ``` | ||
| class Coe (α : semiOutParam (Type u)) (β : Type v) | ||
| ``` | ||
| This means that all `Coe` instances should provide a concrete value for `α`. |
There was a problem hiding this comment.
| This means that all `Coe` instances should provide a concrete value for `α`. | |
| This means that all `Coe` instances should provide a concrete value for `α` given a concrete value for `β`. |
Here again it's not quite clear to me what "concrete" means in presence of nested mvars. The Coe α (Option α) instance will not get stuck when α is an mvar, will it?
There was a problem hiding this comment.
Right, it won't get stuck.
Part of #2117, hopefully with less regression on core.
The order in which subgoals are synthesized is automatically determined when adding an instance to the environment. If you have subgoals like
[Monoid A] [Monoid B] [MulHomClass F A B], then they are processed in the order 2, 0, 1. This removes the need to mark arguments to instances as implicit instead of instance-implicit.To make it possible to compute this order, we add an additional
semiOutParamgadget. One way to think of it is "like an out-param, but with multiple results." It means that all instances of the class need to provide a concrete value for this parameter. For example, the first argument ofCoeis a semi-out-param, soinstance : Coe α Nat where coe _ := 42is not a valid instance because it does not assign theα(the instance needs to be aCoeHeadinstead).