Skip to content

Commit

Permalink
chore: add a basic test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Oct 28, 2024
1 parent 36fc525 commit 6f01573
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/lean_action_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: DeterminateSystems/nix-installer-action@main

- name: install cadical
run: nix profile install nixpkgs#bitwuzla

- uses: actions/checkout@v4

- uses: leanprover/lean-action@v1
with:
test: true
13 changes: 11 additions & 2 deletions Leanwuzla.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Lean.Elab.Tactic.BVDecide.Frontend.BVDecide
Invoke Bitwuzla on an SMT-fied version of a bitvector goal to see if it holds or not.
Does not generate a proof term.
-/
syntax (name := bvBitwuzla) "bv_bitwuzla" str : tactic
syntax (name := bvBitwuzla) "bv_bitwuzla" (str)? : tactic

/--
Compare the performance of `bv_decide` and `bv_bitwuzla`.
-/
syntax (name := bvCompare) "bv_compare" str : tactic
syntax (name := bvCompare) "bv_compare" (str)? : tactic

namespace Lean.Elab.Tactic.BVDecide
namespace Frontend
Expand Down Expand Up @@ -223,6 +223,9 @@ def evalBvBitwuzla : Tactic := fun
| `(tactic| bv_bitwuzla $solverPath:str) => do
liftMetaFinishingTactic fun g => do
discard <| bvBitwuzla g solverPath.getString
| `(tactic| bv_bitwuzla) => do
liftMetaFinishingTactic fun g => do
discard <| bvBitwuzla g "bitwuzla"
| _ => throwUnsupportedSyntax

structure BitwuzlaPerf where
Expand Down Expand Up @@ -412,6 +415,12 @@ def evalBvCompare : Tactic := fun
let g ← getMainGoal
let res ← bvCompare g solverPath.getString cfg
logInfo <| toString res
| `(tactic| bv_compare) => do
IO.FS.withTempFile fun _ lratFile => do
let cfg ← TacticContext.new lratFile
let g ← getMainGoal
let res ← bvCompare g "bitwuzla" cfg
logInfo <| toString res
| _ => throwUnsupportedSyntax

end Frontend
Expand Down
6 changes: 6 additions & 0 deletions Test.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/-
Copyright (c) 2024 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving
-/
import Test.Bitwuzla
79 changes: 79 additions & 0 deletions Test/Bitwuzla.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/-
Copyright (c) 2024 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik Böving
-/
import Leanwuzla

variable (a b c : Bool)
variable (x y z : BitVec 32)

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x + y = y + x := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x - 1 ≠ x := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : (-x) + y = y - x:= by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x * y = y * x := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x / y ≤ x := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example (hx : BitVec.slt 0 x) (hy : BitVec.slt 0 y) : x.msb = y.msb := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : (x.zeroExtend 64).msb = false := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example (hx : BitVec.slt 0 x) : (x.signExtend 64).msb = false := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x &&& y = y &&& x := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x ||| y = y ||| x := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : ~~~(x ||| y) = (~~~y &&& ~~~x) := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x <<< 32 = 0 := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : x >>> x = 0 := by
bv_bitwuzla

/-- error: Bitwuzla thinks it's right but can't trust the wuzla! -/
#guard_msgs in
example : (x ++ x).extractLsb' 0 32 = x := by
bv_bitwuzla
9 changes: 0 additions & 9 deletions lakefile.lean

This file was deleted.

10 changes: 10 additions & 0 deletions lakefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "leanwuzla"
version = "0.1.0"
defaultTargets = ["Leanwuzla"]
testRunner = "Test"

[[lean_lib]]
name = "Test"

[[lean_lib]]
name = "Leanwuzla"

0 comments on commit 6f01573

Please sign in to comment.