fix: reduceNat? match terms with free or meta variables#3139
fix: reduceNat? match terms with free or meta variables#3139leodemoura merged 2 commits intomasterfrom
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
testMulthantestModbecausewhnfends up evaluateing128 * 1using Peano arithmetic while128 % 1024is able to avoid that treatment since128 < 1024.