This PR sets up the new integrated test/bench suite. It then migrates all benchmarks and some related tests to the new suite. There's also some documentation and some linting. For now, a lot of the old tests are left alone so this PR doesn't become even larger than it already is. Eventually, all tests should be migrated to the new suite though so there isn't a confusing mix of two systems.
52 lines
1.3 KiB
Text
52 lines
1.3 KiB
Text
import Lean
|
|
|
|
open Lean
|
|
|
|
partial def mkTower : Nat → Expr
|
|
| 0 => mkConst `a
|
|
| n+1 => mkApp2 (mkConst `f) (mkTower n) (mkTower n)
|
|
|
|
partial def depth : Expr → MonadCacheT Expr Nat CoreM Nat
|
|
| e =>
|
|
checkCache e fun _ =>
|
|
match e with
|
|
| Expr.const c [] => pure 1
|
|
| Expr.app f a => do pure $ Nat.max (← depth f) (← depth a) + 1
|
|
| _ => pure 0
|
|
|
|
#eval (depth (mkTower 100)).run
|
|
|
|
partial def visit : Expr → MonadCacheT Expr Expr CoreM Expr
|
|
| e =>
|
|
checkCache e fun _ =>
|
|
match e with
|
|
| Expr.const `a [] => pure $ mkConst `b
|
|
| Expr.app f a => e.updateApp! <$> visit f <*> visit a
|
|
| _ => pure e
|
|
|
|
#eval (visit (mkTower 4)).run
|
|
|
|
def tst : CoreM Nat := do
|
|
let e ← (visit (mkTower 100)).run; (depth e).run
|
|
|
|
#eval tst
|
|
|
|
partial def visitNoCache : Expr → CoreM Expr
|
|
| e =>
|
|
match e with
|
|
| Expr.const `a [] => pure $ mkConst `b
|
|
| Expr.app f a => e.updateApp! <$> visitNoCache f <*> visitNoCache a
|
|
| _ => pure e
|
|
|
|
-- The following is super slow
|
|
-- #eval do e ← visitNoCache (mkTower 30); (depth e).run
|
|
|
|
def displayConsts (e : Expr) : CoreM Unit :=
|
|
e.forEach fun e => match e with
|
|
| Expr.const c _ => do IO.println c
|
|
| _ => pure ()
|
|
|
|
def tst2 : CoreM Unit := do
|
|
let e ← (visit (mkTower 100)).run; displayConsts e
|
|
|
|
#eval tst2
|