Compare commits

...

7 Commits

Author SHA1 Message Date
Scott Morrison
d0170cc2d8 fix test 2024-04-24 13:40:44 +10:00
Scott Morrison
a9364ded19 fix test 2024-04-24 13:16:29 +10:00
Scott Morrison
d74c2e8d19 Merge remote-tracking branch 'origin/master' into test_extern_update 2024-04-24 13:11:37 +10:00
Scott Morrison
8a99675b08 merge master 2024-04-22 17:01:36 +10:00
Scott Morrison
5cc1acc1f1 fix .expected.out 2023-12-15 13:21:36 +11:00
Scott Morrison
e43d727f5b add implemented_by test 2023-12-15 13:11:13 +11:00
Scott Morrison
847b8419a1 feat: improvements to test_extern command 2023-12-15 13:06:45 +11:00
4 changed files with 18 additions and 9 deletions

View File

@@ -8,8 +8,9 @@ import Lean.Elab.SyntheticMVars
import Lean.Elab.Command
import Lean.Meta.Tactic.Unfold
import Lean.Meta.Eval
import Lean.Compiler.ImplementedByAttr
open Lean Elab Meta Command Term
open Lean Elab Meta Command Term Compiler
syntax (name := testExternCmd) "test_extern " term : command
@@ -18,14 +19,15 @@ syntax (name := testExternCmd) "test_extern " term : command
let t elabTermAndSynthesize t none
match t.getAppFn with
| .const f _ =>
if isExtern ( getEnv) f then
let env getEnv
if isExtern env f || (getImplementedBy? env f).isSome then
let t' := ( unfold t f).expr
let r := mkApp (.const ``reduceBool []) ( mkAppM ``BEq.beq #[t, t'])
let r := mkApp (.const ``reduceBool []) ( mkDecide ( mkEq t t'))
if ! ( evalExpr Bool (.const ``Bool []) r) then
throwError
("native implementation did not agree with reference implementation!\n" ++
m!"Compare the outputs of:\n#eval {t}\n and\n#eval {t'}")
else
throwError "test_extern: {f} does not have an @[extern] attribute"
throwError "test_extern: {f} does not have an @[extern] attribute or @[implemented_by] attribute"
| _ => throwError "test_extern: expects a function application"
| _ => throwUnsupportedSyntax

View File

@@ -1,7 +1,6 @@
import Lean.Util.TestExtern
instance : BEq ByteArray where
beq x y := x.data == y.data
deriving instance DecidableEq for ByteArray
test_extern String.toUTF8 ""
test_extern String.toUTF8 "\x00"

View File

@@ -1,9 +1,15 @@
import Lean.Util.TestExtern
instance : BEq ByteArray where
beq x y := x.data == y.data
deriving instance DecidableEq for ByteArray
test_extern Nat.add 12 37
test_extern 4 + 5
test_extern ByteArray.copySlice #[1,2,3] 1 #[4, 5, 6, 7, 8, 9, 10, 11, 12, 13] 0 6
def f := 3
@[implemented_by f]
def g := 4
test_extern g

View File

@@ -1 +1,3 @@
test_extern.lean:7:0-7:17: error: test_extern: HAdd.hAdd does not have an @[extern] attribute
test_extern.lean:6:0-6:17: error: test_extern: HAdd.hAdd does not have an @[extern] attribute or @[implemented_by] attribute
test_extern.lean:15:0-15:13: error: native implementation did not agree with reference implementation!
Compare the outputs of: #eval g and #eval 4