-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: modify projection instance binder info #5376
Conversation
closes #5333 This PR tries to address issue #5333. My conjecture is that the binder annotations for `C.toB` and `Algebra.toSMul` are not ideal. `Algebra.toSMul` is one of declarations where the new command `set_synth_order` was used. Both classes, `C` and `Algebra`, are parametric over instances, and in both cases, the issue arises due to projection instances: `C.toB` and `Algebra.toSMul`. Let's focus on the binder annotations for `C.toB`. They are as follows: ``` C.toB [inst : A 20000] [self : @C inst] : @b ... ``` As a projection, it seems odd that `inst` is an instance-implicit argument instead of an implicit one, given that its value is fixed by `self`. We observe the same issue in `Algebra.toSMul`: ``` Algebra.toSMul {R : Type u} {A : Type v} [inst1 : CommSemiring R] [inst2 : Semiring A] [self : @algebra R A inst1 inst2] : SMul R A ``` The PR changes the binder annotations as follows: ``` C.toB {inst : A 20000} [self : @C inst] : @b ... ``` and ``` Algebra.toSMul {R : Type u} {A : Type v} {inst1 : CommSemiring R} {inst2 : Semiring A} [self : @algebra R A inst1 inst2] : SMul R A ``` In both cases, the `set_synth_order` is used to force `self` to be processed first. In the MWE, there is no instance for `C ...`, and `C.toB` is quickly discarded. I suspect a similar issue occurs when trying to use `Algebra.toSMul`, where there is no `@Algebra R A ... ...`, but Lean spends unnecessary time trying to synthesize `CommSemiring R` and `Semiring A` instances. I believe the new binder annotations make sense, as if there is a way to synthesize `Algebra R A ... ...`, it will tell us how to retrieve the instance-implicit arguments. Not sure what the impact will be on Mathlib.
Mathlib CI status (docs):
|
!bench |
Here are the benchmark results for commit 170166e. Benchmark Metric Change
================================================
- ilean roundtrip compress 1.0% (17.6 σ)
+ lake build no-op task-clock -2.1% (-23.4 σ) |
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Yes, this is exactly my understanding of the problem in Mathlib and this fix is far more sensible. Thanks @leodemoura ! |
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
Co-authored-by: Johan Commelin <[email protected]>
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
With the change to the construction of the synthesis order algorithm, we want to avoid searches with metavariables by specifying more `outParam`s.
closes #5333
This PR tries to address issue #5333.
My conjecture is that the binder annotations for
C.toB
andAlgebra.toSMul
are not ideal.Algebra.toSMul
is one of declarations where the new commandset_synth_order
was used. Both classes,C
andAlgebra
, are parametric over instances, and in both cases, the issue arises due to projection instances:C.toB
andAlgebra.toSMul
. Let's focus on the binder annotations forC.toB
. They are as follows:As a projection, it seems odd that
inst
is an instance-implicit argument instead of an implicit one, given that its value is fixed byself
. We observe the same issue inAlgebra.toSMul
:The PR changes the binder annotations as follows:
and
In both cases, the
set_synth_order
is used to forceself
to be processed first.In the MWE, there is no instance for
C ...
, andC.toB
is quickly discarded. I suspect a similar issue occurs when trying to useAlgebra.toSMul
, where there is no@Algebra R A ... ...
, but Lean spends unnecessary time trying to synthesizeCommSemiring R
andSemiring A
instances. I believe the new binder annotations make sense, as if there is a way to synthesizeAlgebra R A ... ...
, it will tell us how to retrieve the instance-implicit arguments.TODO: