summaryrefslogtreecommitdiff
path: root/tests/lean
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/lean/Constants.lean29
-rw-r--r--tests/lean/External/Funs.lean16
-rw-r--r--tests/lean/Loops/Funs.lean161
-rw-r--r--tests/lean/Paper.lean48
4 files changed, 132 insertions, 122 deletions
diff --git a/tests/lean/Constants.lean b/tests/lean/Constants.lean
index b0cdaa90..2603cbbf 100644
--- a/tests/lean/Constants.lean
+++ b/tests/lean/Constants.lean
@@ -6,7 +6,7 @@ open Primitives
namespace constants
/- [constants::X0] -/
-def x0_body : Result U32 := Result.ret (U32.ofInt 0)
+def x0_body : Result U32 := Result.ret 0#u32
def x0_c : U32 := eval_global x0_body (by simp)
/- [constants::X1] -/
@@ -14,15 +14,15 @@ def x1_body : Result U32 := Result.ret core_u32_max
def x1_c : U32 := eval_global x1_body (by simp)
/- [constants::X2] -/
-def x2_body : Result U32 := Result.ret (U32.ofInt 3)
+def x2_body : Result U32 := Result.ret 3#u32
def x2_c : U32 := eval_global x2_body (by simp)
/- [constants::incr]: forward function -/
def incr (n : U32) : Result U32 :=
- n + (U32.ofInt 1)
+ n + 1#u32
/- [constants::X3] -/
-def x3_body : Result U32 := incr (U32.ofInt 32)
+def x3_body : Result U32 := incr 32#u32
def x3_c : U32 := eval_global x3_body (by simp)
/- [constants::mk_pair0]: forward function -/
@@ -39,20 +39,19 @@ def mk_pair1 (x : U32) (y : U32) : Result (Pair U32 U32) :=
Result.ret { x := x, y := y }
/- [constants::P0] -/
-def p0_body : Result (U32 × U32) := mk_pair0 (U32.ofInt 0) (U32.ofInt 1)
+def p0_body : Result (U32 × U32) := mk_pair0 0#u32 1#u32
def p0_c : (U32 × U32) := eval_global p0_body (by simp)
/- [constants::P1] -/
-def p1_body : Result (Pair U32 U32) := mk_pair1 (U32.ofInt 0) (U32.ofInt 1)
+def p1_body : Result (Pair U32 U32) := mk_pair1 0#u32 1#u32
def p1_c : Pair U32 U32 := eval_global p1_body (by simp)
/- [constants::P2] -/
-def p2_body : Result (U32 × U32) := Result.ret ((U32.ofInt 0), (U32.ofInt 1))
+def p2_body : Result (U32 × U32) := Result.ret (0#u32, 1#u32)
def p2_c : (U32 × U32) := eval_global p2_body (by simp)
/- [constants::P3] -/
-def p3_body : Result (Pair U32 U32) :=
- Result.ret { x := (U32.ofInt 0), y := (U32.ofInt 1) }
+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 simp)
/- [constants::Wrap] -/
@@ -64,7 +63,7 @@ def Wrap.new (T : Type) (val : T) : Result (Wrap T) :=
Result.ret { val := val }
/- [constants::Y] -/
-def y_body : Result (Wrap I32) := Wrap.new I32 (I32.ofInt 2)
+def y_body : Result (Wrap I32) := Wrap.new I32 2#i32
def y_c : Wrap I32 := eval_global y_body (by simp)
/- [constants::unwrap_y]: forward function -/
@@ -76,7 +75,7 @@ def yval_body : Result I32 := unwrap_y
def yval_c : I32 := eval_global yval_body (by simp)
/- [constants::get_z1::Z1] -/
-def get_z1_z1_body : Result I32 := Result.ret (I32.ofInt 3)
+def get_z1_z1_body : Result I32 := Result.ret 3#i32
def get_z1_z1_c : I32 := eval_global get_z1_z1_body (by simp)
/- [constants::get_z1]: forward function -/
@@ -88,7 +87,7 @@ def add (a : I32) (b : I32) : Result I32 :=
a + b
/- [constants::Q1] -/
-def q1_body : Result I32 := Result.ret (I32.ofInt 5)
+def q1_body : Result I32 := Result.ret 5#i32
def q1_c : I32 := eval_global q1_body (by simp)
/- [constants::Q2] -/
@@ -96,7 +95,7 @@ def q2_body : Result I32 := Result.ret q1_c
def q2_c : I32 := eval_global q2_body (by simp)
/- [constants::Q3] -/
-def q3_body : Result I32 := add q2_c (I32.ofInt 3)
+def q3_body : Result I32 := add q2_c 3#i32
def q3_c : I32 := eval_global q3_body (by simp)
/- [constants::get_z2]: forward function -/
@@ -107,7 +106,7 @@ def get_z2 : Result I32 :=
add q1_c i0
/- [constants::S1] -/
-def s1_body : Result U32 := Result.ret (U32.ofInt 6)
+def s1_body : Result U32 := Result.ret 6#u32
def s1_c : U32 := eval_global s1_body (by simp)
/- [constants::S2] -/
@@ -119,7 +118,7 @@ def s3_body : Result (Pair U32 U32) := Result.ret p3_c
def s3_c : Pair U32 U32 := eval_global s3_body (by simp)
/- [constants::S4] -/
-def s4_body : Result (Pair U32 U32) := mk_pair1 (U32.ofInt 7) (U32.ofInt 8)
+def s4_body : Result (Pair U32 U32) := mk_pair1 7#u32 8#u32
def s4_c : Pair U32 U32 := eval_global s4_body (by simp)
end constants
diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean
index 055d7860..55fb07be 100644
--- a/tests/lean/External/Funs.lean
+++ b/tests/lean/External/Funs.lean
@@ -30,14 +30,14 @@ def swap_back
def test_new_non_zero_u32
(x : U32) (st : State) : Result (State × core.num.nonzero.NonZeroU32) :=
do
- let (st0, opt) ← core.num.nonzero.NonZeroU32.new x st
- core.option.Option.unwrap core.num.nonzero.NonZeroU32 opt st0
+ let (st0, o) ← core.num.nonzero.NonZeroU32.new x st
+ core.option.Option.unwrap core.num.nonzero.NonZeroU32 o st0
/- [external::test_vec]: forward function -/
def test_vec : Result Unit :=
do
- let v := Vec.new U32
- let _ ← Vec.push U32 v (U32.ofInt 0)
+ let v := alloc.vec.Vec.new U32
+ let _ ← alloc.vec.Vec.push U32 v 0#u32
Result.ret ()
/- Unit test for [external::test_vec] -/
@@ -75,14 +75,14 @@ def test_custom_swap_back
(x : U32) (y : U32) (st : State) (st0 : State) :
Result (State × (U32 × U32))
:=
- custom_swap_back U32 x y st (U32.ofInt 1) st0
+ custom_swap_back U32 x y st 1#u32 st0
/- [external::test_swap_non_zero]: forward function -/
def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) :=
do
- let (st0, _) ← swap U32 x (U32.ofInt 0) st
- let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0) st st0
- if x0 = (U32.ofInt 0)
+ let (st0, _) ← swap U32 x 0#u32 st
+ let (st1, (x0, _)) ← swap_back U32 x 0#u32 st st0
+ if x0 = 0#u32
then Result.fail Error.panic
else Result.ret (st1, x0)
diff --git a/tests/lean/Loops/Funs.lean b/tests/lean/Loops/Funs.lean
index 5fbe200f..f9c7569e 100644
--- a/tests/lean/Loops/Funs.lean
+++ b/tests/lean/Loops/Funs.lean
@@ -11,13 +11,13 @@ divergent def sum_loop (max : U32) (i : U32) (s : U32) : Result U32 :=
if i < max
then do
let s0 ← s + i
- let i0 ← i + (U32.ofInt 1)
+ let i0 ← i + 1#u32
sum_loop max i0 s0
- else s * (U32.ofInt 2)
+ else s * 2#u32
/- [loops::sum]: forward function -/
def sum (max : U32) : Result U32 :=
- sum_loop max (U32.ofInt 0) (U32.ofInt 0)
+ sum_loop max 0#u32 0#u32
/- [loops::sum_with_mut_borrows]: loop 0: forward function -/
divergent def sum_with_mut_borrows_loop
@@ -26,13 +26,13 @@ divergent def sum_with_mut_borrows_loop
then
do
let ms0 ← ms + mi
- let mi0 ← mi + (U32.ofInt 1)
+ let mi0 ← mi + 1#u32
sum_with_mut_borrows_loop max mi0 ms0
- else ms * (U32.ofInt 2)
+ else ms * 2#u32
/- [loops::sum_with_mut_borrows]: forward function -/
def sum_with_mut_borrows (max : U32) : Result U32 :=
- sum_with_mut_borrows_loop max (U32.ofInt 0) (U32.ofInt 0)
+ sum_with_mut_borrows_loop max 0#u32 0#u32
/- [loops::sum_with_shared_borrows]: loop 0: forward function -/
divergent def sum_with_shared_borrows_loop
@@ -40,31 +40,34 @@ divergent def sum_with_shared_borrows_loop
if i < max
then
do
- let i0 ← i + (U32.ofInt 1)
+ let i0 ← i + 1#u32
let s0 ← s + i0
sum_with_shared_borrows_loop max i0 s0
- else s * (U32.ofInt 2)
+ else s * 2#u32
/- [loops::sum_with_shared_borrows]: forward function -/
def sum_with_shared_borrows (max : U32) : Result U32 :=
- sum_with_shared_borrows_loop max (U32.ofInt 0) (U32.ofInt 0)
+ sum_with_shared_borrows_loop max 0#u32 0#u32
/- [loops::clear]: loop 0: merged forward/backward function
(there is a single backward function, and the forward function returns ()) -/
-divergent def clear_loop (v : Vec U32) (i : Usize) : Result (Vec U32) :=
- let i0 := Vec.len U32 v
+divergent def clear_loop
+ (v : alloc.vec.Vec U32) (i : Usize) : Result (alloc.vec.Vec U32) :=
+ let i0 := alloc.vec.Vec.len U32 v
if i < i0
then
do
- let i1 ← i + (Usize.ofInt 1)
- let v0 ← Vec.index_mut_back U32 v i (U32.ofInt 0)
+ let i1 ← i + 1#usize
+ let v0 ←
+ alloc.vec.Vec.index_mut_back U32 Usize
+ (core.slice.index.usize.coresliceindexSliceIndexInst U32) v i 0#u32
clear_loop v0 i1
else Result.ret v
/- [loops::clear]: merged forward/backward function
(there is a single backward function, and the forward function returns ()) -/
-def clear (v : Vec U32) : Result (Vec U32) :=
- clear_loop v (Usize.ofInt 0)
+def clear (v : alloc.vec.Vec U32) : Result (alloc.vec.Vec U32) :=
+ clear_loop v 0#usize
/- [loops::list_mem]: loop 0: forward function -/
divergent def list_mem_loop (x : U32) (ls : List U32) : Result Bool :=
@@ -83,10 +86,10 @@ divergent def list_nth_mut_loop_loop
(T : Type) (ls : List T) (i : U32) : Result T :=
match ls with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret x
else do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_mut_loop_loop T tl i0
| List.Nil => Result.fail Error.panic
@@ -99,11 +102,11 @@ divergent def list_nth_mut_loop_loop_back
(T : Type) (ls : List T) (i : U32) (ret0 : T) : Result (List T) :=
match ls with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl0 ← list_nth_mut_loop_loop_back T tl i0 ret0
Result.ret (List.Cons x tl0)
| List.Nil => Result.fail Error.panic
@@ -118,10 +121,10 @@ divergent def list_nth_shared_loop_loop
(T : Type) (ls : List T) (i : U32) : Result T :=
match ls with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret x
else do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_shared_loop_loop T tl i0
| List.Nil => Result.fail Error.panic
@@ -138,9 +141,13 @@ divergent def get_elem_mut_loop (x : Usize) (ls : List Usize) : Result Usize :=
| List.Nil => Result.fail Error.panic
/- [loops::get_elem_mut]: forward function -/
-def get_elem_mut (slots : Vec (List Usize)) (x : Usize) : Result Usize :=
+def get_elem_mut
+ (slots : alloc.vec.Vec (List Usize)) (x : Usize) : Result Usize :=
do
- let l ← Vec.index_mut (List Usize) slots (Usize.ofInt 0)
+ let l ←
+ alloc.vec.Vec.index_mut (List Usize) Usize
+ (core.slice.index.usize.coresliceindexSliceIndexInst (List Usize))
+ slots 0#usize
get_elem_mut_loop x l
/- [loops::get_elem_mut]: loop 0: backward function 0 -/
@@ -158,13 +165,18 @@ divergent def get_elem_mut_loop_back
/- [loops::get_elem_mut]: backward function 0 -/
def get_elem_mut_back
- (slots : Vec (List Usize)) (x : Usize) (ret0 : Usize) :
- Result (Vec (List Usize))
+ (slots : alloc.vec.Vec (List Usize)) (x : Usize) (ret0 : Usize) :
+ Result (alloc.vec.Vec (List Usize))
:=
do
- let l ← Vec.index_mut (List Usize) slots (Usize.ofInt 0)
+ let l ←
+ alloc.vec.Vec.index_mut (List Usize) Usize
+ (core.slice.index.usize.coresliceindexSliceIndexInst (List Usize))
+ slots 0#usize
let l0 ← get_elem_mut_loop_back x l ret0
- Vec.index_mut_back (List Usize) slots (Usize.ofInt 0) l0
+ alloc.vec.Vec.index_mut_back (List Usize) Usize
+ (core.slice.index.usize.coresliceindexSliceIndexInst (List Usize)) slots
+ 0#usize l0
/- [loops::get_elem_shared]: loop 0: forward function -/
divergent def get_elem_shared_loop
@@ -176,9 +188,13 @@ divergent def get_elem_shared_loop
| List.Nil => Result.fail Error.panic
/- [loops::get_elem_shared]: forward function -/
-def get_elem_shared (slots : Vec (List Usize)) (x : Usize) : Result Usize :=
+def get_elem_shared
+ (slots : alloc.vec.Vec (List Usize)) (x : Usize) : Result Usize :=
do
- let l ← Vec.index_shared (List Usize) slots (Usize.ofInt 0)
+ let l ←
+ alloc.vec.Vec.index (List Usize) Usize
+ (core.slice.index.usize.coresliceindexSliceIndexInst (List Usize))
+ slots 0#usize
get_elem_shared_loop x l
/- [loops::id_mut]: forward function -/
@@ -198,10 +214,10 @@ divergent def list_nth_mut_loop_with_id_loop
(T : Type) (i : U32) (ls : List T) : Result T :=
match ls with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret x
else do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_mut_loop_with_id_loop T i0 tl
| List.Nil => Result.fail Error.panic
@@ -216,11 +232,11 @@ divergent def list_nth_mut_loop_with_id_loop_back
(T : Type) (i : U32) (ls : List T) (ret0 : T) : Result (List T) :=
match ls with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl0 ← list_nth_mut_loop_with_id_loop_back T i0 tl ret0
Result.ret (List.Cons x tl0)
| List.Nil => Result.fail Error.panic
@@ -238,12 +254,11 @@ divergent def list_nth_shared_loop_with_id_loop
(T : Type) (i : U32) (ls : List T) : Result T :=
match ls with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret x
- else
- do
- let i0 ← i - (U32.ofInt 1)
- list_nth_shared_loop_with_id_loop T i0 tl
+ else do
+ let i0 ← i - 1#u32
+ list_nth_shared_loop_with_id_loop T i0 tl
| List.Nil => Result.fail Error.panic
/- [loops::list_nth_shared_loop_with_id]: forward function -/
@@ -260,12 +275,11 @@ divergent def list_nth_mut_loop_pair_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
- else
- do
- let i0 ← i - (U32.ofInt 1)
- list_nth_mut_loop_pair_loop T tl0 tl1 i0
+ else do
+ let i0 ← i - 1#u32
+ list_nth_mut_loop_pair_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -283,11 +297,11 @@ divergent def list_nth_mut_loop_pair_loop_back'a
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl0)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl00 ← list_nth_mut_loop_pair_loop_back'a T tl0 tl1 i0 ret0
Result.ret (List.Cons x0 tl00)
| List.Nil => Result.fail Error.panic
@@ -309,11 +323,11 @@ divergent def list_nth_mut_loop_pair_loop_back'b
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl10 ← list_nth_mut_loop_pair_loop_back'b T tl0 tl1 i0 ret0
Result.ret (List.Cons x1 tl10)
| List.Nil => Result.fail Error.panic
@@ -333,12 +347,11 @@ divergent def list_nth_shared_loop_pair_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
- else
- do
- let i0 ← i - (U32.ofInt 1)
- list_nth_shared_loop_pair_loop T tl0 tl1 i0
+ else do
+ let i0 ← i - 1#u32
+ list_nth_shared_loop_pair_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -354,11 +367,11 @@ divergent def list_nth_mut_loop_pair_merge_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_mut_loop_pair_merge_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -377,12 +390,12 @@ divergent def list_nth_mut_loop_pair_merge_loop_back
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then let (t, t0) := ret0
Result.ret (List.Cons t tl0, List.Cons t0 tl1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let (tl00, tl10) ←
list_nth_mut_loop_pair_merge_loop_back T tl0 tl1 i0 ret0
Result.ret (List.Cons x0 tl00, List.Cons x1 tl10)
@@ -403,11 +416,11 @@ divergent def list_nth_shared_loop_pair_merge_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_shared_loop_pair_merge_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -424,11 +437,11 @@ divergent def list_nth_mut_shared_loop_pair_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_mut_shared_loop_pair_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -447,11 +460,11 @@ divergent def list_nth_mut_shared_loop_pair_loop_back
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl0)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl00 ←
list_nth_mut_shared_loop_pair_loop_back T tl0 tl1 i0 ret0
Result.ret (List.Cons x0 tl00)
@@ -472,11 +485,11 @@ divergent def list_nth_mut_shared_loop_pair_merge_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_mut_shared_loop_pair_merge_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -495,11 +508,11 @@ divergent def list_nth_mut_shared_loop_pair_merge_loop_back
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl0)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl00 ←
list_nth_mut_shared_loop_pair_merge_loop_back T tl0 tl1 i0 ret0
Result.ret (List.Cons x0 tl00)
@@ -520,11 +533,11 @@ divergent def list_nth_shared_mut_loop_pair_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_shared_mut_loop_pair_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -543,11 +556,11 @@ divergent def list_nth_shared_mut_loop_pair_loop_back
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl10 ←
list_nth_shared_mut_loop_pair_loop_back T tl0 tl1 i0 ret0
Result.ret (List.Cons x1 tl10)
@@ -568,11 +581,11 @@ divergent def list_nth_shared_mut_loop_pair_merge_loop
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (x0, x1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_shared_mut_loop_pair_merge_loop T tl0 tl1 i0
| List.Nil => Result.fail Error.panic
| List.Nil => Result.fail Error.panic
@@ -591,11 +604,11 @@ divergent def list_nth_shared_mut_loop_pair_merge_loop_back
| List.Cons x0 tl0 =>
match ls1 with
| List.Cons x1 tl1 =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl1)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl10 ←
list_nth_shared_mut_loop_pair_merge_loop_back T tl0 tl1 i0 ret0
Result.ret (List.Cons x1 tl10)
diff --git a/tests/lean/Paper.lean b/tests/lean/Paper.lean
index c15c5e4b..ae4dd243 100644
--- a/tests/lean/Paper.lean
+++ b/tests/lean/Paper.lean
@@ -8,13 +8,13 @@ namespace paper
/- [paper::ref_incr]: merged forward/backward function
(there is a single backward function, and the forward function returns ()) -/
def ref_incr (x : I32) : Result I32 :=
- x + (I32.ofInt 1)
+ x + 1#i32
/- [paper::test_incr]: forward function -/
def test_incr : Result Unit :=
do
- let x ← ref_incr (I32.ofInt 0)
- if not (x = (I32.ofInt 1))
+ let x ← ref_incr 0#i32
+ if not (x = 1#i32)
then Result.fail Error.panic
else Result.ret ()
@@ -37,19 +37,18 @@ def choose_back
/- [paper::test_choose]: forward function -/
def test_choose : Result Unit :=
do
- let z ← choose I32 true (I32.ofInt 0) (I32.ofInt 0)
- let z0 ← z + (I32.ofInt 1)
- if not (z0 = (I32.ofInt 1))
+ let z ← choose I32 true 0#i32 0#i32
+ let z0 ← z + 1#i32
+ if not (z0 = 1#i32)
then Result.fail Error.panic
else
do
- let (x, y) ← choose_back I32 true (I32.ofInt 0) (I32.ofInt 0) z0
- if not (x = (I32.ofInt 1))
+ let (x, y) ← choose_back I32 true 0#i32 0#i32 z0
+ if not (x = 1#i32)
then Result.fail Error.panic
- else
- if not (y = (I32.ofInt 0))
- then Result.fail Error.panic
- else Result.ret ()
+ else if not (y = 0#i32)
+ then Result.fail Error.panic
+ else Result.ret ()
/- Unit test for [paper::test_choose] -/
#assert (test_choose == .ret ())
@@ -63,10 +62,10 @@ inductive List (T : Type) :=
divergent def list_nth_mut (T : Type) (l : List T) (i : U32) : Result T :=
match l with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret x
else do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
list_nth_mut T tl i0
| List.Nil => Result.fail Error.panic
@@ -75,11 +74,11 @@ divergent def list_nth_mut_back
(T : Type) (l : List T) (i : U32) (ret0 : T) : Result (List T) :=
match l with
| List.Cons x tl =>
- if i = (U32.ofInt 0)
+ if i = 0#u32
then Result.ret (List.Cons ret0 tl)
else
do
- let i0 ← i - (U32.ofInt 1)
+ let i0 ← i - 1#u32
let tl0 ← list_nth_mut_back T tl i0 ret0
Result.ret (List.Cons x tl0)
| List.Nil => Result.fail Error.panic
@@ -90,20 +89,19 @@ divergent def sum (l : List I32) : Result I32 :=
| List.Cons x tl => do
let i ← sum tl
x + i
- | List.Nil => Result.ret (I32.ofInt 0)
+ | List.Nil => Result.ret 0#i32
/- [paper::test_nth]: forward function -/
def test_nth : Result Unit :=
do
let l := List.Nil
- let l0 := List.Cons (I32.ofInt 3) l
- let l1 := List.Cons (I32.ofInt 2) l0
- let x ← list_nth_mut I32 (List.Cons (I32.ofInt 1) l1) (U32.ofInt 2)
- let x0 ← x + (I32.ofInt 1)
- let l2 ←
- list_nth_mut_back I32 (List.Cons (I32.ofInt 1) l1) (U32.ofInt 2) x0
+ let l0 := List.Cons 3#i32 l
+ let l1 := List.Cons 2#i32 l0
+ let x ← list_nth_mut I32 (List.Cons 1#i32 l1) 2#u32
+ let x0 ← x + 1#i32
+ let l2 ← list_nth_mut_back I32 (List.Cons 1#i32 l1) 2#u32 x0
let i ← sum l2
- if not (i = (I32.ofInt 7))
+ if not (i = 7#i32)
then Result.fail Error.panic
else Result.ret ()
@@ -115,7 +113,7 @@ def call_choose (p : (U32 × U32)) : Result U32 :=
do
let (px, py) := p
let pz ← choose U32 true px py
- let pz0 ← pz + (U32.ofInt 1)
+ let pz0 ← pz + 1#u32
let (px0, _) ← choose_back U32 true px py pz0
Result.ret px0