summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSon Ho2024-03-08 09:42:29 +0100
committerSon Ho2024-03-08 09:42:29 +0100
commit44248ccfe3bfb8c45e5bb434d8dfb3dfa6e6b69c (patch)
treedd824e0ac83bb8ee885907615d972b6a522689aa
parent9d541d1ab6b91e59e4f78f4711af085a33ee4f82 (diff)
Update the generation of constant bodies for Lean
-rw-r--r--backends/lean/Base/Primitives/Base.lean4
-rw-r--r--compiler/Extract.ml3
-rw-r--r--tests/lean/Arrays.lean2
-rw-r--r--tests/lean/Constants.lean36
-rw-r--r--tests/lean/NoNestedBorrows.lean4
-rw-r--r--tests/lean/Traits.lean5
6 files changed, 26 insertions, 28 deletions
diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean
index 9dbaf133..0b9d9c39 100644
--- a/backends/lean/Base/Primitives/Base.lean
+++ b/backends/lean/Base/Primitives/Base.lean
@@ -69,7 +69,7 @@ def div? {α: Type u} (r: Result α): Bool :=
def massert (b:Bool) : Result Unit :=
if b then ret () else fail assertionFailure
-def eval_global {α: Type u} (x: Result α) (_: ret? x): α :=
+def eval_global {α: Type u} (x: Result α) (_: ret? x := by decide): α :=
match x with
| fail _ | div => by contradiction
| ret x => x
@@ -78,7 +78,7 @@ def eval_global {α: Type u} (x: Result α) (_: ret? x): α :=
def bind {α : Type u} {β : Type v} (x: Result α) (f: α → Result β) : Result β :=
match x with
- | ret v => f v
+ | ret v => f v
| fail v => fail v
| div => div
diff --git a/compiler/Extract.ml b/compiler/Extract.ml
index 6c523549..0a21d4ec 100644
--- a/compiler/Extract.ml
+++ b/compiler/Extract.ml
@@ -1863,8 +1863,7 @@ let extract_global_decl (ctx : extraction_ctx) (fmt : F.formatter)
(fun fmt ->
let body =
match !backend with
- | FStar -> "eval_global " ^ body_name
- | Lean -> "eval_global " ^ body_name ^ " (by decide)"
+ | FStar | Lean -> "eval_global " ^ body_name
| Coq -> body_name ^ "%global"
| HOL4 -> "get_return_value " ^ body_name
in
diff --git a/tests/lean/Arrays.lean b/tests/lean/Arrays.lean
index 6f9cd94c..d2bb7cf2 100644
--- a/tests/lean/Arrays.lean
+++ b/tests/lean/Arrays.lean
@@ -452,7 +452,7 @@ def f3 : Result U32 :=
/- [arrays::SZ]
Source: 'src/arrays.rs', lines 286:0-286:19 -/
def sz_body : Result Usize := Result.ret 32#usize
-def sz_c : Usize := eval_global sz_body (by decide)
+def sz_c : Usize := eval_global sz_body
/- [arrays::f5]:
Source: 'src/arrays.rs', lines 289:0-289:31 -/
diff --git a/tests/lean/Constants.lean b/tests/lean/Constants.lean
index 4c626ab3..32e0317b 100644
--- a/tests/lean/Constants.lean
+++ b/tests/lean/Constants.lean
@@ -8,17 +8,17 @@ namespace constants
/- [constants::X0]
Source: 'src/constants.rs', lines 5:0-5:17 -/
def x0_body : Result U32 := Result.ret 0#u32
-def x0_c : U32 := eval_global x0_body (by decide)
+def x0_c : U32 := eval_global x0_body
/- [constants::X1]
Source: 'src/constants.rs', lines 7:0-7:17 -/
def x1_body : Result U32 := Result.ret core_u32_max
-def x1_c : U32 := eval_global x1_body (by decide)
+def x1_c : U32 := eval_global x1_body
/- [constants::X2]
Source: 'src/constants.rs', lines 10:0-10:17 -/
def x2_body : Result U32 := Result.ret 3#u32
-def x2_c : U32 := eval_global x2_body (by decide)
+def x2_c : U32 := eval_global x2_body
/- [constants::incr]:
Source: 'src/constants.rs', lines 17:0-17:32 -/
@@ -28,7 +28,7 @@ def incr (n : U32) : Result U32 :=
/- [constants::X3]
Source: 'src/constants.rs', lines 15:0-15:17 -/
def x3_body : Result U32 := incr 32#u32
-def x3_c : U32 := eval_global x3_body (by decide)
+def x3_c : U32 := eval_global x3_body
/- [constants::mk_pair0]:
Source: 'src/constants.rs', lines 23:0-23:51 -/
@@ -49,22 +49,22 @@ def mk_pair1 (x : U32) (y : U32) : Result (Pair U32 U32) :=
/- [constants::P0]
Source: 'src/constants.rs', lines 31:0-31:24 -/
def p0_body : Result (U32 × U32) := mk_pair0 0#u32 1#u32
-def p0_c : (U32 × U32) := eval_global p0_body (by decide)
+def p0_c : (U32 × U32) := eval_global p0_body
/- [constants::P1]
Source: 'src/constants.rs', lines 32:0-32:28 -/
def p1_body : Result (Pair U32 U32) := mk_pair1 0#u32 1#u32
-def p1_c : Pair U32 U32 := eval_global p1_body (by decide)
+def p1_c : Pair U32 U32 := eval_global p1_body
/- [constants::P2]
Source: 'src/constants.rs', lines 33:0-33:24 -/
def p2_body : Result (U32 × U32) := Result.ret (0#u32, 1#u32)
-def p2_c : (U32 × U32) := eval_global p2_body (by decide)
+def p2_c : (U32 × U32) := eval_global p2_body
/- [constants::P3]
Source: 'src/constants.rs', lines 34:0-34:28 -/
def p3_body : Result (Pair U32 U32) := Result.ret { x := 0#u32, y := 1#u32 }
-def p3_c : Pair U32 U32 := eval_global p3_body (by decide)
+def p3_c : Pair U32 U32 := eval_global p3_body
/- [constants::Wrap]
Source: 'src/constants.rs', lines 49:0-49:18 -/
@@ -79,7 +79,7 @@ def Wrap.new (T : Type) (value : T) : Result (Wrap T) :=
/- [constants::Y]
Source: 'src/constants.rs', lines 41:0-41:22 -/
def y_body : Result (Wrap I32) := Wrap.new I32 2#i32
-def y_c : Wrap I32 := eval_global y_body (by decide)
+def y_c : Wrap I32 := eval_global y_body
/- [constants::unwrap_y]:
Source: 'src/constants.rs', lines 43:0-43:30 -/
@@ -89,12 +89,12 @@ def unwrap_y : Result I32 :=
/- [constants::YVAL]
Source: 'src/constants.rs', lines 47:0-47:19 -/
def yval_body : Result I32 := unwrap_y
-def yval_c : I32 := eval_global yval_body (by decide)
+def yval_c : I32 := eval_global yval_body
/- [constants::get_z1::Z1]
Source: 'src/constants.rs', lines 62:4-62:17 -/
def get_z1_z1_body : Result I32 := Result.ret 3#i32
-def get_z1_z1_c : I32 := eval_global get_z1_z1_body (by decide)
+def get_z1_z1_c : I32 := eval_global get_z1_z1_body
/- [constants::get_z1]:
Source: 'src/constants.rs', lines 61:0-61:28 -/
@@ -109,17 +109,17 @@ def add (a : I32) (b : I32) : Result I32 :=
/- [constants::Q1]
Source: 'src/constants.rs', lines 74:0-74:17 -/
def q1_body : Result I32 := Result.ret 5#i32
-def q1_c : I32 := eval_global q1_body (by decide)
+def q1_c : I32 := eval_global q1_body
/- [constants::Q2]
Source: 'src/constants.rs', lines 75:0-75:17 -/
def q2_body : Result I32 := Result.ret q1_c
-def q2_c : I32 := eval_global q2_body (by decide)
+def q2_c : I32 := eval_global q2_body
/- [constants::Q3]
Source: 'src/constants.rs', lines 76:0-76:17 -/
def q3_body : Result I32 := add q2_c 3#i32
-def q3_c : I32 := eval_global q3_body (by decide)
+def q3_c : I32 := eval_global q3_body
/- [constants::get_z2]:
Source: 'src/constants.rs', lines 70:0-70:28 -/
@@ -132,21 +132,21 @@ def get_z2 : Result I32 :=
/- [constants::S1]
Source: 'src/constants.rs', lines 80:0-80:18 -/
def s1_body : Result U32 := Result.ret 6#u32
-def s1_c : U32 := eval_global s1_body (by decide)
+def s1_c : U32 := eval_global s1_body
/- [constants::S2]
Source: 'src/constants.rs', lines 81:0-81:18 -/
def s2_body : Result U32 := incr s1_c
-def s2_c : U32 := eval_global s2_body (by decide)
+def s2_c : U32 := eval_global s2_body
/- [constants::S3]
Source: 'src/constants.rs', lines 82:0-82:29 -/
def s3_body : Result (Pair U32 U32) := Result.ret p3_c
-def s3_c : Pair U32 U32 := eval_global s3_body (by decide)
+def s3_c : Pair U32 U32 := eval_global s3_body
/- [constants::S4]
Source: 'src/constants.rs', lines 83:0-83:29 -/
def s4_body : Result (Pair U32 U32) := mk_pair1 7#u32 8#u32
-def s4_c : Pair U32 U32 := eval_global s4_body (by decide)
+def s4_c : Pair U32 U32 := eval_global s4_body
end constants
diff --git a/tests/lean/NoNestedBorrows.lean b/tests/lean/NoNestedBorrows.lean
index ef81f2e9..71d064d8 100644
--- a/tests/lean/NoNestedBorrows.lean
+++ b/tests/lean/NoNestedBorrows.lean
@@ -139,12 +139,12 @@ def mix_arith_i32 (x : I32) (y : I32) (z : I32) : Result I32 :=
/- [no_nested_borrows::CONST0]
Source: 'src/no_nested_borrows.rs', lines 125:0-125:23 -/
def const0_body : Result Usize := 1#usize + 1#usize
-def const0_c : Usize := eval_global const0_body (by decide)
+def const0_c : Usize := eval_global const0_body
/- [no_nested_borrows::CONST1]
Source: 'src/no_nested_borrows.rs', lines 126:0-126:23 -/
def const1_body : Result Usize := 2#usize * 2#usize
-def const1_c : Usize := eval_global const1_body (by decide)
+def const1_c : Usize := eval_global const1_body
/- [no_nested_borrows::cast_u32_to_i32]:
Source: 'src/no_nested_borrows.rs', lines 128:0-128:37 -/
diff --git a/tests/lean/Traits.lean b/tests/lean/Traits.lean
index 3ef4febc..f83fbc2f 100644
--- a/tests/lean/Traits.lean
+++ b/tests/lean/Traits.lean
@@ -248,8 +248,7 @@ def traits.ToTypetraitsBoolWrapperTInst (T : Type) (ToTypeBoolTInst : ToType
/- [traits::WithConstTy::LEN2]
Source: 'src/traits.rs', lines 164:4-164:21 -/
def with_const_ty_len2_body : Result Usize := Result.ret 32#usize
-def with_const_ty_len2_c : Usize :=
- eval_global with_const_ty_len2_body (by decide)
+def with_const_ty_len2_c : Usize := eval_global with_const_ty_len2_body
/- Trait declaration: [traits::WithConstTy]
Source: 'src/traits.rs', lines 161:0-161:39 -/
@@ -264,7 +263,7 @@ structure WithConstTy (Self : Type) (LEN : Usize) where
/- [traits::{bool#8}::LEN1]
Source: 'src/traits.rs', lines 175:4-175:21 -/
def bool_len1_body : Result Usize := Result.ret 12#usize
-def bool_len1_c : Usize := eval_global bool_len1_body (by decide)
+def bool_len1_c : Usize := eval_global bool_len1_body
/- [traits::{bool#8}::f]:
Source: 'src/traits.rs', lines 180:4-180:39 -/