summaryrefslogtreecommitdiff
path: root/tests/coq/misc/Paper.v
diff options
context:
space:
mode:
authorSon HO2023-12-23 01:46:58 +0100
committerGitHub2023-12-23 01:46:58 +0100
commit15a7d7b7322a1cd0ebeb328fde214060e23fa8b4 (patch)
tree6cce7d76969870f5bc18c5a7cd585e8873a1c0dc /tests/coq/misc/Paper.v
parentc3e0b90e422cbd902ee6d2b47073940c0017b7fb (diff)
parent63ccbd914d5d44aa30dee38a6fcc019310ab640b (diff)
Merge pull request #64 from AeneasVerif/son/merge_back
Merge the forward/backward functions
Diffstat (limited to '')
-rw-r--r--tests/coq/misc/Paper.v99
1 files changed, 46 insertions, 53 deletions
diff --git a/tests/coq/misc/Paper.v b/tests/coq/misc/Paper.v
index 6b110193..769cf34c 100644
--- a/tests/coq/misc/Paper.v
+++ b/tests/coq/misc/Paper.v
@@ -8,44 +8,40 @@ Import ListNotations.
Local Open Scope Primitives_scope.
Module Paper.
-(** [paper::ref_incr]: merged forward/backward function
- (there is a single backward function, and the forward function returns ())
+(** [paper::ref_incr]:
Source: 'src/paper.rs', lines 4:0-4:28 *)
Definition ref_incr (x : i32) : result i32 :=
i32_add x 1%i32.
-(** [paper::test_incr]: forward function
+(** [paper::test_incr]:
Source: 'src/paper.rs', lines 8:0-8:18 *)
Definition test_incr : result unit :=
- x <- ref_incr 0%i32; if negb (x s= 1%i32) then Fail_ Failure else Return tt
+ i <- ref_incr 0%i32; if negb (i s= 1%i32) then Fail_ Failure else Return tt
.
(** Unit test for [paper::test_incr] *)
Check (test_incr )%return.
-(** [paper::choose]: forward function
+(** [paper::choose]:
Source: 'src/paper.rs', lines 15:0-15:70 *)
-Definition choose (T : Type) (b : bool) (x : T) (y : T) : result T :=
- if b then Return x else Return y
+Definition choose
+ (T : Type) (b : bool) (x : T) (y : T) : result (T * (T -> result (T * T))) :=
+ if b
+ then let back_'a := fun (ret : T) => Return (ret, y) in Return (x, back_'a)
+ else let back_'a := fun (ret : T) => Return (x, ret) in Return (y, back_'a)
.
-(** [paper::choose]: backward function 0
- Source: 'src/paper.rs', lines 15:0-15:70 *)
-Definition choose_back
- (T : Type) (b : bool) (x : T) (y : T) (ret : T) : result (T * T) :=
- if b then Return (ret, y) else Return (x, ret)
-.
-
-(** [paper::test_choose]: forward function
+(** [paper::test_choose]:
Source: 'src/paper.rs', lines 23:0-23:20 *)
Definition test_choose : result unit :=
- z <- choose i32 true 0%i32 0%i32;
- z0 <- i32_add z 1%i32;
- if negb (z0 s= 1%i32)
+ p <- choose i32 true 0%i32 0%i32;
+ let (z, choose_back) := p in
+ z1 <- i32_add z 1%i32;
+ if negb (z1 s= 1%i32)
then Fail_ Failure
else (
- p <- choose_back i32 true 0%i32 0%i32 z0;
- let (x, y) := p in
+ p1 <- choose_back z1;
+ let (x, y) := p1 in
if negb (x s= 1%i32)
then Fail_ Failure
else if negb (y s= 0%i32) then Fail_ Failure else Return tt)
@@ -64,35 +60,31 @@ Inductive List_t (T : Type) :=
Arguments List_Cons { _ }.
Arguments List_Nil { _ }.
-(** [paper::list_nth_mut]: forward function
- Source: 'src/paper.rs', lines 42:0-42:67 *)
-Fixpoint list_nth_mut (T : Type) (l : List_t T) (i : u32) : result T :=
- match l with
- | List_Cons x tl =>
- if i s= 0%u32
- then Return x
- else (i0 <- u32_sub i 1%u32; list_nth_mut T tl i0)
- | List_Nil => Fail_ Failure
- end
-.
-
-(** [paper::list_nth_mut]: backward function 0
+(** [paper::list_nth_mut]:
Source: 'src/paper.rs', lines 42:0-42:67 *)
-Fixpoint list_nth_mut_back
- (T : Type) (l : List_t T) (i : u32) (ret : T) : result (List_t T) :=
+Fixpoint list_nth_mut
+ (T : Type) (l : List_t T) (i : u32) :
+ result (T * (T -> result (List_t T)))
+ :=
match l with
| List_Cons x tl =>
if i s= 0%u32
- then Return (List_Cons ret tl)
+ then
+ let back_'a := fun (ret : T) => Return (List_Cons ret tl) in
+ Return (x, back_'a)
else (
- i0 <- u32_sub i 1%u32;
- tl0 <- list_nth_mut_back T tl i0 ret;
- Return (List_Cons x tl0))
+ i1 <- u32_sub i 1%u32;
+ p <- list_nth_mut T tl i1;
+ let (t, list_nth_mut_back) := p in
+ let back_'a :=
+ fun (ret : T) => tl1 <- list_nth_mut_back ret; Return (List_Cons x tl1)
+ in
+ Return (t, back_'a))
| List_Nil => Fail_ Failure
end
.
-(** [paper::sum]: forward function
+(** [paper::sum]:
Source: 'src/paper.rs', lines 57:0-57:32 *)
Fixpoint sum (l : List_t i32) : result i32 :=
match l with
@@ -101,15 +93,15 @@ Fixpoint sum (l : List_t i32) : result i32 :=
end
.
-(** [paper::test_nth]: forward function
+(** [paper::test_nth]:
Source: 'src/paper.rs', lines 68:0-68:17 *)
Definition test_nth : result unit :=
- let l := List_Nil in
- let l0 := List_Cons 3%i32 l in
- let l1 := List_Cons 2%i32 l0 in
- x <- list_nth_mut i32 (List_Cons 1%i32 l1) 2%u32;
- x0 <- i32_add x 1%i32;
- l2 <- list_nth_mut_back i32 (List_Cons 1%i32 l1) 2%u32 x0;
+ let l := List_Cons 3%i32 List_Nil in
+ let l1 := List_Cons 2%i32 l in
+ p <- list_nth_mut i32 (List_Cons 1%i32 l1) 2%u32;
+ let (x, list_nth_mut_back) := p in
+ x1 <- i32_add x 1%i32;
+ l2 <- list_nth_mut_back x1;
i <- sum l2;
if negb (i s= 7%i32) then Fail_ Failure else Return tt
.
@@ -117,15 +109,16 @@ Definition test_nth : result unit :=
(** Unit test for [paper::test_nth] *)
Check (test_nth )%return.
-(** [paper::call_choose]: forward function
+(** [paper::call_choose]:
Source: 'src/paper.rs', lines 76:0-76:44 *)
Definition call_choose (p : (u32 * u32)) : result u32 :=
let (px, py) := p in
- pz <- choose u32 true px py;
- pz0 <- u32_add pz 1%u32;
- p0 <- choose_back u32 true px py pz0;
- let (px0, _) := p0 in
- Return px0
+ p1 <- choose u32 true px py;
+ let (pz, choose_back) := p1 in
+ pz1 <- u32_add pz 1%u32;
+ p2 <- choose_back pz1;
+ let (px1, _) := p2 in
+ Return px1
.
End Paper.