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(*): lower instance priority #1724
Conversation
use lower instance priority for instances that always apply also do this for automatically generated instances using the `extend` keyword also add a comment to most places where we short-circuit type-class inference. This can lead to greatly increased search times (see issue #1561), so we might want to delete some/all of them.
Default priority also applies to all instances, not just automatically-generates ones the scope of set_option is limited to a section
This looks like a very good idea, but I am afraid people will forget about it constantly, and it adds some boilerplate. Is it impossible to do it by automation, i.e., when an instance or a class is declared, change the priority on the fly depending on the shape of the statement (unless the priority is specified explicitly, and then respect the explicit choice)? |
@fpvandoorn Thank you for doing this! I tried (briefly) a few weeks ago, and it seemed like it would be hard to do locally -- changing a few priorities broke many things, which required more priority changes to fix, and so on. But it's definitely a worthwhile change.
There's a linting test for it. It's temporarily disabled in CI, but after this PR lands we can enable it, so forgetting about it will be automatically detected. I suppose 3.5c could use the same test to set the priority automatically. But this would be a destructive change (mathlib compiling with 3.5c would no longer compile with 3.4.2). |
Maybe it's time to switch to 3.5c? |
Maybe. I think it's a good thing to discuss at Lean Together in January. The list of reasons is growing. |
It might actually be good to make this change in a branch of 3.5c before continuing on this PR. I suspect it will be a lot less work, and it would show any unexpected consequences (good or bad) of these changes. |
In addition to what Rob said, forgetting it is not worse than the situation we are currently in. It just means that in some cases you're doing unnecessary search before trying the easy instances. The linter test doesn't apply to all automatically generated instances, since automatically generated instances are currently ignored by the linter. I'll try to fix that later. (If It would be nice to set the priority automatically in the community fork, but until we adopt the community fork, I still want to finish and merge this PR. As expected, there are some breakages. Some of the changes I had to make strictly improved a proof (e.g. replacing There was also one case where a new construction was marked with |
I have already done all the priority changes. The only thing left to do is to fix resulting errors. |
The library now compiles locally for me. |
Do you understand why you had to increase |
Also, can you say how you determined the instances that needed tweaking (did you rely on the linter, or a clever grep, or did you look at all files one by one)? And do you have statistics of compile time before/after? (If you have more than a 5% gain, I will merge this right away without letting time for others to complain that it is not automated :) |
No, probably just some instances that are a slightly different priority, causing some searches to take longer and some searches to become quicker. Out of the 50+ instances where max_depth is increased, I had to increase 3 further, and probably there is a nonzero amount of them that can be reduced/removed now.
There are plenty of bad instances. The I'm happy to investigate those further in a future PR.
I searched for
No. I am strongly trying to minimize the amount of local compilations of mathlib. |
5% reduction of total compile time is probably unreasonable to expect: I expect that less than 10% of the compilation time of mathlib is spend in type class inference: simp, tidy and other tactics probably take much longer. |
The global strategy is clearly sound. Let me merge this, and then if we want to automate this it will be easy to come back to it with a simple grep as everything is clearly marked in the source code. |
* fix(*): lower instance priority use lower instance priority for instances that always apply also do this for automatically generated instances using the `extend` keyword also add a comment to most places where we short-circuit type-class inference. This can lead to greatly increased search times (see issue leanprover-community#1561), so we might want to delete some/all of them. * put default_priority option inside section Default priority also applies to all instances, not just automatically-generates ones the scope of set_option is limited to a section * two more low priorities * fix some broken proofs * fix proof * more fixes * more fixes * increase max_depth a bit * update notes * fix linter issues
* fix(*): lower instance priority use lower instance priority for instances that always apply also do this for automatically generated instances using the `extend` keyword also add a comment to most places where we short-circuit type-class inference. This can lead to greatly increased search times (see issue leanprover-community#1561), so we might want to delete some/all of them. * put default_priority option inside section Default priority also applies to all instances, not just automatically-generates ones the scope of set_option is limited to a section * two more low priorities * fix some broken proofs * fix proof * more fixes * more fixes * increase max_depth a bit * update notes * fix linter issues
use lower instance priority for instances that always apply
also do this for automatically generated instances using the
extend
keywordalso add a comment to most places where we short-circuit type-class inference. This can lead to greatly increased search times (see issue #1561), so we might want to delete some/all of them.
This PR will almost certainly break things, although I strongly expect that it will decrease the overall type-class inference search space. I investigated one place where type-class inference was short-circuited. This short-circuiting was necessary before the change, but not afterwards.