summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSon Ho2024-03-18 01:39:29 +0100
committerSon Ho2024-03-18 01:39:29 +0100
commitd281f43fd5dfeab24fe582fd88564f6c1ab7f934 (patch)
treeb99dc104821234f6e519bf5f0615e62d1aeee20f
parenta8ebfc3947adb052f36775c664e43a8dc7434660 (diff)
Regenerate the constants tests and update Primitives/Base.lean
-rw-r--r--backends/lean/Base/Primitives/Base.lean2
-rw-r--r--tests/coq/misc/Constants.v53
-rw-r--r--tests/fstar/misc/Constants.fst50
-rw-r--r--tests/lean/Constants.lean51
4 files changed, 101 insertions, 55 deletions
diff --git a/backends/lean/Base/Primitives/Base.lean b/backends/lean/Base/Primitives/Base.lean
index 0b9d9c39..d2695854 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 := by decide): α :=
+def eval_global {α: Type u} (x: Result α) (_: ret? x := by first | apply Eq.refl | decide): α :=
match x with
| fail _ | div => by contradiction
| ret x => x
diff --git a/tests/coq/misc/Constants.v b/tests/coq/misc/Constants.v
index 5fa952b4..81240847 100644
--- a/tests/coq/misc/Constants.v
+++ b/tests/coq/misc/Constants.v
@@ -11,17 +11,17 @@ Module Constants.
(** [constants::X0]
Source: 'src/constants.rs', lines 5:0-5:17 *)
Definition x0_body : result u32 := Return 0%u32.
-Definition x0 : u32 := x0_body%global.
+Definition x0 : u32 := (x0_body)%global.
(** [constants::X1]
Source: 'src/constants.rs', lines 7:0-7:17 *)
Definition x1_body : result u32 := Return core_u32_max.
-Definition x1 : u32 := x1_body%global.
+Definition x1 : u32 := (x1_body)%global.
(** [constants::X2]
Source: 'src/constants.rs', lines 10:0-10:17 *)
Definition x2_body : result u32 := Return 3%u32.
-Definition x2 : u32 := x2_body%global.
+Definition x2 : u32 := (x2_body)%global.
(** [constants::incr]:
Source: 'src/constants.rs', lines 17:0-17:32 *)
@@ -31,7 +31,7 @@ Definition incr (n : u32) : result u32 :=
(** [constants::X3]
Source: 'src/constants.rs', lines 15:0-15:17 *)
Definition x3_body : result u32 := incr 32%u32.
-Definition x3 : u32 := x3_body%global.
+Definition x3 : u32 := (x3_body)%global.
(** [constants::mk_pair0]:
Source: 'src/constants.rs', lines 23:0-23:51 *)
@@ -56,24 +56,24 @@ Definition mk_pair1 (x : u32) (y1 : u32) : result (Pair_t u32 u32) :=
(** [constants::P0]
Source: 'src/constants.rs', lines 31:0-31:24 *)
Definition p0_body : result (u32 * u32) := mk_pair0 0%u32 1%u32.
-Definition p0 : (u32 * u32) := p0_body%global.
+Definition p0 : (u32 * u32) := (p0_body)%global.
(** [constants::P1]
Source: 'src/constants.rs', lines 32:0-32:28 *)
Definition p1_body : result (Pair_t u32 u32) := mk_pair1 0%u32 1%u32.
-Definition p1 : Pair_t u32 u32 := p1_body%global.
+Definition p1 : Pair_t u32 u32 := (p1_body)%global.
(** [constants::P2]
Source: 'src/constants.rs', lines 33:0-33:24 *)
Definition p2_body : result (u32 * u32) := Return (0%u32, 1%u32).
-Definition p2 : (u32 * u32) := p2_body%global.
+Definition p2 : (u32 * u32) := (p2_body)%global.
(** [constants::P3]
Source: 'src/constants.rs', lines 34:0-34:28 *)
Definition p3_body : result (Pair_t u32 u32) :=
Return {| pair_x := 0%u32; pair_y := 1%u32 |}
.
-Definition p3 : Pair_t u32 u32 := p3_body%global.
+Definition p3 : Pair_t u32 u32 := (p3_body)%global.
(** [constants::Wrap]
Source: 'src/constants.rs', lines 49:0-49:18 *)
@@ -91,7 +91,7 @@ Definition wrap_new (T : Type) (value : T) : result (Wrap_t T) :=
(** [constants::Y]
Source: 'src/constants.rs', lines 41:0-41:22 *)
Definition y_body : result (Wrap_t i32) := wrap_new i32 2%i32.
-Definition y : Wrap_t i32 := y_body%global.
+Definition y : Wrap_t i32 := (y_body)%global.
(** [constants::unwrap_y]:
Source: 'src/constants.rs', lines 43:0-43:30 *)
@@ -101,12 +101,12 @@ Definition unwrap_y : result i32 :=
(** [constants::YVAL]
Source: 'src/constants.rs', lines 47:0-47:19 *)
Definition yval_body : result i32 := unwrap_y.
-Definition yval : i32 := yval_body%global.
+Definition yval : i32 := (yval_body)%global.
(** [constants::get_z1::Z1]
Source: 'src/constants.rs', lines 62:4-62:17 *)
Definition get_z1_z1_body : result i32 := Return 3%i32.
-Definition get_z1_z1 : i32 := get_z1_z1_body%global.
+Definition get_z1_z1 : i32 := (get_z1_z1_body)%global.
(** [constants::get_z1]:
Source: 'src/constants.rs', lines 61:0-61:28 *)
@@ -121,17 +121,17 @@ Definition add (a : i32) (b : i32) : result i32 :=
(** [constants::Q1]
Source: 'src/constants.rs', lines 74:0-74:17 *)
Definition q1_body : result i32 := Return 5%i32.
-Definition q1 : i32 := q1_body%global.
+Definition q1 : i32 := (q1_body)%global.
(** [constants::Q2]
Source: 'src/constants.rs', lines 75:0-75:17 *)
Definition q2_body : result i32 := Return q1.
-Definition q2 : i32 := q2_body%global.
+Definition q2 : i32 := (q2_body)%global.
(** [constants::Q3]
Source: 'src/constants.rs', lines 76:0-76:17 *)
Definition q3_body : result i32 := add q2 3%i32.
-Definition q3 : i32 := q3_body%global.
+Definition q3 : i32 := (q3_body)%global.
(** [constants::get_z2]:
Source: 'src/constants.rs', lines 70:0-70:28 *)
@@ -141,21 +141,38 @@ Definition get_z2 : result i32 :=
(** [constants::S1]
Source: 'src/constants.rs', lines 80:0-80:18 *)
Definition s1_body : result u32 := Return 6%u32.
-Definition s1 : u32 := s1_body%global.
+Definition s1 : u32 := (s1_body)%global.
(** [constants::S2]
Source: 'src/constants.rs', lines 81:0-81:18 *)
Definition s2_body : result u32 := incr s1.
-Definition s2 : u32 := s2_body%global.
+Definition s2 : u32 := (s2_body)%global.
(** [constants::S3]
Source: 'src/constants.rs', lines 82:0-82:29 *)
Definition s3_body : result (Pair_t u32 u32) := Return p3.
-Definition s3 : Pair_t u32 u32 := s3_body%global.
+Definition s3 : Pair_t u32 u32 := (s3_body)%global.
(** [constants::S4]
Source: 'src/constants.rs', lines 83:0-83:29 *)
Definition s4_body : result (Pair_t u32 u32) := mk_pair1 7%u32 8%u32.
-Definition s4 : Pair_t u32 u32 := s4_body%global.
+Definition s4 : Pair_t u32 u32 := (s4_body)%global.
+
+(** [constants::V]
+ Source: 'src/constants.rs', lines 86:0-86:31 *)
+Record V_t (T : Type) (N : usize) := mkV_t { v_x : array T N; }.
+
+Arguments mkV_t { _ _ }.
+Arguments v_x { _ _ }.
+
+(** [constants::{constants::V<T, N>#1}::LEN]
+ Source: 'src/constants.rs', lines 91:4-91:24 *)
+Definition v_len_body (T : Type) (N : usize) : result usize := Return N.
+Definition v_len (T : Type) (N : usize) : usize := (v_len_body T N)%global.
+
+(** [constants::use_v]:
+ Source: 'src/constants.rs', lines 94:0-94:42 *)
+Definition use_v (T : Type) (N : usize) : result usize :=
+ Return (v_len T N).
End Constants.
diff --git a/tests/fstar/misc/Constants.fst b/tests/fstar/misc/Constants.fst
index 66429c80..3664c7d6 100644
--- a/tests/fstar/misc/Constants.fst
+++ b/tests/fstar/misc/Constants.fst
@@ -8,17 +8,17 @@ open Primitives
(** [constants::X0]
Source: 'src/constants.rs', lines 5:0-5:17 *)
let x0_body : result u32 = Return 0
-let x0 : u32 = eval_global x0_body
+let x0 : u32 = eval_global (x0_body)
(** [constants::X1]
Source: 'src/constants.rs', lines 7:0-7:17 *)
let x1_body : result u32 = Return core_u32_max
-let x1 : u32 = eval_global x1_body
+let x1 : u32 = eval_global (x1_body)
(** [constants::X2]
Source: 'src/constants.rs', lines 10:0-10:17 *)
let x2_body : result u32 = Return 3
-let x2 : u32 = eval_global x2_body
+let x2 : u32 = eval_global (x2_body)
(** [constants::incr]:
Source: 'src/constants.rs', lines 17:0-17:32 *)
@@ -28,7 +28,7 @@ let incr (n : u32) : result u32 =
(** [constants::X3]
Source: 'src/constants.rs', lines 15:0-15:17 *)
let x3_body : result u32 = incr 32
-let x3 : u32 = eval_global x3_body
+let x3 : u32 = eval_global (x3_body)
(** [constants::mk_pair0]:
Source: 'src/constants.rs', lines 23:0-23:51 *)
@@ -47,22 +47,22 @@ let mk_pair1 (x : u32) (y1 : u32) : result (pair_t u32 u32) =
(** [constants::P0]
Source: 'src/constants.rs', lines 31:0-31:24 *)
let p0_body : result (u32 & u32) = mk_pair0 0 1
-let p0 : (u32 & u32) = eval_global p0_body
+let p0 : (u32 & u32) = eval_global (p0_body)
(** [constants::P1]
Source: 'src/constants.rs', lines 32:0-32:28 *)
let p1_body : result (pair_t u32 u32) = mk_pair1 0 1
-let p1 : pair_t u32 u32 = eval_global p1_body
+let p1 : pair_t u32 u32 = eval_global (p1_body)
(** [constants::P2]
Source: 'src/constants.rs', lines 33:0-33:24 *)
let p2_body : result (u32 & u32) = Return (0, 1)
-let p2 : (u32 & u32) = eval_global p2_body
+let p2 : (u32 & u32) = eval_global (p2_body)
(** [constants::P3]
Source: 'src/constants.rs', lines 34:0-34:28 *)
let p3_body : result (pair_t u32 u32) = Return { x = 0; y = 1 }
-let p3 : pair_t u32 u32 = eval_global p3_body
+let p3 : pair_t u32 u32 = eval_global (p3_body)
(** [constants::Wrap]
Source: 'src/constants.rs', lines 49:0-49:18 *)
@@ -76,7 +76,7 @@ let wrap_new (t : Type0) (value : t) : result (wrap_t t) =
(** [constants::Y]
Source: 'src/constants.rs', lines 41:0-41:22 *)
let y_body : result (wrap_t i32) = wrap_new i32 2
-let y : wrap_t i32 = eval_global y_body
+let y : wrap_t i32 = eval_global (y_body)
(** [constants::unwrap_y]:
Source: 'src/constants.rs', lines 43:0-43:30 *)
@@ -86,12 +86,12 @@ let unwrap_y : result i32 =
(** [constants::YVAL]
Source: 'src/constants.rs', lines 47:0-47:19 *)
let yval_body : result i32 = unwrap_y
-let yval : i32 = eval_global yval_body
+let yval : i32 = eval_global (yval_body)
(** [constants::get_z1::Z1]
Source: 'src/constants.rs', lines 62:4-62:17 *)
let get_z1_z1_body : result i32 = Return 3
-let get_z1_z1 : i32 = eval_global get_z1_z1_body
+let get_z1_z1 : i32 = eval_global (get_z1_z1_body)
(** [constants::get_z1]:
Source: 'src/constants.rs', lines 61:0-61:28 *)
@@ -106,17 +106,17 @@ let add (a : i32) (b : i32) : result i32 =
(** [constants::Q1]
Source: 'src/constants.rs', lines 74:0-74:17 *)
let q1_body : result i32 = Return 5
-let q1 : i32 = eval_global q1_body
+let q1 : i32 = eval_global (q1_body)
(** [constants::Q2]
Source: 'src/constants.rs', lines 75:0-75:17 *)
let q2_body : result i32 = Return q1
-let q2 : i32 = eval_global q2_body
+let q2 : i32 = eval_global (q2_body)
(** [constants::Q3]
Source: 'src/constants.rs', lines 76:0-76:17 *)
let q3_body : result i32 = add q2 3
-let q3 : i32 = eval_global q3_body
+let q3 : i32 = eval_global (q3_body)
(** [constants::get_z2]:
Source: 'src/constants.rs', lines 70:0-70:28 *)
@@ -126,20 +126,34 @@ let get_z2 : result i32 =
(** [constants::S1]
Source: 'src/constants.rs', lines 80:0-80:18 *)
let s1_body : result u32 = Return 6
-let s1 : u32 = eval_global s1_body
+let s1 : u32 = eval_global (s1_body)
(** [constants::S2]
Source: 'src/constants.rs', lines 81:0-81:18 *)
let s2_body : result u32 = incr s1
-let s2 : u32 = eval_global s2_body
+let s2 : u32 = eval_global (s2_body)
(** [constants::S3]
Source: 'src/constants.rs', lines 82:0-82:29 *)
let s3_body : result (pair_t u32 u32) = Return p3
-let s3 : pair_t u32 u32 = eval_global s3_body
+let s3 : pair_t u32 u32 = eval_global (s3_body)
(** [constants::S4]
Source: 'src/constants.rs', lines 83:0-83:29 *)
let s4_body : result (pair_t u32 u32) = mk_pair1 7 8
-let s4 : pair_t u32 u32 = eval_global s4_body
+let s4 : pair_t u32 u32 = eval_global (s4_body)
+
+(** [constants::V]
+ Source: 'src/constants.rs', lines 86:0-86:31 *)
+type v_t (t : Type0) (n : usize) = { x : array t n; }
+
+(** [constants::{constants::V<T, N>#1}::LEN]
+ Source: 'src/constants.rs', lines 91:4-91:24 *)
+let v_len_body (t : Type0) (n : usize) : result usize = Return n
+let v_len (t : Type0) (n : usize) : usize = eval_global (v_len_body t n)
+
+(** [constants::use_v]:
+ Source: 'src/constants.rs', lines 94:0-94:42 *)
+let use_v (t : Type0) (n : usize) : result usize =
+ Return (v_len t n)
diff --git a/tests/lean/Constants.lean b/tests/lean/Constants.lean
index 7949a25c..3727e393 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 : U32 := eval_global X0_body
+def X0 : 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 : U32 := eval_global X1_body
+def X1 : 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 : U32 := eval_global X2_body
+def X2 : 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 : U32 := eval_global X3_body
+def X3 : 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 : (U32 × U32) := eval_global P0_body
+def P0 : (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 : Pair U32 U32 := eval_global P1_body
+def P1 : 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 : (U32 × U32) := eval_global P2_body
+def P2 : (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 : Pair U32 U32 := eval_global P3_body
+def P3 : 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 : Wrap I32 := eval_global Y_body
+def Y : 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 : I32 := eval_global YVAL_body
+def YVAL : 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 : I32 := eval_global get_z1.Z1_body
+def get_z1.Z1 : 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 : I32 := eval_global Q1_body
+def Q1 : I32 := eval_global (Q1_body)
/- [constants::Q2]
Source: 'src/constants.rs', lines 75:0-75:17 -/
def Q2_body : Result I32 := Result.ret Q1
-def Q2 : I32 := eval_global Q2_body
+def Q2 : I32 := eval_global (Q2_body)
/- [constants::Q3]
Source: 'src/constants.rs', lines 76:0-76:17 -/
def Q3_body : Result I32 := add Q2 3#i32
-def Q3 : I32 := eval_global Q3_body
+def Q3 : I32 := eval_global (Q3_body)
/- [constants::get_z2]:
Source: 'src/constants.rs', lines 70:0-70:28 -/
@@ -132,21 +132,36 @@ 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 : U32 := eval_global S1_body
+def S1 : U32 := eval_global (S1_body)
/- [constants::S2]
Source: 'src/constants.rs', lines 81:0-81:18 -/
def S2_body : Result U32 := incr S1
-def S2 : U32 := eval_global S2_body
+def S2 : 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
-def S3 : Pair U32 U32 := eval_global S3_body
+def S3 : 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 : Pair U32 U32 := eval_global S4_body
+def S4 : Pair U32 U32 := eval_global (S4_body)
+
+/- [constants::V]
+ Source: 'src/constants.rs', lines 86:0-86:31 -/
+structure V (T : Type) (N : Usize) where
+ x : Array T N
+
+/- [constants::{constants::V<T, N>#1}::LEN]
+ Source: 'src/constants.rs', lines 91:4-91:24 -/
+def V.LEN_body (T : Type) (N : Usize) : Result Usize := Result.ret N
+def V.LEN (T : Type) (N : Usize) : Usize := eval_global (V.LEN_body T N)
+
+/- [constants::use_v]:
+ Source: 'src/constants.rs', lines 94:0-94:42 -/
+def use_v (T : Type) (N : Usize) : Result Usize :=
+ Result.ret (V.LEN T N)
end constants