From df4d60b71bcabf9897656d6d74157a4c7d8d539c Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 16 May 2023 11:45:43 +0200 Subject: Make good progress on generating code for HOL4 --- tests/coq/betree/BetreeMain_Funs.v | 13 +++-- tests/coq/hashmap/Hashmap_Funs.v | 37 +++++++------- tests/coq/hashmap_on_disk/HashmapMain_Funs.v | 36 +++++++------- tests/coq/misc/Constants.v | 26 +++++----- tests/coq/misc/External_Funs.v | 8 ++-- tests/coq/misc/Loops.v | 18 +++---- tests/coq/misc/NoNestedBorrows.v | 56 ++++++++++------------ tests/coq/misc/Paper.v | 16 +++---- tests/hol4/Holmakefile.template | 3 ++ tests/hol4/Makefile | 39 +++++++++++++++ .../misc-no_nested_borrows/NoNestedBorrows.lean | 5 +- 11 files changed, 148 insertions(+), 109 deletions(-) create mode 100644 tests/hol4/Holmakefile.template create mode 100644 tests/hol4/Makefile (limited to 'tests') diff --git a/tests/coq/betree/BetreeMain_Funs.v b/tests/coq/betree/BetreeMain_Funs.v index dc97a9e9..940b8650 100644 --- a/tests/coq/betree/BetreeMain_Funs.v +++ b/tests/coq/betree/BetreeMain_Funs.v @@ -56,7 +56,7 @@ Definition betree_fresh_node_id_back (counter : u64) : result u64 := (** [betree_main::betree::NodeIdCounter::{0}::new] *) Definition betree_node_id_counter_new_fwd : result Betree_node_id_counter_t := - Return {| Betree_node_id_counter_next_node_id := (0%u64) |} + Return {| Betree_node_id_counter_next_node_id := 0%u64 |} . (** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) @@ -75,7 +75,7 @@ Definition betree_node_id_counter_fresh_id_back (** [core::num::u64::{10}::MAX] *) Definition core_num_u64_max_body : result u64 := - Return (18446744073709551615%u64) + Return 18446744073709551615%u64 . Definition core_num_u64_max_c : u64 := core_num_u64_max_body%global. @@ -86,7 +86,7 @@ Definition betree_upsert_update_fwd | None => match st with | BetreeUpsertFunStateAdd v => Return v - | BetreeUpsertFunStateSub i => Return (0%u64) + | BetreeUpsertFunStateSub i => Return 0%u64 end | Some prev0 => match st with @@ -94,7 +94,7 @@ Definition betree_upsert_update_fwd margin <- u64_sub core_num_u64_max_c prev0; if margin s>= v then u64_add prev0 v else Return core_num_u64_max_c | BetreeUpsertFunStateSub v => - if prev0 s>= v then u64_sub prev0 v else Return (0%u64) + if prev0 s>= v then u64_sub prev0 v else Return 0%u64 end end . @@ -107,7 +107,7 @@ Fixpoint betree_list_len_fwd | S n0 => match self with | BetreeListCons t tl => i <- betree_list_len_fwd T n0 tl; u64_add 1%u64 i - | BetreeListNil => Return (0%u64) + | BetreeListNil => Return 0%u64 end end . @@ -1061,8 +1061,7 @@ Definition betree_be_tree_new_fwd |}; Betree_be_tree_node_id_cnt := node_id_cnt0; Betree_be_tree_root := - (BetreeNodeLeaf - {| Betree_leaf_id := id; Betree_leaf_size := (0%u64) |}) + (BetreeNodeLeaf {| Betree_leaf_id := id; Betree_leaf_size := 0%u64 |}) |}) . diff --git a/tests/coq/hashmap/Hashmap_Funs.v b/tests/coq/hashmap/Hashmap_Funs.v index 1245c654..6bc82677 100644 --- a/tests/coq/hashmap/Hashmap_Funs.v +++ b/tests/coq/hashmap/Hashmap_Funs.v @@ -49,7 +49,7 @@ Definition hash_map_new_with_capacity_fwd i0 <- usize_div i max_load_divisor; Return {| - Hash_map_num_entries := (0%usize); + Hash_map_num_entries := 0%usize; Hash_map_max_load_factor := (max_load_dividend, max_load_divisor); Hash_map_max_load := i0; Hash_map_slots := slots @@ -58,7 +58,7 @@ Definition hash_map_new_with_capacity_fwd (** [hashmap::HashMap::{0}::new] *) Definition hash_map_new_fwd (T : Type) (n : nat) : result (Hash_map_t T) := - hash_map_new_with_capacity_fwd T n (32%usize) (4%usize) (5%usize) + hash_map_new_with_capacity_fwd T n 32%usize 4%usize 5%usize . (** [hashmap::HashMap::{0}::clear] *) @@ -82,10 +82,10 @@ Fixpoint hash_map_clear_loop_fwd_back (** [hashmap::HashMap::{0}::clear] *) Definition hash_map_clear_fwd_back (T : Type) (n : nat) (self : Hash_map_t T) : result (Hash_map_t T) := - v <- hash_map_clear_loop_fwd_back T n self.(Hash_map_slots) (0%usize); + v <- hash_map_clear_loop_fwd_back T n self.(Hash_map_slots) 0%usize; Return {| - Hash_map_num_entries := (0%usize); + Hash_map_num_entries := 0%usize; Hash_map_max_load_factor := self.(Hash_map_max_load_factor); Hash_map_max_load := self.(Hash_map_max_load); Hash_map_slots := v @@ -186,7 +186,7 @@ Definition hash_map_insert_no_resize_fwd_back . (** [core::num::u32::{9}::MAX] *) -Definition core_num_u32_max_body : result u32 := Return (4294967295%u32). +Definition core_num_u32_max_body : result u32 := Return 4294967295%u32. Definition core_num_u32_max_c : u32 := core_num_u32_max_body%global. (** [hashmap::HashMap::{0}::move_elements_from_list] *) @@ -259,8 +259,7 @@ Definition hash_map_try_resize_fwd_back i2 <- usize_mul capacity 2%usize; ntable <- hash_map_new_with_capacity_fwd T n i2 i i0; p <- - hash_map_move_elements_fwd_back T n ntable self.(Hash_map_slots) - (0%usize); + hash_map_move_elements_fwd_back T n ntable self.(Hash_map_slots) 0%usize; let (ntable0, _) := p in Return {| @@ -546,36 +545,36 @@ Definition hash_map_remove_back (** [hashmap::test1] *) Definition test1_fwd (n : nat) : result unit := hm <- hash_map_new_fwd u64 n; - hm0 <- hash_map_insert_fwd_back u64 n hm (0%usize) (42%u64); - hm1 <- hash_map_insert_fwd_back u64 n hm0 (128%usize) (18%u64); - hm2 <- hash_map_insert_fwd_back u64 n hm1 (1024%usize) (138%u64); - hm3 <- hash_map_insert_fwd_back u64 n hm2 (1056%usize) (256%u64); - i <- hash_map_get_fwd u64 n hm3 (128%usize); + hm0 <- hash_map_insert_fwd_back u64 n hm 0%usize 42%u64; + hm1 <- hash_map_insert_fwd_back u64 n hm0 128%usize 18%u64; + hm2 <- hash_map_insert_fwd_back u64 n hm1 1024%usize 138%u64; + hm3 <- hash_map_insert_fwd_back u64 n hm2 1056%usize 256%u64; + i <- hash_map_get_fwd u64 n hm3 128%usize; if negb (i s= 18%u64) then Fail_ Failure else ( - hm4 <- hash_map_get_mut_back u64 n hm3 (1024%usize) (56%u64); - i0 <- hash_map_get_fwd u64 n hm4 (1024%usize); + hm4 <- hash_map_get_mut_back u64 n hm3 1024%usize 56%u64; + i0 <- hash_map_get_fwd u64 n hm4 1024%usize; if negb (i0 s= 56%u64) then Fail_ Failure else ( - x <- hash_map_remove_fwd u64 n hm4 (1024%usize); + x <- hash_map_remove_fwd u64 n hm4 1024%usize; match x with | None => Fail_ Failure | Some x0 => if negb (x0 s= 56%u64) then Fail_ Failure else ( - hm5 <- hash_map_remove_back u64 n hm4 (1024%usize); - i1 <- hash_map_get_fwd u64 n hm5 (0%usize); + hm5 <- hash_map_remove_back u64 n hm4 1024%usize; + i1 <- hash_map_get_fwd u64 n hm5 0%usize; if negb (i1 s= 42%u64) then Fail_ Failure else ( - i2 <- hash_map_get_fwd u64 n hm5 (128%usize); + i2 <- hash_map_get_fwd u64 n hm5 128%usize; if negb (i2 s= 18%u64) then Fail_ Failure else ( - i3 <- hash_map_get_fwd u64 n hm5 (1056%usize); + i3 <- hash_map_get_fwd u64 n hm5 1056%usize; if negb (i3 s= 256%u64) then Fail_ Failure else Return tt))) end)) . diff --git a/tests/coq/hashmap_on_disk/HashmapMain_Funs.v b/tests/coq/hashmap_on_disk/HashmapMain_Funs.v index 804f466a..2d1bcda6 100644 --- a/tests/coq/hashmap_on_disk/HashmapMain_Funs.v +++ b/tests/coq/hashmap_on_disk/HashmapMain_Funs.v @@ -51,7 +51,7 @@ Definition hashmap_hash_map_new_with_capacity_fwd i0 <- usize_div i max_load_divisor; Return {| - Hashmap_hash_map_num_entries := (0%usize); + Hashmap_hash_map_num_entries := 0%usize; Hashmap_hash_map_max_load_factor := (max_load_dividend, max_load_divisor); Hashmap_hash_map_max_load := i0; Hashmap_hash_map_slots := slots @@ -61,7 +61,7 @@ Definition hashmap_hash_map_new_with_capacity_fwd (** [hashmap_main::hashmap::HashMap::{0}::new] *) Definition hashmap_hash_map_new_fwd (T : Type) (n : nat) : result (Hashmap_hash_map_t T) := - hashmap_hash_map_new_with_capacity_fwd T n (32%usize) (4%usize) (5%usize) + hashmap_hash_map_new_with_capacity_fwd T n 32%usize 4%usize 5%usize . (** [hashmap_main::hashmap::HashMap::{0}::clear] *) @@ -89,10 +89,10 @@ Definition hashmap_hash_map_clear_fwd_back := v <- hashmap_hash_map_clear_loop_fwd_back T n self.(Hashmap_hash_map_slots) - (0%usize); + 0%usize; Return {| - Hashmap_hash_map_num_entries := (0%usize); + Hashmap_hash_map_num_entries := 0%usize; Hashmap_hash_map_max_load_factor := self.(Hashmap_hash_map_max_load_factor); Hashmap_hash_map_max_load := self.(Hashmap_hash_map_max_load); @@ -204,7 +204,7 @@ Definition hashmap_hash_map_insert_no_resize_fwd_back . (** [core::num::u32::{9}::MAX] *) -Definition core_num_u32_max_body : result u32 := Return (4294967295%u32). +Definition core_num_u32_max_body : result u32 := Return 4294967295%u32. Definition core_num_u32_max_c : u32 := core_num_u32_max_body%global. (** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] *) @@ -283,7 +283,7 @@ Definition hashmap_hash_map_try_resize_fwd_back ntable <- hashmap_hash_map_new_with_capacity_fwd T n i2 i i0; p <- hashmap_hash_map_move_elements_fwd_back T n ntable - self.(Hashmap_hash_map_slots) (0%usize); + self.(Hashmap_hash_map_slots) 0%usize; let (ntable0, _) := p in Return {| @@ -602,36 +602,36 @@ Definition hashmap_hash_map_remove_back (** [hashmap_main::hashmap::test1] *) Definition hashmap_test1_fwd (n : nat) : result unit := hm <- hashmap_hash_map_new_fwd u64 n; - hm0 <- hashmap_hash_map_insert_fwd_back u64 n hm (0%usize) (42%u64); - hm1 <- hashmap_hash_map_insert_fwd_back u64 n hm0 (128%usize) (18%u64); - hm2 <- hashmap_hash_map_insert_fwd_back u64 n hm1 (1024%usize) (138%u64); - hm3 <- hashmap_hash_map_insert_fwd_back u64 n hm2 (1056%usize) (256%u64); - i <- hashmap_hash_map_get_fwd u64 n hm3 (128%usize); + hm0 <- hashmap_hash_map_insert_fwd_back u64 n hm 0%usize 42%u64; + hm1 <- hashmap_hash_map_insert_fwd_back u64 n hm0 128%usize 18%u64; + hm2 <- hashmap_hash_map_insert_fwd_back u64 n hm1 1024%usize 138%u64; + hm3 <- hashmap_hash_map_insert_fwd_back u64 n hm2 1056%usize 256%u64; + i <- hashmap_hash_map_get_fwd u64 n hm3 128%usize; if negb (i s= 18%u64) then Fail_ Failure else ( - hm4 <- hashmap_hash_map_get_mut_back u64 n hm3 (1024%usize) (56%u64); - i0 <- hashmap_hash_map_get_fwd u64 n hm4 (1024%usize); + hm4 <- hashmap_hash_map_get_mut_back u64 n hm3 1024%usize 56%u64; + i0 <- hashmap_hash_map_get_fwd u64 n hm4 1024%usize; if negb (i0 s= 56%u64) then Fail_ Failure else ( - x <- hashmap_hash_map_remove_fwd u64 n hm4 (1024%usize); + x <- hashmap_hash_map_remove_fwd u64 n hm4 1024%usize; match x with | None => Fail_ Failure | Some x0 => if negb (x0 s= 56%u64) then Fail_ Failure else ( - hm5 <- hashmap_hash_map_remove_back u64 n hm4 (1024%usize); - i1 <- hashmap_hash_map_get_fwd u64 n hm5 (0%usize); + hm5 <- hashmap_hash_map_remove_back u64 n hm4 1024%usize; + i1 <- hashmap_hash_map_get_fwd u64 n hm5 0%usize; if negb (i1 s= 42%u64) then Fail_ Failure else ( - i2 <- hashmap_hash_map_get_fwd u64 n hm5 (128%usize); + i2 <- hashmap_hash_map_get_fwd u64 n hm5 128%usize; if negb (i2 s= 18%u64) then Fail_ Failure else ( - i3 <- hashmap_hash_map_get_fwd u64 n hm5 (1056%usize); + i3 <- hashmap_hash_map_get_fwd u64 n hm5 1056%usize; if negb (i3 s= 256%u64) then Fail_ Failure else Return tt))) end)) . diff --git a/tests/coq/misc/Constants.v b/tests/coq/misc/Constants.v index cd3880c2..6a5f2696 100644 --- a/tests/coq/misc/Constants.v +++ b/tests/coq/misc/Constants.v @@ -7,11 +7,11 @@ Local Open Scope Primitives_scope. Module Constants. (** [constants::X0] *) -Definition x0_body : result u32 := Return (0%u32). +Definition x0_body : result u32 := Return 0%u32. Definition x0_c : u32 := x0_body%global. (** [core::num::u32::{9}::MAX] *) -Definition core_num_u32_max_body : result u32 := Return (4294967295%u32). +Definition core_num_u32_max_body : result u32 := Return 4294967295%u32. Definition core_num_u32_max_c : u32 := core_num_u32_max_body%global. (** [constants::X1] *) @@ -19,7 +19,7 @@ Definition x1_body : result u32 := Return core_num_u32_max_c. Definition x1_c : u32 := x1_body%global. (** [constants::X2] *) -Definition x2_body : result u32 := Return (3%u32). +Definition x2_body : result u32 := Return 3%u32. Definition x2_c : u32 := x2_body%global. (** [constants::incr] *) @@ -27,7 +27,7 @@ Definition incr_fwd (n : u32) : result u32 := u32_add n 1%u32. (** [constants::X3] *) -Definition x3_body : result u32 := incr_fwd (32%u32). +Definition x3_body : result u32 := incr_fwd 32%u32. Definition x3_c : u32 := x3_body%global. (** [constants::mk_pair0] *) @@ -48,11 +48,11 @@ Definition mk_pair1_fwd (x : u32) (y : u32) : result (Pair_t u32 u32) := . (** [constants::P0] *) -Definition p0_body : result (u32 * u32) := mk_pair0_fwd (0%u32) (1%u32). +Definition p0_body : result (u32 * u32) := mk_pair0_fwd 0%u32 1%u32. Definition p0_c : (u32 * u32) := p0_body%global. (** [constants::P1] *) -Definition p1_body : result (Pair_t u32 u32) := mk_pair1_fwd (0%u32) (1%u32). +Definition p1_body : result (Pair_t u32 u32) := mk_pair1_fwd 0%u32 1%u32. Definition p1_c : Pair_t u32 u32 := p1_body%global. (** [constants::P2] *) @@ -61,7 +61,7 @@ Definition p2_c : (u32 * u32) := p2_body%global. (** [constants::P3] *) Definition p3_body : result (Pair_t u32 u32) := - Return {| Pair_x := (0%u32); Pair_y := (1%u32) |} + Return {| Pair_x := 0%u32; Pair_y := 1%u32 |} . Definition p3_c : Pair_t u32 u32 := p3_body%global. @@ -77,7 +77,7 @@ Definition wrap_new_fwd (T : Type) (val : T) : result (Wrap_t T) := . (** [constants::Y] *) -Definition y_body : result (Wrap_t i32) := wrap_new_fwd i32 (2%i32). +Definition y_body : result (Wrap_t i32) := wrap_new_fwd i32 2%i32. Definition y_c : Wrap_t i32 := y_body%global. (** [constants::unwrap_y] *) @@ -89,7 +89,7 @@ Definition yval_body : result i32 := unwrap_y_fwd. Definition yval_c : i32 := yval_body%global. (** [constants::get_z1::Z1] *) -Definition get_z1_z1_body : result i32 := Return (3%i32). +Definition get_z1_z1_body : result i32 := Return 3%i32. Definition get_z1_z1_c : i32 := get_z1_z1_body%global. (** [constants::get_z1] *) @@ -101,7 +101,7 @@ Definition add_fwd (a : i32) (b : i32) : result i32 := i32_add a b. (** [constants::Q1] *) -Definition q1_body : result i32 := Return (5%i32). +Definition q1_body : result i32 := Return 5%i32. Definition q1_c : i32 := q1_body%global. (** [constants::Q2] *) @@ -109,7 +109,7 @@ Definition q2_body : result i32 := Return q1_c. Definition q2_c : i32 := q2_body%global. (** [constants::Q3] *) -Definition q3_body : result i32 := add_fwd q2_c (3%i32). +Definition q3_body : result i32 := add_fwd q2_c 3%i32. Definition q3_c : i32 := q3_body%global. (** [constants::get_z2] *) @@ -118,7 +118,7 @@ Definition get_z2_fwd : result i32 := . (** [constants::S1] *) -Definition s1_body : result u32 := Return (6%u32). +Definition s1_body : result u32 := Return 6%u32. Definition s1_c : u32 := s1_body%global. (** [constants::S2] *) @@ -130,7 +130,7 @@ Definition s3_body : result (Pair_t u32 u32) := Return p3_c. Definition s3_c : Pair_t u32 u32 := s3_body%global. (** [constants::S4] *) -Definition s4_body : result (Pair_t u32 u32) := mk_pair1_fwd (7%u32) (8%u32). +Definition s4_body : result (Pair_t u32 u32) := mk_pair1_fwd 7%u32 8%u32. Definition s4_c : Pair_t u32 u32 := s4_body%global. End Constants . diff --git a/tests/coq/misc/External_Funs.v b/tests/coq/misc/External_Funs.v index b5476f25..05dd8f2e 100644 --- a/tests/coq/misc/External_Funs.v +++ b/tests/coq/misc/External_Funs.v @@ -46,7 +46,7 @@ Definition test_new_non_zero_u32_fwd (** [external::test_vec] *) Definition test_vec_fwd : result unit := - let v := vec_new u32 in _ <- vec_push_back u32 v (0%u32); Return tt + let v := vec_new u32 in _ <- vec_push_back u32 v 0%u32; Return tt . (** Unit test for [external::test_vec] *) @@ -89,15 +89,15 @@ Definition test_custom_swap_back (x : u32) (y : u32) (st : state) (st0 : state) : result (state * (u32 * u32)) := - custom_swap_back u32 x y st (1%u32) st0 + custom_swap_back u32 x y st 1%u32 st0 . (** [external::test_swap_non_zero] *) Definition test_swap_non_zero_fwd (x : u32) (st : state) : result (state * u32) := - p <- swap_fwd u32 x (0%u32) st; + p <- swap_fwd u32 x 0%u32 st; let (st0, _) := p in - p0 <- swap_back u32 x (0%u32) st st0; + p0 <- swap_back u32 x 0%u32 st st0; let (st1, p1) := p0 in let (x0, _) := p1 in if x0 s= 0%u32 then Fail_ Failure else Return (st1, x0) diff --git a/tests/coq/misc/Loops.v b/tests/coq/misc/Loops.v index bcbfc8df..a5cb3688 100644 --- a/tests/coq/misc/Loops.v +++ b/tests/coq/misc/Loops.v @@ -19,7 +19,7 @@ Fixpoint sum_loop_fwd (n : nat) (max : u32) (i : u32) (s : u32) : result u32 := (** [loops::sum] *) Definition sum_fwd (n : nat) (max : u32) : result u32 := - sum_loop_fwd n max (0%u32) (0%u32) + sum_loop_fwd n max 0%u32 0%u32 . (** [loops::sum_with_mut_borrows] *) @@ -39,7 +39,7 @@ Fixpoint sum_with_mut_borrows_loop_fwd (** [loops::sum_with_mut_borrows] *) Definition sum_with_mut_borrows_fwd (n : nat) (max : u32) : result u32 := - sum_with_mut_borrows_loop_fwd n max (0%u32) (0%u32) + sum_with_mut_borrows_loop_fwd n max 0%u32 0%u32 . (** [loops::sum_with_shared_borrows] *) @@ -59,7 +59,7 @@ Fixpoint sum_with_shared_borrows_loop_fwd (** [loops::sum_with_shared_borrows] *) Definition sum_with_shared_borrows_fwd (n : nat) (max : u32) : result u32 := - sum_with_shared_borrows_loop_fwd n max (0%u32) (0%u32) + sum_with_shared_borrows_loop_fwd n max 0%u32 0%u32 . (** [loops::clear] *) @@ -72,7 +72,7 @@ Fixpoint clear_loop_fwd_back if i s< i0 then ( i1 <- usize_add i 1%usize; - v0 <- vec_index_mut_back u32 v i (0%u32); + v0 <- vec_index_mut_back u32 v i 0%u32; clear_loop_fwd_back n0 v0 i1) else Return v end @@ -80,7 +80,7 @@ Fixpoint clear_loop_fwd_back (** [loops::clear] *) Definition clear_fwd_back (n : nat) (v : vec u32) : result (vec u32) := - clear_loop_fwd_back n v (0%usize) + clear_loop_fwd_back n v 0%usize . (** [loops::List] *) @@ -201,7 +201,7 @@ Fixpoint get_elem_mut_loop_fwd (** [loops::get_elem_mut] *) Definition get_elem_mut_fwd (n : nat) (slots : vec (List_t usize)) (x : usize) : result usize := - l <- vec_index_mut_fwd (List_t usize) slots (0%usize); + l <- vec_index_mut_fwd (List_t usize) slots 0%usize; get_elem_mut_loop_fwd n x l . @@ -228,9 +228,9 @@ Definition get_elem_mut_back (n : nat) (slots : vec (List_t usize)) (x : usize) (ret : usize) : result (vec (List_t usize)) := - l <- vec_index_mut_fwd (List_t usize) slots (0%usize); + l <- vec_index_mut_fwd (List_t usize) slots 0%usize; l0 <- get_elem_mut_loop_back n x l ret; - vec_index_mut_back (List_t usize) slots (0%usize) l0 + vec_index_mut_back (List_t usize) slots 0%usize l0 . (** [loops::get_elem_shared] *) @@ -250,7 +250,7 @@ Fixpoint get_elem_shared_loop_fwd (** [loops::get_elem_shared] *) Definition get_elem_shared_fwd (n : nat) (slots : vec (List_t usize)) (x : usize) : result usize := - l <- vec_index_fwd (List_t usize) slots (0%usize); + l <- vec_index_fwd (List_t usize) slots 0%usize; get_elem_shared_loop_fwd n x l . diff --git a/tests/coq/misc/NoNestedBorrows.v b/tests/coq/misc/NoNestedBorrows.v index 826b52b6..96d62711 100644 --- a/tests/coq/misc/NoNestedBorrows.v +++ b/tests/coq/misc/NoNestedBorrows.v @@ -87,8 +87,8 @@ Definition get_max_fwd (x : u32) (y : u32) : result u32 := (** [no_nested_borrows::test3] *) Definition test3_fwd : result unit := - x <- get_max_fwd (4%u32) (3%u32); - y <- get_max_fwd (10%u32) (11%u32); + x <- get_max_fwd 4%u32 3%u32; + y <- get_max_fwd 10%u32 11%u32; z <- u32_add x y; if negb (z s= 15%u32) then Fail_ Failure else Return tt . @@ -98,8 +98,7 @@ Check (test3_fwd )%return. (** [no_nested_borrows::test_neg1] *) Definition test_neg1_fwd : result unit := - y <- i32_neg (3%i32); - if negb (y s= (-3)%i32) then Fail_ Failure else Return tt + y <- i32_neg 3%i32; if negb (y s= (-3)%i32) then Fail_ Failure else Return tt . (** Unit test for [no_nested_borrows::test_neg1] *) @@ -162,7 +161,7 @@ Definition test_panic_fwd (b : bool) : result unit := (** [no_nested_borrows::test_copy_int] *) Definition test_copy_int_fwd : result unit := - y <- copy_int_fwd (0%i32); + y <- copy_int_fwd 0%i32; if negb (0%i32 s= y) then Fail_ Failure else Return tt . @@ -177,7 +176,7 @@ Definition is_cons_fwd (T : Type) (l : List_t T) : result bool := (** [no_nested_borrows::test_is_cons] *) Definition test_is_cons_fwd : result unit := let l := ListNil in - b <- is_cons_fwd i32 (ListCons (0%i32) l); + b <- is_cons_fwd i32 (ListCons 0%i32 l); if negb b then Fail_ Failure else Return tt . @@ -196,7 +195,7 @@ Definition split_list_fwd (** [no_nested_borrows::test_split_list] *) Definition test_split_list_fwd : result unit := let l := ListNil in - p <- split_list_fwd i32 (ListCons (0%i32) l); + p <- split_list_fwd i32 (ListCons 0%i32 l); let (hd, _) := p in if negb (hd s= 0%i32) then Fail_ Failure else Return tt . @@ -217,12 +216,12 @@ Definition choose_back (** [no_nested_borrows::choose_test] *) Definition choose_test_fwd : result unit := - z <- choose_fwd i32 true (0%i32) (0%i32); + z <- choose_fwd i32 true 0%i32 0%i32; z0 <- i32_add z 1%i32; if negb (z0 s= 1%i32) then Fail_ Failure else ( - p <- choose_back i32 true (0%i32) (0%i32) z0; + p <- choose_back i32 true 0%i32 0%i32 z0; let (x, y) := p in if negb (x s= 1%i32) then Fail_ Failure @@ -258,7 +257,7 @@ Arguments TreeNode {T} _ _ _. Fixpoint list_length_fwd (T : Type) (l : List_t T) : result u32 := match l with | ListCons t l1 => i <- list_length_fwd T l1; u32_add 1%u32 i - | ListNil => Return (0%u32) + | ListNil => Return 0%u32 end . @@ -317,34 +316,34 @@ Definition list_rev_fwd_back (T : Type) (l : List_t T) : result (List_t T) := (** [no_nested_borrows::test_list_functions] *) Definition test_list_functions_fwd : result unit := let l := ListNil in - let l0 := ListCons (2%i32) l in - let l1 := ListCons (1%i32) l0 in - i <- list_length_fwd i32 (ListCons (0%i32) l1); + let l0 := ListCons 2%i32 l in + let l1 := ListCons 1%i32 l0 in + i <- list_length_fwd i32 (ListCons 0%i32 l1); if negb (i s= 3%u32) then Fail_ Failure else ( - i0 <- list_nth_shared_fwd i32 (ListCons (0%i32) l1) (0%u32); + i0 <- list_nth_shared_fwd i32 (ListCons 0%i32 l1) 0%u32; if negb (i0 s= 0%i32) then Fail_ Failure else ( - i1 <- list_nth_shared_fwd i32 (ListCons (0%i32) l1) (1%u32); + i1 <- list_nth_shared_fwd i32 (ListCons 0%i32 l1) 1%u32; if negb (i1 s= 1%i32) then Fail_ Failure else ( - i2 <- list_nth_shared_fwd i32 (ListCons (0%i32) l1) (2%u32); + i2 <- list_nth_shared_fwd i32 (ListCons 0%i32 l1) 2%u32; if negb (i2 s= 2%i32) then Fail_ Failure else ( - ls <- list_nth_mut_back i32 (ListCons (0%i32) l1) (1%u32) (3%i32); - i3 <- list_nth_shared_fwd i32 ls (0%u32); + ls <- list_nth_mut_back i32 (ListCons 0%i32 l1) 1%u32 3%i32; + i3 <- list_nth_shared_fwd i32 ls 0%u32; if negb (i3 s= 0%i32) then Fail_ Failure else ( - i4 <- list_nth_shared_fwd i32 ls (1%u32); + i4 <- list_nth_shared_fwd i32 ls 1%u32; if negb (i4 s= 3%i32) then Fail_ Failure else ( - i5 <- list_nth_shared_fwd i32 ls (2%u32); + i5 <- list_nth_shared_fwd i32 ls 2%u32; if negb (i5 s= 2%i32) then Fail_ Failure else Return tt)))))) . @@ -448,7 +447,7 @@ Arguments Struct_with_pair_p {T1} {T2}. (** [no_nested_borrows::new_pair1] *) Definition new_pair1_fwd : result (Struct_with_pair_t u32 u32) := - Return {| Struct_with_pair_p := {| Pair_x := (1%u32); Pair_y := (2%u32) |} |} + Return {| Struct_with_pair_p := {| Pair_x := 1%u32; Pair_y := 2%u32 |} |} . (** [no_nested_borrows::test_constants] *) @@ -486,29 +485,26 @@ Check (test_weird_borrows1_fwd )%return. (** [no_nested_borrows::test_mem_replace] *) Definition test_mem_replace_fwd_back (px : u32) : result u32 := - let y := mem_replace_fwd u32 px (1%u32) in - if negb (y s= 0%u32) then Fail_ Failure else Return (2%u32) + let y := mem_replace_fwd u32 px 1%u32 in + if negb (y s= 0%u32) then Fail_ Failure else Return 2%u32 . (** [no_nested_borrows::test_shared_borrow_bool1] *) Definition test_shared_borrow_bool1_fwd (b : bool) : result u32 := - if b then Return (0%u32) else Return (1%u32) + if b then Return 0%u32 else Return 1%u32 . (** [no_nested_borrows::test_shared_borrow_bool2] *) Definition test_shared_borrow_bool2_fwd : result u32 := - Return (0%u32). + Return 0%u32. (** [no_nested_borrows::test_shared_borrow_enum1] *) Definition test_shared_borrow_enum1_fwd (l : List_t u32) : result u32 := - match l with - | ListCons i l0 => Return (1%u32) - | ListNil => Return (0%u32) - end + match l with | ListCons i l0 => Return 1%u32 | ListNil => Return 0%u32 end . (** [no_nested_borrows::test_shared_borrow_enum2] *) Definition test_shared_borrow_enum2_fwd : result u32 := - Return (0%u32). + Return 0%u32. End NoNestedBorrows . diff --git a/tests/coq/misc/Paper.v b/tests/coq/misc/Paper.v index 8045222d..513bc749 100644 --- a/tests/coq/misc/Paper.v +++ b/tests/coq/misc/Paper.v @@ -12,7 +12,7 @@ Definition ref_incr_fwd_back (x : i32) : result i32 := (** [paper::test_incr] *) Definition test_incr_fwd : result unit := - x <- ref_incr_fwd_back (0%i32); + x <- ref_incr_fwd_back 0%i32; if negb (x s= 1%i32) then Fail_ Failure else Return tt . @@ -32,12 +32,12 @@ Definition choose_back (** [paper::test_choose] *) Definition test_choose_fwd : result unit := - z <- choose_fwd i32 true (0%i32) (0%i32); + z <- choose_fwd i32 true 0%i32 0%i32; z0 <- i32_add z 1%i32; if negb (z0 s= 1%i32) then Fail_ Failure else ( - p <- choose_back i32 true (0%i32) (0%i32) z0; + p <- choose_back i32 true 0%i32 0%i32 z0; let (x, y) := p in if negb (x s= 1%i32) then Fail_ Failure @@ -86,18 +86,18 @@ Fixpoint list_nth_mut_back Fixpoint sum_fwd (l : List_t i32) : result i32 := match l with | ListCons x tl => i <- sum_fwd tl; i32_add x i - | ListNil => Return (0%i32) + | ListNil => Return 0%i32 end . (** [paper::test_nth] *) Definition test_nth_fwd : result unit := let l := ListNil in - let l0 := ListCons (3%i32) l in - let l1 := ListCons (2%i32) l0 in - x <- list_nth_mut_fwd i32 (ListCons (1%i32) l1) (2%u32); + let l0 := ListCons 3%i32 l in + let l1 := ListCons 2%i32 l0 in + x <- list_nth_mut_fwd i32 (ListCons 1%i32 l1) 2%u32; x0 <- i32_add x 1%i32; - l2 <- list_nth_mut_back i32 (ListCons (1%i32) l1) (2%u32) x0; + l2 <- list_nth_mut_back i32 (ListCons 1%i32 l1) 2%u32 x0; i <- sum_fwd l2; if negb (i s= 7%i32) then Fail_ Failure else Return tt . diff --git a/tests/hol4/Holmakefile.template b/tests/hol4/Holmakefile.template new file mode 100644 index 00000000..c86fad70 --- /dev/null +++ b/tests/hol4/Holmakefile.template @@ -0,0 +1,3 @@ + +all: $(DEFAULT_TARGETS) +.PHONY: all diff --git a/tests/hol4/Makefile b/tests/hol4/Makefile new file mode 100644 index 00000000..fa2c5512 --- /dev/null +++ b/tests/hol4/Makefile @@ -0,0 +1,39 @@ +ALL_DIRS ?= $(filter-out %~ Makefile% Holmakefile%, $(wildcard *)) + +UPDATE_DIRS = $(addprefix update-,$(ALL_DIRS)) + +VERIFY_DIRS = $(addprefix verif-,$(ALL_DIRS)) + +CLEAN_DIRS = $(addprefix clean-,$(ALL_DIRS)) + +COPY_HOLMAKEFILE = $(addprefix copy-holmakefile-,$(ALL_DIRS)) + +# This allows to customize the INCLUDES variable of the Holmakefile - useful for Nix +HOLMAKEFILE_INCLUDES ?= ../../../backends/hol4 + +.PHONY: all +all: prepare-projects verify + +.PHONY: prepare-projects +prepare-projects: $(COPY_HOLMAKEFILE) + +.PHONY: prepare-projects +copy-holmakefile-%: + rm -f $*/Holmakefile + echo "# This file was automatically generated - modify ../Holmakefile.template instead" >> $*/Holmakefile + echo "INCLUDES = " $(HOLMAKEFILE_INCLUDES) >> $*/Holmakefile + cat Holmakefile.template >> $*/Holmakefile + +.PHONY: verify +verify: $(VERIFY_DIRS) + +.PHONY: verif-% +verif-%: + cd $* && Holmake + +.PHONY: clean +clean: $(CLEAN_DIRS) + +.PHONY: clean-% +clean-%: + cd $* && Holmake clean diff --git a/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean b/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean index a73848de..12c7d8f7 100644 --- a/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean +++ b/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean @@ -249,8 +249,10 @@ def choose_test_fwd : Result Unit := def test_char_fwd : Result Char := Result.ret 'a' +mutual + /- [no_nested_borrows::NodeElem] -/ -mutual inductive node_elem_t (T : Type) := +inductive node_elem_t (T : Type) := | Cons : tree_t T -> node_elem_t T -> node_elem_t T | Nil : node_elem_t T @@ -258,6 +260,7 @@ mutual inductive node_elem_t (T : Type) := inductive tree_t (T : Type) := | Leaf : T -> tree_t T | Node : T -> node_elem_t T -> tree_t T -> tree_t T + end /- [no_nested_borrows::list_length] -/ -- cgit v1.2.3