-
Notifications
You must be signed in to change notification settings - Fork 327
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: reduceNat? match terms with free or meta variables #3139
Conversation
|
@joehendrix Thanks for catching this issue. Could you please add new tests using |
3f83693
to
dd153ba
Compare
Yes, I validated on my machine, and reordered the commits too so hopefully the CI will report the first commit fails. |
Oh, I'm not sure if it ran the tests after all, but the commit shows a failure. If there's something else that needs to be done with this, let me know. |
!bench |
Here are the benchmark results for commit d0d3678. Benchmark Metric Change
=========================================
+ stdlib wall-clock -1.1% (-34.9 σ) |
Uh oh, this has caused a bunch of timeouts in Mathlib. I wish that we had tested Mathlib first before merging! (Per the bot's instructions above, this requires basing the Lean PR off |
This removes checks in `Lean.Meta.reduceNat?` that caused it to fail on terms it could handle because they contain meta variables in arguments. This lead to those operations being reduced using their equational definitions and slow performance on large patterns: ``` set_option profiler true set_option profiler.threshold 1 def testMod (x:Nat) := match x with | 128 % 1024 => true | _ => false -- elaboration took 3.02ms def testMul (x:Nat) := match x with | 128 * 1 => true | _ => false -- type checking took 11.1ms -- compilation of testMul.match_1 took 313ms -- compilation of testMul took 65.7ms -- elaboration took 58.9ms ``` Performance is slower on `testMul` than `testMod` because `whnf` ends up evaluateing `128 * 1` using Peano arithmetic while `128 % 1024` is able to avoid that treatment since `128 < 1024`.
This proof has been causing timeouts for both leanprover/lean4#3124 and leanprover/lean4#3139 (and its in-progress fixes), so I'm just fixing it pre-emptively here. (Fix due to @joehendrix.) Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
This removes checks in
Lean.Meta.reduceNat?
that caused it to fail on terms it could handle because they contain meta variables in arguments. This lead to those operations being reduced using their equational definitions and slow performance on large patterns:Performance is slower on
testMul
thantestMod
becausewhnf
ends up evaluateing128 * 1
using Peano arithmetic while128 % 1024
is able to avoid that treatment since128 < 1024
.