test: speed up vcgen_get_throw_set.lean by partially evaluating specs (#12670)

This PR speeds up the vcgen_get_throw_set benchmark by a factor of 4 by
partially evaluating specs.
This commit is contained in:
Sebastian Graf 2026-02-24 14:10:42 +01:00 committed by GitHub
parent 65f112a165
commit 8916246be5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,18 +9,35 @@ import Driver
open Lean Parser Meta Elab Tactic Sym Std Do SpecAttr
@[spec]
theorem Spec.monadLift_ExceptT [Monad m] [WPMonad m ps] {x : m α} :
⦃wp⟦x⟧ (Q.1, Q.2.2)⦄ monadLift (n := ExceptT ε m) x ⦃Q⦄ := by
simp [Triple.iff, monadLift, MonadLift.monadLift, MonadLiftT.monadLift, ExceptT.lift, wp]
set_option mvcgen.warning false
def step (lim : Nat) : ExceptT String (StateM Nat) Unit := do
abbrev M := ExceptT String <| StateM Nat
-- We partially evaluate a couple of specs for best performance.
-- If you comment those out, you will see a 4x slowdown.
@[spec high]
theorem Spec.throw_M {e : String} :
⦃Q.2.1 e⦄ throw (m := M) e ⦃Q⦄ := by
mvcgen
@[spec high]
theorem Spec.set_M {s : Nat} :
⦃fun _ => Q.1 ⟨⟩ s⦄ set (m := M) s ⦃Q⦄ := by
mvcgen
@[spec high]
theorem Spec.get_M :
⦃fun s => Q.1 s s⦄ get (m := M) ⦃Q⦄ := by
mvcgen
def step (lim : Nat) : M Unit := do
let s ← get
if s > lim then
throw "s is too large"
set (s + 1)
def loop (n : Nat) : ExceptT String (StateM Nat) Unit := do
def loop (n : Nat) : M Unit := do
match n with
| 0 => pure ()
| n+1 => loop n; step n
@ -30,13 +47,6 @@ def Goal (n : Nat) : Prop := ⦃fun s => ⌜s = 0⌝⦄ loop n ⦃⇓_ s => ⌜s
set_option maxRecDepth 10000
set_option maxHeartbeats 10000000
/-
example : Goal 20 := by
simp only [Goal, loop, step]
mvcgen'
all_goals sorry
-/
#eval runBenchUsingTactic ``Goal [``loop, ``step] `(tactic| mvcgen') `(tactic| sorry)
[100, 500, 1000]
-- [1000]