diff options
author | Son HO | 2023-07-31 16:15:58 +0200 |
---|---|---|
committer | GitHub | 2023-07-31 16:15:58 +0200 |
commit | 887d0ef1efc8912c6273b5ebcf979384e9d7fa97 (patch) | |
tree | 92d6021eb549f7cc25501856edd58859786b7e90 /tests | |
parent | 53adf30fe440eb8b6f58ba89f4a4c0acc7877498 (diff) | |
parent | 9b3a58e423333fc9a4a5a264c3beb0a3d951e86b (diff) |
Merge pull request #31 from AeneasVerif/son_lean_backend
Improve the Lean backend
Diffstat (limited to '')
128 files changed, 5350 insertions, 9615 deletions
diff --git a/tests/coq/betree/BetreeMain_Funs.v b/tests/coq/betree/BetreeMain_Funs.v index 940b8650..86a9d5f2 100644 --- a/tests/coq/betree/BetreeMain_Funs.v +++ b/tests/coq/betree/BetreeMain_Funs.v @@ -10,7 +10,7 @@ Require Export BetreeMain_Opaque. Import BetreeMain_Opaque. Module BetreeMain_Funs. -(** [betree_main::betree::load_internal_node] *) +(** [betree_main::betree::load_internal_node]: forward function *) Definition betree_load_internal_node_fwd (id : u64) (st : state) : result (state * (Betree_list_t (u64 * Betree_message_t))) @@ -18,7 +18,7 @@ Definition betree_load_internal_node_fwd betree_utils_load_internal_node_fwd id st . -(** [betree_main::betree::store_internal_node] *) +(** [betree_main::betree::store_internal_node]: forward function *) Definition betree_store_internal_node_fwd (id : u64) (content : Betree_list_t (u64 * Betree_message_t)) (st : state) : result (state * unit) @@ -28,13 +28,13 @@ Definition betree_store_internal_node_fwd Return (st0, tt) . -(** [betree_main::betree::load_leaf_node] *) +(** [betree_main::betree::load_leaf_node]: forward function *) Definition betree_load_leaf_node_fwd (id : u64) (st : state) : result (state * (Betree_list_t (u64 * u64))) := betree_utils_load_leaf_node_fwd id st . -(** [betree_main::betree::store_leaf_node] *) +(** [betree_main::betree::store_leaf_node]: forward function *) Definition betree_store_leaf_node_fwd (id : u64) (content : Betree_list_t (u64 * u64)) (st : state) : result (state * unit) @@ -44,29 +44,29 @@ Definition betree_store_leaf_node_fwd Return (st0, tt) . -(** [betree_main::betree::fresh_node_id] *) +(** [betree_main::betree::fresh_node_id]: forward function *) Definition betree_fresh_node_id_fwd (counter : u64) : result u64 := _ <- u64_add counter 1%u64; Return counter . -(** [betree_main::betree::fresh_node_id] *) +(** [betree_main::betree::fresh_node_id]: backward function 0 *) Definition betree_fresh_node_id_back (counter : u64) : result u64 := u64_add counter 1%u64 . -(** [betree_main::betree::NodeIdCounter::{0}::new] *) +(** [betree_main::betree::NodeIdCounter::{0}::new]: forward function *) Definition betree_node_id_counter_new_fwd : result Betree_node_id_counter_t := Return {| Betree_node_id_counter_next_node_id := 0%u64 |} . -(** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) +(** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function *) Definition betree_node_id_counter_fresh_id_fwd (self : Betree_node_id_counter_t) : result u64 := _ <- u64_add self.(Betree_node_id_counter_next_node_id) 1%u64; Return self.(Betree_node_id_counter_next_node_id) . -(** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) +(** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 *) Definition betree_node_id_counter_fresh_id_back (self : Betree_node_id_counter_t) : result Betree_node_id_counter_t := i <- u64_add self.(Betree_node_id_counter_next_node_id) 1%u64; @@ -79,7 +79,7 @@ Definition core_num_u64_max_body : result u64 := . Definition core_num_u64_max_c : u64 := core_num_u64_max_body%global. -(** [betree_main::betree::upsert_update] *) +(** [betree_main::betree::upsert_update]: forward function *) Definition betree_upsert_update_fwd (prev : option u64) (st : Betree_upsert_fun_state_t) : result u64 := match prev with @@ -99,7 +99,7 @@ Definition betree_upsert_update_fwd end . -(** [betree_main::betree::List::{1}::len] *) +(** [betree_main::betree::List::{1}::len]: forward function *) Fixpoint betree_list_len_fwd (T : Type) (n : nat) (self : Betree_list_t T) : result u64 := match n with @@ -112,7 +112,7 @@ Fixpoint betree_list_len_fwd end . -(** [betree_main::betree::List::{1}::split_at] *) +(** [betree_main::betree::List::{1}::split_at]: forward function *) Fixpoint betree_list_split_at_fwd (T : Type) (n : nat) (self : Betree_list_t T) (n0 : u64) : result ((Betree_list_t T) * (Betree_list_t T)) @@ -135,7 +135,8 @@ Fixpoint betree_list_split_at_fwd end . -(** [betree_main::betree::List::{1}::push_front] *) +(** [betree_main::betree::List::{1}::push_front]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition betree_list_push_front_fwd_back (T : Type) (self : Betree_list_t T) (x : T) : result (Betree_list_t T) := let tl := mem_replace_fwd (Betree_list_t T) self BetreeListNil in @@ -143,7 +144,7 @@ Definition betree_list_push_front_fwd_back Return (BetreeListCons x l) . -(** [betree_main::betree::List::{1}::pop_front] *) +(** [betree_main::betree::List::{1}::pop_front]: forward function *) Definition betree_list_pop_front_fwd (T : Type) (self : Betree_list_t T) : result T := let ls := mem_replace_fwd (Betree_list_t T) self BetreeListNil in @@ -153,7 +154,7 @@ Definition betree_list_pop_front_fwd end . -(** [betree_main::betree::List::{1}::pop_front] *) +(** [betree_main::betree::List::{1}::pop_front]: backward function 0 *) Definition betree_list_pop_front_back (T : Type) (self : Betree_list_t T) : result (Betree_list_t T) := let ls := mem_replace_fwd (Betree_list_t T) self BetreeListNil in @@ -163,7 +164,7 @@ Definition betree_list_pop_front_back end . -(** [betree_main::betree::List::{1}::hd] *) +(** [betree_main::betree::List::{1}::hd]: forward function *) Definition betree_list_hd_fwd (T : Type) (self : Betree_list_t T) : result T := match self with | BetreeListCons hd l => Return hd @@ -171,7 +172,7 @@ Definition betree_list_hd_fwd (T : Type) (self : Betree_list_t T) : result T := end . -(** [betree_main::betree::List::{2}::head_has_key] *) +(** [betree_main::betree::List::{2}::head_has_key]: forward function *) Definition betree_list_head_has_key_fwd (T : Type) (self : Betree_list_t (u64 * T)) (key : u64) : result bool := match self with @@ -180,7 +181,7 @@ Definition betree_list_head_has_key_fwd end . -(** [betree_main::betree::List::{2}::partition_at_pivot] *) +(** [betree_main::betree::List::{2}::partition_at_pivot]: forward function *) Fixpoint betree_list_partition_at_pivot_fwd (T : Type) (n : nat) (self : Betree_list_t (u64 * T)) (pivot : u64) : result ((Betree_list_t (u64 * T)) * (Betree_list_t (u64 * T))) @@ -203,7 +204,7 @@ Fixpoint betree_list_partition_at_pivot_fwd end . -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: forward function *) Definition betree_leaf_split_fwd (n : nat) (self : Betree_leaf_t) (content : Betree_list_t (u64 * u64)) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) @@ -236,7 +237,7 @@ Definition betree_leaf_split_fwd Return (st1, mkBetree_internal_t self.(Betree_leaf_id) pivot n0 n1) . -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: backward function 2 *) Definition betree_leaf_split_back (n : nat) (self : Betree_leaf_t) (content : Betree_list_t (u64 * u64)) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) @@ -257,7 +258,7 @@ Definition betree_leaf_split_back betree_node_id_counter_fresh_id_back node_id_cnt0 . -(** [betree_main::betree::Node::{5}::lookup_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_in_bindings]: forward function *) Fixpoint betree_node_lookup_in_bindings_fwd (n : nat) (key : u64) (bindings : Betree_list_t (u64 * u64)) : result (option u64) @@ -279,7 +280,7 @@ Fixpoint betree_node_lookup_in_bindings_fwd end . -(** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: forward function *) Fixpoint betree_node_lookup_first_message_for_key_fwd (n : nat) (key : u64) (msgs : Betree_list_t (u64 * Betree_message_t)) : result (Betree_list_t (u64 * Betree_message_t)) @@ -298,7 +299,7 @@ Fixpoint betree_node_lookup_first_message_for_key_fwd end . -(** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: backward function 0 *) Fixpoint betree_node_lookup_first_message_for_key_back (n : nat) (key : u64) (msgs : Betree_list_t (u64 * Betree_message_t)) (ret : Betree_list_t (u64 * Betree_message_t)) : @@ -321,7 +322,7 @@ Fixpoint betree_node_lookup_first_message_for_key_back end . -(** [betree_main::betree::Node::{5}::apply_upserts] *) +(** [betree_main::betree::Node::{5}::apply_upserts]: forward function *) Fixpoint betree_node_apply_upserts_fwd (n : nat) (msgs : Betree_list_t (u64 * Betree_message_t)) (prev : option u64) (key : u64) (st : state) : @@ -353,7 +354,7 @@ Fixpoint betree_node_apply_upserts_fwd end . -(** [betree_main::betree::Node::{5}::apply_upserts] *) +(** [betree_main::betree::Node::{5}::apply_upserts]: backward function 0 *) Fixpoint betree_node_apply_upserts_back (n : nat) (msgs : Betree_list_t (u64 * Betree_message_t)) (prev : option u64) (key : u64) (st : state) : @@ -383,7 +384,7 @@ Fixpoint betree_node_apply_upserts_back end . -(** [betree_main::betree::Node::{5}::lookup] *) +(** [betree_main::betree::Node::{5}::lookup]: forward function *) Fixpoint betree_node_lookup_fwd (n : nat) (self : Betree_node_t) (key : u64) (st : state) : result (state * (option u64)) @@ -455,7 +456,7 @@ Fixpoint betree_node_lookup_fwd end end -(** [betree_main::betree::Node::{5}::lookup] *) +(** [betree_main::betree::Node::{5}::lookup]: backward function 0 *) with betree_node_lookup_back (n : nat) (self : Betree_node_t) (key : u64) (st : state) : result Betree_node_t @@ -524,7 +525,7 @@ with betree_node_lookup_back end end -(** [betree_main::betree::Internal::{4}::lookup_in_children] *) +(** [betree_main::betree::Internal::{4}::lookup_in_children]: forward function *) with betree_internal_lookup_in_children_fwd (n : nat) (self : Betree_internal_t) (key : u64) (st : state) : result (state * (option u64)) @@ -537,7 +538,7 @@ with betree_internal_lookup_in_children_fwd else betree_node_lookup_fwd n0 self.(Betree_internal_right) key st end -(** [betree_main::betree::Internal::{4}::lookup_in_children] *) +(** [betree_main::betree::Internal::{4}::lookup_in_children]: backward function 0 *) with betree_internal_lookup_in_children_back (n : nat) (self : Betree_internal_t) (key : u64) (st : state) : result Betree_internal_t @@ -557,7 +558,7 @@ with betree_internal_lookup_in_children_back end . -(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: forward function *) Fixpoint betree_node_lookup_mut_in_bindings_fwd (n : nat) (key : u64) (bindings : Betree_list_t (u64 * u64)) : result (Betree_list_t (u64 * u64)) @@ -576,7 +577,7 @@ Fixpoint betree_node_lookup_mut_in_bindings_fwd end . -(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: backward function 0 *) Fixpoint betree_node_lookup_mut_in_bindings_back (n : nat) (key : u64) (bindings : Betree_list_t (u64 * u64)) (ret : Betree_list_t (u64 * u64)) : @@ -598,7 +599,8 @@ Fixpoint betree_node_lookup_mut_in_bindings_back end . -(** [betree_main::betree::Node::{5}::apply_to_leaf] *) +(** [betree_main::betree::Node::{5}::apply_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition betree_node_apply_to_leaf_fwd_back (n : nat) (bindings : Betree_list_t (u64 * u64)) (key : u64) (new_msg : Betree_message_t) : @@ -642,7 +644,8 @@ Definition betree_node_apply_to_leaf_fwd_back end . -(** [betree_main::betree::Node::{5}::apply_messages_to_leaf] *) +(** [betree_main::betree::Node::{5}::apply_messages_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint betree_node_apply_messages_to_leaf_fwd_back (n : nat) (bindings : Betree_list_t (u64 * u64)) (new_msgs : Betree_list_t (u64 * Betree_message_t)) : @@ -661,7 +664,8 @@ Fixpoint betree_node_apply_messages_to_leaf_fwd_back end . -(** [betree_main::betree::Node::{5}::filter_messages_for_key] *) +(** [betree_main::betree::Node::{5}::filter_messages_for_key]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint betree_node_filter_messages_for_key_fwd_back (n : nat) (key : u64) (msgs : Betree_list_t (u64 * Betree_message_t)) : result (Betree_list_t (u64 * Betree_message_t)) @@ -684,7 +688,7 @@ Fixpoint betree_node_filter_messages_for_key_fwd_back end . -(** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: forward function *) Fixpoint betree_node_lookup_first_message_after_key_fwd (n : nat) (key : u64) (msgs : Betree_list_t (u64 * Betree_message_t)) : result (Betree_list_t (u64 * Betree_message_t)) @@ -703,7 +707,7 @@ Fixpoint betree_node_lookup_first_message_after_key_fwd end . -(** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: backward function 0 *) Fixpoint betree_node_lookup_first_message_after_key_back (n : nat) (key : u64) (msgs : Betree_list_t (u64 * Betree_message_t)) (ret : Betree_list_t (u64 * Betree_message_t)) : @@ -726,7 +730,8 @@ Fixpoint betree_node_lookup_first_message_after_key_back end . -(** [betree_main::betree::Node::{5}::apply_to_internal] *) +(** [betree_main::betree::Node::{5}::apply_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition betree_node_apply_to_internal_fwd_back (n : nat) (msgs : Betree_list_t (u64 * Betree_message_t)) (key : u64) (new_msg : Betree_message_t) : @@ -784,7 +789,8 @@ Definition betree_node_apply_to_internal_fwd_back betree_node_lookup_first_message_for_key_back n key msgs msgs1) . -(** [betree_main::betree::Node::{5}::apply_messages_to_internal] *) +(** [betree_main::betree::Node::{5}::apply_messages_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint betree_node_apply_messages_to_internal_fwd_back (n : nat) (msgs : Betree_list_t (u64 * Betree_message_t)) (new_msgs : Betree_list_t (u64 * Betree_message_t)) : @@ -803,7 +809,7 @@ Fixpoint betree_node_apply_messages_to_internal_fwd_back end . -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: forward function *) Fixpoint betree_node_apply_messages_fwd (n : nat) (self : Betree_node_t) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) @@ -859,7 +865,7 @@ Fixpoint betree_node_apply_messages_fwd end end -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: backward function 0 *) with betree_node_apply_messages_back (n : nat) (self : Betree_node_t) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) @@ -915,7 +921,7 @@ with betree_node_apply_messages_back end end -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: forward function *) with betree_internal_flush_fwd (n : nat) (self : Betree_internal_t) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) @@ -963,7 +969,7 @@ with betree_internal_flush_fwd Return (st0, msgs_left)) end -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: backward function 0 *) with betree_internal_flush_back (n : nat) (self : Betree_internal_t) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) @@ -1012,7 +1018,7 @@ with betree_internal_flush_back end . -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: forward function *) Definition betree_node_apply_fwd (n : nat) (self : Betree_node_t) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) (key : u64) @@ -1030,7 +1036,7 @@ Definition betree_node_apply_fwd Return (st0, tt) . -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: backward function 0 *) Definition betree_node_apply_back (n : nat) (self : Betree_node_t) (params : Betree_params_t) (node_id_cnt : Betree_node_id_counter_t) (key : u64) @@ -1042,7 +1048,7 @@ Definition betree_node_apply_back (key, new_msg) l) st . -(** [betree_main::betree::BeTree::{6}::new] *) +(** [betree_main::betree::BeTree::{6}::new]: forward function *) Definition betree_be_tree_new_fwd (min_flush_size : u64) (split_size : u64) (st : state) : result (state * Betree_be_tree_t) @@ -1065,7 +1071,7 @@ Definition betree_be_tree_new_fwd |}) . -(** [betree_main::betree::BeTree::{6}::apply] *) +(** [betree_main::betree::BeTree::{6}::apply]: forward function *) Definition betree_be_tree_apply_fwd (n : nat) (self : Betree_be_tree_t) (key : u64) (msg : Betree_message_t) (st : state) : @@ -1081,7 +1087,7 @@ Definition betree_be_tree_apply_fwd Return (st0, tt) . -(** [betree_main::betree::BeTree::{6}::apply] *) +(** [betree_main::betree::BeTree::{6}::apply]: backward function 0 *) Definition betree_be_tree_apply_back (n : nat) (self : Betree_be_tree_t) (key : u64) (msg : Betree_message_t) (st : state) : @@ -1099,7 +1105,7 @@ Definition betree_be_tree_apply_back |} . -(** [betree_main::betree::BeTree::{6}::insert] *) +(** [betree_main::betree::BeTree::{6}::insert]: forward function *) Definition betree_be_tree_insert_fwd (n : nat) (self : Betree_be_tree_t) (key : u64) (value : u64) (st : state) : result (state * unit) @@ -1110,7 +1116,7 @@ Definition betree_be_tree_insert_fwd Return (st0, tt) . -(** [betree_main::betree::BeTree::{6}::insert] *) +(** [betree_main::betree::BeTree::{6}::insert]: backward function 0 *) Definition betree_be_tree_insert_back (n : nat) (self : Betree_be_tree_t) (key : u64) (value : u64) (st : state) : result Betree_be_tree_t @@ -1118,7 +1124,7 @@ Definition betree_be_tree_insert_back betree_be_tree_apply_back n self key (BetreeMessageInsert value) st . -(** [betree_main::betree::BeTree::{6}::delete] *) +(** [betree_main::betree::BeTree::{6}::delete]: forward function *) Definition betree_be_tree_delete_fwd (n : nat) (self : Betree_be_tree_t) (key : u64) (st : state) : result (state * unit) @@ -1129,7 +1135,7 @@ Definition betree_be_tree_delete_fwd Return (st0, tt) . -(** [betree_main::betree::BeTree::{6}::delete] *) +(** [betree_main::betree::BeTree::{6}::delete]: backward function 0 *) Definition betree_be_tree_delete_back (n : nat) (self : Betree_be_tree_t) (key : u64) (st : state) : result Betree_be_tree_t @@ -1137,7 +1143,7 @@ Definition betree_be_tree_delete_back betree_be_tree_apply_back n self key BetreeMessageDelete st . -(** [betree_main::betree::BeTree::{6}::upsert] *) +(** [betree_main::betree::BeTree::{6}::upsert]: forward function *) Definition betree_be_tree_upsert_fwd (n : nat) (self : Betree_be_tree_t) (key : u64) (upd : Betree_upsert_fun_state_t) (st : state) : @@ -1149,7 +1155,7 @@ Definition betree_be_tree_upsert_fwd Return (st0, tt) . -(** [betree_main::betree::BeTree::{6}::upsert] *) +(** [betree_main::betree::BeTree::{6}::upsert]: backward function 0 *) Definition betree_be_tree_upsert_back (n : nat) (self : Betree_be_tree_t) (key : u64) (upd : Betree_upsert_fun_state_t) (st : state) : @@ -1158,7 +1164,7 @@ Definition betree_be_tree_upsert_back betree_be_tree_apply_back n self key (BetreeMessageUpsert upd) st . -(** [betree_main::betree::BeTree::{6}::lookup] *) +(** [betree_main::betree::BeTree::{6}::lookup]: forward function *) Definition betree_be_tree_lookup_fwd (n : nat) (self : Betree_be_tree_t) (key : u64) (st : state) : result (state * (option u64)) @@ -1166,7 +1172,7 @@ Definition betree_be_tree_lookup_fwd betree_node_lookup_fwd n self.(Betree_be_tree_root) key st . -(** [betree_main::betree::BeTree::{6}::lookup] *) +(** [betree_main::betree::BeTree::{6}::lookup]: backward function 0 *) Definition betree_be_tree_lookup_back (n : nat) (self : Betree_be_tree_t) (key : u64) (st : state) : result Betree_be_tree_t @@ -1180,7 +1186,7 @@ Definition betree_be_tree_lookup_back |} . -(** [betree_main::main] *) +(** [betree_main::main]: forward function *) Definition main_fwd : result unit := Return tt. diff --git a/tests/coq/betree/BetreeMain_Opaque.v b/tests/coq/betree/BetreeMain_Opaque.v index 08ab530a..bd49500b 100644 --- a/tests/coq/betree/BetreeMain_Opaque.v +++ b/tests/coq/betree/BetreeMain_Opaque.v @@ -1,5 +1,5 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [betree_main]: opaque function definitions *) +(** [betree_main]: external function declarations *) Require Import Primitives. Import Primitives. Require Import Coq.ZArith.ZArith. @@ -8,29 +8,29 @@ Require Export BetreeMain_Types. Import BetreeMain_Types. Module BetreeMain_Opaque. -(** [betree_main::betree_utils::load_internal_node] *) +(** [betree_main::betree_utils::load_internal_node]: forward function *) Axiom betree_utils_load_internal_node_fwd : u64 -> state -> result (state * (Betree_list_t (u64 * Betree_message_t))) . -(** [betree_main::betree_utils::store_internal_node] *) +(** [betree_main::betree_utils::store_internal_node]: forward function *) Axiom betree_utils_store_internal_node_fwd : u64 -> Betree_list_t (u64 * Betree_message_t) -> state -> result (state * unit) . -(** [betree_main::betree_utils::load_leaf_node] *) +(** [betree_main::betree_utils::load_leaf_node]: forward function *) Axiom betree_utils_load_leaf_node_fwd : u64 -> state -> result (state * (Betree_list_t (u64 * u64))) . -(** [betree_main::betree_utils::store_leaf_node] *) +(** [betree_main::betree_utils::store_leaf_node]: forward function *) Axiom betree_utils_store_leaf_node_fwd : u64 -> Betree_list_t (u64 * u64) -> state -> result (state * unit) . -(** [core::option::Option::{0}::unwrap] *) +(** [core::option::Option::{0}::unwrap]: forward function *) Axiom core_option_option_unwrap_fwd : forall(T : Type), option T -> state -> result (state * T) . diff --git a/tests/coq/betree/_CoqProject b/tests/coq/betree/_CoqProject index e5a3f799..42c62421 100644 --- a/tests/coq/betree/_CoqProject +++ b/tests/coq/betree/_CoqProject @@ -3,7 +3,7 @@ -arg -w -arg all -Primitives.v BetreeMain_Types.v +Primitives.v BetreeMain_Funs.v BetreeMain_Opaque.v diff --git a/tests/coq/hashmap/Hashmap_Funs.v b/tests/coq/hashmap/Hashmap_Funs.v index 6bc82677..c8630eb6 100644 --- a/tests/coq/hashmap/Hashmap_Funs.v +++ b/tests/coq/hashmap/Hashmap_Funs.v @@ -8,11 +8,11 @@ Require Export Hashmap_Types. Import Hashmap_Types. Module Hashmap_Funs. -(** [hashmap::hash_key] *) +(** [hashmap::hash_key]: forward function *) Definition hash_key_fwd (k : usize) : result usize := Return k. -(** [hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function *) Fixpoint hash_map_allocate_slots_loop_fwd (T : Type) (n : nat) (slots : vec (List_t T)) (n0 : usize) : result (vec (List_t T)) @@ -29,7 +29,7 @@ Fixpoint hash_map_allocate_slots_loop_fwd end . -(** [hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap::HashMap::{0}::allocate_slots]: forward function *) Definition hash_map_allocate_slots_fwd (T : Type) (n : nat) (slots : vec (List_t T)) (n0 : usize) : result (vec (List_t T)) @@ -37,7 +37,7 @@ Definition hash_map_allocate_slots_fwd hash_map_allocate_slots_loop_fwd T n slots n0 . -(** [hashmap::HashMap::{0}::new_with_capacity] *) +(** [hashmap::HashMap::{0}::new_with_capacity]: forward function *) Definition hash_map_new_with_capacity_fwd (T : Type) (n : nat) (capacity : usize) (max_load_dividend : usize) (max_load_divisor : usize) : @@ -56,12 +56,13 @@ Definition hash_map_new_with_capacity_fwd |} . -(** [hashmap::HashMap::{0}::new] *) +(** [hashmap::HashMap::{0}::new]: forward function *) 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 . -(** [hashmap::HashMap::{0}::clear] *) +(** [hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint hash_map_clear_loop_fwd_back (T : Type) (n : nat) (slots : vec (List_t T)) (i : usize) : result (vec (List_t T)) @@ -79,7 +80,8 @@ Fixpoint hash_map_clear_loop_fwd_back end . -(** [hashmap::HashMap::{0}::clear] *) +(** [hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) 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; @@ -92,12 +94,12 @@ Definition hash_map_clear_fwd_back |} . -(** [hashmap::HashMap::{0}::len] *) +(** [hashmap::HashMap::{0}::len]: forward function *) Definition hash_map_len_fwd (T : Type) (self : Hash_map_t T) : result usize := Return self.(Hash_map_num_entries) . -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function *) Fixpoint hash_map_insert_in_list_loop_fwd (T : Type) (n : nat) (key : usize) (value : T) (ls : List_t T) : result bool @@ -115,7 +117,7 @@ Fixpoint hash_map_insert_in_list_loop_fwd end . -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: forward function *) Definition hash_map_insert_in_list_fwd (T : Type) (n : nat) (key : usize) (value : T) (ls : List_t T) : result bool @@ -123,7 +125,7 @@ Definition hash_map_insert_in_list_fwd hash_map_insert_in_list_loop_fwd T n key value ls . -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 *) Fixpoint hash_map_insert_in_list_loop_back (T : Type) (n : nat) (key : usize) (value : T) (ls : List_t T) : result (List_t T) @@ -143,7 +145,7 @@ Fixpoint hash_map_insert_in_list_loop_back end . -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: backward function 0 *) Definition hash_map_insert_in_list_back (T : Type) (n : nat) (key : usize) (value : T) (ls : List_t T) : result (List_t T) @@ -151,7 +153,8 @@ Definition hash_map_insert_in_list_back hash_map_insert_in_list_loop_back T n key value ls . -(** [hashmap::HashMap::{0}::insert_no_resize] *) +(** [hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hash_map_insert_no_resize_fwd_back (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) (value : T) : result (Hash_map_t T) @@ -189,7 +192,8 @@ Definition hash_map_insert_no_resize_fwd_back 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] *) +(** [hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint hash_map_move_elements_from_list_loop_fwd_back (T : Type) (n : nat) (ntable : Hash_map_t T) (ls : List_t T) : result (Hash_map_t T) @@ -206,7 +210,8 @@ Fixpoint hash_map_move_elements_from_list_loop_fwd_back end . -(** [hashmap::HashMap::{0}::move_elements_from_list] *) +(** [hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hash_map_move_elements_from_list_fwd_back (T : Type) (n : nat) (ntable : Hash_map_t T) (ls : List_t T) : result (Hash_map_t T) @@ -214,7 +219,8 @@ Definition hash_map_move_elements_from_list_fwd_back hash_map_move_elements_from_list_loop_fwd_back T n ntable ls . -(** [hashmap::HashMap::{0}::move_elements] *) +(** [hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint hash_map_move_elements_loop_fwd_back (T : Type) (n : nat) (ntable : Hash_map_t T) (slots : vec (List_t T)) (i : usize) : @@ -237,7 +243,8 @@ Fixpoint hash_map_move_elements_loop_fwd_back end . -(** [hashmap::HashMap::{0}::move_elements] *) +(** [hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hash_map_move_elements_fwd_back (T : Type) (n : nat) (ntable : Hash_map_t T) (slots : vec (List_t T)) (i : usize) : @@ -246,7 +253,8 @@ Definition hash_map_move_elements_fwd_back hash_map_move_elements_loop_fwd_back T n ntable slots i . -(** [hashmap::HashMap::{0}::try_resize] *) +(** [hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hash_map_try_resize_fwd_back (T : Type) (n : nat) (self : Hash_map_t T) : result (Hash_map_t T) := max_usize <- scalar_cast U32 Usize core_num_u32_max_c; @@ -278,7 +286,8 @@ Definition hash_map_try_resize_fwd_back |} . -(** [hashmap::HashMap::{0}::insert] *) +(** [hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hash_map_insert_fwd_back (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) (value : T) : result (Hash_map_t T) @@ -290,7 +299,7 @@ Definition hash_map_insert_fwd_back else Return self0 . -(** [hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function *) Fixpoint hash_map_contains_key_in_list_loop_fwd (T : Type) (n : nat) (key : usize) (ls : List_t T) : result bool := match n with @@ -306,13 +315,13 @@ Fixpoint hash_map_contains_key_in_list_loop_fwd end . -(** [hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap::HashMap::{0}::contains_key_in_list]: forward function *) Definition hash_map_contains_key_in_list_fwd (T : Type) (n : nat) (key : usize) (ls : List_t T) : result bool := hash_map_contains_key_in_list_loop_fwd T n key ls . -(** [hashmap::HashMap::{0}::contains_key] *) +(** [hashmap::HashMap::{0}::contains_key]: forward function *) Definition hash_map_contains_key_fwd (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) : result bool := hash <- hash_key_fwd key; @@ -322,7 +331,7 @@ Definition hash_map_contains_key_fwd hash_map_contains_key_in_list_fwd T n key l . -(** [hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap::HashMap::{0}::get_in_list]: loop 0: forward function *) Fixpoint hash_map_get_in_list_loop_fwd (T : Type) (n : nat) (key : usize) (ls : List_t T) : result T := match n with @@ -338,13 +347,13 @@ Fixpoint hash_map_get_in_list_loop_fwd end . -(** [hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap::HashMap::{0}::get_in_list]: forward function *) Definition hash_map_get_in_list_fwd (T : Type) (n : nat) (key : usize) (ls : List_t T) : result T := hash_map_get_in_list_loop_fwd T n key ls . -(** [hashmap::HashMap::{0}::get] *) +(** [hashmap::HashMap::{0}::get]: forward function *) Definition hash_map_get_fwd (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) : result T := hash <- hash_key_fwd key; @@ -354,7 +363,7 @@ Definition hash_map_get_fwd hash_map_get_in_list_fwd T n key l . -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function *) Fixpoint hash_map_get_mut_in_list_loop_fwd (T : Type) (n : nat) (ls : List_t T) (key : usize) : result T := match n with @@ -370,13 +379,13 @@ Fixpoint hash_map_get_mut_in_list_loop_fwd end . -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: forward function *) Definition hash_map_get_mut_in_list_fwd (T : Type) (n : nat) (ls : List_t T) (key : usize) : result T := hash_map_get_mut_in_list_loop_fwd T n ls key . -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 *) Fixpoint hash_map_get_mut_in_list_loop_back (T : Type) (n : nat) (ls : List_t T) (key : usize) (ret : T) : result (List_t T) @@ -396,7 +405,7 @@ Fixpoint hash_map_get_mut_in_list_loop_back end . -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 *) Definition hash_map_get_mut_in_list_back (T : Type) (n : nat) (ls : List_t T) (key : usize) (ret : T) : result (List_t T) @@ -404,7 +413,7 @@ Definition hash_map_get_mut_in_list_back hash_map_get_mut_in_list_loop_back T n ls key ret . -(** [hashmap::HashMap::{0}::get_mut] *) +(** [hashmap::HashMap::{0}::get_mut]: forward function *) Definition hash_map_get_mut_fwd (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) : result T := hash <- hash_key_fwd key; @@ -414,7 +423,7 @@ Definition hash_map_get_mut_fwd hash_map_get_mut_in_list_fwd T n l key . -(** [hashmap::HashMap::{0}::get_mut] *) +(** [hashmap::HashMap::{0}::get_mut]: backward function 0 *) Definition hash_map_get_mut_back (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) (ret : T) : result (Hash_map_t T) @@ -434,7 +443,7 @@ Definition hash_map_get_mut_back |} . -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function *) Fixpoint hash_map_remove_from_list_loop_fwd (T : Type) (n : nat) (key : usize) (ls : List_t T) : result (option T) := match n with @@ -455,13 +464,13 @@ Fixpoint hash_map_remove_from_list_loop_fwd end . -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: forward function *) Definition hash_map_remove_from_list_fwd (T : Type) (n : nat) (key : usize) (ls : List_t T) : result (option T) := hash_map_remove_from_list_loop_fwd T n key ls . -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 *) Fixpoint hash_map_remove_from_list_loop_back (T : Type) (n : nat) (key : usize) (ls : List_t T) : result (List_t T) := match n with @@ -484,13 +493,13 @@ Fixpoint hash_map_remove_from_list_loop_back end . -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: backward function 1 *) Definition hash_map_remove_from_list_back (T : Type) (n : nat) (key : usize) (ls : List_t T) : result (List_t T) := hash_map_remove_from_list_loop_back T n key ls . -(** [hashmap::HashMap::{0}::remove] *) +(** [hashmap::HashMap::{0}::remove]: forward function *) Definition hash_map_remove_fwd (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) : result (option T) @@ -507,7 +516,7 @@ Definition hash_map_remove_fwd end . -(** [hashmap::HashMap::{0}::remove] *) +(** [hashmap::HashMap::{0}::remove]: backward function 0 *) Definition hash_map_remove_back (T : Type) (n : nat) (self : Hash_map_t T) (key : usize) : result (Hash_map_t T) @@ -542,7 +551,7 @@ Definition hash_map_remove_back end . -(** [hashmap::test1] *) +(** [hashmap::test1]: forward function *) 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; diff --git a/tests/coq/hashmap/_CoqProject b/tests/coq/hashmap/_CoqProject index daa9b2ba..7f80afbf 100644 --- a/tests/coq/hashmap/_CoqProject +++ b/tests/coq/hashmap/_CoqProject @@ -3,6 +3,6 @@ -arg -w -arg all -Primitives.v Hashmap_Types.v +Primitives.v Hashmap_Funs.v diff --git a/tests/coq/hashmap_on_disk/HashmapMain_Funs.v b/tests/coq/hashmap_on_disk/HashmapMain_Funs.v index 2d1bcda6..1b7304cc 100644 --- a/tests/coq/hashmap_on_disk/HashmapMain_Funs.v +++ b/tests/coq/hashmap_on_disk/HashmapMain_Funs.v @@ -10,11 +10,11 @@ Require Export HashmapMain_Opaque. Import HashmapMain_Opaque. Module HashmapMain_Funs. -(** [hashmap_main::hashmap::hash_key] *) +(** [hashmap_main::hashmap::hash_key]: forward function *) Definition hashmap_hash_key_fwd (k : usize) : result usize := Return k. -(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function *) Fixpoint hashmap_hash_map_allocate_slots_loop_fwd (T : Type) (n : nat) (slots : vec (Hashmap_list_t T)) (n0 : usize) : result (vec (Hashmap_list_t T)) @@ -31,7 +31,7 @@ Fixpoint hashmap_hash_map_allocate_slots_loop_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: forward function *) Definition hashmap_hash_map_allocate_slots_fwd (T : Type) (n : nat) (slots : vec (Hashmap_list_t T)) (n0 : usize) : result (vec (Hashmap_list_t T)) @@ -39,7 +39,7 @@ Definition hashmap_hash_map_allocate_slots_fwd hashmap_hash_map_allocate_slots_loop_fwd T n slots n0 . -(** [hashmap_main::hashmap::HashMap::{0}::new_with_capacity] *) +(** [hashmap_main::hashmap::HashMap::{0}::new_with_capacity]: forward function *) Definition hashmap_hash_map_new_with_capacity_fwd (T : Type) (n : nat) (capacity : usize) (max_load_dividend : usize) (max_load_divisor : usize) : @@ -58,13 +58,14 @@ Definition hashmap_hash_map_new_with_capacity_fwd |} . -(** [hashmap_main::hashmap::HashMap::{0}::new] *) +(** [hashmap_main::hashmap::HashMap::{0}::new]: forward function *) 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_main::hashmap::HashMap::{0}::clear] *) +(** [hashmap_main::hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint hashmap_hash_map_clear_loop_fwd_back (T : Type) (n : nat) (slots : vec (Hashmap_list_t T)) (i : usize) : result (vec (Hashmap_list_t T)) @@ -82,7 +83,8 @@ Fixpoint hashmap_hash_map_clear_loop_fwd_back end . -(** [hashmap_main::hashmap::HashMap::{0}::clear] *) +(** [hashmap_main::hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hashmap_hash_map_clear_fwd_back (T : Type) (n : nat) (self : Hashmap_hash_map_t T) : result (Hashmap_hash_map_t T) @@ -100,13 +102,13 @@ Definition hashmap_hash_map_clear_fwd_back |} . -(** [hashmap_main::hashmap::HashMap::{0}::len] *) +(** [hashmap_main::hashmap::HashMap::{0}::len]: forward function *) Definition hashmap_hash_map_len_fwd (T : Type) (self : Hashmap_hash_map_t T) : result usize := Return self.(Hashmap_hash_map_num_entries) . -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function *) Fixpoint hashmap_hash_map_insert_in_list_loop_fwd (T : Type) (n : nat) (key : usize) (value : T) (ls : Hashmap_list_t T) : result bool @@ -124,7 +126,7 @@ Fixpoint hashmap_hash_map_insert_in_list_loop_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: forward function *) Definition hashmap_hash_map_insert_in_list_fwd (T : Type) (n : nat) (key : usize) (value : T) (ls : Hashmap_list_t T) : result bool @@ -132,7 +134,7 @@ Definition hashmap_hash_map_insert_in_list_fwd hashmap_hash_map_insert_in_list_loop_fwd T n key value ls . -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 *) Fixpoint hashmap_hash_map_insert_in_list_loop_back (T : Type) (n : nat) (key : usize) (value : T) (ls : Hashmap_list_t T) : result (Hashmap_list_t T) @@ -153,7 +155,7 @@ Fixpoint hashmap_hash_map_insert_in_list_loop_back end . -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: backward function 0 *) Definition hashmap_hash_map_insert_in_list_back (T : Type) (n : nat) (key : usize) (value : T) (ls : Hashmap_list_t T) : result (Hashmap_list_t T) @@ -161,7 +163,8 @@ Definition hashmap_hash_map_insert_in_list_back hashmap_hash_map_insert_in_list_loop_back T n key value ls . -(** [hashmap_main::hashmap::HashMap::{0}::insert_no_resize] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hashmap_hash_map_insert_no_resize_fwd_back (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) (value : T) : @@ -207,7 +210,8 @@ Definition hashmap_hash_map_insert_no_resize_fwd_back 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] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint hashmap_hash_map_move_elements_from_list_loop_fwd_back (T : Type) (n : nat) (ntable : Hashmap_hash_map_t T) (ls : Hashmap_list_t T) : @@ -225,7 +229,8 @@ Fixpoint hashmap_hash_map_move_elements_from_list_loop_fwd_back end . -(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hashmap_hash_map_move_elements_from_list_fwd_back (T : Type) (n : nat) (ntable : Hashmap_hash_map_t T) (ls : Hashmap_list_t T) : @@ -234,7 +239,8 @@ Definition hashmap_hash_map_move_elements_from_list_fwd_back hashmap_hash_map_move_elements_from_list_loop_fwd_back T n ntable ls . -(** [hashmap_main::hashmap::HashMap::{0}::move_elements] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint hashmap_hash_map_move_elements_loop_fwd_back (T : Type) (n : nat) (ntable : Hashmap_hash_map_t T) (slots : vec (Hashmap_list_t T)) (i : usize) : @@ -258,7 +264,8 @@ Fixpoint hashmap_hash_map_move_elements_loop_fwd_back end . -(** [hashmap_main::hashmap::HashMap::{0}::move_elements] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hashmap_hash_map_move_elements_fwd_back (T : Type) (n : nat) (ntable : Hashmap_hash_map_t T) (slots : vec (Hashmap_list_t T)) (i : usize) : @@ -267,7 +274,8 @@ Definition hashmap_hash_map_move_elements_fwd_back hashmap_hash_map_move_elements_loop_fwd_back T n ntable slots i . -(** [hashmap_main::hashmap::HashMap::{0}::try_resize] *) +(** [hashmap_main::hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hashmap_hash_map_try_resize_fwd_back (T : Type) (n : nat) (self : Hashmap_hash_map_t T) : result (Hashmap_hash_map_t T) @@ -302,7 +310,8 @@ Definition hashmap_hash_map_try_resize_fwd_back |} . -(** [hashmap_main::hashmap::HashMap::{0}::insert] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition hashmap_hash_map_insert_fwd_back (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) (value : T) : @@ -315,7 +324,7 @@ Definition hashmap_hash_map_insert_fwd_back else Return self0 . -(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function *) Fixpoint hashmap_hash_map_contains_key_in_list_loop_fwd (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result bool := match n with @@ -331,13 +340,13 @@ Fixpoint hashmap_hash_map_contains_key_in_list_loop_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: forward function *) Definition hashmap_hash_map_contains_key_in_list_fwd (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result bool := hashmap_hash_map_contains_key_in_list_loop_fwd T n key ls . -(** [hashmap_main::hashmap::HashMap::{0}::contains_key] *) +(** [hashmap_main::hashmap::HashMap::{0}::contains_key]: forward function *) Definition hashmap_hash_map_contains_key_fwd (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) : result bool @@ -349,7 +358,7 @@ Definition hashmap_hash_map_contains_key_fwd hashmap_hash_map_contains_key_in_list_fwd T n key l . -(** [hashmap_main::hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_in_list]: loop 0: forward function *) Fixpoint hashmap_hash_map_get_in_list_loop_fwd (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result T := match n with @@ -365,13 +374,13 @@ Fixpoint hashmap_hash_map_get_in_list_loop_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_in_list]: forward function *) Definition hashmap_hash_map_get_in_list_fwd (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result T := hashmap_hash_map_get_in_list_loop_fwd T n key ls . -(** [hashmap_main::hashmap::HashMap::{0}::get] *) +(** [hashmap_main::hashmap::HashMap::{0}::get]: forward function *) Definition hashmap_hash_map_get_fwd (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) : result T @@ -383,7 +392,7 @@ Definition hashmap_hash_map_get_fwd hashmap_hash_map_get_in_list_fwd T n key l . -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function *) Fixpoint hashmap_hash_map_get_mut_in_list_loop_fwd (T : Type) (n : nat) (ls : Hashmap_list_t T) (key : usize) : result T := match n with @@ -399,13 +408,13 @@ Fixpoint hashmap_hash_map_get_mut_in_list_loop_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: forward function *) Definition hashmap_hash_map_get_mut_in_list_fwd (T : Type) (n : nat) (ls : Hashmap_list_t T) (key : usize) : result T := hashmap_hash_map_get_mut_in_list_loop_fwd T n ls key . -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 *) Fixpoint hashmap_hash_map_get_mut_in_list_loop_back (T : Type) (n : nat) (ls : Hashmap_list_t T) (key : usize) (ret : T) : result (Hashmap_list_t T) @@ -425,7 +434,7 @@ Fixpoint hashmap_hash_map_get_mut_in_list_loop_back end . -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 *) Definition hashmap_hash_map_get_mut_in_list_back (T : Type) (n : nat) (ls : Hashmap_list_t T) (key : usize) (ret : T) : result (Hashmap_list_t T) @@ -433,7 +442,7 @@ Definition hashmap_hash_map_get_mut_in_list_back hashmap_hash_map_get_mut_in_list_loop_back T n ls key ret . -(** [hashmap_main::hashmap::HashMap::{0}::get_mut] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut]: forward function *) Definition hashmap_hash_map_get_mut_fwd (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) : result T @@ -446,7 +455,7 @@ Definition hashmap_hash_map_get_mut_fwd hashmap_hash_map_get_mut_in_list_fwd T n l key . -(** [hashmap_main::hashmap::HashMap::{0}::get_mut] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut]: backward function 0 *) Definition hashmap_hash_map_get_mut_back (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) (ret : T) : result (Hashmap_hash_map_t T) @@ -470,7 +479,7 @@ Definition hashmap_hash_map_get_mut_back |} . -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function *) Fixpoint hashmap_hash_map_remove_from_list_loop_fwd (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result (option T) @@ -495,7 +504,7 @@ Fixpoint hashmap_hash_map_remove_from_list_loop_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: forward function *) Definition hashmap_hash_map_remove_from_list_fwd (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result (option T) @@ -503,7 +512,7 @@ Definition hashmap_hash_map_remove_from_list_fwd hashmap_hash_map_remove_from_list_loop_fwd T n key ls . -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 *) Fixpoint hashmap_hash_map_remove_from_list_loop_back (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result (Hashmap_list_t T) @@ -530,7 +539,7 @@ Fixpoint hashmap_hash_map_remove_from_list_loop_back end . -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: backward function 1 *) Definition hashmap_hash_map_remove_from_list_back (T : Type) (n : nat) (key : usize) (ls : Hashmap_list_t T) : result (Hashmap_list_t T) @@ -538,7 +547,7 @@ Definition hashmap_hash_map_remove_from_list_back hashmap_hash_map_remove_from_list_loop_back T n key ls . -(** [hashmap_main::hashmap::HashMap::{0}::remove] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove]: forward function *) Definition hashmap_hash_map_remove_fwd (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) : result (option T) @@ -557,7 +566,7 @@ Definition hashmap_hash_map_remove_fwd end . -(** [hashmap_main::hashmap::HashMap::{0}::remove] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove]: backward function 0 *) Definition hashmap_hash_map_remove_back (T : Type) (n : nat) (self : Hashmap_hash_map_t T) (key : usize) : result (Hashmap_hash_map_t T) @@ -599,7 +608,7 @@ Definition hashmap_hash_map_remove_back end . -(** [hashmap_main::hashmap::test1] *) +(** [hashmap_main::hashmap::test1]: forward function *) 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; @@ -636,7 +645,7 @@ Definition hashmap_test1_fwd (n : nat) : result unit := end)) . -(** [hashmap_main::insert_on_disk] *) +(** [hashmap_main::insert_on_disk]: forward function *) Definition insert_on_disk_fwd (n : nat) (key : usize) (value : u64) (st : state) : result (state * unit) := p <- hashmap_utils_deserialize_fwd st; @@ -647,7 +656,7 @@ Definition insert_on_disk_fwd Return (st1, tt) . -(** [hashmap_main::main] *) +(** [hashmap_main::main]: forward function *) Definition main_fwd : result unit := Return tt. diff --git a/tests/coq/hashmap_on_disk/HashmapMain_Opaque.v b/tests/coq/hashmap_on_disk/HashmapMain_Opaque.v index 6152b94b..1ad9c697 100644 --- a/tests/coq/hashmap_on_disk/HashmapMain_Opaque.v +++ b/tests/coq/hashmap_on_disk/HashmapMain_Opaque.v @@ -1,5 +1,5 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [hashmap_main]: opaque function definitions *) +(** [hashmap_main]: external function declarations *) Require Import Primitives. Import Primitives. Require Import Coq.ZArith.ZArith. @@ -8,12 +8,12 @@ Require Export HashmapMain_Types. Import HashmapMain_Types. Module HashmapMain_Opaque. -(** [hashmap_main::hashmap_utils::deserialize] *) +(** [hashmap_main::hashmap_utils::deserialize]: forward function *) Axiom hashmap_utils_deserialize_fwd : state -> result (state * (Hashmap_hash_map_t u64)) . -(** [hashmap_main::hashmap_utils::serialize] *) +(** [hashmap_main::hashmap_utils::serialize]: forward function *) Axiom hashmap_utils_serialize_fwd : Hashmap_hash_map_t u64 -> state -> result (state * unit) . diff --git a/tests/coq/misc/Constants.v b/tests/coq/misc/Constants.v index 6a5f2696..14c05c61 100644 --- a/tests/coq/misc/Constants.v +++ b/tests/coq/misc/Constants.v @@ -22,7 +22,7 @@ Definition x1_c : u32 := x1_body%global. Definition x2_body : result u32 := Return 3%u32. Definition x2_c : u32 := x2_body%global. -(** [constants::incr] *) +(** [constants::incr]: forward function *) Definition incr_fwd (n : u32) : result u32 := u32_add n 1%u32. @@ -30,7 +30,7 @@ Definition incr_fwd (n : u32) : result u32 := Definition x3_body : result u32 := incr_fwd 32%u32. Definition x3_c : u32 := x3_body%global. -(** [constants::mk_pair0] *) +(** [constants::mk_pair0]: forward function *) Definition mk_pair0_fwd (x : u32) (y : u32) : result (u32 * u32) := Return (x, y) . @@ -42,7 +42,7 @@ Arguments mkPair_t {T1} {T2} _ _. Arguments Pair_x {T1} {T2}. Arguments Pair_y {T1} {T2}. -(** [constants::mk_pair1] *) +(** [constants::mk_pair1]: forward function *) Definition mk_pair1_fwd (x : u32) (y : u32) : result (Pair_t u32 u32) := Return {| Pair_x := x; Pair_y := y |} . @@ -71,7 +71,7 @@ Record Wrap_t (T : Type) := mkWrap_t { Wrap_val : T; }. Arguments mkWrap_t {T} _. Arguments Wrap_val {T}. -(** [constants::Wrap::{0}::new] *) +(** [constants::Wrap::{0}::new]: forward function *) Definition wrap_new_fwd (T : Type) (val : T) : result (Wrap_t T) := Return {| Wrap_val := val |} . @@ -80,7 +80,7 @@ Definition wrap_new_fwd (T : Type) (val : T) : result (Wrap_t T) := 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] *) +(** [constants::unwrap_y]: forward function *) Definition unwrap_y_fwd : result i32 := Return y_c.(Wrap_val). @@ -92,11 +92,11 @@ Definition yval_c : i32 := yval_body%global. Definition get_z1_z1_body : result i32 := Return 3%i32. Definition get_z1_z1_c : i32 := get_z1_z1_body%global. -(** [constants::get_z1] *) +(** [constants::get_z1]: forward function *) Definition get_z1_fwd : result i32 := Return get_z1_z1_c. -(** [constants::add] *) +(** [constants::add]: forward function *) Definition add_fwd (a : i32) (b : i32) : result i32 := i32_add a b. @@ -112,7 +112,7 @@ Definition q2_c : i32 := q2_body%global. Definition q3_body : result i32 := add_fwd q2_c 3%i32. Definition q3_c : i32 := q3_body%global. -(** [constants::get_z2] *) +(** [constants::get_z2]: forward function *) Definition get_z2_fwd : result i32 := i <- get_z1_fwd; i0 <- add_fwd i q3_c; add_fwd q1_c i0 . diff --git a/tests/coq/misc/External_Funs.v b/tests/coq/misc/External_Funs.v index 05dd8f2e..f18bbd1f 100644 --- a/tests/coq/misc/External_Funs.v +++ b/tests/coq/misc/External_Funs.v @@ -10,7 +10,7 @@ Require Export External_Opaque. Import External_Opaque. Module External_Funs. -(** [external::swap] *) +(** [external::swap]: forward function *) Definition swap_fwd (T : Type) (x : T) (y : T) (st : state) : result (state * unit) := p <- core_mem_swap_fwd T x y st; @@ -22,7 +22,7 @@ Definition swap_fwd Return (st2, tt) . -(** [external::swap] *) +(** [external::swap]: backward function 0 *) Definition swap_back (T : Type) (x : T) (y : T) (st : state) (st0 : state) : result (state * (T * T)) @@ -36,7 +36,7 @@ Definition swap_back Return (st0, (x0, y0)) . -(** [external::test_new_non_zero_u32] *) +(** [external::test_new_non_zero_u32]: forward function *) Definition test_new_non_zero_u32_fwd (x : u32) (st : state) : result (state * Core_num_nonzero_non_zero_u32_t) := p <- core_num_nonzero_non_zero_u32_new_fwd x st; @@ -44,7 +44,7 @@ Definition test_new_non_zero_u32_fwd core_option_option_unwrap_fwd Core_num_nonzero_non_zero_u32_t opt st0 . -(** [external::test_vec] *) +(** [external::test_vec]: forward function *) Definition test_vec_fwd : result unit := let v := vec_new u32 in _ <- vec_push_back u32 v 0%u32; Return tt . @@ -52,7 +52,7 @@ Definition test_vec_fwd : result unit := (** Unit test for [external::test_vec] *) Check (test_vec_fwd )%return. -(** [external::custom_swap] *) +(** [external::custom_swap]: forward function *) Definition custom_swap_fwd (T : Type) (x : T) (y : T) (st : state) : result (state * T) := p <- core_mem_swap_fwd T x y st; @@ -64,7 +64,7 @@ Definition custom_swap_fwd Return (st2, x0) . -(** [external::custom_swap] *) +(** [external::custom_swap]: backward function 0 *) Definition custom_swap_back (T : Type) (x : T) (y : T) (st : state) (ret : T) (st0 : state) : result (state * (T * T)) @@ -78,13 +78,13 @@ Definition custom_swap_back Return (st0, (ret, y0)) . -(** [external::test_custom_swap] *) +(** [external::test_custom_swap]: forward function *) Definition test_custom_swap_fwd (x : u32) (y : u32) (st : state) : result (state * unit) := p <- custom_swap_fwd u32 x y st; let (st0, _) := p in Return (st0, tt) . -(** [external::test_custom_swap] *) +(** [external::test_custom_swap]: backward function 0 *) Definition test_custom_swap_back (x : u32) (y : u32) (st : state) (st0 : state) : result (state * (u32 * u32)) @@ -92,7 +92,7 @@ Definition test_custom_swap_back custom_swap_back u32 x y st 1%u32 st0 . -(** [external::test_swap_non_zero] *) +(** [external::test_swap_non_zero]: forward function *) Definition test_swap_non_zero_fwd (x : u32) (st : state) : result (state * u32) := p <- swap_fwd u32 x 0%u32 st; diff --git a/tests/coq/misc/External_Opaque.v b/tests/coq/misc/External_Opaque.v index d60251e0..1224f426 100644 --- a/tests/coq/misc/External_Opaque.v +++ b/tests/coq/misc/External_Opaque.v @@ -1,5 +1,5 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [external]: opaque function definitions *) +(** [external]: external function declarations *) Require Import Primitives. Import Primitives. Require Import Coq.ZArith.ZArith. @@ -8,27 +8,27 @@ Require Export External_Types. Import External_Types. Module External_Opaque. -(** [core::mem::swap] *) +(** [core::mem::swap]: forward function *) Axiom core_mem_swap_fwd : forall(T : Type), T -> T -> state -> result (state * unit) . -(** [core::mem::swap] *) +(** [core::mem::swap]: backward function 0 *) Axiom core_mem_swap_back0 : forall(T : Type), T -> T -> state -> state -> result (state * T) . -(** [core::mem::swap] *) +(** [core::mem::swap]: backward function 1 *) Axiom core_mem_swap_back1 : forall(T : Type), T -> T -> state -> state -> result (state * T) . -(** [core::num::nonzero::NonZeroU32::{14}::new] *) +(** [core::num::nonzero::NonZeroU32::{14}::new]: forward function *) Axiom core_num_nonzero_non_zero_u32_new_fwd : u32 -> state -> result (state * (option Core_num_nonzero_non_zero_u32_t)) . -(** [core::option::Option::{0}::unwrap] *) +(** [core::option::Option::{0}::unwrap]: forward function *) Axiom core_option_option_unwrap_fwd : forall(T : Type), option T -> state -> result (state * T) . diff --git a/tests/coq/misc/Loops.v b/tests/coq/misc/Loops.v index a5cb3688..f17eb986 100644 --- a/tests/coq/misc/Loops.v +++ b/tests/coq/misc/Loops.v @@ -6,7 +6,7 @@ Require Import Coq.ZArith.ZArith. Local Open Scope Primitives_scope. Module Loops. -(** [loops::sum] *) +(** [loops::sum]: loop 0: forward function *) Fixpoint sum_loop_fwd (n : nat) (max : u32) (i : u32) (s : u32) : result u32 := match n with | O => Fail_ OutOfFuel @@ -17,12 +17,12 @@ Fixpoint sum_loop_fwd (n : nat) (max : u32) (i : u32) (s : u32) : result u32 := end . -(** [loops::sum] *) +(** [loops::sum]: forward function *) Definition sum_fwd (n : nat) (max : u32) : result u32 := sum_loop_fwd n max 0%u32 0%u32 . -(** [loops::sum_with_mut_borrows] *) +(** [loops::sum_with_mut_borrows]: loop 0: forward function *) Fixpoint sum_with_mut_borrows_loop_fwd (n : nat) (max : u32) (mi : u32) (ms : u32) : result u32 := match n with @@ -37,12 +37,12 @@ Fixpoint sum_with_mut_borrows_loop_fwd end . -(** [loops::sum_with_mut_borrows] *) +(** [loops::sum_with_mut_borrows]: forward function *) Definition sum_with_mut_borrows_fwd (n : nat) (max : u32) : result u32 := sum_with_mut_borrows_loop_fwd n max 0%u32 0%u32 . -(** [loops::sum_with_shared_borrows] *) +(** [loops::sum_with_shared_borrows]: loop 0: forward function *) Fixpoint sum_with_shared_borrows_loop_fwd (n : nat) (max : u32) (i : u32) (s : u32) : result u32 := match n with @@ -57,12 +57,13 @@ Fixpoint sum_with_shared_borrows_loop_fwd end . -(** [loops::sum_with_shared_borrows] *) +(** [loops::sum_with_shared_borrows]: forward function *) Definition sum_with_shared_borrows_fwd (n : nat) (max : u32) : result u32 := sum_with_shared_borrows_loop_fwd n max 0%u32 0%u32 . -(** [loops::clear] *) +(** [loops::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Fixpoint clear_loop_fwd_back (n : nat) (v : vec u32) (i : usize) : result (vec u32) := match n with @@ -78,7 +79,8 @@ Fixpoint clear_loop_fwd_back end . -(** [loops::clear] *) +(** [loops::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition clear_fwd_back (n : nat) (v : vec u32) : result (vec u32) := clear_loop_fwd_back n v 0%usize . @@ -92,7 +94,7 @@ Inductive List_t (T : Type) := Arguments ListCons {T} _ _. Arguments ListNil {T}. -(** [loops::list_mem] *) +(** [loops::list_mem]: loop 0: forward function *) Fixpoint list_mem_loop_fwd (n : nat) (x : u32) (ls : List_t u32) : result bool := match n with @@ -106,12 +108,12 @@ Fixpoint list_mem_loop_fwd end . -(** [loops::list_mem] *) +(** [loops::list_mem]: forward function *) Definition list_mem_fwd (n : nat) (x : u32) (ls : List_t u32) : result bool := list_mem_loop_fwd n x ls . -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: loop 0: forward function *) Fixpoint list_nth_mut_loop_loop_fwd (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := match n with @@ -127,13 +129,13 @@ Fixpoint list_nth_mut_loop_loop_fwd end . -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: forward function *) Definition list_nth_mut_loop_fwd (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := list_nth_mut_loop_loop_fwd T n ls i . -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: loop 0: backward function 0 *) Fixpoint list_nth_mut_loop_loop_back (T : Type) (n : nat) (ls : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -154,7 +156,7 @@ Fixpoint list_nth_mut_loop_loop_back end . -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: backward function 0 *) Definition list_nth_mut_loop_back (T : Type) (n : nat) (ls : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -162,7 +164,7 @@ Definition list_nth_mut_loop_back list_nth_mut_loop_loop_back T n ls i ret . -(** [loops::list_nth_shared_loop] *) +(** [loops::list_nth_shared_loop]: loop 0: forward function *) Fixpoint list_nth_shared_loop_loop_fwd (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := match n with @@ -178,13 +180,13 @@ Fixpoint list_nth_shared_loop_loop_fwd end . -(** [loops::list_nth_shared_loop] *) +(** [loops::list_nth_shared_loop]: forward function *) Definition list_nth_shared_loop_fwd (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := list_nth_shared_loop_loop_fwd T n ls i . -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: loop 0: forward function *) Fixpoint get_elem_mut_loop_fwd (n : nat) (x : usize) (ls : List_t usize) : result usize := match n with @@ -198,14 +200,14 @@ Fixpoint get_elem_mut_loop_fwd end . -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: forward function *) 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; get_elem_mut_loop_fwd n x l . -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: loop 0: backward function 0 *) Fixpoint get_elem_mut_loop_back (n : nat) (x : usize) (ls : List_t usize) (ret : usize) : result (List_t usize) @@ -223,7 +225,7 @@ Fixpoint get_elem_mut_loop_back end . -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: backward function 0 *) Definition get_elem_mut_back (n : nat) (slots : vec (List_t usize)) (x : usize) (ret : usize) : result (vec (List_t usize)) @@ -233,7 +235,7 @@ Definition get_elem_mut_back vec_index_mut_back (List_t usize) slots 0%usize l0 . -(** [loops::get_elem_shared] *) +(** [loops::get_elem_shared]: loop 0: forward function *) Fixpoint get_elem_shared_loop_fwd (n : nat) (x : usize) (ls : List_t usize) : result usize := match n with @@ -247,30 +249,30 @@ Fixpoint get_elem_shared_loop_fwd end . -(** [loops::get_elem_shared] *) +(** [loops::get_elem_shared]: forward function *) 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; get_elem_shared_loop_fwd n x l . -(** [loops::id_mut] *) +(** [loops::id_mut]: forward function *) Definition id_mut_fwd (T : Type) (ls : List_t T) : result (List_t T) := Return ls . -(** [loops::id_mut] *) +(** [loops::id_mut]: backward function 0 *) Definition id_mut_back (T : Type) (ls : List_t T) (ret : List_t T) : result (List_t T) := Return ret . -(** [loops::id_shared] *) +(** [loops::id_shared]: forward function *) Definition id_shared_fwd (T : Type) (ls : List_t T) : result (List_t T) := Return ls . -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: loop 0: forward function *) Fixpoint list_nth_mut_loop_with_id_loop_fwd (T : Type) (n : nat) (i : u32) (ls : List_t T) : result T := match n with @@ -287,13 +289,13 @@ Fixpoint list_nth_mut_loop_with_id_loop_fwd end . -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: forward function *) Definition list_nth_mut_loop_with_id_fwd (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := ls0 <- id_mut_fwd T ls; list_nth_mut_loop_with_id_loop_fwd T n i ls0 . -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: loop 0: backward function 0 *) Fixpoint list_nth_mut_loop_with_id_loop_back (T : Type) (n : nat) (i : u32) (ls : List_t T) (ret : T) : result (List_t T) @@ -314,7 +316,7 @@ Fixpoint list_nth_mut_loop_with_id_loop_back end . -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: backward function 0 *) Definition list_nth_mut_loop_with_id_back (T : Type) (n : nat) (ls : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -324,7 +326,7 @@ Definition list_nth_mut_loop_with_id_back id_mut_back T ls l . -(** [loops::list_nth_shared_loop_with_id] *) +(** [loops::list_nth_shared_loop_with_id]: loop 0: forward function *) Fixpoint list_nth_shared_loop_with_id_loop_fwd (T : Type) (n : nat) (i : u32) (ls : List_t T) : result T := match n with @@ -341,13 +343,13 @@ Fixpoint list_nth_shared_loop_with_id_loop_fwd end . -(** [loops::list_nth_shared_loop_with_id] *) +(** [loops::list_nth_shared_loop_with_id]: forward function *) Definition list_nth_shared_loop_with_id_fwd (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := ls0 <- id_shared_fwd T ls; list_nth_shared_loop_with_id_loop_fwd T n i ls0 . -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: loop 0: forward function *) Fixpoint list_nth_mut_loop_pair_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -371,7 +373,7 @@ Fixpoint list_nth_mut_loop_pair_loop_fwd end . -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: forward function *) Definition list_nth_mut_loop_pair_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -379,7 +381,7 @@ Definition list_nth_mut_loop_pair_fwd list_nth_mut_loop_pair_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: loop 0: backward function 0 *) Fixpoint list_nth_mut_loop_pair_loop_back'a (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -404,7 +406,7 @@ Fixpoint list_nth_mut_loop_pair_loop_back'a end . -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: backward function 0 *) Definition list_nth_mut_loop_pair_back'a (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -412,7 +414,7 @@ Definition list_nth_mut_loop_pair_back'a list_nth_mut_loop_pair_loop_back'a T n ls0 ls1 i ret . -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: loop 0: backward function 1 *) Fixpoint list_nth_mut_loop_pair_loop_back'b (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -437,7 +439,7 @@ Fixpoint list_nth_mut_loop_pair_loop_back'b end . -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: backward function 1 *) Definition list_nth_mut_loop_pair_back'b (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -445,7 +447,7 @@ Definition list_nth_mut_loop_pair_back'b list_nth_mut_loop_pair_loop_back'b T n ls0 ls1 i ret . -(** [loops::list_nth_shared_loop_pair] *) +(** [loops::list_nth_shared_loop_pair]: loop 0: forward function *) Fixpoint list_nth_shared_loop_pair_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -469,7 +471,7 @@ Fixpoint list_nth_shared_loop_pair_loop_fwd end . -(** [loops::list_nth_shared_loop_pair] *) +(** [loops::list_nth_shared_loop_pair]: forward function *) Definition list_nth_shared_loop_pair_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -477,7 +479,7 @@ Definition list_nth_shared_loop_pair_fwd list_nth_shared_loop_pair_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: loop 0: forward function *) Fixpoint list_nth_mut_loop_pair_merge_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -501,7 +503,7 @@ Fixpoint list_nth_mut_loop_pair_merge_loop_fwd end . -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: forward function *) Definition list_nth_mut_loop_pair_merge_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -509,7 +511,7 @@ Definition list_nth_mut_loop_pair_merge_fwd list_nth_mut_loop_pair_merge_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: loop 0: backward function 0 *) Fixpoint list_nth_mut_loop_pair_merge_loop_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : (T * T)) : @@ -536,7 +538,7 @@ Fixpoint list_nth_mut_loop_pair_merge_loop_back end . -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: backward function 0 *) Definition list_nth_mut_loop_pair_merge_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : (T * T)) : @@ -545,7 +547,7 @@ Definition list_nth_mut_loop_pair_merge_back list_nth_mut_loop_pair_merge_loop_back T n ls0 ls1 i ret . -(** [loops::list_nth_shared_loop_pair_merge] *) +(** [loops::list_nth_shared_loop_pair_merge]: loop 0: forward function *) Fixpoint list_nth_shared_loop_pair_merge_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -569,7 +571,7 @@ Fixpoint list_nth_shared_loop_pair_merge_loop_fwd end . -(** [loops::list_nth_shared_loop_pair_merge] *) +(** [loops::list_nth_shared_loop_pair_merge]: forward function *) Definition list_nth_shared_loop_pair_merge_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -577,7 +579,7 @@ Definition list_nth_shared_loop_pair_merge_fwd list_nth_shared_loop_pair_merge_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: loop 0: forward function *) Fixpoint list_nth_mut_shared_loop_pair_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -601,7 +603,7 @@ Fixpoint list_nth_mut_shared_loop_pair_loop_fwd end . -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: forward function *) Definition list_nth_mut_shared_loop_pair_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -609,7 +611,7 @@ Definition list_nth_mut_shared_loop_pair_fwd list_nth_mut_shared_loop_pair_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: loop 0: backward function 0 *) Fixpoint list_nth_mut_shared_loop_pair_loop_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -634,7 +636,7 @@ Fixpoint list_nth_mut_shared_loop_pair_loop_back end . -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: backward function 0 *) Definition list_nth_mut_shared_loop_pair_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -642,7 +644,7 @@ Definition list_nth_mut_shared_loop_pair_back list_nth_mut_shared_loop_pair_loop_back T n ls0 ls1 i ret . -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: forward function *) Fixpoint list_nth_mut_shared_loop_pair_merge_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -666,7 +668,7 @@ Fixpoint list_nth_mut_shared_loop_pair_merge_loop_fwd end . -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: forward function *) Definition list_nth_mut_shared_loop_pair_merge_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -674,7 +676,7 @@ Definition list_nth_mut_shared_loop_pair_merge_fwd list_nth_mut_shared_loop_pair_merge_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: backward function 0 *) Fixpoint list_nth_mut_shared_loop_pair_merge_loop_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -700,7 +702,7 @@ Fixpoint list_nth_mut_shared_loop_pair_merge_loop_back end . -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: backward function 0 *) Definition list_nth_mut_shared_loop_pair_merge_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -708,7 +710,7 @@ Definition list_nth_mut_shared_loop_pair_merge_back list_nth_mut_shared_loop_pair_merge_loop_back T n ls0 ls1 i ret . -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: loop 0: forward function *) Fixpoint list_nth_shared_mut_loop_pair_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -732,7 +734,7 @@ Fixpoint list_nth_shared_mut_loop_pair_loop_fwd end . -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: forward function *) Definition list_nth_shared_mut_loop_pair_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -740,7 +742,7 @@ Definition list_nth_shared_mut_loop_pair_fwd list_nth_shared_mut_loop_pair_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: loop 0: backward function 1 *) Fixpoint list_nth_shared_mut_loop_pair_loop_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -765,7 +767,7 @@ Fixpoint list_nth_shared_mut_loop_pair_loop_back end . -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: backward function 1 *) Definition list_nth_shared_mut_loop_pair_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -773,7 +775,7 @@ Definition list_nth_shared_mut_loop_pair_back list_nth_shared_mut_loop_pair_loop_back T n ls0 ls1 i ret . -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: forward function *) Fixpoint list_nth_shared_mut_loop_pair_merge_loop_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -797,7 +799,7 @@ Fixpoint list_nth_shared_mut_loop_pair_merge_loop_fwd end . -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: forward function *) Definition list_nth_shared_mut_loop_pair_merge_fwd (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -805,7 +807,7 @@ Definition list_nth_shared_mut_loop_pair_merge_fwd list_nth_shared_mut_loop_pair_merge_loop_fwd T n ls0 ls1 i . -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: backward function 0 *) Fixpoint list_nth_shared_mut_loop_pair_merge_loop_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) @@ -831,7 +833,7 @@ Fixpoint list_nth_shared_mut_loop_pair_merge_loop_back end . -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: backward function 0 *) Definition list_nth_shared_mut_loop_pair_merge_back (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) (ret : T) : result (List_t T) diff --git a/tests/coq/misc/NoNestedBorrows.v b/tests/coq/misc/NoNestedBorrows.v index 96d62711..470a2cde 100644 --- a/tests/coq/misc/NoNestedBorrows.v +++ b/tests/coq/misc/NoNestedBorrows.v @@ -45,47 +45,47 @@ Inductive Sum_t (T1 T2 : Type) := Arguments SumLeft {T1} {T2} _. Arguments SumRight {T1} {T2} _. -(** [no_nested_borrows::neg_test] *) +(** [no_nested_borrows::neg_test]: forward function *) Definition neg_test_fwd (x : i32) : result i32 := i32_neg x. -(** [no_nested_borrows::add_test] *) +(** [no_nested_borrows::add_test]: forward function *) Definition add_test_fwd (x : u32) (y : u32) : result u32 := u32_add x y. -(** [no_nested_borrows::subs_test] *) +(** [no_nested_borrows::subs_test]: forward function *) Definition subs_test_fwd (x : u32) (y : u32) : result u32 := u32_sub x y. -(** [no_nested_borrows::div_test] *) +(** [no_nested_borrows::div_test]: forward function *) Definition div_test_fwd (x : u32) (y : u32) : result u32 := u32_div x y. -(** [no_nested_borrows::div_test1] *) +(** [no_nested_borrows::div_test1]: forward function *) Definition div_test1_fwd (x : u32) : result u32 := u32_div x 2%u32. -(** [no_nested_borrows::rem_test] *) +(** [no_nested_borrows::rem_test]: forward function *) Definition rem_test_fwd (x : u32) (y : u32) : result u32 := u32_rem x y. -(** [no_nested_borrows::cast_test] *) +(** [no_nested_borrows::cast_test]: forward function *) Definition cast_test_fwd (x : u32) : result i32 := scalar_cast U32 I32 x. -(** [no_nested_borrows::test2] *) +(** [no_nested_borrows::test2]: forward function *) Definition test2_fwd : result unit := _ <- u32_add 23%u32 44%u32; Return tt. (** Unit test for [no_nested_borrows::test2] *) Check (test2_fwd )%return. -(** [no_nested_borrows::get_max] *) +(** [no_nested_borrows::get_max]: forward function *) Definition get_max_fwd (x : u32) (y : u32) : result u32 := if x s>= y then Return x else Return y . -(** [no_nested_borrows::test3] *) +(** [no_nested_borrows::test3]: forward function *) Definition test3_fwd : result unit := x <- get_max_fwd 4%u32 3%u32; y <- get_max_fwd 10%u32 11%u32; @@ -96,7 +96,7 @@ Definition test3_fwd : result unit := (** Unit test for [no_nested_borrows::test3] *) Check (test3_fwd )%return. -(** [no_nested_borrows::test_neg1] *) +(** [no_nested_borrows::test_neg1]: forward function *) Definition test_neg1_fwd : result unit := y <- i32_neg 3%i32; if negb (y s= (-3)%i32) then Fail_ Failure else Return tt . @@ -104,7 +104,7 @@ Definition test_neg1_fwd : result unit := (** Unit test for [no_nested_borrows::test_neg1] *) Check (test_neg1_fwd )%return. -(** [no_nested_borrows::refs_test1] *) +(** [no_nested_borrows::refs_test1]: forward function *) Definition refs_test1_fwd : result unit := if negb (1%i32 s= 1%i32) then Fail_ Failure else Return tt . @@ -112,7 +112,7 @@ Definition refs_test1_fwd : result unit := (** Unit test for [no_nested_borrows::refs_test1] *) Check (refs_test1_fwd )%return. -(** [no_nested_borrows::refs_test2] *) +(** [no_nested_borrows::refs_test2]: forward function *) Definition refs_test2_fwd : result unit := if negb (2%i32 s= 2%i32) then Fail_ Failure @@ -128,14 +128,14 @@ Definition refs_test2_fwd : result unit := (** Unit test for [no_nested_borrows::refs_test2] *) Check (refs_test2_fwd )%return. -(** [no_nested_borrows::test_list1] *) +(** [no_nested_borrows::test_list1]: forward function *) Definition test_list1_fwd : result unit := Return tt. (** Unit test for [no_nested_borrows::test_list1] *) Check (test_list1_fwd )%return. -(** [no_nested_borrows::test_box1] *) +(** [no_nested_borrows::test_box1]: forward function *) Definition test_box1_fwd : result unit := let b := 1%i32 in let x := b in @@ -145,21 +145,21 @@ Definition test_box1_fwd : result unit := (** Unit test for [no_nested_borrows::test_box1] *) Check (test_box1_fwd )%return. -(** [no_nested_borrows::copy_int] *) +(** [no_nested_borrows::copy_int]: forward function *) Definition copy_int_fwd (x : i32) : result i32 := Return x. -(** [no_nested_borrows::test_unreachable] *) +(** [no_nested_borrows::test_unreachable]: forward function *) Definition test_unreachable_fwd (b : bool) : result unit := if b then Fail_ Failure else Return tt . -(** [no_nested_borrows::test_panic] *) +(** [no_nested_borrows::test_panic]: forward function *) Definition test_panic_fwd (b : bool) : result unit := if b then Fail_ Failure else Return tt . -(** [no_nested_borrows::test_copy_int] *) +(** [no_nested_borrows::test_copy_int]: forward function *) Definition test_copy_int_fwd : result unit := y <- copy_int_fwd 0%i32; if negb (0%i32 s= y) then Fail_ Failure else Return tt @@ -168,12 +168,12 @@ Definition test_copy_int_fwd : result unit := (** Unit test for [no_nested_borrows::test_copy_int] *) Check (test_copy_int_fwd )%return. -(** [no_nested_borrows::is_cons] *) +(** [no_nested_borrows::is_cons]: forward function *) Definition is_cons_fwd (T : Type) (l : List_t T) : result bool := match l with | ListCons t l0 => Return true | ListNil => Return false end . -(** [no_nested_borrows::test_is_cons] *) +(** [no_nested_borrows::test_is_cons]: forward function *) Definition test_is_cons_fwd : result unit := let l := ListNil in b <- is_cons_fwd i32 (ListCons 0%i32 l); @@ -183,7 +183,7 @@ Definition test_is_cons_fwd : result unit := (** Unit test for [no_nested_borrows::test_is_cons] *) Check (test_is_cons_fwd )%return. -(** [no_nested_borrows::split_list] *) +(** [no_nested_borrows::split_list]: forward function *) Definition split_list_fwd (T : Type) (l : List_t T) : result (T * (List_t T)) := match l with @@ -192,7 +192,7 @@ Definition split_list_fwd end . -(** [no_nested_borrows::test_split_list] *) +(** [no_nested_borrows::test_split_list]: forward function *) Definition test_split_list_fwd : result unit := let l := ListNil in p <- split_list_fwd i32 (ListCons 0%i32 l); @@ -203,18 +203,18 @@ Definition test_split_list_fwd : result unit := (** Unit test for [no_nested_borrows::test_split_list] *) Check (test_split_list_fwd )%return. -(** [no_nested_borrows::choose] *) +(** [no_nested_borrows::choose]: forward function *) Definition choose_fwd (T : Type) (b : bool) (x : T) (y : T) : result T := if b then Return x else Return y . -(** [no_nested_borrows::choose] *) +(** [no_nested_borrows::choose]: backward function 0 *) 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) . -(** [no_nested_borrows::choose_test] *) +(** [no_nested_borrows::choose_test]: forward function *) Definition choose_test_fwd : result unit := z <- choose_fwd i32 true 0%i32 0%i32; z0 <- i32_add z 1%i32; @@ -231,7 +231,7 @@ Definition choose_test_fwd : result unit := (** Unit test for [no_nested_borrows::choose_test] *) Check (choose_test_fwd )%return. -(** [no_nested_borrows::test_char] *) +(** [no_nested_borrows::test_char]: forward function *) Definition test_char_fwd : result char := Return (char_of_byte Coq.Init.Byte.x61) . @@ -253,7 +253,7 @@ Arguments NodeElemNil {T}. Arguments TreeLeaf {T} _. Arguments TreeNode {T} _ _ _. -(** [no_nested_borrows::list_length] *) +(** [no_nested_borrows::list_length]: forward function *) 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 @@ -261,7 +261,7 @@ Fixpoint list_length_fwd (T : Type) (l : List_t T) : result u32 := end . -(** [no_nested_borrows::list_nth_shared] *) +(** [no_nested_borrows::list_nth_shared]: forward function *) Fixpoint list_nth_shared_fwd (T : Type) (l : List_t T) (i : u32) : result T := match l with | ListCons x tl => @@ -272,7 +272,7 @@ Fixpoint list_nth_shared_fwd (T : Type) (l : List_t T) (i : u32) : result T := end . -(** [no_nested_borrows::list_nth_mut] *) +(** [no_nested_borrows::list_nth_mut]: forward function *) Fixpoint list_nth_mut_fwd (T : Type) (l : List_t T) (i : u32) : result T := match l with | ListCons x tl => @@ -283,7 +283,7 @@ Fixpoint list_nth_mut_fwd (T : Type) (l : List_t T) (i : u32) : result T := end . -(** [no_nested_borrows::list_nth_mut] *) +(** [no_nested_borrows::list_nth_mut]: backward function 0 *) Fixpoint list_nth_mut_back (T : Type) (l : List_t T) (i : u32) (ret : T) : result (List_t T) := match l with @@ -298,7 +298,7 @@ Fixpoint list_nth_mut_back end . -(** [no_nested_borrows::list_rev_aux] *) +(** [no_nested_borrows::list_rev_aux]: forward function *) Fixpoint list_rev_aux_fwd (T : Type) (li : List_t T) (lo : List_t T) : result (List_t T) := match li with @@ -307,13 +307,14 @@ Fixpoint list_rev_aux_fwd end . -(** [no_nested_borrows::list_rev] *) +(** [no_nested_borrows::list_rev]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition list_rev_fwd_back (T : Type) (l : List_t T) : result (List_t T) := let li := mem_replace_fwd (List_t T) l ListNil in list_rev_aux_fwd T li ListNil . -(** [no_nested_borrows::test_list_functions] *) +(** [no_nested_borrows::test_list_functions]: forward function *) Definition test_list_functions_fwd : result unit := let l := ListNil in let l0 := ListCons 2%i32 l in @@ -350,61 +351,61 @@ Definition test_list_functions_fwd : result unit := (** Unit test for [no_nested_borrows::test_list_functions] *) Check (test_list_functions_fwd )%return. -(** [no_nested_borrows::id_mut_pair1] *) +(** [no_nested_borrows::id_mut_pair1]: forward function *) Definition id_mut_pair1_fwd (T1 T2 : Type) (x : T1) (y : T2) : result (T1 * T2) := Return (x, y) . -(** [no_nested_borrows::id_mut_pair1] *) +(** [no_nested_borrows::id_mut_pair1]: backward function 0 *) Definition id_mut_pair1_back (T1 T2 : Type) (x : T1) (y : T2) (ret : (T1 * T2)) : result (T1 * T2) := let (t, t0) := ret in Return (t, t0) . -(** [no_nested_borrows::id_mut_pair2] *) +(** [no_nested_borrows::id_mut_pair2]: forward function *) Definition id_mut_pair2_fwd (T1 T2 : Type) (p : (T1 * T2)) : result (T1 * T2) := let (t, t0) := p in Return (t, t0) . -(** [no_nested_borrows::id_mut_pair2] *) +(** [no_nested_borrows::id_mut_pair2]: backward function 0 *) Definition id_mut_pair2_back (T1 T2 : Type) (p : (T1 * T2)) (ret : (T1 * T2)) : result (T1 * T2) := let (t, t0) := ret in Return (t, t0) . -(** [no_nested_borrows::id_mut_pair3] *) +(** [no_nested_borrows::id_mut_pair3]: forward function *) Definition id_mut_pair3_fwd (T1 T2 : Type) (x : T1) (y : T2) : result (T1 * T2) := Return (x, y) . -(** [no_nested_borrows::id_mut_pair3] *) +(** [no_nested_borrows::id_mut_pair3]: backward function 0 *) Definition id_mut_pair3_back'a (T1 T2 : Type) (x : T1) (y : T2) (ret : T1) : result T1 := Return ret . -(** [no_nested_borrows::id_mut_pair3] *) +(** [no_nested_borrows::id_mut_pair3]: backward function 1 *) Definition id_mut_pair3_back'b (T1 T2 : Type) (x : T1) (y : T2) (ret : T2) : result T2 := Return ret . -(** [no_nested_borrows::id_mut_pair4] *) +(** [no_nested_borrows::id_mut_pair4]: forward function *) Definition id_mut_pair4_fwd (T1 T2 : Type) (p : (T1 * T2)) : result (T1 * T2) := let (t, t0) := p in Return (t, t0) . -(** [no_nested_borrows::id_mut_pair4] *) +(** [no_nested_borrows::id_mut_pair4]: backward function 0 *) Definition id_mut_pair4_back'a (T1 T2 : Type) (p : (T1 * T2)) (ret : T1) : result T1 := Return ret . -(** [no_nested_borrows::id_mut_pair4] *) +(** [no_nested_borrows::id_mut_pair4]: backward function 1 *) Definition id_mut_pair4_back'b (T1 T2 : Type) (p : (T1 * T2)) (ret : T2) : result T2 := Return ret @@ -420,17 +421,17 @@ mkStruct_with_tuple_t { Arguments mkStruct_with_tuple_t {T1} {T2} _. Arguments Struct_with_tuple_p {T1} {T2}. -(** [no_nested_borrows::new_tuple1] *) +(** [no_nested_borrows::new_tuple1]: forward function *) Definition new_tuple1_fwd : result (Struct_with_tuple_t u32 u32) := Return {| Struct_with_tuple_p := (1%u32, 2%u32) |} . -(** [no_nested_borrows::new_tuple2] *) +(** [no_nested_borrows::new_tuple2]: forward function *) Definition new_tuple2_fwd : result (Struct_with_tuple_t i16 i16) := Return {| Struct_with_tuple_p := (1%i16, 2%i16) |} . -(** [no_nested_borrows::new_tuple3] *) +(** [no_nested_borrows::new_tuple3]: forward function *) Definition new_tuple3_fwd : result (Struct_with_tuple_t u64 i64) := Return {| Struct_with_tuple_p := (1%u64, 2%i64) |} . @@ -445,12 +446,12 @@ mkStruct_with_pair_t { Arguments mkStruct_with_pair_t {T1} {T2} _. Arguments Struct_with_pair_p {T1} {T2}. -(** [no_nested_borrows::new_pair1] *) +(** [no_nested_borrows::new_pair1]: forward function *) Definition new_pair1_fwd : result (Struct_with_pair_t u32 u32) := Return {| Struct_with_pair_p := {| Pair_x := 1%u32; Pair_y := 2%u32 |} |} . -(** [no_nested_borrows::test_constants] *) +(** [no_nested_borrows::test_constants]: forward function *) Definition test_constants_fwd : result unit := swt <- new_tuple1_fwd; let (i, _) := swt.(Struct_with_tuple_p) in @@ -476,34 +477,35 @@ Definition test_constants_fwd : result unit := (** Unit test for [no_nested_borrows::test_constants] *) Check (test_constants_fwd )%return. -(** [no_nested_borrows::test_weird_borrows1] *) +(** [no_nested_borrows::test_weird_borrows1]: forward function *) Definition test_weird_borrows1_fwd : result unit := Return tt. (** Unit test for [no_nested_borrows::test_weird_borrows1] *) Check (test_weird_borrows1_fwd )%return. -(** [no_nested_borrows::test_mem_replace] *) +(** [no_nested_borrows::test_mem_replace]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) 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 . -(** [no_nested_borrows::test_shared_borrow_bool1] *) +(** [no_nested_borrows::test_shared_borrow_bool1]: forward function *) Definition test_shared_borrow_bool1_fwd (b : bool) : result u32 := if b then Return 0%u32 else Return 1%u32 . -(** [no_nested_borrows::test_shared_borrow_bool2] *) +(** [no_nested_borrows::test_shared_borrow_bool2]: forward function *) Definition test_shared_borrow_bool2_fwd : result u32 := Return 0%u32. -(** [no_nested_borrows::test_shared_borrow_enum1] *) +(** [no_nested_borrows::test_shared_borrow_enum1]: forward function *) 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 . -(** [no_nested_borrows::test_shared_borrow_enum2] *) +(** [no_nested_borrows::test_shared_borrow_enum2]: forward function *) Definition test_shared_borrow_enum2_fwd : result u32 := Return 0%u32. diff --git a/tests/coq/misc/Paper.v b/tests/coq/misc/Paper.v index 513bc749..0f854f31 100644 --- a/tests/coq/misc/Paper.v +++ b/tests/coq/misc/Paper.v @@ -6,11 +6,12 @@ Require Import Coq.ZArith.ZArith. Local Open Scope Primitives_scope. Module Paper. -(** [paper::ref_incr] *) +(** [paper::ref_incr]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) Definition ref_incr_fwd_back (x : i32) : result i32 := i32_add x 1%i32. -(** [paper::test_incr] *) +(** [paper::test_incr]: forward function *) Definition test_incr_fwd : result unit := x <- ref_incr_fwd_back 0%i32; if negb (x s= 1%i32) then Fail_ Failure else Return tt @@ -19,18 +20,18 @@ Definition test_incr_fwd : result unit := (** Unit test for [paper::test_incr] *) Check (test_incr_fwd )%return. -(** [paper::choose] *) +(** [paper::choose]: forward function *) Definition choose_fwd (T : Type) (b : bool) (x : T) (y : T) : result T := if b then Return x else Return y . -(** [paper::choose] *) +(** [paper::choose]: backward function 0 *) 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] *) +(** [paper::test_choose]: forward function *) Definition test_choose_fwd : result unit := z <- choose_fwd i32 true 0%i32 0%i32; z0 <- i32_add z 1%i32; @@ -56,7 +57,7 @@ Inductive List_t (T : Type) := Arguments ListCons {T} _ _. Arguments ListNil {T}. -(** [paper::list_nth_mut] *) +(** [paper::list_nth_mut]: forward function *) Fixpoint list_nth_mut_fwd (T : Type) (l : List_t T) (i : u32) : result T := match l with | ListCons x tl => @@ -67,7 +68,7 @@ Fixpoint list_nth_mut_fwd (T : Type) (l : List_t T) (i : u32) : result T := end . -(** [paper::list_nth_mut] *) +(** [paper::list_nth_mut]: backward function 0 *) Fixpoint list_nth_mut_back (T : Type) (l : List_t T) (i : u32) (ret : T) : result (List_t T) := match l with @@ -82,7 +83,7 @@ Fixpoint list_nth_mut_back end . -(** [paper::sum] *) +(** [paper::sum]: forward function *) Fixpoint sum_fwd (l : List_t i32) : result i32 := match l with | ListCons x tl => i <- sum_fwd tl; i32_add x i @@ -90,7 +91,7 @@ Fixpoint sum_fwd (l : List_t i32) : result i32 := end . -(** [paper::test_nth] *) +(** [paper::test_nth]: forward function *) Definition test_nth_fwd : result unit := let l := ListNil in let l0 := ListCons 3%i32 l in @@ -105,7 +106,7 @@ Definition test_nth_fwd : result unit := (** Unit test for [paper::test_nth] *) Check (test_nth_fwd )%return. -(** [paper::call_choose] *) +(** [paper::call_choose]: forward function *) Definition call_choose_fwd (p : (u32 * u32)) : result u32 := let (px, py) := p in pz <- choose_fwd u32 true px py; diff --git a/tests/coq/misc/PoloniusList.v b/tests/coq/misc/PoloniusList.v index bd6df02e..e94b6dcb 100644 --- a/tests/coq/misc/PoloniusList.v +++ b/tests/coq/misc/PoloniusList.v @@ -15,7 +15,7 @@ Inductive List_t (T : Type) := Arguments ListCons {T} _ _. Arguments ListNil {T}. -(** [polonius_list::get_list_at_x] *) +(** [polonius_list::get_list_at_x]: forward function *) Fixpoint get_list_at_x_fwd (ls : List_t u32) (x : u32) : result (List_t u32) := match ls with | ListCons hd tl => @@ -24,7 +24,7 @@ Fixpoint get_list_at_x_fwd (ls : List_t u32) (x : u32) : result (List_t u32) := end . -(** [polonius_list::get_list_at_x] *) +(** [polonius_list::get_list_at_x]: backward function 0 *) Fixpoint get_list_at_x_back (ls : List_t u32) (x : u32) (ret : List_t u32) : result (List_t u32) := match ls with diff --git a/tests/coq/misc/_CoqProject b/tests/coq/misc/_CoqProject index 87dea3e6..db6c2742 100644 --- a/tests/coq/misc/_CoqProject +++ b/tests/coq/misc/_CoqProject @@ -3,12 +3,12 @@ -arg -w -arg all -Constants.v -External_Types.v -Primitives.v Loops.v +Primitives.v External_Funs.v +Constants.v PoloniusList.v +External_Types.v NoNestedBorrows.v External_Opaque.v Paper.v diff --git a/tests/fstar/betree/BetreeMain.Funs.fst b/tests/fstar/betree/BetreeMain.Funs.fst index 0c868f47..f1bc1191 100644 --- a/tests/fstar/betree/BetreeMain.Funs.fst +++ b/tests/fstar/betree/BetreeMain.Funs.fst @@ -8,14 +8,14 @@ include BetreeMain.Clauses #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [betree_main::betree::load_internal_node] *) +(** [betree_main::betree::load_internal_node]: forward function *) let betree_load_internal_node_fwd (id : u64) (st : state) : result (state & (betree_list_t (u64 & betree_message_t))) = betree_utils_load_internal_node_fwd id st -(** [betree_main::betree::store_internal_node] *) +(** [betree_main::betree::store_internal_node]: forward function *) let betree_store_internal_node_fwd (id : u64) (content : betree_list_t (u64 & betree_message_t)) (st : state) : result (state & unit) @@ -23,12 +23,12 @@ let betree_store_internal_node_fwd let* (st0, _) = betree_utils_store_internal_node_fwd id content st in Return (st0, ()) -(** [betree_main::betree::load_leaf_node] *) +(** [betree_main::betree::load_leaf_node]: forward function *) let betree_load_leaf_node_fwd (id : u64) (st : state) : result (state & (betree_list_t (u64 & u64))) = betree_utils_load_leaf_node_fwd id st -(** [betree_main::betree::store_leaf_node] *) +(** [betree_main::betree::store_leaf_node]: forward function *) let betree_store_leaf_node_fwd (id : u64) (content : betree_list_t (u64 & u64)) (st : state) : result (state & unit) @@ -36,25 +36,25 @@ let betree_store_leaf_node_fwd let* (st0, _) = betree_utils_store_leaf_node_fwd id content st in Return (st0, ()) -(** [betree_main::betree::fresh_node_id] *) +(** [betree_main::betree::fresh_node_id]: forward function *) let betree_fresh_node_id_fwd (counter : u64) : result u64 = let* _ = u64_add counter 1 in Return counter -(** [betree_main::betree::fresh_node_id] *) +(** [betree_main::betree::fresh_node_id]: backward function 0 *) let betree_fresh_node_id_back (counter : u64) : result u64 = u64_add counter 1 -(** [betree_main::betree::NodeIdCounter::{0}::new] *) +(** [betree_main::betree::NodeIdCounter::{0}::new]: forward function *) let betree_node_id_counter_new_fwd : result betree_node_id_counter_t = Return { betree_node_id_counter_next_node_id = 0 } -(** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) +(** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function *) let betree_node_id_counter_fresh_id_fwd (self : betree_node_id_counter_t) : result u64 = let* _ = u64_add self.betree_node_id_counter_next_node_id 1 in Return self.betree_node_id_counter_next_node_id -(** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) +(** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 *) let betree_node_id_counter_fresh_id_back (self : betree_node_id_counter_t) : result betree_node_id_counter_t = let* i = u64_add self.betree_node_id_counter_next_node_id 1 in @@ -64,7 +64,7 @@ let betree_node_id_counter_fresh_id_back let core_num_u64_max_body : result u64 = Return 18446744073709551615 let core_num_u64_max_c : u64 = eval_global core_num_u64_max_body -(** [betree_main::betree::upsert_update] *) +(** [betree_main::betree::upsert_update]: forward function *) let betree_upsert_update_fwd (prev : option u64) (st : betree_upsert_fun_state_t) : result u64 = begin match prev with @@ -83,7 +83,7 @@ let betree_upsert_update_fwd end end -(** [betree_main::betree::List::{1}::len] *) +(** [betree_main::betree::List::{1}::len]: forward function *) let rec betree_list_len_fwd (t : Type0) (self : betree_list_t t) : Tot (result u64) (decreases (betree_list_len_decreases t self)) @@ -93,7 +93,7 @@ let rec betree_list_len_fwd | BetreeListNil -> Return 0 end -(** [betree_main::betree::List::{1}::split_at] *) +(** [betree_main::betree::List::{1}::split_at]: forward function *) let rec betree_list_split_at_fwd (t : Type0) (self : betree_list_t t) (n : u64) : Tot (result ((betree_list_t t) & (betree_list_t t))) @@ -112,14 +112,15 @@ let rec betree_list_split_at_fwd | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{1}::push_front] *) +(** [betree_main::betree::List::{1}::push_front]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let betree_list_push_front_fwd_back (t : Type0) (self : betree_list_t t) (x : t) : result (betree_list_t t) = let tl = mem_replace_fwd (betree_list_t t) self BetreeListNil in let l = tl in Return (BetreeListCons x l) -(** [betree_main::betree::List::{1}::pop_front] *) +(** [betree_main::betree::List::{1}::pop_front]: forward function *) let betree_list_pop_front_fwd (t : Type0) (self : betree_list_t t) : result t = let ls = mem_replace_fwd (betree_list_t t) self BetreeListNil in begin match ls with @@ -127,7 +128,7 @@ let betree_list_pop_front_fwd (t : Type0) (self : betree_list_t t) : result t = | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{1}::pop_front] *) +(** [betree_main::betree::List::{1}::pop_front]: backward function 0 *) let betree_list_pop_front_back (t : Type0) (self : betree_list_t t) : result (betree_list_t t) = let ls = mem_replace_fwd (betree_list_t t) self BetreeListNil in @@ -136,14 +137,14 @@ let betree_list_pop_front_back | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{1}::hd] *) +(** [betree_main::betree::List::{1}::hd]: forward function *) let betree_list_hd_fwd (t : Type0) (self : betree_list_t t) : result t = begin match self with | BetreeListCons hd l -> Return hd | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{2}::head_has_key] *) +(** [betree_main::betree::List::{2}::head_has_key]: forward function *) let betree_list_head_has_key_fwd (t : Type0) (self : betree_list_t (u64 & t)) (key : u64) : result bool = begin match self with @@ -151,7 +152,7 @@ let betree_list_head_has_key_fwd | BetreeListNil -> Return false end -(** [betree_main::betree::List::{2}::partition_at_pivot] *) +(** [betree_main::betree::List::{2}::partition_at_pivot]: forward function *) let rec betree_list_partition_at_pivot_fwd (t : Type0) (self : betree_list_t (u64 & t)) (pivot : u64) : Tot (result ((betree_list_t (u64 & t)) & (betree_list_t (u64 & t)))) @@ -170,7 +171,7 @@ let rec betree_list_partition_at_pivot_fwd | BetreeListNil -> Return (BetreeListNil, BetreeListNil) end -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: forward function *) let betree_leaf_split_fwd (self : betree_leaf_t) (content : betree_list_t (u64 & u64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -202,7 +203,7 @@ let betree_leaf_split_fwd betree_internal_right = n0 }) -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: backward function 2 *) let betree_leaf_split_back (self : betree_leaf_t) (content : betree_list_t (u64 & u64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -221,7 +222,7 @@ let betree_leaf_split_back let* _ = betree_store_leaf_node_fwd id1 content1 st0 in betree_node_id_counter_fresh_id_back node_id_cnt0 -(** [betree_main::betree::Node::{5}::lookup_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_in_bindings]: forward function *) let rec betree_node_lookup_in_bindings_fwd (key : u64) (bindings : betree_list_t (u64 & u64)) : Tot (result (option u64)) @@ -239,7 +240,7 @@ let rec betree_node_lookup_in_bindings_fwd | BetreeListNil -> Return None end -(** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: forward function *) let rec betree_node_lookup_first_message_for_key_fwd (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) : Tot (result (betree_list_t (u64 & betree_message_t))) @@ -254,7 +255,7 @@ let rec betree_node_lookup_first_message_for_key_fwd | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: backward function 0 *) let rec betree_node_lookup_first_message_for_key_back (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) (ret : betree_list_t (u64 & betree_message_t)) : @@ -273,7 +274,7 @@ let rec betree_node_lookup_first_message_for_key_back | BetreeListNil -> Return ret end -(** [betree_main::betree::Node::{5}::apply_upserts] *) +(** [betree_main::betree::Node::{5}::apply_upserts]: forward function *) let rec betree_node_apply_upserts_fwd (msgs : betree_list_t (u64 & betree_message_t)) (prev : option u64) (key : u64) (st : state) : @@ -300,7 +301,7 @@ let rec betree_node_apply_upserts_fwd BetreeMessageInsert v) in Return (st0, v) -(** [betree_main::betree::Node::{5}::apply_upserts] *) +(** [betree_main::betree::Node::{5}::apply_upserts]: backward function 0 *) let rec betree_node_apply_upserts_back (msgs : betree_list_t (u64 & betree_message_t)) (prev : option u64) (key : u64) (st : state) : @@ -325,7 +326,7 @@ let rec betree_node_apply_upserts_back betree_list_push_front_fwd_back (u64 & betree_message_t) msgs (key, BetreeMessageInsert v) -(** [betree_main::betree::Node::{5}::lookup] *) +(** [betree_main::betree::Node::{5}::lookup]: forward function *) let rec betree_node_lookup_fwd (self : betree_node_t) (key : u64) (st : state) : Tot (result (state & (option u64))) @@ -388,7 +389,7 @@ let rec betree_node_lookup_fwd Return (st0, opt) end -(** [betree_main::betree::Node::{5}::lookup] *) +(** [betree_main::betree::Node::{5}::lookup]: backward function 0 *) and betree_node_lookup_back (self : betree_node_t) (key : u64) (st : state) : Tot (result betree_node_t) @@ -450,7 +451,7 @@ and betree_node_lookup_back Return (BetreeNodeLeaf node) end -(** [betree_main::betree::Internal::{4}::lookup_in_children] *) +(** [betree_main::betree::Internal::{4}::lookup_in_children]: forward function *) and betree_internal_lookup_in_children_fwd (self : betree_internal_t) (key : u64) (st : state) : Tot (result (state & (option u64))) @@ -460,7 +461,7 @@ and betree_internal_lookup_in_children_fwd then betree_node_lookup_fwd self.betree_internal_left key st else betree_node_lookup_fwd self.betree_internal_right key st -(** [betree_main::betree::Internal::{4}::lookup_in_children] *) +(** [betree_main::betree::Internal::{4}::lookup_in_children]: backward function 0 *) and betree_internal_lookup_in_children_back (self : betree_internal_t) (key : u64) (st : state) : Tot (result betree_internal_t) @@ -474,7 +475,7 @@ and betree_internal_lookup_in_children_back let* n = betree_node_lookup_back self.betree_internal_right key st in Return { self with betree_internal_right = n } -(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: forward function *) let rec betree_node_lookup_mut_in_bindings_fwd (key : u64) (bindings : betree_list_t (u64 & u64)) : Tot (result (betree_list_t (u64 & u64))) @@ -489,7 +490,7 @@ let rec betree_node_lookup_mut_in_bindings_fwd | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: backward function 0 *) let rec betree_node_lookup_mut_in_bindings_back (key : u64) (bindings : betree_list_t (u64 & u64)) (ret : betree_list_t (u64 & u64)) : @@ -507,7 +508,8 @@ let rec betree_node_lookup_mut_in_bindings_back | BetreeListNil -> Return ret end -(** [betree_main::betree::Node::{5}::apply_to_leaf] *) +(** [betree_main::betree::Node::{5}::apply_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let betree_node_apply_to_leaf_fwd_back (bindings : betree_list_t (u64 & u64)) (key : u64) (new_msg : betree_message_t) : @@ -550,7 +552,8 @@ let betree_node_apply_to_leaf_fwd_back betree_node_lookup_mut_in_bindings_back key bindings bindings1 end -(** [betree_main::betree::Node::{5}::apply_messages_to_leaf] *) +(** [betree_main::betree::Node::{5}::apply_messages_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec betree_node_apply_messages_to_leaf_fwd_back (bindings : betree_list_t (u64 & u64)) (new_msgs : betree_list_t (u64 & betree_message_t)) : @@ -565,7 +568,8 @@ let rec betree_node_apply_messages_to_leaf_fwd_back | BetreeListNil -> Return bindings end -(** [betree_main::betree::Node::{5}::filter_messages_for_key] *) +(** [betree_main::betree::Node::{5}::filter_messages_for_key]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec betree_node_filter_messages_for_key_fwd_back (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) : Tot (result (betree_list_t (u64 & betree_message_t))) @@ -584,7 +588,7 @@ let rec betree_node_filter_messages_for_key_fwd_back | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: forward function *) let rec betree_node_lookup_first_message_after_key_fwd (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) : Tot (result (betree_list_t (u64 & betree_message_t))) @@ -599,7 +603,7 @@ let rec betree_node_lookup_first_message_after_key_fwd | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: backward function 0 *) let rec betree_node_lookup_first_message_after_key_back (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) (ret : betree_list_t (u64 & betree_message_t)) : @@ -618,7 +622,8 @@ let rec betree_node_lookup_first_message_after_key_back | BetreeListNil -> Return ret end -(** [betree_main::betree::Node::{5}::apply_to_internal] *) +(** [betree_main::betree::Node::{5}::apply_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let betree_node_apply_to_internal_fwd_back (msgs : betree_list_t (u64 & betree_message_t)) (key : u64) (new_msg : betree_message_t) : @@ -678,7 +683,8 @@ let betree_node_apply_to_internal_fwd_back new_msg) in betree_node_lookup_first_message_for_key_back key msgs msgs1 -(** [betree_main::betree::Node::{5}::apply_messages_to_internal] *) +(** [betree_main::betree::Node::{5}::apply_messages_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec betree_node_apply_messages_to_internal_fwd_back (msgs : betree_list_t (u64 & betree_message_t)) (new_msgs : betree_list_t (u64 & betree_message_t)) : @@ -693,7 +699,7 @@ let rec betree_node_apply_messages_to_internal_fwd_back | BetreeListNil -> Return msgs end -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: forward function *) let rec betree_node_apply_messages_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -740,7 +746,7 @@ let rec betree_node_apply_messages_fwd Return (st1, ()) end -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: backward function 0 *) and betree_node_apply_messages_back (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -788,7 +794,7 @@ and betree_node_apply_messages_back Return (BetreeNodeLeaf { node with betree_leaf_size = len }, node_id_cnt) end -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: forward function *) and betree_internal_flush_fwd (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -830,7 +836,7 @@ and betree_internal_flush_fwd node_id_cnt msgs_right st in Return (st0, msgs_left) -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: backward function 0 *) and betree_internal_flush_back (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -868,7 +874,7 @@ and betree_internal_flush_back node_id_cnt msgs_right st in Return ({ self with betree_internal_right = n }, node_id_cnt0) -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: forward function *) let betree_node_apply_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -884,7 +890,7 @@ let betree_node_apply_fwd (key, new_msg) l) st in Return (st0, ()) -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: backward function 0 *) let betree_node_apply_back (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -895,7 +901,7 @@ let betree_node_apply_back betree_node_apply_messages_back self params node_id_cnt (BetreeListCons (key, new_msg) l) st -(** [betree_main::betree::BeTree::{6}::new] *) +(** [betree_main::betree::BeTree::{6}::new]: forward function *) let betree_be_tree_new_fwd (min_flush_size : u64) (split_size : u64) (st : state) : result (state & betree_be_tree_t) @@ -916,7 +922,7 @@ let betree_be_tree_new_fwd (BetreeNodeLeaf { betree_leaf_id = id; betree_leaf_size = 0 }) }) -(** [betree_main::betree::BeTree::{6}::apply] *) +(** [betree_main::betree::BeTree::{6}::apply]: forward function *) let betree_be_tree_apply_fwd (self : betree_be_tree_t) (key : u64) (msg : betree_message_t) (st : state) : result (state & unit) @@ -929,7 +935,7 @@ let betree_be_tree_apply_fwd self.betree_be_tree_node_id_cnt key msg st in Return (st0, ()) -(** [betree_main::betree::BeTree::{6}::apply] *) +(** [betree_main::betree::BeTree::{6}::apply]: backward function 0 *) let betree_be_tree_apply_back (self : betree_be_tree_t) (key : u64) (msg : betree_message_t) (st : state) : result betree_be_tree_t @@ -940,7 +946,7 @@ let betree_be_tree_apply_back Return { self with betree_be_tree_node_id_cnt = nic; betree_be_tree_root = n } -(** [betree_main::betree::BeTree::{6}::insert] *) +(** [betree_main::betree::BeTree::{6}::insert]: forward function *) let betree_be_tree_insert_fwd (self : betree_be_tree_t) (key : u64) (value : u64) (st : state) : result (state & unit) @@ -950,28 +956,28 @@ let betree_be_tree_insert_fwd let* _ = betree_be_tree_apply_back self key (BetreeMessageInsert value) st in Return (st0, ()) -(** [betree_main::betree::BeTree::{6}::insert] *) +(** [betree_main::betree::BeTree::{6}::insert]: backward function 0 *) let betree_be_tree_insert_back (self : betree_be_tree_t) (key : u64) (value : u64) (st : state) : result betree_be_tree_t = betree_be_tree_apply_back self key (BetreeMessageInsert value) st -(** [betree_main::betree::BeTree::{6}::delete] *) +(** [betree_main::betree::BeTree::{6}::delete]: forward function *) let betree_be_tree_delete_fwd (self : betree_be_tree_t) (key : u64) (st : state) : result (state & unit) = let* (st0, _) = betree_be_tree_apply_fwd self key BetreeMessageDelete st in let* _ = betree_be_tree_apply_back self key BetreeMessageDelete st in Return (st0, ()) -(** [betree_main::betree::BeTree::{6}::delete] *) +(** [betree_main::betree::BeTree::{6}::delete]: backward function 0 *) let betree_be_tree_delete_back (self : betree_be_tree_t) (key : u64) (st : state) : result betree_be_tree_t = betree_be_tree_apply_back self key BetreeMessageDelete st -(** [betree_main::betree::BeTree::{6}::upsert] *) +(** [betree_main::betree::BeTree::{6}::upsert]: forward function *) let betree_be_tree_upsert_fwd (self : betree_be_tree_t) (key : u64) (upd : betree_upsert_fun_state_t) (st : state) : @@ -982,7 +988,7 @@ let betree_be_tree_upsert_fwd let* _ = betree_be_tree_apply_back self key (BetreeMessageUpsert upd) st in Return (st0, ()) -(** [betree_main::betree::BeTree::{6}::upsert] *) +(** [betree_main::betree::BeTree::{6}::upsert]: backward function 0 *) let betree_be_tree_upsert_back (self : betree_be_tree_t) (key : u64) (upd : betree_upsert_fun_state_t) (st : state) : @@ -990,14 +996,14 @@ let betree_be_tree_upsert_back = betree_be_tree_apply_back self key (BetreeMessageUpsert upd) st -(** [betree_main::betree::BeTree::{6}::lookup] *) +(** [betree_main::betree::BeTree::{6}::lookup]: forward function *) let betree_be_tree_lookup_fwd (self : betree_be_tree_t) (key : u64) (st : state) : result (state & (option u64)) = betree_node_lookup_fwd self.betree_be_tree_root key st -(** [betree_main::betree::BeTree::{6}::lookup] *) +(** [betree_main::betree::BeTree::{6}::lookup]: backward function 0 *) let betree_be_tree_lookup_back (self : betree_be_tree_t) (key : u64) (st : state) : result betree_be_tree_t @@ -1005,7 +1011,7 @@ let betree_be_tree_lookup_back let* n = betree_node_lookup_back self.betree_be_tree_root key st in Return { self with betree_be_tree_root = n } -(** [betree_main::main] *) +(** [betree_main::main]: forward function *) let main_fwd : result unit = Return () diff --git a/tests/fstar/betree/BetreeMain.Opaque.fsti b/tests/fstar/betree/BetreeMain.Opaque.fsti index dc49601a..c33cf225 100644 --- a/tests/fstar/betree/BetreeMain.Opaque.fsti +++ b/tests/fstar/betree/BetreeMain.Opaque.fsti @@ -1,30 +1,30 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [betree_main]: opaque function definitions *) +(** [betree_main]: external function declarations *) module BetreeMain.Opaque open Primitives include BetreeMain.Types #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [betree_main::betree_utils::load_internal_node] *) +(** [betree_main::betree_utils::load_internal_node]: forward function *) val betree_utils_load_internal_node_fwd : u64 -> state -> result (state & (betree_list_t (u64 & betree_message_t))) -(** [betree_main::betree_utils::store_internal_node] *) +(** [betree_main::betree_utils::store_internal_node]: forward function *) val betree_utils_store_internal_node_fwd : u64 -> betree_list_t (u64 & betree_message_t) -> state -> result (state & unit) -(** [betree_main::betree_utils::load_leaf_node] *) +(** [betree_main::betree_utils::load_leaf_node]: forward function *) val betree_utils_load_leaf_node_fwd : u64 -> state -> result (state & (betree_list_t (u64 & u64))) -(** [betree_main::betree_utils::store_leaf_node] *) +(** [betree_main::betree_utils::store_leaf_node]: forward function *) val betree_utils_store_leaf_node_fwd : u64 -> betree_list_t (u64 & u64) -> state -> result (state & unit) -(** [core::option::Option::{0}::unwrap] *) +(** [core::option::Option::{0}::unwrap]: forward function *) val core_option_option_unwrap_fwd (t : Type0) : option t -> state -> result (state & t) diff --git a/tests/fstar/betree_back_stateful/BetreeMain.Funs.fst b/tests/fstar/betree_back_stateful/BetreeMain.Funs.fst index c70bef08..12402fb4 100644 --- a/tests/fstar/betree_back_stateful/BetreeMain.Funs.fst +++ b/tests/fstar/betree_back_stateful/BetreeMain.Funs.fst @@ -8,14 +8,14 @@ include BetreeMain.Clauses #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [betree_main::betree::load_internal_node] *) +(** [betree_main::betree::load_internal_node]: forward function *) let betree_load_internal_node_fwd (id : u64) (st : state) : result (state & (betree_list_t (u64 & betree_message_t))) = betree_utils_load_internal_node_fwd id st -(** [betree_main::betree::store_internal_node] *) +(** [betree_main::betree::store_internal_node]: forward function *) let betree_store_internal_node_fwd (id : u64) (content : betree_list_t (u64 & betree_message_t)) (st : state) : result (state & unit) @@ -23,12 +23,12 @@ let betree_store_internal_node_fwd let* (st0, _) = betree_utils_store_internal_node_fwd id content st in Return (st0, ()) -(** [betree_main::betree::load_leaf_node] *) +(** [betree_main::betree::load_leaf_node]: forward function *) let betree_load_leaf_node_fwd (id : u64) (st : state) : result (state & (betree_list_t (u64 & u64))) = betree_utils_load_leaf_node_fwd id st -(** [betree_main::betree::store_leaf_node] *) +(** [betree_main::betree::store_leaf_node]: forward function *) let betree_store_leaf_node_fwd (id : u64) (content : betree_list_t (u64 & u64)) (st : state) : result (state & unit) @@ -36,25 +36,25 @@ let betree_store_leaf_node_fwd let* (st0, _) = betree_utils_store_leaf_node_fwd id content st in Return (st0, ()) -(** [betree_main::betree::fresh_node_id] *) +(** [betree_main::betree::fresh_node_id]: forward function *) let betree_fresh_node_id_fwd (counter : u64) : result u64 = let* _ = u64_add counter 1 in Return counter -(** [betree_main::betree::fresh_node_id] *) +(** [betree_main::betree::fresh_node_id]: backward function 0 *) let betree_fresh_node_id_back (counter : u64) : result u64 = u64_add counter 1 -(** [betree_main::betree::NodeIdCounter::{0}::new] *) +(** [betree_main::betree::NodeIdCounter::{0}::new]: forward function *) let betree_node_id_counter_new_fwd : result betree_node_id_counter_t = Return { betree_node_id_counter_next_node_id = 0 } -(** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) +(** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function *) let betree_node_id_counter_fresh_id_fwd (self : betree_node_id_counter_t) : result u64 = let* _ = u64_add self.betree_node_id_counter_next_node_id 1 in Return self.betree_node_id_counter_next_node_id -(** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) +(** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 *) let betree_node_id_counter_fresh_id_back (self : betree_node_id_counter_t) : result betree_node_id_counter_t = let* i = u64_add self.betree_node_id_counter_next_node_id 1 in @@ -64,7 +64,7 @@ let betree_node_id_counter_fresh_id_back let core_num_u64_max_body : result u64 = Return 18446744073709551615 let core_num_u64_max_c : u64 = eval_global core_num_u64_max_body -(** [betree_main::betree::upsert_update] *) +(** [betree_main::betree::upsert_update]: forward function *) let betree_upsert_update_fwd (prev : option u64) (st : betree_upsert_fun_state_t) : result u64 = begin match prev with @@ -83,7 +83,7 @@ let betree_upsert_update_fwd end end -(** [betree_main::betree::List::{1}::len] *) +(** [betree_main::betree::List::{1}::len]: forward function *) let rec betree_list_len_fwd (t : Type0) (self : betree_list_t t) : Tot (result u64) (decreases (betree_list_len_decreases t self)) @@ -93,7 +93,7 @@ let rec betree_list_len_fwd | BetreeListNil -> Return 0 end -(** [betree_main::betree::List::{1}::split_at] *) +(** [betree_main::betree::List::{1}::split_at]: forward function *) let rec betree_list_split_at_fwd (t : Type0) (self : betree_list_t t) (n : u64) : Tot (result ((betree_list_t t) & (betree_list_t t))) @@ -112,14 +112,15 @@ let rec betree_list_split_at_fwd | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{1}::push_front] *) +(** [betree_main::betree::List::{1}::push_front]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let betree_list_push_front_fwd_back (t : Type0) (self : betree_list_t t) (x : t) : result (betree_list_t t) = let tl = mem_replace_fwd (betree_list_t t) self BetreeListNil in let l = tl in Return (BetreeListCons x l) -(** [betree_main::betree::List::{1}::pop_front] *) +(** [betree_main::betree::List::{1}::pop_front]: forward function *) let betree_list_pop_front_fwd (t : Type0) (self : betree_list_t t) : result t = let ls = mem_replace_fwd (betree_list_t t) self BetreeListNil in begin match ls with @@ -127,7 +128,7 @@ let betree_list_pop_front_fwd (t : Type0) (self : betree_list_t t) : result t = | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{1}::pop_front] *) +(** [betree_main::betree::List::{1}::pop_front]: backward function 0 *) let betree_list_pop_front_back (t : Type0) (self : betree_list_t t) : result (betree_list_t t) = let ls = mem_replace_fwd (betree_list_t t) self BetreeListNil in @@ -136,14 +137,14 @@ let betree_list_pop_front_back | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{1}::hd] *) +(** [betree_main::betree::List::{1}::hd]: forward function *) let betree_list_hd_fwd (t : Type0) (self : betree_list_t t) : result t = begin match self with | BetreeListCons hd l -> Return hd | BetreeListNil -> Fail Failure end -(** [betree_main::betree::List::{2}::head_has_key] *) +(** [betree_main::betree::List::{2}::head_has_key]: forward function *) let betree_list_head_has_key_fwd (t : Type0) (self : betree_list_t (u64 & t)) (key : u64) : result bool = begin match self with @@ -151,7 +152,7 @@ let betree_list_head_has_key_fwd | BetreeListNil -> Return false end -(** [betree_main::betree::List::{2}::partition_at_pivot] *) +(** [betree_main::betree::List::{2}::partition_at_pivot]: forward function *) let rec betree_list_partition_at_pivot_fwd (t : Type0) (self : betree_list_t (u64 & t)) (pivot : u64) : Tot (result ((betree_list_t (u64 & t)) & (betree_list_t (u64 & t)))) @@ -170,7 +171,7 @@ let rec betree_list_partition_at_pivot_fwd | BetreeListNil -> Return (BetreeListNil, BetreeListNil) end -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: forward function *) let betree_leaf_split_fwd (self : betree_leaf_t) (content : betree_list_t (u64 & u64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -202,7 +203,7 @@ let betree_leaf_split_fwd betree_internal_right = n0 }) -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: backward function 0 *) let betree_leaf_split_back0 (self : betree_leaf_t) (content : betree_list_t (u64 & u64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -221,7 +222,7 @@ let betree_leaf_split_back0 let* _ = betree_store_leaf_node_fwd id1 content1 st1 in Return (st0, ()) -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: backward function 1 *) let betree_leaf_split_back1 (self : betree_leaf_t) (content : betree_list_t (u64 & u64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -240,7 +241,7 @@ let betree_leaf_split_back1 let* _ = betree_store_leaf_node_fwd id1 content1 st1 in Return (st0, ()) -(** [betree_main::betree::Leaf::{3}::split] *) +(** [betree_main::betree::Leaf::{3}::split]: backward function 2 *) let betree_leaf_split_back2 (self : betree_leaf_t) (content : betree_list_t (u64 & u64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -260,7 +261,7 @@ let betree_leaf_split_back2 let* node_id_cnt1 = betree_node_id_counter_fresh_id_back node_id_cnt0 in Return (st0, node_id_cnt1) -(** [betree_main::betree::Node::{5}::lookup_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_in_bindings]: forward function *) let rec betree_node_lookup_in_bindings_fwd (key : u64) (bindings : betree_list_t (u64 & u64)) : Tot (result (option u64)) @@ -278,7 +279,7 @@ let rec betree_node_lookup_in_bindings_fwd | BetreeListNil -> Return None end -(** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: forward function *) let rec betree_node_lookup_first_message_for_key_fwd (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) : Tot (result (betree_list_t (u64 & betree_message_t))) @@ -293,7 +294,7 @@ let rec betree_node_lookup_first_message_for_key_fwd | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: backward function 0 *) let rec betree_node_lookup_first_message_for_key_back (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) (ret : betree_list_t (u64 & betree_message_t)) : @@ -312,7 +313,7 @@ let rec betree_node_lookup_first_message_for_key_back | BetreeListNil -> Return ret end -(** [betree_main::betree::Node::{5}::apply_upserts] *) +(** [betree_main::betree::Node::{5}::apply_upserts]: forward function *) let rec betree_node_apply_upserts_fwd (msgs : betree_list_t (u64 & betree_message_t)) (prev : option u64) (key : u64) (st : state) : @@ -339,7 +340,7 @@ let rec betree_node_apply_upserts_fwd BetreeMessageInsert v) in Return (st0, v) -(** [betree_main::betree::Node::{5}::apply_upserts] *) +(** [betree_main::betree::Node::{5}::apply_upserts]: backward function 0 *) let rec betree_node_apply_upserts_back (msgs : betree_list_t (u64 & betree_message_t)) (prev : option u64) (key : u64) (st : state) (st0 : state) : @@ -366,7 +367,7 @@ let rec betree_node_apply_upserts_back BetreeMessageInsert v) in Return (st0, msgs0) -(** [betree_main::betree::Node::{5}::lookup] *) +(** [betree_main::betree::Node::{5}::lookup]: forward function *) let rec betree_node_lookup_fwd (self : betree_node_t) (key : u64) (st : state) : Tot (result (state & (option u64))) @@ -430,7 +431,7 @@ let rec betree_node_lookup_fwd Return (st0, opt) end -(** [betree_main::betree::Node::{5}::lookup] *) +(** [betree_main::betree::Node::{5}::lookup]: backward function 0 *) and betree_node_lookup_back (self : betree_node_t) (key : u64) (st : state) (st0 : state) : Tot (result (state & betree_node_t)) @@ -495,7 +496,7 @@ and betree_node_lookup_back Return (st0, BetreeNodeLeaf node) end -(** [betree_main::betree::Internal::{4}::lookup_in_children] *) +(** [betree_main::betree::Internal::{4}::lookup_in_children]: forward function *) and betree_internal_lookup_in_children_fwd (self : betree_internal_t) (key : u64) (st : state) : Tot (result (state & (option u64))) @@ -505,7 +506,7 @@ and betree_internal_lookup_in_children_fwd then betree_node_lookup_fwd self.betree_internal_left key st else betree_node_lookup_fwd self.betree_internal_right key st -(** [betree_main::betree::Internal::{4}::lookup_in_children] *) +(** [betree_main::betree::Internal::{4}::lookup_in_children]: backward function 0 *) and betree_internal_lookup_in_children_back (self : betree_internal_t) (key : u64) (st : state) (st0 : state) : Tot (result (state & betree_internal_t)) @@ -521,7 +522,7 @@ and betree_internal_lookup_in_children_back betree_node_lookup_back self.betree_internal_right key st st0 in Return (st1, { self with betree_internal_right = n }) -(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: forward function *) let rec betree_node_lookup_mut_in_bindings_fwd (key : u64) (bindings : betree_list_t (u64 & u64)) : Tot (result (betree_list_t (u64 & u64))) @@ -536,7 +537,7 @@ let rec betree_node_lookup_mut_in_bindings_fwd | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) +(** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: backward function 0 *) let rec betree_node_lookup_mut_in_bindings_back (key : u64) (bindings : betree_list_t (u64 & u64)) (ret : betree_list_t (u64 & u64)) : @@ -554,7 +555,8 @@ let rec betree_node_lookup_mut_in_bindings_back | BetreeListNil -> Return ret end -(** [betree_main::betree::Node::{5}::apply_to_leaf] *) +(** [betree_main::betree::Node::{5}::apply_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let betree_node_apply_to_leaf_fwd_back (bindings : betree_list_t (u64 & u64)) (key : u64) (new_msg : betree_message_t) : @@ -597,7 +599,8 @@ let betree_node_apply_to_leaf_fwd_back betree_node_lookup_mut_in_bindings_back key bindings bindings1 end -(** [betree_main::betree::Node::{5}::apply_messages_to_leaf] *) +(** [betree_main::betree::Node::{5}::apply_messages_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec betree_node_apply_messages_to_leaf_fwd_back (bindings : betree_list_t (u64 & u64)) (new_msgs : betree_list_t (u64 & betree_message_t)) : @@ -612,7 +615,8 @@ let rec betree_node_apply_messages_to_leaf_fwd_back | BetreeListNil -> Return bindings end -(** [betree_main::betree::Node::{5}::filter_messages_for_key] *) +(** [betree_main::betree::Node::{5}::filter_messages_for_key]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec betree_node_filter_messages_for_key_fwd_back (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) : Tot (result (betree_list_t (u64 & betree_message_t))) @@ -631,7 +635,7 @@ let rec betree_node_filter_messages_for_key_fwd_back | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: forward function *) let rec betree_node_lookup_first_message_after_key_fwd (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) : Tot (result (betree_list_t (u64 & betree_message_t))) @@ -646,7 +650,7 @@ let rec betree_node_lookup_first_message_after_key_fwd | BetreeListNil -> Return BetreeListNil end -(** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) +(** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: backward function 0 *) let rec betree_node_lookup_first_message_after_key_back (key : u64) (msgs : betree_list_t (u64 & betree_message_t)) (ret : betree_list_t (u64 & betree_message_t)) : @@ -665,7 +669,8 @@ let rec betree_node_lookup_first_message_after_key_back | BetreeListNil -> Return ret end -(** [betree_main::betree::Node::{5}::apply_to_internal] *) +(** [betree_main::betree::Node::{5}::apply_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let betree_node_apply_to_internal_fwd_back (msgs : betree_list_t (u64 & betree_message_t)) (key : u64) (new_msg : betree_message_t) : @@ -725,7 +730,8 @@ let betree_node_apply_to_internal_fwd_back new_msg) in betree_node_lookup_first_message_for_key_back key msgs msgs1 -(** [betree_main::betree::Node::{5}::apply_messages_to_internal] *) +(** [betree_main::betree::Node::{5}::apply_messages_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec betree_node_apply_messages_to_internal_fwd_back (msgs : betree_list_t (u64 & betree_message_t)) (new_msgs : betree_list_t (u64 & betree_message_t)) : @@ -740,7 +746,7 @@ let rec betree_node_apply_messages_to_internal_fwd_back | BetreeListNil -> Return msgs end -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: forward function *) let rec betree_node_apply_messages_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -788,7 +794,7 @@ let rec betree_node_apply_messages_fwd Return (st1, ()) end -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: backward function 0 *) and betree_node_apply_messages_back'a (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -840,7 +846,7 @@ and betree_node_apply_messages_back'a node_id_cnt)) end -(** [betree_main::betree::Node::{5}::apply_messages] *) +(** [betree_main::betree::Node::{5}::apply_messages]: backward function 1 *) and betree_node_apply_messages_back1 (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -889,7 +895,7 @@ and betree_node_apply_messages_back1 Return (st0, ()) end -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: forward function *) and betree_internal_flush_fwd (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -940,7 +946,7 @@ and betree_internal_flush_fwd node_id_cnt msgs_right st st1 in Return (st2, msgs_left) -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: backward function 0 *) and betree_internal_flush_back'a (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -994,7 +1000,7 @@ and betree_internal_flush_back'a node_id_cnt msgs_right st st2 in Return (st0, ({ self with betree_internal_right = n }, node_id_cnt0)) -(** [betree_main::betree::Internal::{4}::flush] *) +(** [betree_main::betree::Internal::{4}::flush]: backward function 1 *) and betree_internal_flush_back1 (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -1046,7 +1052,7 @@ and betree_internal_flush_back1 node_id_cnt msgs_right st st2 in Return (st0, ()) -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: forward function *) let betree_node_apply_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -1063,7 +1069,7 @@ let betree_node_apply_fwd betree_node_apply_messages_back1 self params node_id_cnt (BetreeListCons (key, new_msg) l) st st1 -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: backward function 0 *) let betree_node_apply_back'a (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -1082,7 +1088,7 @@ let betree_node_apply_back'a (key, new_msg) l) st st2 in Return (st0, (self0, node_id_cnt0)) -(** [betree_main::betree::Node::{5}::apply] *) +(** [betree_main::betree::Node::{5}::apply]: backward function 1 *) let betree_node_apply_back1 (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -1101,7 +1107,7 @@ let betree_node_apply_back1 (key, new_msg) l) st st2 in Return (st0, ()) -(** [betree_main::betree::BeTree::{6}::new] *) +(** [betree_main::betree::BeTree::{6}::new]: forward function *) let betree_be_tree_new_fwd (min_flush_size : u64) (split_size : u64) (st : state) : result (state & betree_be_tree_t) @@ -1122,7 +1128,7 @@ let betree_be_tree_new_fwd (BetreeNodeLeaf { betree_leaf_id = id; betree_leaf_size = 0 }) }) -(** [betree_main::betree::BeTree::{6}::apply] *) +(** [betree_main::betree::BeTree::{6}::apply]: forward function *) let betree_be_tree_apply_fwd (self : betree_be_tree_t) (key : u64) (msg : betree_message_t) (st : state) : result (state & unit) @@ -1137,7 +1143,7 @@ let betree_be_tree_apply_fwd betree_node_apply_back1 self.betree_be_tree_root self.betree_be_tree_params self.betree_be_tree_node_id_cnt key msg st st1 -(** [betree_main::betree::BeTree::{6}::apply] *) +(** [betree_main::betree::BeTree::{6}::apply]: backward function 0 *) let betree_be_tree_apply_back (self : betree_be_tree_t) (key : u64) (msg : betree_message_t) (st : state) (st0 : state) : @@ -1156,7 +1162,7 @@ let betree_be_tree_apply_back Return (st0, { self with betree_be_tree_node_id_cnt = nic; betree_be_tree_root = n }) -(** [betree_main::betree::BeTree::{6}::insert] *) +(** [betree_main::betree::BeTree::{6}::insert]: forward function *) let betree_be_tree_insert_fwd (self : betree_be_tree_t) (key : u64) (value : u64) (st : state) : result (state & unit) @@ -1167,7 +1173,7 @@ let betree_be_tree_insert_fwd betree_be_tree_apply_back self key (BetreeMessageInsert value) st st0 in Return (st1, ()) -(** [betree_main::betree::BeTree::{6}::insert] *) +(** [betree_main::betree::BeTree::{6}::insert]: backward function 0 *) let betree_be_tree_insert_back (self : betree_be_tree_t) (key : u64) (value : u64) (st : state) (st0 : state) : @@ -1179,7 +1185,7 @@ let betree_be_tree_insert_back betree_be_tree_apply_back self key (BetreeMessageInsert value) st st1 in Return (st0, self0) -(** [betree_main::betree::BeTree::{6}::delete] *) +(** [betree_main::betree::BeTree::{6}::delete]: forward function *) let betree_be_tree_delete_fwd (self : betree_be_tree_t) (key : u64) (st : state) : result (state & unit) = let* (st0, _) = betree_be_tree_apply_fwd self key BetreeMessageDelete st in @@ -1187,7 +1193,7 @@ let betree_be_tree_delete_fwd in Return (st1, ()) -(** [betree_main::betree::BeTree::{6}::delete] *) +(** [betree_main::betree::BeTree::{6}::delete]: backward function 0 *) let betree_be_tree_delete_back (self : betree_be_tree_t) (key : u64) (st : state) (st0 : state) : result (state & betree_be_tree_t) @@ -1197,7 +1203,7 @@ let betree_be_tree_delete_back betree_be_tree_apply_back self key BetreeMessageDelete st st1 in Return (st0, self0) -(** [betree_main::betree::BeTree::{6}::upsert] *) +(** [betree_main::betree::BeTree::{6}::upsert]: forward function *) let betree_be_tree_upsert_fwd (self : betree_be_tree_t) (key : u64) (upd : betree_upsert_fun_state_t) (st : state) : @@ -1209,7 +1215,7 @@ let betree_be_tree_upsert_fwd betree_be_tree_apply_back self key (BetreeMessageUpsert upd) st st0 in Return (st1, ()) -(** [betree_main::betree::BeTree::{6}::upsert] *) +(** [betree_main::betree::BeTree::{6}::upsert]: backward function 0 *) let betree_be_tree_upsert_back (self : betree_be_tree_t) (key : u64) (upd : betree_upsert_fun_state_t) (st : state) (st0 : state) : @@ -1221,14 +1227,14 @@ let betree_be_tree_upsert_back betree_be_tree_apply_back self key (BetreeMessageUpsert upd) st st1 in Return (st0, self0) -(** [betree_main::betree::BeTree::{6}::lookup] *) +(** [betree_main::betree::BeTree::{6}::lookup]: forward function *) let betree_be_tree_lookup_fwd (self : betree_be_tree_t) (key : u64) (st : state) : result (state & (option u64)) = betree_node_lookup_fwd self.betree_be_tree_root key st -(** [betree_main::betree::BeTree::{6}::lookup] *) +(** [betree_main::betree::BeTree::{6}::lookup]: backward function 0 *) let betree_be_tree_lookup_back (self : betree_be_tree_t) (key : u64) (st : state) (st0 : state) : result (state & betree_be_tree_t) @@ -1237,7 +1243,7 @@ let betree_be_tree_lookup_back in Return (st1, { self with betree_be_tree_root = n }) -(** [betree_main::main] *) +(** [betree_main::main]: forward function *) let main_fwd : result unit = Return () diff --git a/tests/fstar/betree_back_stateful/BetreeMain.Opaque.fsti b/tests/fstar/betree_back_stateful/BetreeMain.Opaque.fsti index dc49601a..c33cf225 100644 --- a/tests/fstar/betree_back_stateful/BetreeMain.Opaque.fsti +++ b/tests/fstar/betree_back_stateful/BetreeMain.Opaque.fsti @@ -1,30 +1,30 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [betree_main]: opaque function definitions *) +(** [betree_main]: external function declarations *) module BetreeMain.Opaque open Primitives include BetreeMain.Types #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [betree_main::betree_utils::load_internal_node] *) +(** [betree_main::betree_utils::load_internal_node]: forward function *) val betree_utils_load_internal_node_fwd : u64 -> state -> result (state & (betree_list_t (u64 & betree_message_t))) -(** [betree_main::betree_utils::store_internal_node] *) +(** [betree_main::betree_utils::store_internal_node]: forward function *) val betree_utils_store_internal_node_fwd : u64 -> betree_list_t (u64 & betree_message_t) -> state -> result (state & unit) -(** [betree_main::betree_utils::load_leaf_node] *) +(** [betree_main::betree_utils::load_leaf_node]: forward function *) val betree_utils_load_leaf_node_fwd : u64 -> state -> result (state & (betree_list_t (u64 & u64))) -(** [betree_main::betree_utils::store_leaf_node] *) +(** [betree_main::betree_utils::store_leaf_node]: forward function *) val betree_utils_store_leaf_node_fwd : u64 -> betree_list_t (u64 & u64) -> state -> result (state & unit) -(** [core::option::Option::{0}::unwrap] *) +(** [core::option::Option::{0}::unwrap]: forward function *) val core_option_option_unwrap_fwd (t : Type0) : option t -> state -> result (state & t) diff --git a/tests/fstar/hashmap/Hashmap.Funs.fst b/tests/fstar/hashmap/Hashmap.Funs.fst index 44ad7463..950f1490 100644 --- a/tests/fstar/hashmap/Hashmap.Funs.fst +++ b/tests/fstar/hashmap/Hashmap.Funs.fst @@ -7,11 +7,11 @@ include Hashmap.Clauses #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [hashmap::hash_key] *) +(** [hashmap::hash_key]: forward function *) let hash_key_fwd (k : usize) : result usize = Return k -(** [hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function *) let rec hash_map_allocate_slots_loop_fwd (t : Type0) (slots : vec (list_t t)) (n : usize) : Tot (result (vec (list_t t))) @@ -24,12 +24,12 @@ let rec hash_map_allocate_slots_loop_fwd hash_map_allocate_slots_loop_fwd t slots0 n0 else Return slots -(** [hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap::HashMap::{0}::allocate_slots]: forward function *) let hash_map_allocate_slots_fwd (t : Type0) (slots : vec (list_t t)) (n : usize) : result (vec (list_t t)) = hash_map_allocate_slots_loop_fwd t slots n -(** [hashmap::HashMap::{0}::new_with_capacity] *) +(** [hashmap::HashMap::{0}::new_with_capacity]: forward function *) let hash_map_new_with_capacity_fwd (t : Type0) (capacity : usize) (max_load_dividend : usize) (max_load_divisor : usize) : @@ -47,11 +47,12 @@ let hash_map_new_with_capacity_fwd hash_map_slots = slots } -(** [hashmap::HashMap::{0}::new] *) +(** [hashmap::HashMap::{0}::new]: forward function *) let hash_map_new_fwd (t : Type0) : result (hash_map_t t) = hash_map_new_with_capacity_fwd t 32 4 5 -(** [hashmap::HashMap::{0}::clear] *) +(** [hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec hash_map_clear_loop_fwd_back (t : Type0) (slots : vec (list_t t)) (i : usize) : Tot (result (vec (list_t t))) @@ -65,17 +66,18 @@ let rec hash_map_clear_loop_fwd_back hash_map_clear_loop_fwd_back t slots0 i1 else Return slots -(** [hashmap::HashMap::{0}::clear] *) +(** [hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hash_map_clear_fwd_back (t : Type0) (self : hash_map_t t) : result (hash_map_t t) = let* v = hash_map_clear_loop_fwd_back t self.hash_map_slots 0 in Return { self with hash_map_num_entries = 0; hash_map_slots = v } -(** [hashmap::HashMap::{0}::len] *) +(** [hashmap::HashMap::{0}::len]: forward function *) let hash_map_len_fwd (t : Type0) (self : hash_map_t t) : result usize = Return self.hash_map_num_entries -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function *) let rec hash_map_insert_in_list_loop_fwd (t : Type0) (key : usize) (value : t) (ls : list_t t) : Tot (result bool) @@ -89,12 +91,12 @@ let rec hash_map_insert_in_list_loop_fwd | ListNil -> Return true end -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: forward function *) let hash_map_insert_in_list_fwd (t : Type0) (key : usize) (value : t) (ls : list_t t) : result bool = hash_map_insert_in_list_loop_fwd t key value ls -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 *) let rec hash_map_insert_in_list_loop_back (t : Type0) (key : usize) (value : t) (ls : list_t t) : Tot (result (list_t t)) @@ -110,12 +112,13 @@ let rec hash_map_insert_in_list_loop_back | ListNil -> let l = ListNil in Return (ListCons key value l) end -(** [hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap::HashMap::{0}::insert_in_list]: backward function 0 *) let hash_map_insert_in_list_back (t : Type0) (key : usize) (value : t) (ls : list_t t) : result (list_t t) = hash_map_insert_in_list_loop_back t key value ls -(** [hashmap::HashMap::{0}::insert_no_resize] *) +(** [hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hash_map_insert_no_resize_fwd_back (t : Type0) (self : hash_map_t t) (key : usize) (value : t) : result (hash_map_t t) @@ -140,7 +143,8 @@ let hash_map_insert_no_resize_fwd_back let core_num_u32_max_body : result u32 = Return 4294967295 let core_num_u32_max_c : u32 = eval_global core_num_u32_max_body -(** [hashmap::HashMap::{0}::move_elements_from_list] *) +(** [hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec hash_map_move_elements_from_list_loop_fwd_back (t : Type0) (ntable : hash_map_t t) (ls : list_t t) : Tot (result (hash_map_t t)) @@ -153,12 +157,14 @@ let rec hash_map_move_elements_from_list_loop_fwd_back | ListNil -> Return ntable end -(** [hashmap::HashMap::{0}::move_elements_from_list] *) +(** [hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hash_map_move_elements_from_list_fwd_back (t : Type0) (ntable : hash_map_t t) (ls : list_t t) : result (hash_map_t t) = hash_map_move_elements_from_list_loop_fwd_back t ntable ls -(** [hashmap::HashMap::{0}::move_elements] *) +(** [hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec hash_map_move_elements_loop_fwd_back (t : Type0) (ntable : hash_map_t t) (slots : vec (list_t t)) (i : usize) : Tot (result ((hash_map_t t) & (vec (list_t t)))) @@ -176,14 +182,16 @@ let rec hash_map_move_elements_loop_fwd_back hash_map_move_elements_loop_fwd_back t ntable0 slots0 i1 else Return (ntable, slots) -(** [hashmap::HashMap::{0}::move_elements] *) +(** [hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hash_map_move_elements_fwd_back (t : Type0) (ntable : hash_map_t t) (slots : vec (list_t t)) (i : usize) : result ((hash_map_t t) & (vec (list_t t))) = hash_map_move_elements_loop_fwd_back t ntable slots i -(** [hashmap::HashMap::{0}::try_resize] *) +(** [hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hash_map_try_resize_fwd_back (t : Type0) (self : hash_map_t t) : result (hash_map_t t) = let* max_usize = scalar_cast U32 Usize core_num_u32_max_c in @@ -206,7 +214,8 @@ let hash_map_try_resize_fwd_back } else Return { self with hash_map_max_load_factor = (i, i0) } -(** [hashmap::HashMap::{0}::insert] *) +(** [hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hash_map_insert_fwd_back (t : Type0) (self : hash_map_t t) (key : usize) (value : t) : result (hash_map_t t) @@ -217,7 +226,7 @@ let hash_map_insert_fwd_back then hash_map_try_resize_fwd_back t self0 else Return self0 -(** [hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function *) let rec hash_map_contains_key_in_list_loop_fwd (t : Type0) (key : usize) (ls : list_t t) : Tot (result bool) @@ -231,12 +240,12 @@ let rec hash_map_contains_key_in_list_loop_fwd | ListNil -> Return false end -(** [hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap::HashMap::{0}::contains_key_in_list]: forward function *) let hash_map_contains_key_in_list_fwd (t : Type0) (key : usize) (ls : list_t t) : result bool = hash_map_contains_key_in_list_loop_fwd t key ls -(** [hashmap::HashMap::{0}::contains_key] *) +(** [hashmap::HashMap::{0}::contains_key]: forward function *) let hash_map_contains_key_fwd (t : Type0) (self : hash_map_t t) (key : usize) : result bool = let* hash = hash_key_fwd key in @@ -245,7 +254,7 @@ let hash_map_contains_key_fwd let* l = vec_index_fwd (list_t t) self.hash_map_slots hash_mod in hash_map_contains_key_in_list_fwd t key l -(** [hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap::HashMap::{0}::get_in_list]: loop 0: forward function *) let rec hash_map_get_in_list_loop_fwd (t : Type0) (key : usize) (ls : list_t t) : Tot (result t) (decreases (hash_map_get_in_list_loop_decreases t key ls)) @@ -258,12 +267,12 @@ let rec hash_map_get_in_list_loop_fwd | ListNil -> Fail Failure end -(** [hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap::HashMap::{0}::get_in_list]: forward function *) let hash_map_get_in_list_fwd (t : Type0) (key : usize) (ls : list_t t) : result t = hash_map_get_in_list_loop_fwd t key ls -(** [hashmap::HashMap::{0}::get] *) +(** [hashmap::HashMap::{0}::get]: forward function *) let hash_map_get_fwd (t : Type0) (self : hash_map_t t) (key : usize) : result t = let* hash = hash_key_fwd key in @@ -272,7 +281,7 @@ let hash_map_get_fwd let* l = vec_index_fwd (list_t t) self.hash_map_slots hash_mod in hash_map_get_in_list_fwd t key l -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function *) let rec hash_map_get_mut_in_list_loop_fwd (t : Type0) (ls : list_t t) (key : usize) : Tot (result t) (decreases (hash_map_get_mut_in_list_loop_decreases t ls key)) @@ -285,12 +294,12 @@ let rec hash_map_get_mut_in_list_loop_fwd | ListNil -> Fail Failure end -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: forward function *) let hash_map_get_mut_in_list_fwd (t : Type0) (ls : list_t t) (key : usize) : result t = hash_map_get_mut_in_list_loop_fwd t ls key -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 *) let rec hash_map_get_mut_in_list_loop_back (t : Type0) (ls : list_t t) (key : usize) (ret : t) : Tot (result (list_t t)) @@ -306,12 +315,12 @@ let rec hash_map_get_mut_in_list_loop_back | ListNil -> Fail Failure end -(** [hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 *) let hash_map_get_mut_in_list_back (t : Type0) (ls : list_t t) (key : usize) (ret : t) : result (list_t t) = hash_map_get_mut_in_list_loop_back t ls key ret -(** [hashmap::HashMap::{0}::get_mut] *) +(** [hashmap::HashMap::{0}::get_mut]: forward function *) let hash_map_get_mut_fwd (t : Type0) (self : hash_map_t t) (key : usize) : result t = let* hash = hash_key_fwd key in @@ -320,7 +329,7 @@ let hash_map_get_mut_fwd let* l = vec_index_mut_fwd (list_t t) self.hash_map_slots hash_mod in hash_map_get_mut_in_list_fwd t l key -(** [hashmap::HashMap::{0}::get_mut] *) +(** [hashmap::HashMap::{0}::get_mut]: backward function 0 *) let hash_map_get_mut_back (t : Type0) (self : hash_map_t t) (key : usize) (ret : t) : result (hash_map_t t) @@ -333,7 +342,7 @@ let hash_map_get_mut_back let* v = vec_index_mut_back (list_t t) self.hash_map_slots hash_mod l0 in Return { self with hash_map_slots = v } -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function *) let rec hash_map_remove_from_list_loop_fwd (t : Type0) (key : usize) (ls : list_t t) : Tot (result (option t)) @@ -352,12 +361,12 @@ let rec hash_map_remove_from_list_loop_fwd | ListNil -> Return None end -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: forward function *) let hash_map_remove_from_list_fwd (t : Type0) (key : usize) (ls : list_t t) : result (option t) = hash_map_remove_from_list_loop_fwd t key ls -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 *) let rec hash_map_remove_from_list_loop_back (t : Type0) (key : usize) (ls : list_t t) : Tot (result (list_t t)) @@ -378,12 +387,12 @@ let rec hash_map_remove_from_list_loop_back | ListNil -> Return ListNil end -(** [hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap::HashMap::{0}::remove_from_list]: backward function 1 *) let hash_map_remove_from_list_back (t : Type0) (key : usize) (ls : list_t t) : result (list_t t) = hash_map_remove_from_list_loop_back t key ls -(** [hashmap::HashMap::{0}::remove] *) +(** [hashmap::HashMap::{0}::remove]: forward function *) let hash_map_remove_fwd (t : Type0) (self : hash_map_t t) (key : usize) : result (option t) = let* hash = hash_key_fwd key in @@ -397,7 +406,7 @@ let hash_map_remove_fwd let* _ = usize_sub self.hash_map_num_entries 1 in Return (Some x0) end -(** [hashmap::HashMap::{0}::remove] *) +(** [hashmap::HashMap::{0}::remove]: backward function 0 *) let hash_map_remove_back (t : Type0) (self : hash_map_t t) (key : usize) : result (hash_map_t t) = let* hash = hash_key_fwd key in @@ -417,7 +426,7 @@ let hash_map_remove_back Return { self with hash_map_num_entries = i0; hash_map_slots = v } end -(** [hashmap::test1] *) +(** [hashmap::test1]: forward function *) let test1_fwd : result unit = let* hm = hash_map_new_fwd u64 in let* hm0 = hash_map_insert_fwd_back u64 hm 0 42 in diff --git a/tests/fstar/hashmap_on_disk/HashmapMain.Funs.fst b/tests/fstar/hashmap_on_disk/HashmapMain.Funs.fst index e8cd54c1..f6d9c8cf 100644 --- a/tests/fstar/hashmap_on_disk/HashmapMain.Funs.fst +++ b/tests/fstar/hashmap_on_disk/HashmapMain.Funs.fst @@ -8,11 +8,11 @@ include HashmapMain.Clauses #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [hashmap_main::hashmap::hash_key] *) +(** [hashmap_main::hashmap::hash_key]: forward function *) let hashmap_hash_key_fwd (k : usize) : result usize = Return k -(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function *) let rec hashmap_hash_map_allocate_slots_loop_fwd (t : Type0) (slots : vec (hashmap_list_t t)) (n : usize) : Tot (result (vec (hashmap_list_t t))) @@ -25,14 +25,14 @@ let rec hashmap_hash_map_allocate_slots_loop_fwd hashmap_hash_map_allocate_slots_loop_fwd t slots0 n0 else Return slots -(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots] *) +(** [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: forward function *) let hashmap_hash_map_allocate_slots_fwd (t : Type0) (slots : vec (hashmap_list_t t)) (n : usize) : result (vec (hashmap_list_t t)) = hashmap_hash_map_allocate_slots_loop_fwd t slots n -(** [hashmap_main::hashmap::HashMap::{0}::new_with_capacity] *) +(** [hashmap_main::hashmap::HashMap::{0}::new_with_capacity]: forward function *) let hashmap_hash_map_new_with_capacity_fwd (t : Type0) (capacity : usize) (max_load_dividend : usize) (max_load_divisor : usize) : @@ -50,11 +50,12 @@ let hashmap_hash_map_new_with_capacity_fwd hashmap_hash_map_slots = slots } -(** [hashmap_main::hashmap::HashMap::{0}::new] *) +(** [hashmap_main::hashmap::HashMap::{0}::new]: forward function *) let hashmap_hash_map_new_fwd (t : Type0) : result (hashmap_hash_map_t t) = hashmap_hash_map_new_with_capacity_fwd t 32 4 5 -(** [hashmap_main::hashmap::HashMap::{0}::clear] *) +(** [hashmap_main::hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec hashmap_hash_map_clear_loop_fwd_back (t : Type0) (slots : vec (hashmap_list_t t)) (i : usize) : Tot (result (vec (hashmap_list_t t))) @@ -69,7 +70,8 @@ let rec hashmap_hash_map_clear_loop_fwd_back hashmap_hash_map_clear_loop_fwd_back t slots0 i1 else Return slots -(** [hashmap_main::hashmap::HashMap::{0}::clear] *) +(** [hashmap_main::hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hashmap_hash_map_clear_fwd_back (t : Type0) (self : hashmap_hash_map_t t) : result (hashmap_hash_map_t t) = let* v = hashmap_hash_map_clear_loop_fwd_back t self.hashmap_hash_map_slots 0 @@ -77,12 +79,12 @@ let hashmap_hash_map_clear_fwd_back Return { self with hashmap_hash_map_num_entries = 0; hashmap_hash_map_slots = v } -(** [hashmap_main::hashmap::HashMap::{0}::len] *) +(** [hashmap_main::hashmap::HashMap::{0}::len]: forward function *) let hashmap_hash_map_len_fwd (t : Type0) (self : hashmap_hash_map_t t) : result usize = Return self.hashmap_hash_map_num_entries -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function *) let rec hashmap_hash_map_insert_in_list_loop_fwd (t : Type0) (key : usize) (value : t) (ls : hashmap_list_t t) : Tot (result bool) @@ -96,12 +98,12 @@ let rec hashmap_hash_map_insert_in_list_loop_fwd | HashmapListNil -> Return true end -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: forward function *) let hashmap_hash_map_insert_in_list_fwd (t : Type0) (key : usize) (value : t) (ls : hashmap_list_t t) : result bool = hashmap_hash_map_insert_in_list_loop_fwd t key value ls -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 *) let rec hashmap_hash_map_insert_in_list_loop_back (t : Type0) (key : usize) (value : t) (ls : hashmap_list_t t) : Tot (result (hashmap_list_t t)) @@ -118,14 +120,15 @@ let rec hashmap_hash_map_insert_in_list_loop_back let l = HashmapListNil in Return (HashmapListCons key value l) end -(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: backward function 0 *) let hashmap_hash_map_insert_in_list_back (t : Type0) (key : usize) (value : t) (ls : hashmap_list_t t) : result (hashmap_list_t t) = hashmap_hash_map_insert_in_list_loop_back t key value ls -(** [hashmap_main::hashmap::HashMap::{0}::insert_no_resize] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hashmap_hash_map_insert_no_resize_fwd_back (t : Type0) (self : hashmap_hash_map_t t) (key : usize) (value : t) : result (hashmap_hash_map_t t) @@ -158,7 +161,8 @@ let hashmap_hash_map_insert_no_resize_fwd_back let core_num_u32_max_body : result u32 = Return 4294967295 let core_num_u32_max_c : u32 = eval_global core_num_u32_max_body -(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec hashmap_hash_map_move_elements_from_list_loop_fwd_back (t : Type0) (ntable : hashmap_hash_map_t t) (ls : hashmap_list_t t) : Tot (result (hashmap_hash_map_t t)) @@ -172,14 +176,16 @@ let rec hashmap_hash_map_move_elements_from_list_loop_fwd_back | HashmapListNil -> Return ntable end -(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hashmap_hash_map_move_elements_from_list_fwd_back (t : Type0) (ntable : hashmap_hash_map_t t) (ls : hashmap_list_t t) : result (hashmap_hash_map_t t) = hashmap_hash_map_move_elements_from_list_loop_fwd_back t ntable ls -(** [hashmap_main::hashmap::HashMap::{0}::move_elements] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec hashmap_hash_map_move_elements_loop_fwd_back (t : Type0) (ntable : hashmap_hash_map_t t) (slots : vec (hashmap_list_t t)) (i : usize) : @@ -199,7 +205,8 @@ let rec hashmap_hash_map_move_elements_loop_fwd_back hashmap_hash_map_move_elements_loop_fwd_back t ntable0 slots0 i1 else Return (ntable, slots) -(** [hashmap_main::hashmap::HashMap::{0}::move_elements] *) +(** [hashmap_main::hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hashmap_hash_map_move_elements_fwd_back (t : Type0) (ntable : hashmap_hash_map_t t) (slots : vec (hashmap_list_t t)) (i : usize) : @@ -207,7 +214,8 @@ let hashmap_hash_map_move_elements_fwd_back = hashmap_hash_map_move_elements_loop_fwd_back t ntable slots i -(** [hashmap_main::hashmap::HashMap::{0}::try_resize] *) +(** [hashmap_main::hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hashmap_hash_map_try_resize_fwd_back (t : Type0) (self : hashmap_hash_map_t t) : result (hashmap_hash_map_t t) = let* max_usize = scalar_cast U32 Usize core_num_u32_max_c in @@ -231,7 +239,8 @@ let hashmap_hash_map_try_resize_fwd_back } else Return { self with hashmap_hash_map_max_load_factor = (i, i0) } -(** [hashmap_main::hashmap::HashMap::{0}::insert] *) +(** [hashmap_main::hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let hashmap_hash_map_insert_fwd_back (t : Type0) (self : hashmap_hash_map_t t) (key : usize) (value : t) : result (hashmap_hash_map_t t) @@ -242,7 +251,7 @@ let hashmap_hash_map_insert_fwd_back then hashmap_hash_map_try_resize_fwd_back t self0 else Return self0 -(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function *) let rec hashmap_hash_map_contains_key_in_list_loop_fwd (t : Type0) (key : usize) (ls : hashmap_list_t t) : Tot (result bool) @@ -256,12 +265,12 @@ let rec hashmap_hash_map_contains_key_in_list_loop_fwd | HashmapListNil -> Return false end -(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: forward function *) let hashmap_hash_map_contains_key_in_list_fwd (t : Type0) (key : usize) (ls : hashmap_list_t t) : result bool = hashmap_hash_map_contains_key_in_list_loop_fwd t key ls -(** [hashmap_main::hashmap::HashMap::{0}::contains_key] *) +(** [hashmap_main::hashmap::HashMap::{0}::contains_key]: forward function *) let hashmap_hash_map_contains_key_fwd (t : Type0) (self : hashmap_hash_map_t t) (key : usize) : result bool = let* hash = hashmap_hash_key_fwd key in @@ -271,7 +280,7 @@ let hashmap_hash_map_contains_key_fwd vec_index_fwd (hashmap_list_t t) self.hashmap_hash_map_slots hash_mod in hashmap_hash_map_contains_key_in_list_fwd t key l -(** [hashmap_main::hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_in_list]: loop 0: forward function *) let rec hashmap_hash_map_get_in_list_loop_fwd (t : Type0) (key : usize) (ls : hashmap_list_t t) : Tot (result t) @@ -285,12 +294,12 @@ let rec hashmap_hash_map_get_in_list_loop_fwd | HashmapListNil -> Fail Failure end -(** [hashmap_main::hashmap::HashMap::{0}::get_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_in_list]: forward function *) let hashmap_hash_map_get_in_list_fwd (t : Type0) (key : usize) (ls : hashmap_list_t t) : result t = hashmap_hash_map_get_in_list_loop_fwd t key ls -(** [hashmap_main::hashmap::HashMap::{0}::get] *) +(** [hashmap_main::hashmap::HashMap::{0}::get]: forward function *) let hashmap_hash_map_get_fwd (t : Type0) (self : hashmap_hash_map_t t) (key : usize) : result t = let* hash = hashmap_hash_key_fwd key in @@ -300,7 +309,7 @@ let hashmap_hash_map_get_fwd vec_index_fwd (hashmap_list_t t) self.hashmap_hash_map_slots hash_mod in hashmap_hash_map_get_in_list_fwd t key l -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function *) let rec hashmap_hash_map_get_mut_in_list_loop_fwd (t : Type0) (ls : hashmap_list_t t) (key : usize) : Tot (result t) @@ -314,12 +323,12 @@ let rec hashmap_hash_map_get_mut_in_list_loop_fwd | HashmapListNil -> Fail Failure end -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: forward function *) let hashmap_hash_map_get_mut_in_list_fwd (t : Type0) (ls : hashmap_list_t t) (key : usize) : result t = hashmap_hash_map_get_mut_in_list_loop_fwd t ls key -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 *) let rec hashmap_hash_map_get_mut_in_list_loop_back (t : Type0) (ls : hashmap_list_t t) (key : usize) (ret : t) : Tot (result (hashmap_list_t t)) @@ -335,14 +344,14 @@ let rec hashmap_hash_map_get_mut_in_list_loop_back | HashmapListNil -> Fail Failure end -(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 *) let hashmap_hash_map_get_mut_in_list_back (t : Type0) (ls : hashmap_list_t t) (key : usize) (ret : t) : result (hashmap_list_t t) = hashmap_hash_map_get_mut_in_list_loop_back t ls key ret -(** [hashmap_main::hashmap::HashMap::{0}::get_mut] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut]: forward function *) let hashmap_hash_map_get_mut_fwd (t : Type0) (self : hashmap_hash_map_t t) (key : usize) : result t = let* hash = hashmap_hash_key_fwd key in @@ -353,7 +362,7 @@ let hashmap_hash_map_get_mut_fwd in hashmap_hash_map_get_mut_in_list_fwd t l key -(** [hashmap_main::hashmap::HashMap::{0}::get_mut] *) +(** [hashmap_main::hashmap::HashMap::{0}::get_mut]: backward function 0 *) let hashmap_hash_map_get_mut_back (t : Type0) (self : hashmap_hash_map_t t) (key : usize) (ret : t) : result (hashmap_hash_map_t t) @@ -370,7 +379,7 @@ let hashmap_hash_map_get_mut_back l0 in Return { self with hashmap_hash_map_slots = v } -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function *) let rec hashmap_hash_map_remove_from_list_loop_fwd (t : Type0) (key : usize) (ls : hashmap_list_t t) : Tot (result (option t)) @@ -391,12 +400,12 @@ let rec hashmap_hash_map_remove_from_list_loop_fwd | HashmapListNil -> Return None end -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: forward function *) let hashmap_hash_map_remove_from_list_fwd (t : Type0) (key : usize) (ls : hashmap_list_t t) : result (option t) = hashmap_hash_map_remove_from_list_loop_fwd t key ls -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 *) let rec hashmap_hash_map_remove_from_list_loop_back (t : Type0) (key : usize) (ls : hashmap_list_t t) : Tot (result (hashmap_list_t t)) @@ -419,14 +428,14 @@ let rec hashmap_hash_map_remove_from_list_loop_back | HashmapListNil -> Return HashmapListNil end -(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: backward function 1 *) let hashmap_hash_map_remove_from_list_back (t : Type0) (key : usize) (ls : hashmap_list_t t) : result (hashmap_list_t t) = hashmap_hash_map_remove_from_list_loop_back t key ls -(** [hashmap_main::hashmap::HashMap::{0}::remove] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove]: forward function *) let hashmap_hash_map_remove_fwd (t : Type0) (self : hashmap_hash_map_t t) (key : usize) : result (option t) = let* hash = hashmap_hash_key_fwd key in @@ -442,7 +451,7 @@ let hashmap_hash_map_remove_fwd let* _ = usize_sub self.hashmap_hash_map_num_entries 1 in Return (Some x0) end -(** [hashmap_main::hashmap::HashMap::{0}::remove] *) +(** [hashmap_main::hashmap::HashMap::{0}::remove]: backward function 0 *) let hashmap_hash_map_remove_back (t : Type0) (self : hashmap_hash_map_t t) (key : usize) : result (hashmap_hash_map_t t) @@ -472,7 +481,7 @@ let hashmap_hash_map_remove_back } end -(** [hashmap_main::hashmap::test1] *) +(** [hashmap_main::hashmap::test1]: forward function *) let hashmap_test1_fwd : result unit = let* hm = hashmap_hash_map_new_fwd u64 in let* hm0 = hashmap_hash_map_insert_fwd_back u64 hm 0 42 in @@ -511,7 +520,7 @@ let hashmap_test1_fwd : result unit = (** Unit test for [hashmap_main::hashmap::test1] *) let _ = assert_norm (hashmap_test1_fwd = Return ()) -(** [hashmap_main::insert_on_disk] *) +(** [hashmap_main::insert_on_disk]: forward function *) let insert_on_disk_fwd (key : usize) (value : u64) (st : state) : result (state & unit) = let* (st0, hm) = hashmap_utils_deserialize_fwd st in @@ -519,7 +528,7 @@ let insert_on_disk_fwd let* (st1, _) = hashmap_utils_serialize_fwd hm0 st0 in Return (st1, ()) -(** [hashmap_main::main] *) +(** [hashmap_main::main]: forward function *) let main_fwd : result unit = Return () diff --git a/tests/fstar/hashmap_on_disk/HashmapMain.Opaque.fsti b/tests/fstar/hashmap_on_disk/HashmapMain.Opaque.fsti index 6e54ea10..78a6c3ba 100644 --- a/tests/fstar/hashmap_on_disk/HashmapMain.Opaque.fsti +++ b/tests/fstar/hashmap_on_disk/HashmapMain.Opaque.fsti @@ -1,16 +1,16 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [hashmap_main]: opaque function definitions *) +(** [hashmap_main]: external function declarations *) module HashmapMain.Opaque open Primitives include HashmapMain.Types #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [hashmap_main::hashmap_utils::deserialize] *) +(** [hashmap_main::hashmap_utils::deserialize]: forward function *) val hashmap_utils_deserialize_fwd : state -> result (state & (hashmap_hash_map_t u64)) -(** [hashmap_main::hashmap_utils::serialize] *) +(** [hashmap_main::hashmap_utils::serialize]: forward function *) val hashmap_utils_serialize_fwd : hashmap_hash_map_t u64 -> state -> result (state & unit) diff --git a/tests/fstar/misc/Constants.fst b/tests/fstar/misc/Constants.fst index bf2f0b1b..aae997fa 100644 --- a/tests/fstar/misc/Constants.fst +++ b/tests/fstar/misc/Constants.fst @@ -21,7 +21,7 @@ let x1_c : u32 = eval_global x1_body let x2_body : result u32 = Return 3 let x2_c : u32 = eval_global x2_body -(** [constants::incr] *) +(** [constants::incr]: forward function *) let incr_fwd (n : u32) : result u32 = u32_add n 1 @@ -29,14 +29,14 @@ let incr_fwd (n : u32) : result u32 = let x3_body : result u32 = incr_fwd 32 let x3_c : u32 = eval_global x3_body -(** [constants::mk_pair0] *) +(** [constants::mk_pair0]: forward function *) let mk_pair0_fwd (x : u32) (y : u32) : result (u32 & u32) = Return (x, y) (** [constants::Pair] *) type pair_t (t1 t2 : Type0) = { pair_x : t1; pair_y : t2; } -(** [constants::mk_pair1] *) +(** [constants::mk_pair1]: forward function *) let mk_pair1_fwd (x : u32) (y : u32) : result (pair_t u32 u32) = Return { pair_x = x; pair_y = y } @@ -59,7 +59,7 @@ let p3_c : pair_t u32 u32 = eval_global p3_body (** [constants::Wrap] *) type wrap_t (t : Type0) = { wrap_val : t; } -(** [constants::Wrap::{0}::new] *) +(** [constants::Wrap::{0}::new]: forward function *) let wrap_new_fwd (t : Type0) (val0 : t) : result (wrap_t t) = Return { wrap_val = val0 } @@ -67,7 +67,7 @@ let wrap_new_fwd (t : Type0) (val0 : t) : result (wrap_t t) = let y_body : result (wrap_t i32) = wrap_new_fwd i32 2 let y_c : wrap_t i32 = eval_global y_body -(** [constants::unwrap_y] *) +(** [constants::unwrap_y]: forward function *) let unwrap_y_fwd : result i32 = Return y_c.wrap_val @@ -79,11 +79,11 @@ let yval_c : i32 = eval_global yval_body let get_z1_z1_body : result i32 = Return 3 let get_z1_z1_c : i32 = eval_global get_z1_z1_body -(** [constants::get_z1] *) +(** [constants::get_z1]: forward function *) let get_z1_fwd : result i32 = Return get_z1_z1_c -(** [constants::add] *) +(** [constants::add]: forward function *) let add_fwd (a : i32) (b : i32) : result i32 = i32_add a b @@ -99,7 +99,7 @@ let q2_c : i32 = eval_global q2_body let q3_body : result i32 = add_fwd q2_c 3 let q3_c : i32 = eval_global q3_body -(** [constants::get_z2] *) +(** [constants::get_z2]: forward function *) let get_z2_fwd : result i32 = let* i = get_z1_fwd in let* i0 = add_fwd i q3_c in add_fwd q1_c i0 diff --git a/tests/fstar/misc/External.Funs.fst b/tests/fstar/misc/External.Funs.fst index f70a9fc6..f118a2cf 100644 --- a/tests/fstar/misc/External.Funs.fst +++ b/tests/fstar/misc/External.Funs.fst @@ -7,14 +7,14 @@ include External.Opaque #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [external::swap] *) +(** [external::swap]: forward function *) let swap_fwd (t : Type0) (x : t) (y : t) (st : state) : result (state & unit) = let* (st0, _) = core_mem_swap_fwd t x y st in let* (st1, _) = core_mem_swap_back0 t x y st st0 in let* (st2, _) = core_mem_swap_back1 t x y st st1 in Return (st2, ()) -(** [external::swap] *) +(** [external::swap]: backward function 0 *) let swap_back (t : Type0) (x : t) (y : t) (st : state) (st0 : state) : result (state & (t & t)) @@ -24,20 +24,20 @@ let swap_back let* (_, y0) = core_mem_swap_back1 t x y st st2 in Return (st0, (x0, y0)) -(** [external::test_new_non_zero_u32] *) +(** [external::test_new_non_zero_u32]: forward function *) let test_new_non_zero_u32_fwd (x : u32) (st : state) : result (state & core_num_nonzero_non_zero_u32_t) = let* (st0, opt) = core_num_nonzero_non_zero_u32_new_fwd x st in core_option_option_unwrap_fwd core_num_nonzero_non_zero_u32_t opt st0 -(** [external::test_vec] *) +(** [external::test_vec]: forward function *) let test_vec_fwd : result unit = let v = vec_new u32 in let* _ = vec_push_back u32 v 0 in Return () (** Unit test for [external::test_vec] *) let _ = assert_norm (test_vec_fwd = Return ()) -(** [external::custom_swap] *) +(** [external::custom_swap]: forward function *) let custom_swap_fwd (t : Type0) (x : t) (y : t) (st : state) : result (state & t) = let* (st0, _) = core_mem_swap_fwd t x y st in @@ -45,7 +45,7 @@ let custom_swap_fwd let* (st2, _) = core_mem_swap_back1 t x y st st1 in Return (st2, x0) -(** [external::custom_swap] *) +(** [external::custom_swap]: backward function 0 *) let custom_swap_back (t : Type0) (x : t) (y : t) (st : state) (ret : t) (st0 : state) : result (state & (t & t)) @@ -55,19 +55,19 @@ let custom_swap_back let* (_, y0) = core_mem_swap_back1 t x y st st2 in Return (st0, (ret, y0)) -(** [external::test_custom_swap] *) +(** [external::test_custom_swap]: forward function *) let test_custom_swap_fwd (x : u32) (y : u32) (st : state) : result (state & unit) = let* (st0, _) = custom_swap_fwd u32 x y st in Return (st0, ()) -(** [external::test_custom_swap] *) +(** [external::test_custom_swap]: backward function 0 *) let test_custom_swap_back (x : u32) (y : u32) (st : state) (st0 : state) : result (state & (u32 & u32)) = custom_swap_back u32 x y st 1 st0 -(** [external::test_swap_non_zero] *) +(** [external::test_swap_non_zero]: forward function *) let test_swap_non_zero_fwd (x : u32) (st : state) : result (state & u32) = let* (st0, _) = swap_fwd u32 x 0 st in let* (st1, (x0, _)) = swap_back u32 x 0 st st0 in diff --git a/tests/fstar/misc/External.Opaque.fsti b/tests/fstar/misc/External.Opaque.fsti index 7d86405a..2e19f767 100644 --- a/tests/fstar/misc/External.Opaque.fsti +++ b/tests/fstar/misc/External.Opaque.fsti @@ -1,27 +1,27 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [external]: opaque function definitions *) +(** [external]: external function declarations *) module External.Opaque open Primitives include External.Types #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [core::mem::swap] *) +(** [core::mem::swap]: forward function *) val core_mem_swap_fwd (t : Type0) : t -> t -> state -> result (state & unit) -(** [core::mem::swap] *) +(** [core::mem::swap]: backward function 0 *) val core_mem_swap_back0 (t : Type0) : t -> t -> state -> state -> result (state & t) -(** [core::mem::swap] *) +(** [core::mem::swap]: backward function 1 *) val core_mem_swap_back1 (t : Type0) : t -> t -> state -> state -> result (state & t) -(** [core::num::nonzero::NonZeroU32::{14}::new] *) +(** [core::num::nonzero::NonZeroU32::{14}::new]: forward function *) val core_num_nonzero_non_zero_u32_new_fwd : u32 -> state -> result (state & (option core_num_nonzero_non_zero_u32_t)) -(** [core::option::Option::{0}::unwrap] *) +(** [core::option::Option::{0}::unwrap]: forward function *) val core_option_option_unwrap_fwd (t : Type0) : option t -> state -> result (state & t) diff --git a/tests/fstar/misc/Loops.Funs.fst b/tests/fstar/misc/Loops.Funs.fst index 7fe175e5..9a80f415 100644 --- a/tests/fstar/misc/Loops.Funs.fst +++ b/tests/fstar/misc/Loops.Funs.fst @@ -7,7 +7,7 @@ include Loops.Clauses #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [loops::sum] *) +(** [loops::sum]: loop 0: forward function *) let rec sum_loop_fwd (max : u32) (i : u32) (s : u32) : Tot (result u32) (decreases (sum_loop_decreases max i s)) @@ -16,11 +16,11 @@ let rec sum_loop_fwd then let* s0 = u32_add s i in let* i0 = u32_add i 1 in sum_loop_fwd max i0 s0 else u32_mul s 2 -(** [loops::sum] *) +(** [loops::sum]: forward function *) let sum_fwd (max : u32) : result u32 = sum_loop_fwd max 0 0 -(** [loops::sum_with_mut_borrows] *) +(** [loops::sum_with_mut_borrows]: loop 0: forward function *) let rec sum_with_mut_borrows_loop_fwd (max : u32) (mi : u32) (ms : u32) : Tot (result u32) (decreases (sum_with_mut_borrows_loop_decreases max mi ms)) @@ -32,11 +32,11 @@ let rec sum_with_mut_borrows_loop_fwd sum_with_mut_borrows_loop_fwd max mi0 ms0 else u32_mul ms 2 -(** [loops::sum_with_mut_borrows] *) +(** [loops::sum_with_mut_borrows]: forward function *) let sum_with_mut_borrows_fwd (max : u32) : result u32 = sum_with_mut_borrows_loop_fwd max 0 0 -(** [loops::sum_with_shared_borrows] *) +(** [loops::sum_with_shared_borrows]: loop 0: forward function *) let rec sum_with_shared_borrows_loop_fwd (max : u32) (i : u32) (s : u32) : Tot (result u32) (decreases (sum_with_shared_borrows_loop_decreases max i s)) @@ -48,11 +48,12 @@ let rec sum_with_shared_borrows_loop_fwd sum_with_shared_borrows_loop_fwd max i0 s0 else u32_mul s 2 -(** [loops::sum_with_shared_borrows] *) +(** [loops::sum_with_shared_borrows]: forward function *) let sum_with_shared_borrows_fwd (max : u32) : result u32 = sum_with_shared_borrows_loop_fwd max 0 0 -(** [loops::clear] *) +(** [loops::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let rec clear_loop_fwd_back (v : vec u32) (i : usize) : Tot (result (vec u32)) (decreases (clear_loop_decreases v i)) @@ -65,11 +66,12 @@ let rec clear_loop_fwd_back clear_loop_fwd_back v0 i1 else Return v -(** [loops::clear] *) +(** [loops::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let clear_fwd_back (v : vec u32) : result (vec u32) = clear_loop_fwd_back v 0 -(** [loops::list_mem] *) +(** [loops::list_mem]: loop 0: forward function *) let rec list_mem_loop_fwd (x : u32) (ls : list_t u32) : Tot (result bool) (decreases (list_mem_loop_decreases x ls)) @@ -79,11 +81,11 @@ let rec list_mem_loop_fwd | ListNil -> Return false end -(** [loops::list_mem] *) +(** [loops::list_mem]: forward function *) let list_mem_fwd (x : u32) (ls : list_t u32) : result bool = list_mem_loop_fwd x ls -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: loop 0: forward function *) let rec list_nth_mut_loop_loop_fwd (t : Type0) (ls : list_t t) (i : u32) : Tot (result t) (decreases (list_nth_mut_loop_loop_decreases t ls i)) @@ -96,11 +98,11 @@ let rec list_nth_mut_loop_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: forward function *) let list_nth_mut_loop_fwd (t : Type0) (ls : list_t t) (i : u32) : result t = list_nth_mut_loop_loop_fwd t ls i -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: loop 0: backward function 0 *) let rec list_nth_mut_loop_loop_back (t : Type0) (ls : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) (decreases (list_nth_mut_loop_loop_decreases t ls i)) @@ -116,12 +118,12 @@ let rec list_nth_mut_loop_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop] *) +(** [loops::list_nth_mut_loop]: backward function 0 *) let list_nth_mut_loop_back (t : Type0) (ls : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_mut_loop_loop_back t ls i ret -(** [loops::list_nth_shared_loop] *) +(** [loops::list_nth_shared_loop]: loop 0: forward function *) let rec list_nth_shared_loop_loop_fwd (t : Type0) (ls : list_t t) (i : u32) : Tot (result t) (decreases (list_nth_shared_loop_loop_decreases t ls i)) @@ -134,11 +136,11 @@ let rec list_nth_shared_loop_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_shared_loop] *) +(** [loops::list_nth_shared_loop]: forward function *) let list_nth_shared_loop_fwd (t : Type0) (ls : list_t t) (i : u32) : result t = list_nth_shared_loop_loop_fwd t ls i -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: loop 0: forward function *) let rec get_elem_mut_loop_fwd (x : usize) (ls : list_t usize) : Tot (result usize) (decreases (get_elem_mut_loop_decreases x ls)) @@ -148,12 +150,12 @@ let rec get_elem_mut_loop_fwd | ListNil -> Fail Failure end -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: forward function *) let get_elem_mut_fwd (slots : vec (list_t usize)) (x : usize) : result usize = let* l = vec_index_mut_fwd (list_t usize) slots 0 in get_elem_mut_loop_fwd x l -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: loop 0: backward function 0 *) let rec get_elem_mut_loop_back (x : usize) (ls : list_t usize) (ret : usize) : Tot (result (list_t usize)) (decreases (get_elem_mut_loop_decreases x ls)) @@ -166,7 +168,7 @@ let rec get_elem_mut_loop_back | ListNil -> Fail Failure end -(** [loops::get_elem_mut] *) +(** [loops::get_elem_mut]: backward function 0 *) let get_elem_mut_back (slots : vec (list_t usize)) (x : usize) (ret : usize) : result (vec (list_t usize)) @@ -175,7 +177,7 @@ let get_elem_mut_back let* l0 = get_elem_mut_loop_back x l ret in vec_index_mut_back (list_t usize) slots 0 l0 -(** [loops::get_elem_shared] *) +(** [loops::get_elem_shared]: loop 0: forward function *) let rec get_elem_shared_loop_fwd (x : usize) (ls : list_t usize) : Tot (result usize) (decreases (get_elem_shared_loop_decreases x ls)) @@ -185,25 +187,25 @@ let rec get_elem_shared_loop_fwd | ListNil -> Fail Failure end -(** [loops::get_elem_shared] *) +(** [loops::get_elem_shared]: forward function *) let get_elem_shared_fwd (slots : vec (list_t usize)) (x : usize) : result usize = let* l = vec_index_fwd (list_t usize) slots 0 in get_elem_shared_loop_fwd x l -(** [loops::id_mut] *) +(** [loops::id_mut]: forward function *) let id_mut_fwd (t : Type0) (ls : list_t t) : result (list_t t) = Return ls -(** [loops::id_mut] *) +(** [loops::id_mut]: backward function 0 *) let id_mut_back (t : Type0) (ls : list_t t) (ret : list_t t) : result (list_t t) = Return ret -(** [loops::id_shared] *) +(** [loops::id_shared]: forward function *) let id_shared_fwd (t : Type0) (ls : list_t t) : result (list_t t) = Return ls -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: loop 0: forward function *) let rec list_nth_mut_loop_with_id_loop_fwd (t : Type0) (i : u32) (ls : list_t t) : Tot (result t) (decreases (list_nth_mut_loop_with_id_loop_decreases t i ls)) @@ -216,12 +218,12 @@ let rec list_nth_mut_loop_with_id_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: forward function *) let list_nth_mut_loop_with_id_fwd (t : Type0) (ls : list_t t) (i : u32) : result t = let* ls0 = id_mut_fwd t ls in list_nth_mut_loop_with_id_loop_fwd t i ls0 -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: loop 0: backward function 0 *) let rec list_nth_mut_loop_with_id_loop_back (t : Type0) (i : u32) (ls : list_t t) (ret : t) : Tot (result (list_t t)) @@ -238,14 +240,14 @@ let rec list_nth_mut_loop_with_id_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_with_id] *) +(** [loops::list_nth_mut_loop_with_id]: backward function 0 *) let list_nth_mut_loop_with_id_back (t : Type0) (ls : list_t t) (i : u32) (ret : t) : result (list_t t) = let* ls0 = id_mut_fwd t ls in let* l = list_nth_mut_loop_with_id_loop_back t i ls0 ret in id_mut_back t ls l -(** [loops::list_nth_shared_loop_with_id] *) +(** [loops::list_nth_shared_loop_with_id]: loop 0: forward function *) let rec list_nth_shared_loop_with_id_loop_fwd (t : Type0) (i : u32) (ls : list_t t) : Tot (result t) @@ -259,13 +261,13 @@ let rec list_nth_shared_loop_with_id_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_shared_loop_with_id] *) +(** [loops::list_nth_shared_loop_with_id]: forward function *) let list_nth_shared_loop_with_id_fwd (t : Type0) (ls : list_t t) (i : u32) : result t = let* ls0 = id_shared_fwd t ls in list_nth_shared_loop_with_id_loop_fwd t i ls0 -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: loop 0: forward function *) let rec list_nth_mut_loop_pair_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -284,12 +286,12 @@ let rec list_nth_mut_loop_pair_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: forward function *) let list_nth_mut_loop_pair_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_loop_pair_loop_fwd t ls0 ls1 i -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: loop 0: backward function 0 *) let rec list_nth_mut_loop_pair_loop_back'a (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -310,14 +312,14 @@ let rec list_nth_mut_loop_pair_loop_back'a | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: backward function 0 *) let list_nth_mut_loop_pair_back'a (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_mut_loop_pair_loop_back'a t ls0 ls1 i ret -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: loop 0: backward function 1 *) let rec list_nth_mut_loop_pair_loop_back'b (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -338,14 +340,14 @@ let rec list_nth_mut_loop_pair_loop_back'b | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_pair] *) +(** [loops::list_nth_mut_loop_pair]: backward function 1 *) let list_nth_mut_loop_pair_back'b (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_mut_loop_pair_loop_back'b t ls0 ls1 i ret -(** [loops::list_nth_shared_loop_pair] *) +(** [loops::list_nth_shared_loop_pair]: loop 0: forward function *) let rec list_nth_shared_loop_pair_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -365,12 +367,12 @@ let rec list_nth_shared_loop_pair_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_shared_loop_pair] *) +(** [loops::list_nth_shared_loop_pair]: forward function *) let list_nth_shared_loop_pair_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_loop_pair_loop_fwd t ls0 ls1 i -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: loop 0: forward function *) let rec list_nth_mut_loop_pair_merge_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -390,12 +392,12 @@ let rec list_nth_mut_loop_pair_merge_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: forward function *) let list_nth_mut_loop_pair_merge_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_loop_pair_merge_loop_fwd t ls0 ls1 i -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: loop 0: backward function 0 *) let rec list_nth_mut_loop_pair_merge_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : (t & t)) : Tot (result ((list_t t) & (list_t t))) @@ -417,14 +419,14 @@ let rec list_nth_mut_loop_pair_merge_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_mut_loop_pair_merge] *) +(** [loops::list_nth_mut_loop_pair_merge]: backward function 0 *) let list_nth_mut_loop_pair_merge_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : (t & t)) : result ((list_t t) & (list_t t)) = list_nth_mut_loop_pair_merge_loop_back t ls0 ls1 i ret -(** [loops::list_nth_shared_loop_pair_merge] *) +(** [loops::list_nth_shared_loop_pair_merge]: loop 0: forward function *) let rec list_nth_shared_loop_pair_merge_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -444,12 +446,12 @@ let rec list_nth_shared_loop_pair_merge_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_shared_loop_pair_merge] *) +(** [loops::list_nth_shared_loop_pair_merge]: forward function *) let list_nth_shared_loop_pair_merge_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_loop_pair_merge_loop_fwd t ls0 ls1 i -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: loop 0: forward function *) let rec list_nth_mut_shared_loop_pair_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -469,12 +471,12 @@ let rec list_nth_mut_shared_loop_pair_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: forward function *) let list_nth_mut_shared_loop_pair_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_shared_loop_pair_loop_fwd t ls0 ls1 i -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: loop 0: backward function 0 *) let rec list_nth_mut_shared_loop_pair_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -495,14 +497,14 @@ let rec list_nth_mut_shared_loop_pair_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_mut_shared_loop_pair] *) +(** [loops::list_nth_mut_shared_loop_pair]: backward function 0 *) let list_nth_mut_shared_loop_pair_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_mut_shared_loop_pair_loop_back t ls0 ls1 i ret -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: forward function *) let rec list_nth_mut_shared_loop_pair_merge_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -522,12 +524,12 @@ let rec list_nth_mut_shared_loop_pair_merge_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: forward function *) let list_nth_mut_shared_loop_pair_merge_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_shared_loop_pair_merge_loop_fwd t ls0 ls1 i -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: backward function 0 *) let rec list_nth_mut_shared_loop_pair_merge_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -549,14 +551,14 @@ let rec list_nth_mut_shared_loop_pair_merge_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_mut_shared_loop_pair_merge] *) +(** [loops::list_nth_mut_shared_loop_pair_merge]: backward function 0 *) let list_nth_mut_shared_loop_pair_merge_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_mut_shared_loop_pair_merge_loop_back t ls0 ls1 i ret -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: loop 0: forward function *) let rec list_nth_shared_mut_loop_pair_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -576,12 +578,12 @@ let rec list_nth_shared_mut_loop_pair_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: forward function *) let list_nth_shared_mut_loop_pair_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_mut_loop_pair_loop_fwd t ls0 ls1 i -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: loop 0: backward function 1 *) let rec list_nth_shared_mut_loop_pair_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -602,14 +604,14 @@ let rec list_nth_shared_mut_loop_pair_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_shared_mut_loop_pair] *) +(** [loops::list_nth_shared_mut_loop_pair]: backward function 1 *) let list_nth_shared_mut_loop_pair_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_shared_mut_loop_pair_loop_back t ls0 ls1 i ret -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: forward function *) let rec list_nth_shared_mut_loop_pair_merge_loop_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -629,12 +631,12 @@ let rec list_nth_shared_mut_loop_pair_merge_loop_fwd | ListNil -> Fail Failure end -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: forward function *) let list_nth_shared_mut_loop_pair_merge_fwd (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_mut_loop_pair_merge_loop_fwd t ls0 ls1 i -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: backward function 0 *) let rec list_nth_shared_mut_loop_pair_merge_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -656,7 +658,7 @@ let rec list_nth_shared_mut_loop_pair_merge_loop_back | ListNil -> Fail Failure end -(** [loops::list_nth_shared_mut_loop_pair_merge] *) +(** [loops::list_nth_shared_mut_loop_pair_merge]: backward function 0 *) let list_nth_shared_mut_loop_pair_merge_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) diff --git a/tests/fstar/misc/NoNestedBorrows.fst b/tests/fstar/misc/NoNestedBorrows.fst index 3770ab5d..d790bfa9 100644 --- a/tests/fstar/misc/NoNestedBorrows.fst +++ b/tests/fstar/misc/NoNestedBorrows.fst @@ -30,46 +30,46 @@ type sum_t (t1 t2 : Type0) = | SumLeft : t1 -> sum_t t1 t2 | SumRight : t2 -> sum_t t1 t2 -(** [no_nested_borrows::neg_test] *) +(** [no_nested_borrows::neg_test]: forward function *) let neg_test_fwd (x : i32) : result i32 = i32_neg x -(** [no_nested_borrows::add_test] *) +(** [no_nested_borrows::add_test]: forward function *) let add_test_fwd (x : u32) (y : u32) : result u32 = u32_add x y -(** [no_nested_borrows::subs_test] *) +(** [no_nested_borrows::subs_test]: forward function *) let subs_test_fwd (x : u32) (y : u32) : result u32 = u32_sub x y -(** [no_nested_borrows::div_test] *) +(** [no_nested_borrows::div_test]: forward function *) let div_test_fwd (x : u32) (y : u32) : result u32 = u32_div x y -(** [no_nested_borrows::div_test1] *) +(** [no_nested_borrows::div_test1]: forward function *) let div_test1_fwd (x : u32) : result u32 = u32_div x 2 -(** [no_nested_borrows::rem_test] *) +(** [no_nested_borrows::rem_test]: forward function *) let rem_test_fwd (x : u32) (y : u32) : result u32 = u32_rem x y -(** [no_nested_borrows::cast_test] *) +(** [no_nested_borrows::cast_test]: forward function *) let cast_test_fwd (x : u32) : result i32 = scalar_cast U32 I32 x -(** [no_nested_borrows::test2] *) +(** [no_nested_borrows::test2]: forward function *) let test2_fwd : result unit = let* _ = u32_add 23 44 in Return () (** Unit test for [no_nested_borrows::test2] *) let _ = assert_norm (test2_fwd = Return ()) -(** [no_nested_borrows::get_max] *) +(** [no_nested_borrows::get_max]: forward function *) let get_max_fwd (x : u32) (y : u32) : result u32 = if x >= y then Return x else Return y -(** [no_nested_borrows::test3] *) +(** [no_nested_borrows::test3]: forward function *) let test3_fwd : result unit = let* x = get_max_fwd 4 3 in let* y = get_max_fwd 10 11 in @@ -79,21 +79,21 @@ let test3_fwd : result unit = (** Unit test for [no_nested_borrows::test3] *) let _ = assert_norm (test3_fwd = Return ()) -(** [no_nested_borrows::test_neg1] *) +(** [no_nested_borrows::test_neg1]: forward function *) let test_neg1_fwd : result unit = let* y = i32_neg 3 in if not (y = -3) then Fail Failure else Return () (** Unit test for [no_nested_borrows::test_neg1] *) let _ = assert_norm (test_neg1_fwd = Return ()) -(** [no_nested_borrows::refs_test1] *) +(** [no_nested_borrows::refs_test1]: forward function *) let refs_test1_fwd : result unit = if not (1 = 1) then Fail Failure else Return () (** Unit test for [no_nested_borrows::refs_test1] *) let _ = assert_norm (refs_test1_fwd = Return ()) -(** [no_nested_borrows::refs_test2] *) +(** [no_nested_borrows::refs_test2]: forward function *) let refs_test2_fwd : result unit = if not (2 = 2) then Fail Failure @@ -108,47 +108,47 @@ let refs_test2_fwd : result unit = (** Unit test for [no_nested_borrows::refs_test2] *) let _ = assert_norm (refs_test2_fwd = Return ()) -(** [no_nested_borrows::test_list1] *) +(** [no_nested_borrows::test_list1]: forward function *) let test_list1_fwd : result unit = Return () (** Unit test for [no_nested_borrows::test_list1] *) let _ = assert_norm (test_list1_fwd = Return ()) -(** [no_nested_borrows::test_box1] *) +(** [no_nested_borrows::test_box1]: forward function *) let test_box1_fwd : result unit = let b = 1 in let x = b in if not (x = 1) then Fail Failure else Return () (** Unit test for [no_nested_borrows::test_box1] *) let _ = assert_norm (test_box1_fwd = Return ()) -(** [no_nested_borrows::copy_int] *) +(** [no_nested_borrows::copy_int]: forward function *) let copy_int_fwd (x : i32) : result i32 = Return x -(** [no_nested_borrows::test_unreachable] *) +(** [no_nested_borrows::test_unreachable]: forward function *) let test_unreachable_fwd (b : bool) : result unit = if b then Fail Failure else Return () -(** [no_nested_borrows::test_panic] *) +(** [no_nested_borrows::test_panic]: forward function *) let test_panic_fwd (b : bool) : result unit = if b then Fail Failure else Return () -(** [no_nested_borrows::test_copy_int] *) +(** [no_nested_borrows::test_copy_int]: forward function *) let test_copy_int_fwd : result unit = let* y = copy_int_fwd 0 in if not (0 = y) then Fail Failure else Return () (** Unit test for [no_nested_borrows::test_copy_int] *) let _ = assert_norm (test_copy_int_fwd = Return ()) -(** [no_nested_borrows::is_cons] *) +(** [no_nested_borrows::is_cons]: forward function *) let is_cons_fwd (t : Type0) (l : list_t t) : result bool = begin match l with | ListCons x l0 -> Return true | ListNil -> Return false end -(** [no_nested_borrows::test_is_cons] *) +(** [no_nested_borrows::test_is_cons]: forward function *) let test_is_cons_fwd : result unit = let l = ListNil in let* b = is_cons_fwd i32 (ListCons 0 l) in @@ -157,14 +157,14 @@ let test_is_cons_fwd : result unit = (** Unit test for [no_nested_borrows::test_is_cons] *) let _ = assert_norm (test_is_cons_fwd = Return ()) -(** [no_nested_borrows::split_list] *) +(** [no_nested_borrows::split_list]: forward function *) let split_list_fwd (t : Type0) (l : list_t t) : result (t & (list_t t)) = begin match l with | ListCons hd tl -> Return (hd, tl) | ListNil -> Fail Failure end -(** [no_nested_borrows::test_split_list] *) +(** [no_nested_borrows::test_split_list]: forward function *) let test_split_list_fwd : result unit = let l = ListNil in let* p = split_list_fwd i32 (ListCons 0 l) in @@ -174,16 +174,16 @@ let test_split_list_fwd : result unit = (** Unit test for [no_nested_borrows::test_split_list] *) let _ = assert_norm (test_split_list_fwd = Return ()) -(** [no_nested_borrows::choose] *) +(** [no_nested_borrows::choose]: forward function *) let choose_fwd (t : Type0) (b : bool) (x : t) (y : t) : result t = if b then Return x else Return y -(** [no_nested_borrows::choose] *) +(** [no_nested_borrows::choose]: backward function 0 *) let choose_back (t : Type0) (b : bool) (x : t) (y : t) (ret : t) : result (t & t) = if b then Return (ret, y) else Return (x, ret) -(** [no_nested_borrows::choose_test] *) +(** [no_nested_borrows::choose_test]: forward function *) let choose_test_fwd : result unit = let* z = choose_fwd i32 true 0 0 in let* z0 = i32_add z 1 in @@ -198,7 +198,7 @@ let choose_test_fwd : result unit = (** Unit test for [no_nested_borrows::choose_test] *) let _ = assert_norm (choose_test_fwd = Return ()) -(** [no_nested_borrows::test_char] *) +(** [no_nested_borrows::test_char]: forward function *) let test_char_fwd : result char = Return 'a' @@ -212,14 +212,14 @@ and tree_t (t : Type0) = | TreeLeaf : t -> tree_t t | TreeNode : t -> node_elem_t t -> tree_t t -> tree_t t -(** [no_nested_borrows::list_length] *) +(** [no_nested_borrows::list_length]: forward function *) let rec list_length_fwd (t : Type0) (l : list_t t) : result u32 = begin match l with | ListCons x l1 -> let* i = list_length_fwd t l1 in u32_add 1 i | ListNil -> Return 0 end -(** [no_nested_borrows::list_nth_shared] *) +(** [no_nested_borrows::list_nth_shared]: forward function *) let rec list_nth_shared_fwd (t : Type0) (l : list_t t) (i : u32) : result t = begin match l with | ListCons x tl -> @@ -229,7 +229,7 @@ let rec list_nth_shared_fwd (t : Type0) (l : list_t t) (i : u32) : result t = | ListNil -> Fail Failure end -(** [no_nested_borrows::list_nth_mut] *) +(** [no_nested_borrows::list_nth_mut]: forward function *) let rec list_nth_mut_fwd (t : Type0) (l : list_t t) (i : u32) : result t = begin match l with | ListCons x tl -> @@ -239,7 +239,7 @@ let rec list_nth_mut_fwd (t : Type0) (l : list_t t) (i : u32) : result t = | ListNil -> Fail Failure end -(** [no_nested_borrows::list_nth_mut] *) +(** [no_nested_borrows::list_nth_mut]: backward function 0 *) let rec list_nth_mut_back (t : Type0) (l : list_t t) (i : u32) (ret : t) : result (list_t t) = begin match l with @@ -253,7 +253,7 @@ let rec list_nth_mut_back | ListNil -> Fail Failure end -(** [no_nested_borrows::list_rev_aux] *) +(** [no_nested_borrows::list_rev_aux]: forward function *) let rec list_rev_aux_fwd (t : Type0) (li : list_t t) (lo : list_t t) : result (list_t t) = begin match li with @@ -261,12 +261,13 @@ let rec list_rev_aux_fwd | ListNil -> Return lo end -(** [no_nested_borrows::list_rev] *) +(** [no_nested_borrows::list_rev]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let list_rev_fwd_back (t : Type0) (l : list_t t) : result (list_t t) = let li = mem_replace_fwd (list_t t) l ListNil in list_rev_aux_fwd t li ListNil -(** [no_nested_borrows::test_list_functions] *) +(** [no_nested_borrows::test_list_functions]: forward function *) let test_list_functions_fwd : result unit = let l = ListNil in let l0 = ListCons 2 l in @@ -302,48 +303,48 @@ let test_list_functions_fwd : result unit = (** Unit test for [no_nested_borrows::test_list_functions] *) let _ = assert_norm (test_list_functions_fwd = Return ()) -(** [no_nested_borrows::id_mut_pair1] *) +(** [no_nested_borrows::id_mut_pair1]: forward function *) let id_mut_pair1_fwd (t1 t2 : Type0) (x : t1) (y : t2) : result (t1 & t2) = Return (x, y) -(** [no_nested_borrows::id_mut_pair1] *) +(** [no_nested_borrows::id_mut_pair1]: backward function 0 *) let id_mut_pair1_back (t1 t2 : Type0) (x : t1) (y : t2) (ret : (t1 & t2)) : result (t1 & t2) = let (x0, x1) = ret in Return (x0, x1) -(** [no_nested_borrows::id_mut_pair2] *) +(** [no_nested_borrows::id_mut_pair2]: forward function *) let id_mut_pair2_fwd (t1 t2 : Type0) (p : (t1 & t2)) : result (t1 & t2) = let (x, x0) = p in Return (x, x0) -(** [no_nested_borrows::id_mut_pair2] *) +(** [no_nested_borrows::id_mut_pair2]: backward function 0 *) let id_mut_pair2_back (t1 t2 : Type0) (p : (t1 & t2)) (ret : (t1 & t2)) : result (t1 & t2) = let (x, x0) = ret in Return (x, x0) -(** [no_nested_borrows::id_mut_pair3] *) +(** [no_nested_borrows::id_mut_pair3]: forward function *) let id_mut_pair3_fwd (t1 t2 : Type0) (x : t1) (y : t2) : result (t1 & t2) = Return (x, y) -(** [no_nested_borrows::id_mut_pair3] *) +(** [no_nested_borrows::id_mut_pair3]: backward function 0 *) let id_mut_pair3_back'a (t1 t2 : Type0) (x : t1) (y : t2) (ret : t1) : result t1 = Return ret -(** [no_nested_borrows::id_mut_pair3] *) +(** [no_nested_borrows::id_mut_pair3]: backward function 1 *) let id_mut_pair3_back'b (t1 t2 : Type0) (x : t1) (y : t2) (ret : t2) : result t2 = Return ret -(** [no_nested_borrows::id_mut_pair4] *) +(** [no_nested_borrows::id_mut_pair4]: forward function *) let id_mut_pair4_fwd (t1 t2 : Type0) (p : (t1 & t2)) : result (t1 & t2) = let (x, x0) = p in Return (x, x0) -(** [no_nested_borrows::id_mut_pair4] *) +(** [no_nested_borrows::id_mut_pair4]: backward function 0 *) let id_mut_pair4_back'a (t1 t2 : Type0) (p : (t1 & t2)) (ret : t1) : result t1 = Return ret -(** [no_nested_borrows::id_mut_pair4] *) +(** [no_nested_borrows::id_mut_pair4]: backward function 1 *) let id_mut_pair4_back'b (t1 t2 : Type0) (p : (t1 & t2)) (ret : t2) : result t2 = Return ret @@ -351,15 +352,15 @@ let id_mut_pair4_back'b (** [no_nested_borrows::StructWithTuple] *) type struct_with_tuple_t (t1 t2 : Type0) = { struct_with_tuple_p : (t1 & t2); } -(** [no_nested_borrows::new_tuple1] *) +(** [no_nested_borrows::new_tuple1]: forward function *) let new_tuple1_fwd : result (struct_with_tuple_t u32 u32) = Return { struct_with_tuple_p = (1, 2) } -(** [no_nested_borrows::new_tuple2] *) +(** [no_nested_borrows::new_tuple2]: forward function *) let new_tuple2_fwd : result (struct_with_tuple_t i16 i16) = Return { struct_with_tuple_p = (1, 2) } -(** [no_nested_borrows::new_tuple3] *) +(** [no_nested_borrows::new_tuple3]: forward function *) let new_tuple3_fwd : result (struct_with_tuple_t u64 i64) = Return { struct_with_tuple_p = (1, 2) } @@ -369,11 +370,11 @@ type struct_with_pair_t (t1 t2 : Type0) = struct_with_pair_p : pair_t t1 t2; } -(** [no_nested_borrows::new_pair1] *) +(** [no_nested_borrows::new_pair1]: forward function *) let new_pair1_fwd : result (struct_with_pair_t u32 u32) = Return { struct_with_pair_p = { pair_x = 1; pair_y = 2 } } -(** [no_nested_borrows::test_constants] *) +(** [no_nested_borrows::test_constants]: forward function *) let test_constants_fwd : result unit = let* swt = new_tuple1_fwd in let (i, _) = swt.struct_with_tuple_p in @@ -398,31 +399,32 @@ let test_constants_fwd : result unit = (** Unit test for [no_nested_borrows::test_constants] *) let _ = assert_norm (test_constants_fwd = Return ()) -(** [no_nested_borrows::test_weird_borrows1] *) +(** [no_nested_borrows::test_weird_borrows1]: forward function *) let test_weird_borrows1_fwd : result unit = Return () (** Unit test for [no_nested_borrows::test_weird_borrows1] *) let _ = assert_norm (test_weird_borrows1_fwd = Return ()) -(** [no_nested_borrows::test_mem_replace] *) +(** [no_nested_borrows::test_mem_replace]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let test_mem_replace_fwd_back (px : u32) : result u32 = let y = mem_replace_fwd u32 px 1 in if not (y = 0) then Fail Failure else Return 2 -(** [no_nested_borrows::test_shared_borrow_bool1] *) +(** [no_nested_borrows::test_shared_borrow_bool1]: forward function *) let test_shared_borrow_bool1_fwd (b : bool) : result u32 = if b then Return 0 else Return 1 -(** [no_nested_borrows::test_shared_borrow_bool2] *) +(** [no_nested_borrows::test_shared_borrow_bool2]: forward function *) let test_shared_borrow_bool2_fwd : result u32 = Return 0 -(** [no_nested_borrows::test_shared_borrow_enum1] *) +(** [no_nested_borrows::test_shared_borrow_enum1]: forward function *) let test_shared_borrow_enum1_fwd (l : list_t u32) : result u32 = begin match l with | ListCons i l0 -> Return 1 | ListNil -> Return 0 end -(** [no_nested_borrows::test_shared_borrow_enum2] *) +(** [no_nested_borrows::test_shared_borrow_enum2]: forward function *) let test_shared_borrow_enum2_fwd : result u32 = Return 0 diff --git a/tests/fstar/misc/Paper.fst b/tests/fstar/misc/Paper.fst index 4ab31de3..e2d692c2 100644 --- a/tests/fstar/misc/Paper.fst +++ b/tests/fstar/misc/Paper.fst @@ -5,11 +5,12 @@ open Primitives #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" -(** [paper::ref_incr] *) +(** [paper::ref_incr]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) let ref_incr_fwd_back (x : i32) : result i32 = i32_add x 1 -(** [paper::test_incr] *) +(** [paper::test_incr]: forward function *) let test_incr_fwd : result unit = let* x = ref_incr_fwd_back 0 in if not (x = 1) then Fail Failure else Return () @@ -17,16 +18,16 @@ let test_incr_fwd : result unit = (** Unit test for [paper::test_incr] *) let _ = assert_norm (test_incr_fwd = Return ()) -(** [paper::choose] *) +(** [paper::choose]: forward function *) let choose_fwd (t : Type0) (b : bool) (x : t) (y : t) : result t = if b then Return x else Return y -(** [paper::choose] *) +(** [paper::choose]: backward function 0 *) let choose_back (t : Type0) (b : bool) (x : t) (y : t) (ret : t) : result (t & t) = if b then Return (ret, y) else Return (x, ret) -(** [paper::test_choose] *) +(** [paper::test_choose]: forward function *) let test_choose_fwd : result unit = let* z = choose_fwd i32 true 0 0 in let* z0 = i32_add z 1 in @@ -46,7 +47,7 @@ type list_t (t : Type0) = | ListCons : t -> list_t t -> list_t t | ListNil : list_t t -(** [paper::list_nth_mut] *) +(** [paper::list_nth_mut]: forward function *) let rec list_nth_mut_fwd (t : Type0) (l : list_t t) (i : u32) : result t = begin match l with | ListCons x tl -> @@ -56,7 +57,7 @@ let rec list_nth_mut_fwd (t : Type0) (l : list_t t) (i : u32) : result t = | ListNil -> Fail Failure end -(** [paper::list_nth_mut] *) +(** [paper::list_nth_mut]: backward function 0 *) let rec list_nth_mut_back (t : Type0) (l : list_t t) (i : u32) (ret : t) : result (list_t t) = begin match l with @@ -70,14 +71,14 @@ let rec list_nth_mut_back | ListNil -> Fail Failure end -(** [paper::sum] *) +(** [paper::sum]: forward function *) let rec sum_fwd (l : list_t i32) : result i32 = begin match l with | ListCons x tl -> let* i = sum_fwd tl in i32_add x i | ListNil -> Return 0 end -(** [paper::test_nth] *) +(** [paper::test_nth]: forward function *) let test_nth_fwd : result unit = let l = ListNil in let l0 = ListCons 3 l in @@ -91,7 +92,7 @@ let test_nth_fwd : result unit = (** Unit test for [paper::test_nth] *) let _ = assert_norm (test_nth_fwd = Return ()) -(** [paper::call_choose] *) +(** [paper::call_choose]: forward function *) let call_choose_fwd (p : (u32 & u32)) : result u32 = let (px, py) = p in let* pz = choose_fwd u32 true px py in diff --git a/tests/fstar/misc/PoloniusList.fst b/tests/fstar/misc/PoloniusList.fst index e2144487..79c86606 100644 --- a/tests/fstar/misc/PoloniusList.fst +++ b/tests/fstar/misc/PoloniusList.fst @@ -10,7 +10,7 @@ type list_t (t : Type0) = | ListCons : t -> list_t t -> list_t t | ListNil : list_t t -(** [polonius_list::get_list_at_x] *) +(** [polonius_list::get_list_at_x]: forward function *) let rec get_list_at_x_fwd (ls : list_t u32) (x : u32) : result (list_t u32) = begin match ls with | ListCons hd tl -> @@ -18,7 +18,7 @@ let rec get_list_at_x_fwd (ls : list_t u32) (x : u32) : result (list_t u32) = | ListNil -> Return ListNil end -(** [polonius_list::get_list_at_x] *) +(** [polonius_list::get_list_at_x]: backward function 0 *) let rec get_list_at_x_back (ls : list_t u32) (x : u32) (ret : list_t u32) : result (list_t u32) = begin match ls with diff --git a/tests/hol4/betree/betreeMain_FunsScript.sml b/tests/hol4/betree/betreeMain_FunsScript.sml index df0c6a24..03ff2671 100644 --- a/tests/hol4/betree/betreeMain_FunsScript.sml +++ b/tests/hol4/betree/betreeMain_FunsScript.sml @@ -7,7 +7,7 @@ val _ = new_theory "betreeMain_Funs" val betree_load_internal_node_fwd_def = Define ‘ - (** [betree_main::betree::load_internal_node] *) + (** [betree_main::betree::load_internal_node]: forward function *) betree_load_internal_node_fwd (id : u64) (st : state) : (state # (u64 # betree_message_t) betree_list_t) result @@ -16,7 +16,7 @@ val betree_load_internal_node_fwd_def = Define ‘ ’ val betree_store_internal_node_fwd_def = Define ‘ - (** [betree_main::betree::store_internal_node] *) + (** [betree_main::betree::store_internal_node]: forward function *) betree_store_internal_node_fwd (id : u64) (content : (u64 # betree_message_t) betree_list_t) (st : state) : @@ -29,14 +29,14 @@ val betree_store_internal_node_fwd_def = Define ‘ ’ val betree_load_leaf_node_fwd_def = Define ‘ - (** [betree_main::betree::load_leaf_node] *) + (** [betree_main::betree::load_leaf_node]: forward function *) betree_load_leaf_node_fwd (id : u64) (st : state) : (state # (u64 # u64) betree_list_t) result = betree_utils_load_leaf_node_fwd id st ’ val betree_store_leaf_node_fwd_def = Define ‘ - (** [betree_main::betree::store_leaf_node] *) + (** [betree_main::betree::store_leaf_node]: forward function *) betree_store_leaf_node_fwd (id : u64) (content : (u64 # u64) betree_list_t) (st : state) : (state # unit) result @@ -48,7 +48,7 @@ val betree_store_leaf_node_fwd_def = Define ‘ ’ val betree_fresh_node_id_fwd_def = Define ‘ - (** [betree_main::betree::fresh_node_id] *) + (** [betree_main::betree::fresh_node_id]: forward function *) betree_fresh_node_id_fwd (counter : u64) : u64 result = do _ <- u64_add counter (int_to_u64 1); @@ -57,19 +57,19 @@ val betree_fresh_node_id_fwd_def = Define ‘ ’ val betree_fresh_node_id_back_def = Define ‘ - (** [betree_main::betree::fresh_node_id] *) + (** [betree_main::betree::fresh_node_id]: backward function 0 *) betree_fresh_node_id_back (counter : u64) : u64 result = u64_add counter (int_to_u64 1) ’ val betree_node_id_counter_new_fwd_def = Define ‘ - (** [betree_main::betree::NodeIdCounter::{0}::new] *) + (** [betree_main::betree::NodeIdCounter::{0}::new]: forward function *) betree_node_id_counter_new_fwd : betree_node_id_counter_t result = Return (<| betree_node_id_counter_next_node_id := (int_to_u64 0) |>) ’ val betree_node_id_counter_fresh_id_fwd_def = Define ‘ - (** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) + (** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function *) betree_node_id_counter_fresh_id_fwd (self : betree_node_id_counter_t) : u64 result = do @@ -79,7 +79,7 @@ val betree_node_id_counter_fresh_id_fwd_def = Define ‘ ’ val betree_node_id_counter_fresh_id_back_def = Define ‘ - (** [betree_main::betree::NodeIdCounter::{0}::fresh_id] *) + (** [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 *) betree_node_id_counter_fresh_id_back (self : betree_node_id_counter_t) : betree_node_id_counter_t result = do @@ -97,7 +97,7 @@ Definition core_num_u64_max_c_def: End val betree_upsert_update_fwd_def = Define ‘ - (** [betree_main::betree::upsert_update] *) + (** [betree_main::betree::upsert_update]: forward function *) betree_upsert_update_fwd (prev : u64 option) (st : betree_upsert_fun_state_t) : u64 result = (case prev of @@ -117,7 +117,7 @@ val betree_upsert_update_fwd_def = Define ‘ ’ val [betree_list_len_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::List::{1}::len] *) + (** [betree_main::betree::List::{1}::len]: forward function *) betree_list_len_fwd (self : 't betree_list_t) : u64 result = (case self of | BetreeListCons t tl => @@ -129,7 +129,7 @@ val [betree_list_len_fwd_def] = DefineDiv ‘ ’ val [betree_list_split_at_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::List::{1}::split_at] *) + (** [betree_main::betree::List::{1}::split_at]: forward function *) betree_list_split_at_fwd (self : 't betree_list_t) (n : u64) : ('t betree_list_t # 't betree_list_t) result @@ -148,7 +148,8 @@ val [betree_list_split_at_fwd_def] = DefineDiv ‘ ’ val betree_list_push_front_fwd_back_def = Define ‘ - (** [betree_main::betree::List::{1}::push_front] *) + (** [betree_main::betree::List::{1}::push_front]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) betree_list_push_front_fwd_back (self : 't betree_list_t) (x : 't) : 't betree_list_t result = let tl = mem_replace_fwd self BetreeListNil in @@ -157,7 +158,7 @@ val betree_list_push_front_fwd_back_def = Define ‘ ’ val betree_list_pop_front_fwd_def = Define ‘ - (** [betree_main::betree::List::{1}::pop_front] *) + (** [betree_main::betree::List::{1}::pop_front]: forward function *) betree_list_pop_front_fwd (self : 't betree_list_t) : 't result = let ls = mem_replace_fwd self BetreeListNil in (case ls of @@ -166,7 +167,7 @@ val betree_list_pop_front_fwd_def = Define ‘ ’ val betree_list_pop_front_back_def = Define ‘ - (** [betree_main::betree::List::{1}::pop_front] *) + (** [betree_main::betree::List::{1}::pop_front]: backward function 0 *) betree_list_pop_front_back (self : 't betree_list_t) : 't betree_list_t result = let ls = mem_replace_fwd self BetreeListNil in @@ -176,7 +177,7 @@ val betree_list_pop_front_back_def = Define ‘ ’ val betree_list_hd_fwd_def = Define ‘ - (** [betree_main::betree::List::{1}::hd] *) + (** [betree_main::betree::List::{1}::hd]: forward function *) betree_list_hd_fwd (self : 't betree_list_t) : 't result = (case self of | BetreeListCons hd l => Return hd @@ -184,7 +185,7 @@ val betree_list_hd_fwd_def = Define ‘ ’ val betree_list_head_has_key_fwd_def = Define ‘ - (** [betree_main::betree::List::{2}::head_has_key] *) + (** [betree_main::betree::List::{2}::head_has_key]: forward function *) betree_list_head_has_key_fwd (self : (u64 # 't) betree_list_t) (key : u64) : bool result = (case self of @@ -193,7 +194,7 @@ val betree_list_head_has_key_fwd_def = Define ‘ ’ val [betree_list_partition_at_pivot_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::List::{2}::partition_at_pivot] *) + (** [betree_main::betree::List::{2}::partition_at_pivot]: forward function *) betree_list_partition_at_pivot_fwd (self : (u64 # 't) betree_list_t) (pivot : u64) : ((u64 # 't) betree_list_t # (u64 # 't) betree_list_t) result @@ -214,7 +215,7 @@ val [betree_list_partition_at_pivot_fwd_def] = DefineDiv ‘ ’ val betree_leaf_split_fwd_def = Define ‘ - (** [betree_main::betree::Leaf::{3}::split] *) + (** [betree_main::betree::Leaf::{3}::split]: forward function *) betree_leaf_split_fwd (self : betree_leaf_t) (content : (u64 # u64) betree_list_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -256,7 +257,7 @@ val betree_leaf_split_fwd_def = Define ‘ ’ val betree_leaf_split_back_def = Define ‘ - (** [betree_main::betree::Leaf::{3}::split] *) + (** [betree_main::betree::Leaf::{3}::split]: backward function 2 *) betree_leaf_split_back (self : betree_leaf_t) (content : (u64 # u64) betree_list_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -279,7 +280,7 @@ val betree_leaf_split_back_def = Define ‘ ’ val [betree_node_lookup_in_bindings_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_in_bindings] *) + (** [betree_main::betree::Node::{5}::lookup_in_bindings]: forward function *) betree_node_lookup_in_bindings_fwd (key : u64) (bindings : (u64 # u64) betree_list_t) : u64 option result = (case bindings of @@ -295,7 +296,7 @@ val [betree_node_lookup_in_bindings_fwd_def] = DefineDiv ‘ ’ val [betree_node_lookup_first_message_for_key_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) + (** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: forward function *) betree_node_lookup_first_message_for_key_fwd (key : u64) (msgs : (u64 # betree_message_t) betree_list_t) : (u64 # betree_message_t) betree_list_t result @@ -310,7 +311,7 @@ val [betree_node_lookup_first_message_for_key_fwd_def] = DefineDiv ‘ ’ val [betree_node_lookup_first_message_for_key_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_first_message_for_key] *) + (** [betree_main::betree::Node::{5}::lookup_first_message_for_key]: backward function 0 *) betree_node_lookup_first_message_for_key_back (key : u64) (msgs : (u64 # betree_message_t) betree_list_t) (ret : (u64 # betree_message_t) betree_list_t) : @@ -331,7 +332,7 @@ val [betree_node_lookup_first_message_for_key_back_def] = DefineDiv ‘ ’ val [betree_node_apply_upserts_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::apply_upserts] *) + (** [betree_main::betree::Node::{5}::apply_upserts]: forward function *) betree_node_apply_upserts_fwd (msgs : (u64 # betree_message_t) betree_list_t) (prev : u64 option) (key : u64) (st : state) : @@ -364,7 +365,7 @@ val [betree_node_apply_upserts_fwd_def] = DefineDiv ‘ ’ val [betree_node_apply_upserts_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::apply_upserts] *) + (** [betree_main::betree::Node::{5}::apply_upserts]: backward function 0 *) betree_node_apply_upserts_back (msgs : (u64 # betree_message_t) betree_list_t) (prev : u64 option) (key : u64) (st : state) : @@ -396,7 +397,7 @@ val [betree_node_apply_upserts_back_def] = DefineDiv ‘ ’ val [betree_node_lookup_fwd_def, betree_node_lookup_back_def, betree_internal_lookup_in_children_fwd_def, betree_internal_lookup_in_children_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup] *) + (** [betree_main::betree::Node::{5}::lookup]: forward function *) (betree_node_lookup_fwd (self : betree_node_t) (key : u64) (st : state) : (state # u64 option) result @@ -466,7 +467,7 @@ val [betree_node_lookup_fwd_def, betree_node_lookup_back_def, betree_internal_lo od)) /\ - (** [betree_main::betree::Node::{5}::lookup] *) + (** [betree_main::betree::Node::{5}::lookup]: backward function 0 *) (betree_node_lookup_back (self : betree_node_t) (key : u64) (st : state) : betree_node_t result = (case self of @@ -534,7 +535,7 @@ val [betree_node_lookup_fwd_def, betree_node_lookup_back_def, betree_internal_lo od)) /\ - (** [betree_main::betree::Internal::{4}::lookup_in_children] *) + (** [betree_main::betree::Internal::{4}::lookup_in_children]: forward function *) (betree_internal_lookup_in_children_fwd (self : betree_internal_t) (key : u64) (st : state) : (state # u64 option) result @@ -544,7 +545,7 @@ val [betree_node_lookup_fwd_def, betree_node_lookup_back_def, betree_internal_lo else betree_node_lookup_fwd self.betree_internal_right key st) /\ - (** [betree_main::betree::Internal::{4}::lookup_in_children] *) + (** [betree_main::betree::Internal::{4}::lookup_in_children]: backward function 0 *) betree_internal_lookup_in_children_back (self : betree_internal_t) (key : u64) (st : state) : betree_internal_t result @@ -563,7 +564,7 @@ val [betree_node_lookup_fwd_def, betree_node_lookup_back_def, betree_internal_lo ’ val [betree_node_lookup_mut_in_bindings_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) + (** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: forward function *) betree_node_lookup_mut_in_bindings_fwd (key : u64) (bindings : (u64 # u64) betree_list_t) : (u64 # u64) betree_list_t result @@ -578,7 +579,7 @@ val [betree_node_lookup_mut_in_bindings_fwd_def] = DefineDiv ‘ ’ val [betree_node_lookup_mut_in_bindings_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_mut_in_bindings] *) + (** [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: backward function 0 *) betree_node_lookup_mut_in_bindings_back (key : u64) (bindings : (u64 # u64) betree_list_t) (ret : (u64 # u64) betree_list_t) : @@ -598,7 +599,8 @@ val [betree_node_lookup_mut_in_bindings_back_def] = DefineDiv ‘ ’ val betree_node_apply_to_leaf_fwd_back_def = Define ‘ - (** [betree_main::betree::Node::{5}::apply_to_leaf] *) + (** [betree_main::betree::Node::{5}::apply_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) betree_node_apply_to_leaf_fwd_back (bindings : (u64 # u64) betree_list_t) (key : u64) (new_msg : betree_message_t) : @@ -651,7 +653,8 @@ val betree_node_apply_to_leaf_fwd_back_def = Define ‘ ’ val [betree_node_apply_messages_to_leaf_fwd_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::apply_messages_to_leaf] *) + (** [betree_main::betree::Node::{5}::apply_messages_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) betree_node_apply_messages_to_leaf_fwd_back (bindings : (u64 # u64) betree_list_t) (new_msgs : (u64 # betree_message_t) betree_list_t) : @@ -668,7 +671,8 @@ val [betree_node_apply_messages_to_leaf_fwd_back_def] = DefineDiv ‘ ’ val [betree_node_filter_messages_for_key_fwd_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::filter_messages_for_key] *) + (** [betree_main::betree::Node::{5}::filter_messages_for_key]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) betree_node_filter_messages_for_key_fwd_back (key : u64) (msgs : (u64 # betree_message_t) betree_list_t) : (u64 # betree_message_t) betree_list_t result @@ -687,7 +691,7 @@ val [betree_node_filter_messages_for_key_fwd_back_def] = DefineDiv ‘ ’ val [betree_node_lookup_first_message_after_key_fwd_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) + (** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: forward function *) betree_node_lookup_first_message_after_key_fwd (key : u64) (msgs : (u64 # betree_message_t) betree_list_t) : (u64 # betree_message_t) betree_list_t result @@ -702,7 +706,7 @@ val [betree_node_lookup_first_message_after_key_fwd_def] = DefineDiv ‘ ’ val [betree_node_lookup_first_message_after_key_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::lookup_first_message_after_key] *) + (** [betree_main::betree::Node::{5}::lookup_first_message_after_key]: backward function 0 *) betree_node_lookup_first_message_after_key_back (key : u64) (msgs : (u64 # betree_message_t) betree_list_t) (ret : (u64 # betree_message_t) betree_list_t) : @@ -723,7 +727,8 @@ val [betree_node_lookup_first_message_after_key_back_def] = DefineDiv ‘ ’ val betree_node_apply_to_internal_fwd_back_def = Define ‘ - (** [betree_main::betree::Node::{5}::apply_to_internal] *) + (** [betree_main::betree::Node::{5}::apply_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) betree_node_apply_to_internal_fwd_back (msgs : (u64 # betree_message_t) betree_list_t) (key : u64) (new_msg : betree_message_t) : @@ -789,7 +794,8 @@ val betree_node_apply_to_internal_fwd_back_def = Define ‘ ’ val [betree_node_apply_messages_to_internal_fwd_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::apply_messages_to_internal] *) + (** [betree_main::betree::Node::{5}::apply_messages_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) betree_node_apply_messages_to_internal_fwd_back (msgs : (u64 # betree_message_t) betree_list_t) (new_msgs : (u64 # betree_message_t) betree_list_t) : @@ -806,7 +812,7 @@ val [betree_node_apply_messages_to_internal_fwd_back_def] = DefineDiv ‘ ’ val [betree_node_apply_messages_fwd_def, betree_node_apply_messages_back_def, betree_internal_flush_fwd_def, betree_internal_flush_back_def] = DefineDiv ‘ - (** [betree_main::betree::Node::{5}::apply_messages] *) + (** [betree_main::betree::Node::{5}::apply_messages]: forward function *) (betree_node_apply_messages_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -861,7 +867,7 @@ val [betree_node_apply_messages_fwd_def, betree_node_apply_messages_back_def, be od)) /\ - (** [betree_main::betree::Node::{5}::apply_messages] *) + (** [betree_main::betree::Node::{5}::apply_messages]: backward function 0 *) (betree_node_apply_messages_back (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -918,7 +924,7 @@ val [betree_node_apply_messages_fwd_def, betree_node_apply_messages_back_def, be od)) /\ - (** [betree_main::betree::Internal::{4}::flush] *) + (** [betree_main::betree::Internal::{4}::flush]: forward function *) (betree_internal_flush_fwd (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -967,7 +973,7 @@ val [betree_node_apply_messages_fwd_def, betree_node_apply_messages_back_def, be od) /\ - (** [betree_main::betree::Internal::{4}::flush] *) + (** [betree_main::betree::Internal::{4}::flush]: backward function 0 *) betree_internal_flush_back (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) @@ -1016,7 +1022,7 @@ val [betree_node_apply_messages_fwd_def, betree_node_apply_messages_back_def, be ’ val betree_node_apply_fwd_def = Define ‘ - (** [betree_main::betree::Node::{5}::apply] *) + (** [betree_main::betree::Node::{5}::apply]: forward function *) betree_node_apply_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -1036,7 +1042,7 @@ val betree_node_apply_fwd_def = Define ‘ ’ val betree_node_apply_back_def = Define ‘ - (** [betree_main::betree::Node::{5}::apply] *) + (** [betree_main::betree::Node::{5}::apply]: backward function 0 *) betree_node_apply_back (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : u64) @@ -1049,7 +1055,7 @@ val betree_node_apply_back_def = Define ‘ ’ val betree_be_tree_new_fwd_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::new] *) + (** [betree_main::betree::BeTree::{6}::new]: forward function *) betree_be_tree_new_fwd (min_flush_size : u64) (split_size : u64) (st : state) : (state # betree_be_tree_t) result @@ -1075,7 +1081,7 @@ val betree_be_tree_new_fwd_def = Define ‘ ’ val betree_be_tree_apply_fwd_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::apply] *) + (** [betree_main::betree::BeTree::{6}::apply]: forward function *) betree_be_tree_apply_fwd (self : betree_be_tree_t) (key : u64) (msg : betree_message_t) (st : state) : @@ -1093,7 +1099,7 @@ val betree_be_tree_apply_fwd_def = Define ‘ ’ val betree_be_tree_apply_back_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::apply] *) + (** [betree_main::betree::BeTree::{6}::apply]: backward function 0 *) betree_be_tree_apply_back (self : betree_be_tree_t) (key : u64) (msg : betree_message_t) (st : state) : @@ -1113,7 +1119,7 @@ val betree_be_tree_apply_back_def = Define ‘ ’ val betree_be_tree_insert_fwd_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::insert] *) + (** [betree_main::betree::BeTree::{6}::insert]: forward function *) betree_be_tree_insert_fwd (self : betree_be_tree_t) (key : u64) (value : u64) (st : state) : (state # unit) result @@ -1127,7 +1133,7 @@ val betree_be_tree_insert_fwd_def = Define ‘ ’ val betree_be_tree_insert_back_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::insert] *) + (** [betree_main::betree::BeTree::{6}::insert]: backward function 0 *) betree_be_tree_insert_back (self : betree_be_tree_t) (key : u64) (value : u64) (st : state) : betree_be_tree_t result @@ -1136,7 +1142,7 @@ val betree_be_tree_insert_back_def = Define ‘ ’ val betree_be_tree_delete_fwd_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::delete] *) + (** [betree_main::betree::BeTree::{6}::delete]: forward function *) betree_be_tree_delete_fwd (self : betree_be_tree_t) (key : u64) (st : state) : (state # unit) result @@ -1149,7 +1155,7 @@ val betree_be_tree_delete_fwd_def = Define ‘ ’ val betree_be_tree_delete_back_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::delete] *) + (** [betree_main::betree::BeTree::{6}::delete]: backward function 0 *) betree_be_tree_delete_back (self : betree_be_tree_t) (key : u64) (st : state) : betree_be_tree_t result @@ -1158,7 +1164,7 @@ val betree_be_tree_delete_back_def = Define ‘ ’ val betree_be_tree_upsert_fwd_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::upsert] *) + (** [betree_main::betree::BeTree::{6}::upsert]: forward function *) betree_be_tree_upsert_fwd (self : betree_be_tree_t) (key : u64) (upd : betree_upsert_fun_state_t) (st : state) : @@ -1172,7 +1178,7 @@ val betree_be_tree_upsert_fwd_def = Define ‘ ’ val betree_be_tree_upsert_back_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::upsert] *) + (** [betree_main::betree::BeTree::{6}::upsert]: backward function 0 *) betree_be_tree_upsert_back (self : betree_be_tree_t) (key : u64) (upd : betree_upsert_fun_state_t) (st : state) : @@ -1182,7 +1188,7 @@ val betree_be_tree_upsert_back_def = Define ‘ ’ val betree_be_tree_lookup_fwd_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::lookup] *) + (** [betree_main::betree::BeTree::{6}::lookup]: forward function *) betree_be_tree_lookup_fwd (self : betree_be_tree_t) (key : u64) (st : state) : (state # u64 option) result @@ -1191,7 +1197,7 @@ val betree_be_tree_lookup_fwd_def = Define ‘ ’ val betree_be_tree_lookup_back_def = Define ‘ - (** [betree_main::betree::BeTree::{6}::lookup] *) + (** [betree_main::betree::BeTree::{6}::lookup]: backward function 0 *) betree_be_tree_lookup_back (self : betree_be_tree_t) (key : u64) (st : state) : betree_be_tree_t result @@ -1203,7 +1209,7 @@ val betree_be_tree_lookup_back_def = Define ‘ ’ val main_fwd_def = Define ‘ - (** [betree_main::main] *) + (** [betree_main::main]: forward function *) main_fwd : unit result = Return () ’ diff --git a/tests/hol4/betree/betreeMain_OpaqueScript.sml b/tests/hol4/betree/betreeMain_OpaqueScript.sml index a6f0cf15..1d16db4c 100644 --- a/tests/hol4/betree/betreeMain_OpaqueScript.sml +++ b/tests/hol4/betree/betreeMain_OpaqueScript.sml @@ -1,26 +1,26 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [betree_main]: opaque function definitions *) +(** [betree_main]: external function declarations *) open primitivesLib divDefLib open betreeMain_TypesTheory val _ = new_theory "betreeMain_Opaque" -val _ = new_constant ("betree_utils_load_internal_node_fwd", +(** [betree_main::betree_utils::load_internal_node]: forward function *)val _ = new_constant ("betree_utils_load_internal_node_fwd", “:u64 -> state -> (state # (u64 # betree_message_t) betree_list_t) result”) -val _ = new_constant ("betree_utils_store_internal_node_fwd", +(** [betree_main::betree_utils::store_internal_node]: forward function *)val _ = new_constant ("betree_utils_store_internal_node_fwd", “:u64 -> (u64 # betree_message_t) betree_list_t -> state -> (state # unit) result”) -val _ = new_constant ("betree_utils_load_leaf_node_fwd", +(** [betree_main::betree_utils::load_leaf_node]: forward function *)val _ = new_constant ("betree_utils_load_leaf_node_fwd", “:u64 -> state -> (state # (u64 # u64) betree_list_t) result”) -val _ = new_constant ("betree_utils_store_leaf_node_fwd", +(** [betree_main::betree_utils::store_leaf_node]: forward function *)val _ = new_constant ("betree_utils_store_leaf_node_fwd", “:u64 -> (u64 # u64) betree_list_t -> state -> (state # unit) result”) -val _ = new_constant ("core_option_option_unwrap_fwd", +(** [core::option::Option::{0}::unwrap]: forward function *)val _ = new_constant ("core_option_option_unwrap_fwd", “:'t option -> state -> (state # 't) result”) val _ = export_theory () diff --git a/tests/hol4/hashmap/hashmap_FunsScript.sml b/tests/hol4/hashmap/hashmap_FunsScript.sml index 9ad497f5..1ed57080 100644 --- a/tests/hol4/hashmap/hashmap_FunsScript.sml +++ b/tests/hol4/hashmap/hashmap_FunsScript.sml @@ -7,13 +7,13 @@ val _ = new_theory "hashmap_Funs" val hash_key_fwd_def = Define ‘ - (** [hashmap::hash_key] *) + (** [hashmap::hash_key]: forward function *) hash_key_fwd (k : usize) : usize result = Return k ’ val [hash_map_allocate_slots_loop_fwd_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::allocate_slots] *) + (** [hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function *) hash_map_allocate_slots_loop_fwd (slots : 't list_t vec) (n : usize) : 't list_t vec result = if usize_gt n (int_to_usize 0) @@ -27,14 +27,14 @@ val [hash_map_allocate_slots_loop_fwd_def] = DefineDiv ‘ ’ val hash_map_allocate_slots_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::allocate_slots] *) + (** [hashmap::HashMap::{0}::allocate_slots]: forward function *) hash_map_allocate_slots_fwd (slots : 't list_t vec) (n : usize) : 't list_t vec result = hash_map_allocate_slots_loop_fwd slots n ’ val hash_map_new_with_capacity_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::new_with_capacity] *) + (** [hashmap::HashMap::{0}::new_with_capacity]: forward function *) hash_map_new_with_capacity_fwd (capacity : usize) (max_load_dividend : usize) (max_load_divisor : usize) : 't hash_map_t result @@ -55,14 +55,15 @@ val hash_map_new_with_capacity_fwd_def = Define ‘ ’ val hash_map_new_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::new] *) + (** [hashmap::HashMap::{0}::new]: forward function *) hash_map_new_fwd : 't hash_map_t result = hash_map_new_with_capacity_fwd (int_to_usize 32) (int_to_usize 4) (int_to_usize 5) ’ val [hash_map_clear_loop_fwd_back_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::clear] *) + (** [hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_clear_loop_fwd_back (slots : 't list_t vec) (i : usize) : 't list_t vec result = let i0 = vec_len slots in @@ -77,7 +78,8 @@ val [hash_map_clear_loop_fwd_back_def] = DefineDiv ‘ ’ val hash_map_clear_fwd_back_def = Define ‘ - (** [hashmap::HashMap::{0}::clear] *) + (** [hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_clear_fwd_back (self : 't hash_map_t) : 't hash_map_t result = do v <- hash_map_clear_loop_fwd_back self.hash_map_slots (int_to_usize 0); @@ -91,13 +93,13 @@ val hash_map_clear_fwd_back_def = Define ‘ ’ val hash_map_len_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::len] *) + (** [hashmap::HashMap::{0}::len]: forward function *) hash_map_len_fwd (self : 't hash_map_t) : usize result = Return self.hash_map_num_entries ’ val [hash_map_insert_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function *) hash_map_insert_in_list_loop_fwd (key : usize) (value : 't) (ls : 't list_t) : bool result = (case ls of @@ -109,14 +111,14 @@ val [hash_map_insert_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hash_map_insert_in_list_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap::HashMap::{0}::insert_in_list]: forward function *) hash_map_insert_in_list_fwd (key : usize) (value : 't) (ls : 't list_t) : bool result = hash_map_insert_in_list_loop_fwd key value ls ’ val [hash_map_insert_in_list_loop_back_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 *) hash_map_insert_in_list_loop_back (key : usize) (value : 't) (ls : 't list_t) : 't list_t result = (case ls of @@ -132,14 +134,15 @@ val [hash_map_insert_in_list_loop_back_def] = DefineDiv ‘ ’ val hash_map_insert_in_list_back_def = Define ‘ - (** [hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap::HashMap::{0}::insert_in_list]: backward function 0 *) hash_map_insert_in_list_back (key : usize) (value : 't) (ls : 't list_t) : 't list_t result = hash_map_insert_in_list_loop_back key value ls ’ val hash_map_insert_no_resize_fwd_back_def = Define ‘ - (** [hashmap::HashMap::{0}::insert_no_resize] *) + (** [hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_insert_no_resize_fwd_back (self : 't hash_map_t) (key : usize) (value : 't) : 't hash_map_t result = do @@ -176,7 +179,8 @@ Definition core_num_u32_max_c_def: End val [hash_map_move_elements_from_list_loop_fwd_back_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::move_elements_from_list] *) + (** [hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_move_elements_from_list_loop_fwd_back (ntable : 't hash_map_t) (ls : 't list_t) : 't hash_map_t result = (case ls of @@ -189,14 +193,16 @@ val [hash_map_move_elements_from_list_loop_fwd_back_def] = DefineDiv ‘ ’ val hash_map_move_elements_from_list_fwd_back_def = Define ‘ - (** [hashmap::HashMap::{0}::move_elements_from_list] *) + (** [hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_move_elements_from_list_fwd_back (ntable : 't hash_map_t) (ls : 't list_t) : 't hash_map_t result = hash_map_move_elements_from_list_loop_fwd_back ntable ls ’ val [hash_map_move_elements_loop_fwd_back_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::move_elements] *) + (** [hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_move_elements_loop_fwd_back (ntable : 't hash_map_t) (slots : 't list_t vec) (i : usize) : ('t hash_map_t # 't list_t vec) result @@ -221,7 +227,8 @@ val [hash_map_move_elements_loop_fwd_back_def] = DefineDiv ‘ ’ val hash_map_move_elements_fwd_back_def = Define ‘ - (** [hashmap::HashMap::{0}::move_elements] *) + (** [hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_move_elements_fwd_back (ntable : 't hash_map_t) (slots : 't list_t vec) (i : usize) : ('t hash_map_t # 't list_t vec) result @@ -230,7 +237,8 @@ val hash_map_move_elements_fwd_back_def = Define ‘ ’ val hash_map_try_resize_fwd_back_def = Define ‘ - (** [hashmap::HashMap::{0}::try_resize] *) + (** [hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_try_resize_fwd_back (self : 't hash_map_t) : 't hash_map_t result = do max_usize <- mk_usize (u32_to_int core_num_u32_max_c); @@ -263,7 +271,8 @@ val hash_map_try_resize_fwd_back_def = Define ‘ ’ val hash_map_insert_fwd_back_def = Define ‘ - (** [hashmap::HashMap::{0}::insert] *) + (** [hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hash_map_insert_fwd_back (self : 't hash_map_t) (key : usize) (value : 't) : 't hash_map_t result = do @@ -276,7 +285,7 @@ val hash_map_insert_fwd_back_def = Define ‘ ’ val [hash_map_contains_key_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::contains_key_in_list] *) + (** [hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function *) hash_map_contains_key_in_list_loop_fwd (key : usize) (ls : 't list_t) : bool result = (case ls of @@ -288,14 +297,14 @@ val [hash_map_contains_key_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hash_map_contains_key_in_list_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::contains_key_in_list] *) + (** [hashmap::HashMap::{0}::contains_key_in_list]: forward function *) hash_map_contains_key_in_list_fwd (key : usize) (ls : 't list_t) : bool result = hash_map_contains_key_in_list_loop_fwd key ls ’ val hash_map_contains_key_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::contains_key] *) + (** [hashmap::HashMap::{0}::contains_key]: forward function *) hash_map_contains_key_fwd (self : 't hash_map_t) (key : usize) : bool result = do @@ -310,7 +319,7 @@ val hash_map_contains_key_fwd_def = Define ‘ ’ val [hash_map_get_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::get_in_list] *) + (** [hashmap::HashMap::{0}::get_in_list]: loop 0: forward function *) hash_map_get_in_list_loop_fwd (key : usize) (ls : 't list_t) : 't result = (case ls of | ListCons ckey cvalue tl => @@ -321,13 +330,13 @@ val [hash_map_get_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hash_map_get_in_list_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::get_in_list] *) + (** [hashmap::HashMap::{0}::get_in_list]: forward function *) hash_map_get_in_list_fwd (key : usize) (ls : 't list_t) : 't result = hash_map_get_in_list_loop_fwd key ls ’ val hash_map_get_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::get] *) + (** [hashmap::HashMap::{0}::get]: forward function *) hash_map_get_fwd (self : 't hash_map_t) (key : usize) : 't result = do hash <- hash_key_fwd key; @@ -341,7 +350,7 @@ val hash_map_get_fwd_def = Define ‘ ’ val [hash_map_get_mut_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function *) hash_map_get_mut_in_list_loop_fwd (ls : 't list_t) (key : usize) : 't result = (case ls of @@ -353,13 +362,13 @@ val [hash_map_get_mut_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hash_map_get_mut_in_list_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap::HashMap::{0}::get_mut_in_list]: forward function *) hash_map_get_mut_in_list_fwd (ls : 't list_t) (key : usize) : 't result = hash_map_get_mut_in_list_loop_fwd ls key ’ val [hash_map_get_mut_in_list_loop_back_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 *) hash_map_get_mut_in_list_loop_back (ls : 't list_t) (key : usize) (ret : 't) : 't list_t result = (case ls of @@ -375,14 +384,14 @@ val [hash_map_get_mut_in_list_loop_back_def] = DefineDiv ‘ ’ val hash_map_get_mut_in_list_back_def = Define ‘ - (** [hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 *) hash_map_get_mut_in_list_back (ls : 't list_t) (key : usize) (ret : 't) : 't list_t result = hash_map_get_mut_in_list_loop_back ls key ret ’ val hash_map_get_mut_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::get_mut] *) + (** [hashmap::HashMap::{0}::get_mut]: forward function *) hash_map_get_mut_fwd (self : 't hash_map_t) (key : usize) : 't result = do hash <- hash_key_fwd key; @@ -396,7 +405,7 @@ val hash_map_get_mut_fwd_def = Define ‘ ’ val hash_map_get_mut_back_def = Define ‘ - (** [hashmap::HashMap::{0}::get_mut] *) + (** [hashmap::HashMap::{0}::get_mut]: backward function 0 *) hash_map_get_mut_back (self : 't hash_map_t) (key : usize) (ret : 't) : 't hash_map_t result = do @@ -413,7 +422,7 @@ val hash_map_get_mut_back_def = Define ‘ ’ val [hash_map_remove_from_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function *) hash_map_remove_from_list_loop_fwd (key : usize) (ls : 't list_t) : 't option result = (case ls of @@ -429,14 +438,14 @@ val [hash_map_remove_from_list_loop_fwd_def] = DefineDiv ‘ ’ val hash_map_remove_from_list_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap::HashMap::{0}::remove_from_list]: forward function *) hash_map_remove_from_list_fwd (key : usize) (ls : 't list_t) : 't option result = hash_map_remove_from_list_loop_fwd key ls ’ val [hash_map_remove_from_list_loop_back_def] = DefineDiv ‘ - (** [hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 *) hash_map_remove_from_list_loop_back (key : usize) (ls : 't list_t) : 't list_t result = (case ls of @@ -456,14 +465,14 @@ val [hash_map_remove_from_list_loop_back_def] = DefineDiv ‘ ’ val hash_map_remove_from_list_back_def = Define ‘ - (** [hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap::HashMap::{0}::remove_from_list]: backward function 1 *) hash_map_remove_from_list_back (key : usize) (ls : 't list_t) : 't list_t result = hash_map_remove_from_list_loop_back key ls ’ val hash_map_remove_fwd_def = Define ‘ - (** [hashmap::HashMap::{0}::remove] *) + (** [hashmap::HashMap::{0}::remove]: forward function *) hash_map_remove_fwd (self : 't hash_map_t) (key : usize) : 't option result = do hash <- hash_key_fwd key; @@ -484,7 +493,7 @@ val hash_map_remove_fwd_def = Define ‘ ’ val hash_map_remove_back_def = Define ‘ - (** [hashmap::HashMap::{0}::remove] *) + (** [hashmap::HashMap::{0}::remove]: backward function 0 *) hash_map_remove_back (self : 't hash_map_t) (key : usize) : 't hash_map_t result = do @@ -513,7 +522,7 @@ val hash_map_remove_back_def = Define ‘ ’ val test1_fwd_def = Define ‘ - (** [hashmap::test1] *) + (** [hashmap::test1]: forward function *) test1_fwd : unit result = do hm <- hash_map_new_fwd; diff --git a/tests/hol4/hashmap_on_disk/hashmapMain_FunsScript.sml b/tests/hol4/hashmap_on_disk/hashmapMain_FunsScript.sml index 5a8f7ff8..6ec6223d 100644 --- a/tests/hol4/hashmap_on_disk/hashmapMain_FunsScript.sml +++ b/tests/hol4/hashmap_on_disk/hashmapMain_FunsScript.sml @@ -7,13 +7,13 @@ val _ = new_theory "hashmapMain_Funs" val hashmap_hash_key_fwd_def = Define ‘ - (** [hashmap_main::hashmap::hash_key] *) + (** [hashmap_main::hashmap::hash_key]: forward function *) hashmap_hash_key_fwd (k : usize) : usize result = Return k ’ val [hashmap_hash_map_allocate_slots_loop_fwd_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::allocate_slots] *) + (** [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function *) hashmap_hash_map_allocate_slots_loop_fwd (slots : 't hashmap_list_t vec) (n : usize) : 't hashmap_list_t vec result @@ -29,7 +29,7 @@ val [hashmap_hash_map_allocate_slots_loop_fwd_def] = DefineDiv ‘ ’ val hashmap_hash_map_allocate_slots_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::allocate_slots] *) + (** [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: forward function *) hashmap_hash_map_allocate_slots_fwd (slots : 't hashmap_list_t vec) (n : usize) : 't hashmap_list_t vec result @@ -38,7 +38,7 @@ val hashmap_hash_map_allocate_slots_fwd_def = Define ‘ ’ val hashmap_hash_map_new_with_capacity_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::new_with_capacity] *) + (** [hashmap_main::hashmap::HashMap::{0}::new_with_capacity]: forward function *) hashmap_hash_map_new_with_capacity_fwd (capacity : usize) (max_load_dividend : usize) (max_load_divisor : usize) : 't hashmap_hash_map_t result @@ -60,14 +60,15 @@ val hashmap_hash_map_new_with_capacity_fwd_def = Define ‘ ’ val hashmap_hash_map_new_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::new] *) + (** [hashmap_main::hashmap::HashMap::{0}::new]: forward function *) hashmap_hash_map_new_fwd : 't hashmap_hash_map_t result = hashmap_hash_map_new_with_capacity_fwd (int_to_usize 32) (int_to_usize 4) (int_to_usize 5) ’ val [hashmap_hash_map_clear_loop_fwd_back_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::clear] *) + (** [hashmap_main::hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_clear_loop_fwd_back (slots : 't hashmap_list_t vec) (i : usize) : 't hashmap_list_t vec result @@ -84,7 +85,8 @@ val [hashmap_hash_map_clear_loop_fwd_back_def] = DefineDiv ‘ ’ val hashmap_hash_map_clear_fwd_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::clear] *) + (** [hashmap_main::hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_clear_fwd_back (self : 't hashmap_hash_map_t) : 't hashmap_hash_map_t result = do @@ -102,13 +104,13 @@ val hashmap_hash_map_clear_fwd_back_def = Define ‘ ’ val hashmap_hash_map_len_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::len] *) + (** [hashmap_main::hashmap::HashMap::{0}::len]: forward function *) hashmap_hash_map_len_fwd (self : 't hashmap_hash_map_t) : usize result = Return self.hashmap_hash_map_num_entries ’ val [hashmap_hash_map_insert_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function *) hashmap_hash_map_insert_in_list_loop_fwd (key : usize) (value : 't) (ls : 't hashmap_list_t) : bool result = (case ls of @@ -120,14 +122,14 @@ val [hashmap_hash_map_insert_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hashmap_hash_map_insert_in_list_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: forward function *) hashmap_hash_map_insert_in_list_fwd (key : usize) (value : 't) (ls : 't hashmap_list_t) : bool result = hashmap_hash_map_insert_in_list_loop_fwd key value ls ’ val [hashmap_hash_map_insert_in_list_loop_back_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 *) hashmap_hash_map_insert_in_list_loop_back (key : usize) (value : 't) (ls : 't hashmap_list_t) : 't hashmap_list_t result @@ -146,7 +148,7 @@ val [hashmap_hash_map_insert_in_list_loop_back_def] = DefineDiv ‘ ’ val hashmap_hash_map_insert_in_list_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: backward function 0 *) hashmap_hash_map_insert_in_list_back (key : usize) (value : 't) (ls : 't hashmap_list_t) : 't hashmap_list_t result @@ -155,7 +157,8 @@ val hashmap_hash_map_insert_in_list_back_def = Define ‘ ’ val hashmap_hash_map_insert_no_resize_fwd_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::insert_no_resize] *) + (** [hashmap_main::hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_insert_no_resize_fwd_back (self : 't hashmap_hash_map_t) (key : usize) (value : 't) : 't hashmap_hash_map_t result @@ -199,7 +202,8 @@ Definition core_num_u32_max_c_def: End val [hashmap_hash_map_move_elements_from_list_loop_fwd_back_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_move_elements_from_list_loop_fwd_back (ntable : 't hashmap_hash_map_t) (ls : 't hashmap_list_t) : 't hashmap_hash_map_t result @@ -214,7 +218,8 @@ val [hashmap_hash_map_move_elements_from_list_loop_fwd_back_def] = DefineDiv ‘ ’ val hashmap_hash_map_move_elements_from_list_fwd_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_move_elements_from_list_fwd_back (ntable : 't hashmap_hash_map_t) (ls : 't hashmap_list_t) : 't hashmap_hash_map_t result @@ -223,7 +228,8 @@ val hashmap_hash_map_move_elements_from_list_fwd_back_def = Define ‘ ’ val [hashmap_hash_map_move_elements_loop_fwd_back_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::move_elements] *) + (** [hashmap_main::hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_move_elements_loop_fwd_back (ntable : 't hashmap_hash_map_t) (slots : 't hashmap_list_t vec) (i : usize) : @@ -249,7 +255,8 @@ val [hashmap_hash_map_move_elements_loop_fwd_back_def] = DefineDiv ‘ ’ val hashmap_hash_map_move_elements_fwd_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::move_elements] *) + (** [hashmap_main::hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_move_elements_fwd_back (ntable : 't hashmap_hash_map_t) (slots : 't hashmap_list_t vec) (i : usize) : @@ -259,7 +266,8 @@ val hashmap_hash_map_move_elements_fwd_back_def = Define ‘ ’ val hashmap_hash_map_try_resize_fwd_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::try_resize] *) + (** [hashmap_main::hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_try_resize_fwd_back (self : 't hashmap_hash_map_t) : 't hashmap_hash_map_t result = do @@ -293,7 +301,8 @@ val hashmap_hash_map_try_resize_fwd_back_def = Define ‘ ’ val hashmap_hash_map_insert_fwd_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::insert] *) + (** [hashmap_main::hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) hashmap_hash_map_insert_fwd_back (self : 't hashmap_hash_map_t) (key : usize) (value : 't) : 't hashmap_hash_map_t result @@ -308,7 +317,7 @@ val hashmap_hash_map_insert_fwd_back_def = Define ‘ ’ val [hashmap_hash_map_contains_key_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function *) hashmap_hash_map_contains_key_in_list_loop_fwd (key : usize) (ls : 't hashmap_list_t) : bool result = (case ls of @@ -320,14 +329,14 @@ val [hashmap_hash_map_contains_key_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hashmap_hash_map_contains_key_in_list_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: forward function *) hashmap_hash_map_contains_key_in_list_fwd (key : usize) (ls : 't hashmap_list_t) : bool result = hashmap_hash_map_contains_key_in_list_loop_fwd key ls ’ val hashmap_hash_map_contains_key_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::contains_key] *) + (** [hashmap_main::hashmap::HashMap::{0}::contains_key]: forward function *) hashmap_hash_map_contains_key_fwd (self : 't hashmap_hash_map_t) (key : usize) : bool result = do @@ -342,7 +351,7 @@ val hashmap_hash_map_contains_key_fwd_def = Define ‘ ’ val [hashmap_hash_map_get_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_in_list]: loop 0: forward function *) hashmap_hash_map_get_in_list_loop_fwd (key : usize) (ls : 't hashmap_list_t) : 't result = (case ls of @@ -354,14 +363,14 @@ val [hashmap_hash_map_get_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hashmap_hash_map_get_in_list_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_in_list]: forward function *) hashmap_hash_map_get_in_list_fwd (key : usize) (ls : 't hashmap_list_t) : 't result = hashmap_hash_map_get_in_list_loop_fwd key ls ’ val hashmap_hash_map_get_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get] *) + (** [hashmap_main::hashmap::HashMap::{0}::get]: forward function *) hashmap_hash_map_get_fwd (self : 't hashmap_hash_map_t) (key : usize) : 't result = do @@ -376,7 +385,7 @@ val hashmap_hash_map_get_fwd_def = Define ‘ ’ val [hashmap_hash_map_get_mut_in_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function *) hashmap_hash_map_get_mut_in_list_loop_fwd (ls : 't hashmap_list_t) (key : usize) : 't result = (case ls of @@ -388,14 +397,14 @@ val [hashmap_hash_map_get_mut_in_list_loop_fwd_def] = DefineDiv ‘ ’ val hashmap_hash_map_get_mut_in_list_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: forward function *) hashmap_hash_map_get_mut_in_list_fwd (ls : 't hashmap_list_t) (key : usize) : 't result = hashmap_hash_map_get_mut_in_list_loop_fwd ls key ’ val [hashmap_hash_map_get_mut_in_list_loop_back_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 *) hashmap_hash_map_get_mut_in_list_loop_back (ls : 't hashmap_list_t) (key : usize) (ret : 't) : 't hashmap_list_t result @@ -413,7 +422,7 @@ val [hashmap_hash_map_get_mut_in_list_loop_back_def] = DefineDiv ‘ ’ val hashmap_hash_map_get_mut_in_list_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 *) hashmap_hash_map_get_mut_in_list_back (ls : 't hashmap_list_t) (key : usize) (ret : 't) : 't hashmap_list_t result @@ -422,7 +431,7 @@ val hashmap_hash_map_get_mut_in_list_back_def = Define ‘ ’ val hashmap_hash_map_get_mut_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_mut] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_mut]: forward function *) hashmap_hash_map_get_mut_fwd (self : 't hashmap_hash_map_t) (key : usize) : 't result = do @@ -437,7 +446,7 @@ val hashmap_hash_map_get_mut_fwd_def = Define ‘ ’ val hashmap_hash_map_get_mut_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::get_mut] *) + (** [hashmap_main::hashmap::HashMap::{0}::get_mut]: backward function 0 *) hashmap_hash_map_get_mut_back (self : 't hashmap_hash_map_t) (key : usize) (ret : 't) : 't hashmap_hash_map_t result @@ -456,7 +465,7 @@ val hashmap_hash_map_get_mut_back_def = Define ‘ ’ val [hashmap_hash_map_remove_from_list_loop_fwd_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function *) hashmap_hash_map_remove_from_list_loop_fwd (key : usize) (ls : 't hashmap_list_t) : 't option result = (case ls of @@ -473,14 +482,14 @@ val [hashmap_hash_map_remove_from_list_loop_fwd_def] = DefineDiv ‘ ’ val hashmap_hash_map_remove_from_list_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: forward function *) hashmap_hash_map_remove_from_list_fwd (key : usize) (ls : 't hashmap_list_t) : 't option result = hashmap_hash_map_remove_from_list_loop_fwd key ls ’ val [hashmap_hash_map_remove_from_list_loop_back_def] = DefineDiv ‘ - (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 *) hashmap_hash_map_remove_from_list_loop_back (key : usize) (ls : 't hashmap_list_t) : 't hashmap_list_t result = (case ls of @@ -501,14 +510,14 @@ val [hashmap_hash_map_remove_from_list_loop_back_def] = DefineDiv ‘ ’ val hashmap_hash_map_remove_from_list_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list] *) + (** [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: backward function 1 *) hashmap_hash_map_remove_from_list_back (key : usize) (ls : 't hashmap_list_t) : 't hashmap_list_t result = hashmap_hash_map_remove_from_list_loop_back key ls ’ val hashmap_hash_map_remove_fwd_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::remove] *) + (** [hashmap_main::hashmap::HashMap::{0}::remove]: forward function *) hashmap_hash_map_remove_fwd (self : 't hashmap_hash_map_t) (key : usize) : 't option result = do @@ -530,7 +539,7 @@ val hashmap_hash_map_remove_fwd_def = Define ‘ ’ val hashmap_hash_map_remove_back_def = Define ‘ - (** [hashmap_main::hashmap::HashMap::{0}::remove] *) + (** [hashmap_main::hashmap::HashMap::{0}::remove]: backward function 0 *) hashmap_hash_map_remove_back (self : 't hashmap_hash_map_t) (key : usize) : 't hashmap_hash_map_t result @@ -566,7 +575,7 @@ val hashmap_hash_map_remove_back_def = Define ‘ ’ val hashmap_test1_fwd_def = Define ‘ - (** [hashmap_main::hashmap::test1] *) + (** [hashmap_main::hashmap::test1]: forward function *) hashmap_test1_fwd : unit result = do hm <- hashmap_hash_map_new_fwd; @@ -623,7 +632,7 @@ val hashmap_test1_fwd_def = Define ‘ val _ = assert_return (“hashmap_test1_fwd”) val insert_on_disk_fwd_def = Define ‘ - (** [hashmap_main::insert_on_disk] *) + (** [hashmap_main::insert_on_disk]: forward function *) insert_on_disk_fwd (key : usize) (value : u64) (st : state) : (state # unit) result = do @@ -635,7 +644,7 @@ val insert_on_disk_fwd_def = Define ‘ ’ val main_fwd_def = Define ‘ - (** [hashmap_main::main] *) + (** [hashmap_main::main]: forward function *) main_fwd : unit result = Return () ’ diff --git a/tests/hol4/hashmap_on_disk/hashmapMain_OpaqueScript.sml b/tests/hol4/hashmap_on_disk/hashmapMain_OpaqueScript.sml index 5f6bcbb4..f7221d92 100644 --- a/tests/hol4/hashmap_on_disk/hashmapMain_OpaqueScript.sml +++ b/tests/hol4/hashmap_on_disk/hashmapMain_OpaqueScript.sml @@ -1,15 +1,15 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [hashmap_main]: opaque function definitions *) +(** [hashmap_main]: external function declarations *) open primitivesLib divDefLib open hashmapMain_TypesTheory val _ = new_theory "hashmapMain_Opaque" -val _ = new_constant ("hashmap_utils_deserialize_fwd", +(** [hashmap_main::hashmap_utils::deserialize]: forward function *)val _ = new_constant ("hashmap_utils_deserialize_fwd", “:state -> (state # u64 hashmap_hash_map_t) result”) -val _ = new_constant ("hashmap_utils_serialize_fwd", +(** [hashmap_main::hashmap_utils::serialize]: forward function *)val _ = new_constant ("hashmap_utils_serialize_fwd", “:u64 hashmap_hash_map_t -> state -> (state # unit) result”) val _ = export_theory () diff --git a/tests/hol4/misc-constants/constantsScript.sml b/tests/hol4/misc-constants/constantsScript.sml index 324d553d..145c3e0f 100644 --- a/tests/hol4/misc-constants/constantsScript.sml +++ b/tests/hol4/misc-constants/constantsScript.sml @@ -38,7 +38,7 @@ Definition x2_c_def: End val incr_fwd_def = Define ‘ - (** [constants::incr] *) + (** [constants::incr]: forward function *) incr_fwd (n : u32) : u32 result = u32_add n (int_to_u32 1) ’ @@ -52,7 +52,7 @@ Definition x3_c_def: End val mk_pair0_fwd_def = Define ‘ - (** [constants::mk_pair0] *) + (** [constants::mk_pair0]: forward function *) mk_pair0_fwd (x : u32) (y : u32) : (u32 # u32) result = Return (x, y) ’ @@ -63,7 +63,7 @@ Datatype: End val mk_pair1_fwd_def = Define ‘ - (** [constants::mk_pair1] *) + (** [constants::mk_pair1]: forward function *) mk_pair1_fwd (x : u32) (y : u32) : (u32, u32) pair_t result = Return (<| pair_x := x; pair_y := y |>) ’ @@ -108,7 +108,7 @@ Datatype: End val wrap_new_fwd_def = Define ‘ - (** [constants::Wrap::{0}::new] *) + (** [constants::Wrap::{0}::new]: forward function *) wrap_new_fwd (val : 't) : 't wrap_t result = Return (<| wrap_val := val |>) ’ @@ -122,7 +122,7 @@ Definition y_c_def: End val unwrap_y_fwd_def = Define ‘ - (** [constants::unwrap_y] *) + (** [constants::unwrap_y]: forward function *) unwrap_y_fwd : i32 result = Return y_c.wrap_val ’ @@ -144,13 +144,13 @@ Definition get_z1_z1_c_def: End val get_z1_fwd_def = Define ‘ - (** [constants::get_z1] *) + (** [constants::get_z1]: forward function *) get_z1_fwd : i32 result = Return get_z1_z1_c ’ val add_fwd_def = Define ‘ - (** [constants::add] *) + (** [constants::add]: forward function *) add_fwd (a : i32) (b : i32) : i32 result = i32_add a b ’ @@ -180,7 +180,7 @@ Definition q3_c_def: End val get_z2_fwd_def = Define ‘ - (** [constants::get_z2] *) + (** [constants::get_z2]: forward function *) get_z2_fwd : i32 result = do i <- get_z1_fwd; diff --git a/tests/hol4/misc-external/external_FunsScript.sml b/tests/hol4/misc-external/external_FunsScript.sml index 8172bc1c..f3692ee2 100644 --- a/tests/hol4/misc-external/external_FunsScript.sml +++ b/tests/hol4/misc-external/external_FunsScript.sml @@ -7,7 +7,7 @@ val _ = new_theory "external_Funs" val swap_fwd_def = Define ‘ - (** [external::swap] *) + (** [external::swap]: forward function *) swap_fwd (x : 't) (y : 't) (st : state) : (state # unit) result = do (st0, _) <- core_mem_swap_fwd x y st; @@ -18,7 +18,7 @@ val swap_fwd_def = Define ‘ ’ val swap_back_def = Define ‘ - (** [external::swap] *) + (** [external::swap]: backward function 0 *) swap_back (x : 't) (y : 't) (st : state) (st0 : state) : (state # ('t # 't)) result = do @@ -30,7 +30,7 @@ val swap_back_def = Define ‘ ’ val test_new_non_zero_u32_fwd_def = Define ‘ - (** [external::test_new_non_zero_u32] *) + (** [external::test_new_non_zero_u32]: forward function *) test_new_non_zero_u32_fwd (x : u32) (st : state) : (state # core_num_nonzero_non_zero_u32_t) result = do @@ -40,7 +40,7 @@ val test_new_non_zero_u32_fwd_def = Define ‘ ’ val test_vec_fwd_def = Define ‘ - (** [external::test_vec] *) + (** [external::test_vec]: forward function *) test_vec_fwd : unit result = let v = vec_new in do _ <- vec_push_back v (int_to_u32 0); @@ -52,7 +52,7 @@ val test_vec_fwd_def = Define ‘ val _ = assert_return (“test_vec_fwd”) val custom_swap_fwd_def = Define ‘ - (** [external::custom_swap] *) + (** [external::custom_swap]: forward function *) custom_swap_fwd (x : 't) (y : 't) (st : state) : (state # 't) result = do (st0, _) <- core_mem_swap_fwd x y st; @@ -63,7 +63,7 @@ val custom_swap_fwd_def = Define ‘ ’ val custom_swap_back_def = Define ‘ - (** [external::custom_swap] *) + (** [external::custom_swap]: backward function 0 *) custom_swap_back (x : 't) (y : 't) (st : state) (ret : 't) (st0 : state) : (state # ('t # 't)) result @@ -77,7 +77,7 @@ val custom_swap_back_def = Define ‘ ’ val test_custom_swap_fwd_def = Define ‘ - (** [external::test_custom_swap] *) + (** [external::test_custom_swap]: forward function *) test_custom_swap_fwd (x : u32) (y : u32) (st : state) : (state # unit) result = do @@ -87,7 +87,7 @@ val test_custom_swap_fwd_def = Define ‘ ’ val test_custom_swap_back_def = Define ‘ - (** [external::test_custom_swap] *) + (** [external::test_custom_swap]: backward function 0 *) test_custom_swap_back (x : u32) (y : u32) (st : state) (st0 : state) : (state # (u32 # u32)) result @@ -96,7 +96,7 @@ val test_custom_swap_back_def = Define ‘ ’ val test_swap_non_zero_fwd_def = Define ‘ - (** [external::test_swap_non_zero] *) + (** [external::test_swap_non_zero]: forward function *) test_swap_non_zero_fwd (x : u32) (st : state) : (state # u32) result = do (st0, _) <- swap_fwd x (int_to_u32 0) st; diff --git a/tests/hol4/misc-external/external_OpaqueScript.sml b/tests/hol4/misc-external/external_OpaqueScript.sml index e2fd281d..b5a6d91d 100644 --- a/tests/hol4/misc-external/external_OpaqueScript.sml +++ b/tests/hol4/misc-external/external_OpaqueScript.sml @@ -1,25 +1,25 @@ (** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *) -(** [external]: opaque function definitions *) +(** [external]: external function declarations *) open primitivesLib divDefLib open external_TypesTheory val _ = new_theory "external_Opaque" -val _ = new_constant ("core_mem_swap_fwd", +(** [core::mem::swap]: forward function *)val _ = new_constant ("core_mem_swap_fwd", “:'t -> 't -> state -> (state # unit) result”) -val _ = new_constant ("core_mem_swap_back0", +(** [core::mem::swap]: backward function 0 *)val _ = new_constant ("core_mem_swap_back0", “:'t -> 't -> state -> state -> (state # 't) result”) -val _ = new_constant ("core_mem_swap_back1", +(** [core::mem::swap]: backward function 1 *)val _ = new_constant ("core_mem_swap_back1", “:'t -> 't -> state -> state -> (state # 't) result”) -val _ = new_constant ("core_num_nonzero_non_zero_u32_new_fwd", +(** [core::num::nonzero::NonZeroU32::{14}::new]: forward function *)val _ = new_constant ("core_num_nonzero_non_zero_u32_new_fwd", “:u32 -> state -> (state # core_num_nonzero_non_zero_u32_t option) result”) -val _ = new_constant ("core_option_option_unwrap_fwd", +(** [core::option::Option::{0}::unwrap]: forward function *)val _ = new_constant ("core_option_option_unwrap_fwd", “:'t option -> state -> (state # 't) result”) val _ = export_theory () diff --git a/tests/hol4/misc-loops/loops_FunsScript.sml b/tests/hol4/misc-loops/loops_FunsScript.sml index f0ef036b..65cf77d4 100644 --- a/tests/hol4/misc-loops/loops_FunsScript.sml +++ b/tests/hol4/misc-loops/loops_FunsScript.sml @@ -7,7 +7,7 @@ val _ = new_theory "loops_Funs" val [sum_loop_fwd_def] = DefineDiv ‘ - (** [loops::sum] *) + (** [loops::sum]: loop 0: forward function *) sum_loop_fwd (max : u32) (i : u32) (s : u32) : u32 result = if u32_lt i max then ( @@ -20,13 +20,13 @@ val [sum_loop_fwd_def] = DefineDiv ‘ ’ val sum_fwd_def = Define ‘ - (** [loops::sum] *) + (** [loops::sum]: forward function *) sum_fwd (max : u32) : u32 result = sum_loop_fwd max (int_to_u32 0) (int_to_u32 0) ’ val [sum_with_mut_borrows_loop_fwd_def] = DefineDiv ‘ - (** [loops::sum_with_mut_borrows] *) + (** [loops::sum_with_mut_borrows]: loop 0: forward function *) sum_with_mut_borrows_loop_fwd (max : u32) (mi : u32) (ms : u32) : u32 result = if u32_lt mi max @@ -40,13 +40,13 @@ val [sum_with_mut_borrows_loop_fwd_def] = DefineDiv ‘ ’ val sum_with_mut_borrows_fwd_def = Define ‘ - (** [loops::sum_with_mut_borrows] *) + (** [loops::sum_with_mut_borrows]: forward function *) sum_with_mut_borrows_fwd (max : u32) : u32 result = sum_with_mut_borrows_loop_fwd max (int_to_u32 0) (int_to_u32 0) ’ val [sum_with_shared_borrows_loop_fwd_def] = DefineDiv ‘ - (** [loops::sum_with_shared_borrows] *) + (** [loops::sum_with_shared_borrows]: loop 0: forward function *) sum_with_shared_borrows_loop_fwd (max : u32) (i : u32) (s : u32) : u32 result = if u32_lt i max @@ -60,13 +60,14 @@ val [sum_with_shared_borrows_loop_fwd_def] = DefineDiv ‘ ’ val sum_with_shared_borrows_fwd_def = Define ‘ - (** [loops::sum_with_shared_borrows] *) + (** [loops::sum_with_shared_borrows]: forward function *) sum_with_shared_borrows_fwd (max : u32) : u32 result = sum_with_shared_borrows_loop_fwd max (int_to_u32 0) (int_to_u32 0) ’ val [clear_loop_fwd_back_def] = DefineDiv ‘ - (** [loops::clear] *) + (** [loops::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) clear_loop_fwd_back (v : u32 vec) (i : usize) : u32 vec result = let i0 = vec_len v in if usize_lt i i0 @@ -80,13 +81,14 @@ val [clear_loop_fwd_back_def] = DefineDiv ‘ ’ val clear_fwd_back_def = Define ‘ - (** [loops::clear] *) + (** [loops::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) clear_fwd_back (v : u32 vec) : u32 vec result = clear_loop_fwd_back v (int_to_usize 0) ’ val [list_mem_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_mem] *) + (** [loops::list_mem]: loop 0: forward function *) list_mem_loop_fwd (x : u32) (ls : u32 list_t) : bool result = (case ls of | ListCons y tl => if y = x then Return T else list_mem_loop_fwd x tl @@ -94,13 +96,13 @@ val [list_mem_loop_fwd_def] = DefineDiv ‘ ’ val list_mem_fwd_def = Define ‘ - (** [loops::list_mem] *) + (** [loops::list_mem]: forward function *) list_mem_fwd (x : u32) (ls : u32 list_t) : bool result = list_mem_loop_fwd x ls ’ val [list_nth_mut_loop_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop] *) + (** [loops::list_nth_mut_loop]: loop 0: forward function *) list_nth_mut_loop_loop_fwd (ls : 't list_t) (i : u32) : 't result = (case ls of | ListCons x tl => @@ -115,13 +117,13 @@ val [list_nth_mut_loop_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_mut_loop_fwd_def = Define ‘ - (** [loops::list_nth_mut_loop] *) + (** [loops::list_nth_mut_loop]: forward function *) list_nth_mut_loop_fwd (ls : 't list_t) (i : u32) : 't result = list_nth_mut_loop_loop_fwd ls i ’ val [list_nth_mut_loop_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop] *) + (** [loops::list_nth_mut_loop]: loop 0: backward function 0 *) list_nth_mut_loop_loop_back (ls : 't list_t) (i : u32) (ret : 't) : 't list_t result = (case ls of @@ -138,14 +140,14 @@ val [list_nth_mut_loop_loop_back_def] = DefineDiv ‘ ’ val list_nth_mut_loop_back_def = Define ‘ - (** [loops::list_nth_mut_loop] *) + (** [loops::list_nth_mut_loop]: backward function 0 *) list_nth_mut_loop_back (ls : 't list_t) (i : u32) (ret : 't) : 't list_t result = list_nth_mut_loop_loop_back ls i ret ’ val [list_nth_shared_loop_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_shared_loop] *) + (** [loops::list_nth_shared_loop]: loop 0: forward function *) list_nth_shared_loop_loop_fwd (ls : 't list_t) (i : u32) : 't result = (case ls of | ListCons x tl => @@ -160,13 +162,13 @@ val [list_nth_shared_loop_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_shared_loop_fwd_def = Define ‘ - (** [loops::list_nth_shared_loop] *) + (** [loops::list_nth_shared_loop]: forward function *) list_nth_shared_loop_fwd (ls : 't list_t) (i : u32) : 't result = list_nth_shared_loop_loop_fwd ls i ’ val [get_elem_mut_loop_fwd_def] = DefineDiv ‘ - (** [loops::get_elem_mut] *) + (** [loops::get_elem_mut]: loop 0: forward function *) get_elem_mut_loop_fwd (x : usize) (ls : usize list_t) : usize result = (case ls of | ListCons y tl => if y = x then Return y else get_elem_mut_loop_fwd x tl @@ -174,7 +176,7 @@ val [get_elem_mut_loop_fwd_def] = DefineDiv ‘ ’ val get_elem_mut_fwd_def = Define ‘ - (** [loops::get_elem_mut] *) + (** [loops::get_elem_mut]: forward function *) get_elem_mut_fwd (slots : usize list_t vec) (x : usize) : usize result = do l <- vec_index_mut_fwd slots (int_to_usize 0); @@ -183,7 +185,7 @@ val get_elem_mut_fwd_def = Define ‘ ’ val [get_elem_mut_loop_back_def] = DefineDiv ‘ - (** [loops::get_elem_mut] *) + (** [loops::get_elem_mut]: loop 0: backward function 0 *) get_elem_mut_loop_back (x : usize) (ls : usize list_t) (ret : usize) : usize list_t result = (case ls of @@ -199,7 +201,7 @@ val [get_elem_mut_loop_back_def] = DefineDiv ‘ ’ val get_elem_mut_back_def = Define ‘ - (** [loops::get_elem_mut] *) + (** [loops::get_elem_mut]: backward function 0 *) get_elem_mut_back (slots : usize list_t vec) (x : usize) (ret : usize) : usize list_t vec result @@ -212,7 +214,7 @@ val get_elem_mut_back_def = Define ‘ ’ val [get_elem_shared_loop_fwd_def] = DefineDiv ‘ - (** [loops::get_elem_shared] *) + (** [loops::get_elem_shared]: loop 0: forward function *) get_elem_shared_loop_fwd (x : usize) (ls : usize list_t) : usize result = (case ls of | ListCons y tl => @@ -221,7 +223,7 @@ val [get_elem_shared_loop_fwd_def] = DefineDiv ‘ ’ val get_elem_shared_fwd_def = Define ‘ - (** [loops::get_elem_shared] *) + (** [loops::get_elem_shared]: forward function *) get_elem_shared_fwd (slots : usize list_t vec) (x : usize) : usize result = do l <- vec_index_fwd slots (int_to_usize 0); @@ -230,25 +232,25 @@ val get_elem_shared_fwd_def = Define ‘ ’ val id_mut_fwd_def = Define ‘ - (** [loops::id_mut] *) + (** [loops::id_mut]: forward function *) id_mut_fwd (ls : 't list_t) : 't list_t result = Return ls ’ val id_mut_back_def = Define ‘ - (** [loops::id_mut] *) + (** [loops::id_mut]: backward function 0 *) id_mut_back (ls : 't list_t) (ret : 't list_t) : 't list_t result = Return ret ’ val id_shared_fwd_def = Define ‘ - (** [loops::id_shared] *) + (** [loops::id_shared]: forward function *) id_shared_fwd (ls : 't list_t) : 't list_t result = Return ls ’ val [list_nth_mut_loop_with_id_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_with_id] *) + (** [loops::list_nth_mut_loop_with_id]: loop 0: forward function *) list_nth_mut_loop_with_id_loop_fwd (i : u32) (ls : 't list_t) : 't result = (case ls of | ListCons x tl => @@ -263,7 +265,7 @@ val [list_nth_mut_loop_with_id_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_mut_loop_with_id_fwd_def = Define ‘ - (** [loops::list_nth_mut_loop_with_id] *) + (** [loops::list_nth_mut_loop_with_id]: forward function *) list_nth_mut_loop_with_id_fwd (ls : 't list_t) (i : u32) : 't result = do ls0 <- id_mut_fwd ls; @@ -272,7 +274,7 @@ val list_nth_mut_loop_with_id_fwd_def = Define ‘ ’ val [list_nth_mut_loop_with_id_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_with_id] *) + (** [loops::list_nth_mut_loop_with_id]: loop 0: backward function 0 *) list_nth_mut_loop_with_id_loop_back (i : u32) (ls : 't list_t) (ret : 't) : 't list_t result = (case ls of @@ -289,7 +291,7 @@ val [list_nth_mut_loop_with_id_loop_back_def] = DefineDiv ‘ ’ val list_nth_mut_loop_with_id_back_def = Define ‘ - (** [loops::list_nth_mut_loop_with_id] *) + (** [loops::list_nth_mut_loop_with_id]: backward function 0 *) list_nth_mut_loop_with_id_back (ls : 't list_t) (i : u32) (ret : 't) : 't list_t result = do @@ -300,7 +302,7 @@ val list_nth_mut_loop_with_id_back_def = Define ‘ ’ val [list_nth_shared_loop_with_id_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_shared_loop_with_id] *) + (** [loops::list_nth_shared_loop_with_id]: loop 0: forward function *) list_nth_shared_loop_with_id_loop_fwd (i : u32) (ls : 't list_t) : 't result = (case ls of @@ -316,7 +318,7 @@ val [list_nth_shared_loop_with_id_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_shared_loop_with_id_fwd_def = Define ‘ - (** [loops::list_nth_shared_loop_with_id] *) + (** [loops::list_nth_shared_loop_with_id]: forward function *) list_nth_shared_loop_with_id_fwd (ls : 't list_t) (i : u32) : 't result = do ls0 <- id_shared_fwd ls; @@ -325,7 +327,7 @@ val list_nth_shared_loop_with_id_fwd_def = Define ‘ ’ val [list_nth_mut_loop_pair_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_pair] *) + (** [loops::list_nth_mut_loop_pair]: loop 0: forward function *) list_nth_mut_loop_pair_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -344,14 +346,14 @@ val [list_nth_mut_loop_pair_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_mut_loop_pair_fwd_def = Define ‘ - (** [loops::list_nth_mut_loop_pair] *) + (** [loops::list_nth_mut_loop_pair]: forward function *) list_nth_mut_loop_pair_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_mut_loop_pair_loop_fwd ls0 ls1 i ’ val [list_nth_mut_loop_pair_loop_back'a_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_pair] *) + (** [loops::list_nth_mut_loop_pair]: loop 0: backward function 0 *) list_nth_mut_loop_pair_loop_back'a (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -373,7 +375,7 @@ val [list_nth_mut_loop_pair_loop_back'a_def] = DefineDiv ‘ ’ val list_nth_mut_loop_pair_back'a_def = Define ‘ - (** [loops::list_nth_mut_loop_pair] *) + (** [loops::list_nth_mut_loop_pair]: backward function 0 *) list_nth_mut_loop_pair_back'a (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -382,7 +384,7 @@ val list_nth_mut_loop_pair_back'a_def = Define ‘ ’ val [list_nth_mut_loop_pair_loop_back'b_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_pair] *) + (** [loops::list_nth_mut_loop_pair]: loop 0: backward function 1 *) list_nth_mut_loop_pair_loop_back'b (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -404,7 +406,7 @@ val [list_nth_mut_loop_pair_loop_back'b_def] = DefineDiv ‘ ’ val list_nth_mut_loop_pair_back'b_def = Define ‘ - (** [loops::list_nth_mut_loop_pair] *) + (** [loops::list_nth_mut_loop_pair]: backward function 1 *) list_nth_mut_loop_pair_back'b (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -413,7 +415,7 @@ val list_nth_mut_loop_pair_back'b_def = Define ‘ ’ val [list_nth_shared_loop_pair_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_shared_loop_pair] *) + (** [loops::list_nth_shared_loop_pair]: loop 0: forward function *) list_nth_shared_loop_pair_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -432,14 +434,14 @@ val [list_nth_shared_loop_pair_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_shared_loop_pair_fwd_def = Define ‘ - (** [loops::list_nth_shared_loop_pair] *) + (** [loops::list_nth_shared_loop_pair]: forward function *) list_nth_shared_loop_pair_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_shared_loop_pair_loop_fwd ls0 ls1 i ’ val [list_nth_mut_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_pair_merge] *) + (** [loops::list_nth_mut_loop_pair_merge]: loop 0: forward function *) list_nth_mut_loop_pair_merge_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -458,14 +460,14 @@ val [list_nth_mut_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_mut_loop_pair_merge_fwd_def = Define ‘ - (** [loops::list_nth_mut_loop_pair_merge] *) + (** [loops::list_nth_mut_loop_pair_merge]: forward function *) list_nth_mut_loop_pair_merge_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_mut_loop_pair_merge_loop_fwd ls0 ls1 i ’ val [list_nth_mut_loop_pair_merge_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_mut_loop_pair_merge] *) + (** [loops::list_nth_mut_loop_pair_merge]: loop 0: backward function 0 *) list_nth_mut_loop_pair_merge_loop_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : ('t # 't)) : ('t list_t # 't list_t) result @@ -488,7 +490,7 @@ val [list_nth_mut_loop_pair_merge_loop_back_def] = DefineDiv ‘ ’ val list_nth_mut_loop_pair_merge_back_def = Define ‘ - (** [loops::list_nth_mut_loop_pair_merge] *) + (** [loops::list_nth_mut_loop_pair_merge]: backward function 0 *) list_nth_mut_loop_pair_merge_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : ('t # 't)) : ('t list_t # 't list_t) result @@ -497,7 +499,7 @@ val list_nth_mut_loop_pair_merge_back_def = Define ‘ ’ val [list_nth_shared_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_shared_loop_pair_merge] *) + (** [loops::list_nth_shared_loop_pair_merge]: loop 0: forward function *) list_nth_shared_loop_pair_merge_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -516,14 +518,14 @@ val [list_nth_shared_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_shared_loop_pair_merge_fwd_def = Define ‘ - (** [loops::list_nth_shared_loop_pair_merge] *) + (** [loops::list_nth_shared_loop_pair_merge]: forward function *) list_nth_shared_loop_pair_merge_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_shared_loop_pair_merge_loop_fwd ls0 ls1 i ’ val [list_nth_mut_shared_loop_pair_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_mut_shared_loop_pair] *) + (** [loops::list_nth_mut_shared_loop_pair]: loop 0: forward function *) list_nth_mut_shared_loop_pair_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -542,14 +544,14 @@ val [list_nth_mut_shared_loop_pair_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_mut_shared_loop_pair_fwd_def = Define ‘ - (** [loops::list_nth_mut_shared_loop_pair] *) + (** [loops::list_nth_mut_shared_loop_pair]: forward function *) list_nth_mut_shared_loop_pair_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_mut_shared_loop_pair_loop_fwd ls0 ls1 i ’ val [list_nth_mut_shared_loop_pair_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_mut_shared_loop_pair] *) + (** [loops::list_nth_mut_shared_loop_pair]: loop 0: backward function 0 *) list_nth_mut_shared_loop_pair_loop_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -571,7 +573,7 @@ val [list_nth_mut_shared_loop_pair_loop_back_def] = DefineDiv ‘ ’ val list_nth_mut_shared_loop_pair_back_def = Define ‘ - (** [loops::list_nth_mut_shared_loop_pair] *) + (** [loops::list_nth_mut_shared_loop_pair]: backward function 0 *) list_nth_mut_shared_loop_pair_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -580,7 +582,7 @@ val list_nth_mut_shared_loop_pair_back_def = Define ‘ ’ val [list_nth_mut_shared_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_mut_shared_loop_pair_merge] *) + (** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: forward function *) list_nth_mut_shared_loop_pair_merge_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -599,14 +601,14 @@ val [list_nth_mut_shared_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_mut_shared_loop_pair_merge_fwd_def = Define ‘ - (** [loops::list_nth_mut_shared_loop_pair_merge] *) + (** [loops::list_nth_mut_shared_loop_pair_merge]: forward function *) list_nth_mut_shared_loop_pair_merge_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_mut_shared_loop_pair_merge_loop_fwd ls0 ls1 i ’ val [list_nth_mut_shared_loop_pair_merge_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_mut_shared_loop_pair_merge] *) + (** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: backward function 0 *) list_nth_mut_shared_loop_pair_merge_loop_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -628,7 +630,7 @@ val [list_nth_mut_shared_loop_pair_merge_loop_back_def] = DefineDiv ‘ ’ val list_nth_mut_shared_loop_pair_merge_back_def = Define ‘ - (** [loops::list_nth_mut_shared_loop_pair_merge] *) + (** [loops::list_nth_mut_shared_loop_pair_merge]: backward function 0 *) list_nth_mut_shared_loop_pair_merge_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -637,7 +639,7 @@ val list_nth_mut_shared_loop_pair_merge_back_def = Define ‘ ’ val [list_nth_shared_mut_loop_pair_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_shared_mut_loop_pair] *) + (** [loops::list_nth_shared_mut_loop_pair]: loop 0: forward function *) list_nth_shared_mut_loop_pair_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -656,14 +658,14 @@ val [list_nth_shared_mut_loop_pair_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_shared_mut_loop_pair_fwd_def = Define ‘ - (** [loops::list_nth_shared_mut_loop_pair] *) + (** [loops::list_nth_shared_mut_loop_pair]: forward function *) list_nth_shared_mut_loop_pair_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_shared_mut_loop_pair_loop_fwd ls0 ls1 i ’ val [list_nth_shared_mut_loop_pair_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_shared_mut_loop_pair] *) + (** [loops::list_nth_shared_mut_loop_pair]: loop 0: backward function 1 *) list_nth_shared_mut_loop_pair_loop_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -685,7 +687,7 @@ val [list_nth_shared_mut_loop_pair_loop_back_def] = DefineDiv ‘ ’ val list_nth_shared_mut_loop_pair_back_def = Define ‘ - (** [loops::list_nth_shared_mut_loop_pair] *) + (** [loops::list_nth_shared_mut_loop_pair]: backward function 1 *) list_nth_shared_mut_loop_pair_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -694,7 +696,7 @@ val list_nth_shared_mut_loop_pair_back_def = Define ‘ ’ val [list_nth_shared_mut_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ - (** [loops::list_nth_shared_mut_loop_pair_merge] *) + (** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: forward function *) list_nth_shared_mut_loop_pair_merge_loop_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = (case ls0 of @@ -713,14 +715,14 @@ val [list_nth_shared_mut_loop_pair_merge_loop_fwd_def] = DefineDiv ‘ ’ val list_nth_shared_mut_loop_pair_merge_fwd_def = Define ‘ - (** [loops::list_nth_shared_mut_loop_pair_merge] *) + (** [loops::list_nth_shared_mut_loop_pair_merge]: forward function *) list_nth_shared_mut_loop_pair_merge_fwd (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) : ('t # 't) result = list_nth_shared_mut_loop_pair_merge_loop_fwd ls0 ls1 i ’ val [list_nth_shared_mut_loop_pair_merge_loop_back_def] = DefineDiv ‘ - (** [loops::list_nth_shared_mut_loop_pair_merge] *) + (** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: backward function 0 *) list_nth_shared_mut_loop_pair_merge_loop_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result @@ -742,7 +744,7 @@ val [list_nth_shared_mut_loop_pair_merge_loop_back_def] = DefineDiv ‘ ’ val list_nth_shared_mut_loop_pair_merge_back_def = Define ‘ - (** [loops::list_nth_shared_mut_loop_pair_merge] *) + (** [loops::list_nth_shared_mut_loop_pair_merge]: backward function 0 *) list_nth_shared_mut_loop_pair_merge_back (ls0 : 't list_t) (ls1 : 't list_t) (i : u32) (ret : 't) : 't list_t result diff --git a/tests/hol4/misc-no_nested_borrows/noNestedBorrowsScript.sml b/tests/hol4/misc-no_nested_borrows/noNestedBorrowsScript.sml index c8b106cd..66614c3f 100644 --- a/tests/hol4/misc-no_nested_borrows/noNestedBorrowsScript.sml +++ b/tests/hol4/misc-no_nested_borrows/noNestedBorrowsScript.sml @@ -38,49 +38,49 @@ Datatype: End val neg_test_fwd_def = Define ‘ - (** [no_nested_borrows::neg_test] *) + (** [no_nested_borrows::neg_test]: forward function *) neg_test_fwd (x : i32) : i32 result = i32_neg x ’ val add_test_fwd_def = Define ‘ - (** [no_nested_borrows::add_test] *) + (** [no_nested_borrows::add_test]: forward function *) add_test_fwd (x : u32) (y : u32) : u32 result = u32_add x y ’ val subs_test_fwd_def = Define ‘ - (** [no_nested_borrows::subs_test] *) + (** [no_nested_borrows::subs_test]: forward function *) subs_test_fwd (x : u32) (y : u32) : u32 result = u32_sub x y ’ val div_test_fwd_def = Define ‘ - (** [no_nested_borrows::div_test] *) + (** [no_nested_borrows::div_test]: forward function *) div_test_fwd (x : u32) (y : u32) : u32 result = u32_div x y ’ val div_test1_fwd_def = Define ‘ - (** [no_nested_borrows::div_test1] *) + (** [no_nested_borrows::div_test1]: forward function *) div_test1_fwd (x : u32) : u32 result = u32_div x (int_to_u32 2) ’ val rem_test_fwd_def = Define ‘ - (** [no_nested_borrows::rem_test] *) + (** [no_nested_borrows::rem_test]: forward function *) rem_test_fwd (x : u32) (y : u32) : u32 result = u32_rem x y ’ val cast_test_fwd_def = Define ‘ - (** [no_nested_borrows::cast_test] *) + (** [no_nested_borrows::cast_test]: forward function *) cast_test_fwd (x : u32) : i32 result = mk_i32 (u32_to_int x) ’ val test2_fwd_def = Define ‘ - (** [no_nested_borrows::test2] *) + (** [no_nested_borrows::test2]: forward function *) test2_fwd : unit result = do _ <- u32_add (int_to_u32 23) (int_to_u32 44); @@ -92,13 +92,13 @@ val test2_fwd_def = Define ‘ val _ = assert_return (“test2_fwd”) val get_max_fwd_def = Define ‘ - (** [no_nested_borrows::get_max] *) + (** [no_nested_borrows::get_max]: forward function *) get_max_fwd (x : u32) (y : u32) : u32 result = if u32_ge x y then Return x else Return y ’ val test3_fwd_def = Define ‘ - (** [no_nested_borrows::test3] *) + (** [no_nested_borrows::test3]: forward function *) test3_fwd : unit result = do x <- get_max_fwd (int_to_u32 4) (int_to_u32 3); @@ -112,7 +112,7 @@ val test3_fwd_def = Define ‘ val _ = assert_return (“test3_fwd”) val test_neg1_fwd_def = Define ‘ - (** [no_nested_borrows::test_neg1] *) + (** [no_nested_borrows::test_neg1]: forward function *) test_neg1_fwd : unit result = do y <- i32_neg (int_to_i32 3); @@ -124,7 +124,7 @@ val test_neg1_fwd_def = Define ‘ val _ = assert_return (“test_neg1_fwd”) val refs_test1_fwd_def = Define ‘ - (** [no_nested_borrows::refs_test1] *) + (** [no_nested_borrows::refs_test1]: forward function *) refs_test1_fwd : unit result = if ~ (int_to_i32 1 = int_to_i32 1) then Fail Failure else Return () ’ @@ -133,7 +133,7 @@ val refs_test1_fwd_def = Define ‘ val _ = assert_return (“refs_test1_fwd”) val refs_test2_fwd_def = Define ‘ - (** [no_nested_borrows::refs_test2] *) + (** [no_nested_borrows::refs_test2]: forward function *) refs_test2_fwd : unit result = if ~ (int_to_i32 2 = int_to_i32 2) then Fail Failure @@ -151,7 +151,7 @@ val refs_test2_fwd_def = Define ‘ val _ = assert_return (“refs_test2_fwd”) val test_list1_fwd_def = Define ‘ - (** [no_nested_borrows::test_list1] *) + (** [no_nested_borrows::test_list1]: forward function *) test_list1_fwd : unit result = Return () ’ @@ -160,7 +160,7 @@ val test_list1_fwd_def = Define ‘ val _ = assert_return (“test_list1_fwd”) val test_box1_fwd_def = Define ‘ - (** [no_nested_borrows::test_box1] *) + (** [no_nested_borrows::test_box1]: forward function *) test_box1_fwd : unit result = let b = int_to_i32 1 in let x = b in @@ -171,25 +171,25 @@ val test_box1_fwd_def = Define ‘ val _ = assert_return (“test_box1_fwd”) val copy_int_fwd_def = Define ‘ - (** [no_nested_borrows::copy_int] *) + (** [no_nested_borrows::copy_int]: forward function *) copy_int_fwd (x : i32) : i32 result = Return x ’ val test_unreachable_fwd_def = Define ‘ - (** [no_nested_borrows::test_unreachable] *) + (** [no_nested_borrows::test_unreachable]: forward function *) test_unreachable_fwd (b : bool) : unit result = if b then Fail Failure else Return () ’ val test_panic_fwd_def = Define ‘ - (** [no_nested_borrows::test_panic] *) + (** [no_nested_borrows::test_panic]: forward function *) test_panic_fwd (b : bool) : unit result = if b then Fail Failure else Return () ’ val test_copy_int_fwd_def = Define ‘ - (** [no_nested_borrows::test_copy_int] *) + (** [no_nested_borrows::test_copy_int]: forward function *) test_copy_int_fwd : unit result = do y <- copy_int_fwd (int_to_i32 0); @@ -201,13 +201,13 @@ val test_copy_int_fwd_def = Define ‘ val _ = assert_return (“test_copy_int_fwd”) val is_cons_fwd_def = Define ‘ - (** [no_nested_borrows::is_cons] *) + (** [no_nested_borrows::is_cons]: forward function *) is_cons_fwd (l : 't list_t) : bool result = (case l of | ListCons t l0 => Return T | ListNil => Return F) ’ val test_is_cons_fwd_def = Define ‘ - (** [no_nested_borrows::test_is_cons] *) + (** [no_nested_borrows::test_is_cons]: forward function *) test_is_cons_fwd : unit result = let l = ListNil in do @@ -220,13 +220,13 @@ val test_is_cons_fwd_def = Define ‘ val _ = assert_return (“test_is_cons_fwd”) val split_list_fwd_def = Define ‘ - (** [no_nested_borrows::split_list] *) + (** [no_nested_borrows::split_list]: forward function *) split_list_fwd (l : 't list_t) : ('t # 't list_t) result = (case l of | ListCons hd tl => Return (hd, tl) | ListNil => Fail Failure) ’ val test_split_list_fwd_def = Define ‘ - (** [no_nested_borrows::test_split_list] *) + (** [no_nested_borrows::test_split_list]: forward function *) test_split_list_fwd : unit result = let l = ListNil in do @@ -240,19 +240,19 @@ val test_split_list_fwd_def = Define ‘ val _ = assert_return (“test_split_list_fwd”) val choose_fwd_def = Define ‘ - (** [no_nested_borrows::choose] *) + (** [no_nested_borrows::choose]: forward function *) choose_fwd (b : bool) (x : 't) (y : 't) : 't result = if b then Return x else Return y ’ val choose_back_def = Define ‘ - (** [no_nested_borrows::choose] *) + (** [no_nested_borrows::choose]: backward function 0 *) choose_back (b : bool) (x : 't) (y : 't) (ret : 't) : ('t # 't) result = if b then Return (ret, y) else Return (x, ret) ’ val choose_test_fwd_def = Define ‘ - (** [no_nested_borrows::choose_test] *) + (** [no_nested_borrows::choose_test]: forward function *) choose_test_fwd : unit result = do z <- choose_fwd T (int_to_i32 0) (int_to_i32 0); @@ -273,7 +273,7 @@ val choose_test_fwd_def = Define ‘ val _ = assert_return (“choose_test_fwd”) val test_char_fwd_def = Define ‘ - (** [no_nested_borrows::test_char] *) + (** [no_nested_borrows::test_char]: forward function *) test_char_fwd : char result = Return #"a" ’ @@ -287,7 +287,7 @@ Datatype: End val [list_length_fwd_def] = DefineDiv ‘ - (** [no_nested_borrows::list_length] *) + (** [no_nested_borrows::list_length]: forward function *) list_length_fwd (l : 't list_t) : u32 result = (case l of | ListCons t l1 => do @@ -298,7 +298,7 @@ val [list_length_fwd_def] = DefineDiv ‘ ’ val [list_nth_shared_fwd_def] = DefineDiv ‘ - (** [no_nested_borrows::list_nth_shared] *) + (** [no_nested_borrows::list_nth_shared]: forward function *) list_nth_shared_fwd (l : 't list_t) (i : u32) : 't result = (case l of | ListCons x tl => @@ -312,7 +312,7 @@ val [list_nth_shared_fwd_def] = DefineDiv ‘ ’ val [list_nth_mut_fwd_def] = DefineDiv ‘ - (** [no_nested_borrows::list_nth_mut] *) + (** [no_nested_borrows::list_nth_mut]: forward function *) list_nth_mut_fwd (l : 't list_t) (i : u32) : 't result = (case l of | ListCons x tl => @@ -326,7 +326,7 @@ val [list_nth_mut_fwd_def] = DefineDiv ‘ ’ val [list_nth_mut_back_def] = DefineDiv ‘ - (** [no_nested_borrows::list_nth_mut] *) + (** [no_nested_borrows::list_nth_mut]: backward function 0 *) list_nth_mut_back (l : 't list_t) (i : u32) (ret : 't) : 't list_t result = (case l of | ListCons x tl => @@ -342,7 +342,7 @@ val [list_nth_mut_back_def] = DefineDiv ‘ ’ val [list_rev_aux_fwd_def] = DefineDiv ‘ - (** [no_nested_borrows::list_rev_aux] *) + (** [no_nested_borrows::list_rev_aux]: forward function *) list_rev_aux_fwd (li : 't list_t) (lo : 't list_t) : 't list_t result = (case li of | ListCons hd tl => list_rev_aux_fwd tl (ListCons hd lo) @@ -350,13 +350,14 @@ val [list_rev_aux_fwd_def] = DefineDiv ‘ ’ val list_rev_fwd_back_def = Define ‘ - (** [no_nested_borrows::list_rev] *) + (** [no_nested_borrows::list_rev]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) list_rev_fwd_back (l : 't list_t) : 't list_t result = let li = mem_replace_fwd l ListNil in list_rev_aux_fwd li ListNil ’ val test_list_functions_fwd_def = Define ‘ - (** [no_nested_borrows::test_list_functions] *) + (** [no_nested_borrows::test_list_functions]: forward function *) test_list_functions_fwd : unit result = let l = ListNil in let l0 = ListCons (int_to_i32 2) l in @@ -411,63 +412,63 @@ val test_list_functions_fwd_def = Define ‘ val _ = assert_return (“test_list_functions_fwd”) val id_mut_pair1_fwd_def = Define ‘ - (** [no_nested_borrows::id_mut_pair1] *) + (** [no_nested_borrows::id_mut_pair1]: forward function *) id_mut_pair1_fwd (x : 't1) (y : 't2) : ('t1 # 't2) result = Return (x, y) ’ val id_mut_pair1_back_def = Define ‘ - (** [no_nested_borrows::id_mut_pair1] *) + (** [no_nested_borrows::id_mut_pair1]: backward function 0 *) id_mut_pair1_back (x : 't1) (y : 't2) (ret : ('t1 # 't2)) : ('t1 # 't2) result = let (t, t0) = ret in Return (t, t0) ’ val id_mut_pair2_fwd_def = Define ‘ - (** [no_nested_borrows::id_mut_pair2] *) + (** [no_nested_borrows::id_mut_pair2]: forward function *) id_mut_pair2_fwd (p : ('t1 # 't2)) : ('t1 # 't2) result = let (t, t0) = p in Return (t, t0) ’ val id_mut_pair2_back_def = Define ‘ - (** [no_nested_borrows::id_mut_pair2] *) + (** [no_nested_borrows::id_mut_pair2]: backward function 0 *) id_mut_pair2_back (p : ('t1 # 't2)) (ret : ('t1 # 't2)) : ('t1 # 't2) result = let (t, t0) = ret in Return (t, t0) ’ val id_mut_pair3_fwd_def = Define ‘ - (** [no_nested_borrows::id_mut_pair3] *) + (** [no_nested_borrows::id_mut_pair3]: forward function *) id_mut_pair3_fwd (x : 't1) (y : 't2) : ('t1 # 't2) result = Return (x, y) ’ val id_mut_pair3_back'a_def = Define ‘ - (** [no_nested_borrows::id_mut_pair3] *) + (** [no_nested_borrows::id_mut_pair3]: backward function 0 *) id_mut_pair3_back'a (x : 't1) (y : 't2) (ret : 't1) : 't1 result = Return ret ’ val id_mut_pair3_back'b_def = Define ‘ - (** [no_nested_borrows::id_mut_pair3] *) + (** [no_nested_borrows::id_mut_pair3]: backward function 1 *) id_mut_pair3_back'b (x : 't1) (y : 't2) (ret : 't2) : 't2 result = Return ret ’ val id_mut_pair4_fwd_def = Define ‘ - (** [no_nested_borrows::id_mut_pair4] *) + (** [no_nested_borrows::id_mut_pair4]: forward function *) id_mut_pair4_fwd (p : ('t1 # 't2)) : ('t1 # 't2) result = let (t, t0) = p in Return (t, t0) ’ val id_mut_pair4_back'a_def = Define ‘ - (** [no_nested_borrows::id_mut_pair4] *) + (** [no_nested_borrows::id_mut_pair4]: backward function 0 *) id_mut_pair4_back'a (p : ('t1 # 't2)) (ret : 't1) : 't1 result = Return ret ’ val id_mut_pair4_back'b_def = Define ‘ - (** [no_nested_borrows::id_mut_pair4] *) + (** [no_nested_borrows::id_mut_pair4]: backward function 1 *) id_mut_pair4_back'b (p : ('t1 # 't2)) (ret : 't2) : 't2 result = Return ret ’ @@ -478,19 +479,19 @@ Datatype: End val new_tuple1_fwd_def = Define ‘ - (** [no_nested_borrows::new_tuple1] *) + (** [no_nested_borrows::new_tuple1]: forward function *) new_tuple1_fwd : (u32, u32) struct_with_tuple_t result = Return (<| struct_with_tuple_p := (int_to_u32 1, int_to_u32 2) |>) ’ val new_tuple2_fwd_def = Define ‘ - (** [no_nested_borrows::new_tuple2] *) + (** [no_nested_borrows::new_tuple2]: forward function *) new_tuple2_fwd : (i16, i16) struct_with_tuple_t result = Return (<| struct_with_tuple_p := (int_to_i16 1, int_to_i16 2) |>) ’ val new_tuple3_fwd_def = Define ‘ - (** [no_nested_borrows::new_tuple3] *) + (** [no_nested_borrows::new_tuple3]: forward function *) new_tuple3_fwd : (u64, i64) struct_with_tuple_t result = Return (<| struct_with_tuple_p := (int_to_u64 1, int_to_i64 2) |>) ’ @@ -501,7 +502,7 @@ Datatype: End val new_pair1_fwd_def = Define ‘ - (** [no_nested_borrows::new_pair1] *) + (** [no_nested_borrows::new_pair1]: forward function *) new_pair1_fwd : (u32, u32) struct_with_pair_t result = Return (<| @@ -511,7 +512,7 @@ val new_pair1_fwd_def = Define ‘ ’ val test_constants_fwd_def = Define ‘ - (** [no_nested_borrows::test_constants] *) + (** [no_nested_borrows::test_constants]: forward function *) test_constants_fwd : unit result = do swt <- new_tuple1_fwd; @@ -546,7 +547,7 @@ val test_constants_fwd_def = Define ‘ val _ = assert_return (“test_constants_fwd”) val test_weird_borrows1_fwd_def = Define ‘ - (** [no_nested_borrows::test_weird_borrows1] *) + (** [no_nested_borrows::test_weird_borrows1]: forward function *) test_weird_borrows1_fwd : unit result = Return () ’ @@ -555,26 +556,27 @@ val test_weird_borrows1_fwd_def = Define ‘ val _ = assert_return (“test_weird_borrows1_fwd”) val test_mem_replace_fwd_back_def = Define ‘ - (** [no_nested_borrows::test_mem_replace] *) + (** [no_nested_borrows::test_mem_replace]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) test_mem_replace_fwd_back (px : u32) : u32 result = let y = mem_replace_fwd px (int_to_u32 1) in if ~ (y = int_to_u32 0) then Fail Failure else Return (int_to_u32 2) ’ val test_shared_borrow_bool1_fwd_def = Define ‘ - (** [no_nested_borrows::test_shared_borrow_bool1] *) + (** [no_nested_borrows::test_shared_borrow_bool1]: forward function *) test_shared_borrow_bool1_fwd (b : bool) : u32 result = if b then Return (int_to_u32 0) else Return (int_to_u32 1) ’ val test_shared_borrow_bool2_fwd_def = Define ‘ - (** [no_nested_borrows::test_shared_borrow_bool2] *) + (** [no_nested_borrows::test_shared_borrow_bool2]: forward function *) test_shared_borrow_bool2_fwd : u32 result = Return (int_to_u32 0) ’ val test_shared_borrow_enum1_fwd_def = Define ‘ - (** [no_nested_borrows::test_shared_borrow_enum1] *) + (** [no_nested_borrows::test_shared_borrow_enum1]: forward function *) test_shared_borrow_enum1_fwd (l : u32 list_t) : u32 result = (case l of | ListCons i l0 => Return (int_to_u32 1) @@ -582,7 +584,7 @@ val test_shared_borrow_enum1_fwd_def = Define ‘ ’ val test_shared_borrow_enum2_fwd_def = Define ‘ - (** [no_nested_borrows::test_shared_borrow_enum2] *) + (** [no_nested_borrows::test_shared_borrow_enum2]: forward function *) test_shared_borrow_enum2_fwd : u32 result = Return (int_to_u32 0) ’ diff --git a/tests/hol4/misc-paper/paperScript.sml b/tests/hol4/misc-paper/paperScript.sml index 4d6e99ba..3ac5b6ca 100644 --- a/tests/hol4/misc-paper/paperScript.sml +++ b/tests/hol4/misc-paper/paperScript.sml @@ -6,13 +6,14 @@ val _ = new_theory "paper" val ref_incr_fwd_back_def = Define ‘ - (** [paper::ref_incr] *) + (** [paper::ref_incr]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) *) ref_incr_fwd_back (x : i32) : i32 result = i32_add x (int_to_i32 1) ’ val test_incr_fwd_def = Define ‘ - (** [paper::test_incr] *) + (** [paper::test_incr]: forward function *) test_incr_fwd : unit result = do x <- ref_incr_fwd_back (int_to_i32 0); @@ -24,19 +25,19 @@ val test_incr_fwd_def = Define ‘ val _ = assert_return (“test_incr_fwd”) val choose_fwd_def = Define ‘ - (** [paper::choose] *) + (** [paper::choose]: forward function *) choose_fwd (b : bool) (x : 't) (y : 't) : 't result = if b then Return x else Return y ’ val choose_back_def = Define ‘ - (** [paper::choose] *) + (** [paper::choose]: backward function 0 *) choose_back (b : bool) (x : 't) (y : 't) (ret : 't) : ('t # 't) result = if b then Return (ret, y) else Return (x, ret) ’ val test_choose_fwd_def = Define ‘ - (** [paper::test_choose] *) + (** [paper::test_choose]: forward function *) test_choose_fwd : unit result = do z <- choose_fwd T (int_to_i32 0) (int_to_i32 0); @@ -62,7 +63,7 @@ Datatype: End val [list_nth_mut_fwd_def] = DefineDiv ‘ - (** [paper::list_nth_mut] *) + (** [paper::list_nth_mut]: forward function *) list_nth_mut_fwd (l : 't list_t) (i : u32) : 't result = (case l of | ListCons x tl => @@ -76,7 +77,7 @@ val [list_nth_mut_fwd_def] = DefineDiv ‘ ’ val [list_nth_mut_back_def] = DefineDiv ‘ - (** [paper::list_nth_mut] *) + (** [paper::list_nth_mut]: backward function 0 *) list_nth_mut_back (l : 't list_t) (i : u32) (ret : 't) : 't list_t result = (case l of | ListCons x tl => @@ -92,7 +93,7 @@ val [list_nth_mut_back_def] = DefineDiv ‘ ’ val [sum_fwd_def] = DefineDiv ‘ - (** [paper::sum] *) + (** [paper::sum]: forward function *) sum_fwd (l : i32 list_t) : i32 result = (case l of | ListCons x tl => do @@ -103,7 +104,7 @@ val [sum_fwd_def] = DefineDiv ‘ ’ val test_nth_fwd_def = Define ‘ - (** [paper::test_nth] *) + (** [paper::test_nth]: forward function *) test_nth_fwd : unit result = let l = ListNil in let l0 = ListCons (int_to_i32 3) l in @@ -121,7 +122,7 @@ val test_nth_fwd_def = Define ‘ val _ = assert_return (“test_nth_fwd”) val call_choose_fwd_def = Define ‘ - (** [paper::call_choose] *) + (** [paper::call_choose]: forward function *) call_choose_fwd (p : (u32 # u32)) : u32 result = let (px, py) = p in do diff --git a/tests/hol4/misc-polonius_list/poloniusListScript.sml b/tests/hol4/misc-polonius_list/poloniusListScript.sml index dd631169..06876ed4 100644 --- a/tests/hol4/misc-polonius_list/poloniusListScript.sml +++ b/tests/hol4/misc-polonius_list/poloniusListScript.sml @@ -11,7 +11,7 @@ Datatype: End val [get_list_at_x_fwd_def] = DefineDiv ‘ - (** [polonius_list::get_list_at_x] *) + (** [polonius_list::get_list_at_x]: forward function *) get_list_at_x_fwd (ls : u32 list_t) (x : u32) : u32 list_t result = (case ls of | ListCons hd tl => @@ -20,7 +20,7 @@ val [get_list_at_x_fwd_def] = DefineDiv ‘ ’ val [get_list_at_x_back_def] = DefineDiv ‘ - (** [polonius_list::get_list_at_x] *) + (** [polonius_list::get_list_at_x]: backward function 0 *) get_list_at_x_back (ls : u32 list_t) (x : u32) (ret : u32 list_t) : u32 list_t result = (case ls of diff --git a/tests/lean/.gitignore b/tests/lean/.gitignore index e74f9899..4d1c5853 100644 --- a/tests/lean/.gitignore +++ b/tests/lean/.gitignore @@ -1,2 +1,2 @@ -*/lake-packages/ -*/build/
\ No newline at end of file +lake-packages +build
\ No newline at end of file diff --git a/tests/lean/BetreeMain.lean b/tests/lean/BetreeMain.lean new file mode 100644 index 00000000..5f307877 --- /dev/null +++ b/tests/lean/BetreeMain.lean @@ -0,0 +1 @@ +import BetreeMain.Funs diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean new file mode 100644 index 00000000..142adf08 --- /dev/null +++ b/tests/lean/BetreeMain/Funs.lean @@ -0,0 +1,1023 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: function definitions +import Base +import BetreeMain.Types +import BetreeMain.FunsExternal +open Primitives +namespace betree_main + +/- [betree_main::betree::load_internal_node]: forward function -/ +def betree.load_internal_node + (id : U64) (st : State) : + Result (State × (betree.List (U64 × betree.Message))) + := + betree_utils.load_internal_node id st + +/- [betree_main::betree::store_internal_node]: forward function -/ +def betree.store_internal_node + (id : U64) (content : betree.List (U64 × betree.Message)) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← betree_utils.store_internal_node id content st + Result.ret (st0, ()) + +/- [betree_main::betree::load_leaf_node]: forward function -/ +def betree.load_leaf_node + (id : U64) (st : State) : Result (State × (betree.List (U64 × U64))) := + betree_utils.load_leaf_node id st + +/- [betree_main::betree::store_leaf_node]: forward function -/ +def betree.store_leaf_node + (id : U64) (content : betree.List (U64 × U64)) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← betree_utils.store_leaf_node id content st + Result.ret (st0, ()) + +/- [betree_main::betree::fresh_node_id]: forward function -/ +def betree.fresh_node_id (counter : U64) : Result U64 := + do + let _ ← counter + (U64.ofInt 1) + Result.ret counter + +/- [betree_main::betree::fresh_node_id]: backward function 0 -/ +def betree.fresh_node_id_back (counter : U64) : Result U64 := + counter + (U64.ofInt 1) + +/- [betree_main::betree::NodeIdCounter::{0}::new]: forward function -/ +def betree.NodeIdCounter.new : Result betree.NodeIdCounter := + Result.ret { next_node_id := (U64.ofInt 0) } + +/- [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function -/ +def betree.NodeIdCounter.fresh_id (self : betree.NodeIdCounter) : Result U64 := + do + let _ ← self.next_node_id + (U64.ofInt 1) + Result.ret self.next_node_id + +/- [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 -/ +def betree.NodeIdCounter.fresh_id_back + (self : betree.NodeIdCounter) : Result betree.NodeIdCounter := + do + let i ← self.next_node_id + (U64.ofInt 1) + Result.ret { next_node_id := i } + +/- [core::num::u64::{10}::MAX] -/ +def core_num_u64_max_body : Result U64 := + Result.ret (U64.ofInt 18446744073709551615) +def core_num_u64_max_c : U64 := eval_global core_num_u64_max_body (by simp) + +/- [betree_main::betree::upsert_update]: forward function -/ +def betree.upsert_update + (prev : Option U64) (st : betree.UpsertFunState) : Result U64 := + match prev with + | Option.none => + match st with + | betree.UpsertFunState.Add v => Result.ret v + | betree.UpsertFunState.Sub i => Result.ret (U64.ofInt 0) + | Option.some prev0 => + match st with + | betree.UpsertFunState.Add v => + do + let margin ← core_num_u64_max_c - prev0 + if margin >= v + then prev0 + v + else Result.ret core_num_u64_max_c + | betree.UpsertFunState.Sub v => + if prev0 >= v + then prev0 - v + else Result.ret (U64.ofInt 0) + +/- [betree_main::betree::List::{1}::len]: forward function -/ +divergent def betree.List.len (T : Type) (self : betree.List T) : Result U64 := + match self with + | betree.List.Cons t tl => + do + let i ← betree.List.len T tl + (U64.ofInt 1) + i + | betree.List.Nil => Result.ret (U64.ofInt 0) + +/- [betree_main::betree::List::{1}::split_at]: forward function -/ +divergent def betree.List.split_at + (T : Type) (self : betree.List T) (n : U64) : + Result ((betree.List T) × (betree.List T)) + := + if n = (U64.ofInt 0) + then Result.ret (betree.List.Nil, self) + else + match self with + | betree.List.Cons hd tl => + do + let i ← n - (U64.ofInt 1) + let p ← betree.List.split_at T tl i + let (ls0, ls1) := p + let l := ls0 + Result.ret (betree.List.Cons hd l, ls1) + | betree.List.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{1}::push_front]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def betree.List.push_front + (T : Type) (self : betree.List T) (x : T) : Result (betree.List T) := + let tl := mem.replace (betree.List T) self betree.List.Nil + let l := tl + Result.ret (betree.List.Cons x l) + +/- [betree_main::betree::List::{1}::pop_front]: forward function -/ +def betree.List.pop_front (T : Type) (self : betree.List T) : Result T := + let ls := mem.replace (betree.List T) self betree.List.Nil + match ls with + | betree.List.Cons x tl => Result.ret x + | betree.List.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{1}::pop_front]: backward function 0 -/ +def betree.List.pop_front_back + (T : Type) (self : betree.List T) : Result (betree.List T) := + let ls := mem.replace (betree.List T) self betree.List.Nil + match ls with + | betree.List.Cons x tl => Result.ret tl + | betree.List.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{1}::hd]: forward function -/ +def betree.List.hd (T : Type) (self : betree.List T) : Result T := + match self with + | betree.List.Cons hd l => Result.ret hd + | betree.List.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{2}::head_has_key]: forward function -/ +def betree.List.head_has_key + (T : Type) (self : betree.List (U64 × T)) (key : U64) : Result Bool := + match self with + | betree.List.Cons hd l => let (i, _) := hd + Result.ret (i = key) + | betree.List.Nil => Result.ret false + +/- [betree_main::betree::List::{2}::partition_at_pivot]: forward function -/ +divergent def betree.List.partition_at_pivot + (T : Type) (self : betree.List (U64 × T)) (pivot : U64) : + Result ((betree.List (U64 × T)) × (betree.List (U64 × T))) + := + match self with + | betree.List.Cons hd tl => + let (i, t) := hd + if i >= pivot + then Result.ret (betree.List.Nil, betree.List.Cons (i, t) tl) + else + do + let p ← betree.List.partition_at_pivot T tl pivot + let (ls0, ls1) := p + let l := ls0 + Result.ret (betree.List.Cons (i, t) l, ls1) + | betree.List.Nil => Result.ret (betree.List.Nil, betree.List.Nil) + +/- [betree_main::betree::Leaf::{3}::split]: forward function -/ +def betree.Leaf.split + (self : betree.Leaf) (content : betree.List (U64 × U64)) + (params : betree.Params) (node_id_cnt : betree.NodeIdCounter) (st : State) : + Result (State × betree.Internal) + := + do + let p ← betree.List.split_at (U64 × U64) content params.split_size + let (content0, content1) := p + let p0 ← betree.List.hd (U64 × U64) content1 + let (pivot, _) := p0 + let id0 ← betree.NodeIdCounter.fresh_id node_id_cnt + let node_id_cnt0 ← betree.NodeIdCounter.fresh_id_back node_id_cnt + let id1 ← betree.NodeIdCounter.fresh_id node_id_cnt0 + let (st0, _) ← betree.store_leaf_node id0 content0 st + let (st1, _) ← betree.store_leaf_node id1 content1 st0 + let n := betree.Node.Leaf { id := id0, size := params.split_size } + let n0 := betree.Node.Leaf { id := id1, size := params.split_size } + Result.ret (st1, betree.Internal.mk self.id pivot n n0) + +/- [betree_main::betree::Leaf::{3}::split]: backward function 2 -/ +def betree.Leaf.split_back + (self : betree.Leaf) (content : betree.List (U64 × U64)) + (params : betree.Params) (node_id_cnt : betree.NodeIdCounter) (st : State) : + Result betree.NodeIdCounter + := + do + let p ← betree.List.split_at (U64 × U64) content params.split_size + let (content0, content1) := p + let _ ← betree.List.hd (U64 × U64) content1 + let id0 ← betree.NodeIdCounter.fresh_id node_id_cnt + let node_id_cnt0 ← betree.NodeIdCounter.fresh_id_back node_id_cnt + let id1 ← betree.NodeIdCounter.fresh_id node_id_cnt0 + let (st0, _) ← betree.store_leaf_node id0 content0 st + let _ ← betree.store_leaf_node id1 content1 st0 + betree.NodeIdCounter.fresh_id_back node_id_cnt0 + +/- [betree_main::betree::Node::{5}::lookup_in_bindings]: forward function -/ +divergent def betree.Node.lookup_in_bindings + (key : U64) (bindings : betree.List (U64 × U64)) : Result (Option U64) := + match bindings with + | betree.List.Cons hd tl => + let (i, i0) := hd + if i = key + then Result.ret (Option.some i0) + else + if i > key + then Result.ret Option.none + else betree.Node.lookup_in_bindings key tl + | betree.List.Nil => Result.ret Option.none + +/- [betree_main::betree::Node::{5}::lookup_first_message_for_key]: forward function -/ +divergent def betree.Node.lookup_first_message_for_key + (key : U64) (msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) + := + match msgs with + | betree.List.Cons x next_msgs => + let (i, m) := x + if i >= key + then Result.ret (betree.List.Cons (i, m) next_msgs) + else betree.Node.lookup_first_message_for_key key next_msgs + | betree.List.Nil => Result.ret betree.List.Nil + +/- [betree_main::betree::Node::{5}::lookup_first_message_for_key]: backward function 0 -/ +divergent def betree.Node.lookup_first_message_for_key_back + (key : U64) (msgs : betree.List (U64 × betree.Message)) + (ret0 : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) + := + match msgs with + | betree.List.Cons x next_msgs => + let (i, m) := x + if i >= key + then Result.ret ret0 + else + do + let next_msgs0 ← + betree.Node.lookup_first_message_for_key_back key next_msgs ret0 + Result.ret (betree.List.Cons (i, m) next_msgs0) + | betree.List.Nil => Result.ret ret0 + +/- [betree_main::betree::Node::{5}::apply_upserts]: forward function -/ +divergent def betree.Node.apply_upserts + (msgs : betree.List (U64 × betree.Message)) (prev : Option U64) (key : U64) + (st : State) : + Result (State × U64) + := + do + let b ← betree.List.head_has_key betree.Message msgs key + if b + then + do + let msg ← betree.List.pop_front (U64 × betree.Message) msgs + let (_, m) := msg + match m with + | betree.Message.Insert i => Result.fail Error.panic + | betree.Message.Delete => Result.fail Error.panic + | betree.Message.Upsert s => + do + let v ← betree.upsert_update prev s + let msgs0 ← + betree.List.pop_front_back (U64 × betree.Message) msgs + betree.Node.apply_upserts msgs0 (Option.some v) key st + else + do + let (st0, v) ← core.option.Option.unwrap U64 prev st + let _ ← + betree.List.push_front (U64 × betree.Message) msgs (key, + betree.Message.Insert v) + Result.ret (st0, v) + +/- [betree_main::betree::Node::{5}::apply_upserts]: backward function 0 -/ +divergent def betree.Node.apply_upserts_back + (msgs : betree.List (U64 × betree.Message)) (prev : Option U64) (key : U64) + (st : State) : + Result (betree.List (U64 × betree.Message)) + := + do + let b ← betree.List.head_has_key betree.Message msgs key + if b + then + do + let msg ← betree.List.pop_front (U64 × betree.Message) msgs + let (_, m) := msg + match m with + | betree.Message.Insert i => Result.fail Error.panic + | betree.Message.Delete => Result.fail Error.panic + | betree.Message.Upsert s => + do + let v ← betree.upsert_update prev s + let msgs0 ← + betree.List.pop_front_back (U64 × betree.Message) msgs + betree.Node.apply_upserts_back msgs0 (Option.some v) key st + else + do + let (_, v) ← core.option.Option.unwrap U64 prev st + betree.List.push_front (U64 × betree.Message) msgs (key, + betree.Message.Insert v) + +/- [betree_main::betree::Node::{5}::lookup]: forward function -/ +mutual divergent def betree.Node.lookup + (self : betree.Node) (key : U64) (st : State) : + Result (State × (Option U64)) + := + match self with + | betree.Node.Internal node => + do + let ⟨ i, i0, n, n0 ⟩ := node + let (st0, msgs) ← betree.load_internal_node i st + let pending ← betree.Node.lookup_first_message_for_key key msgs + match pending with + | betree.List.Cons p l => + let (k, msg) := p + if k != key + then + do + let (st1, opt) ← + betree.Internal.lookup_in_children (betree.Internal.mk i i0 n n0) + key st0 + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + (betree.List.Cons (k, msg) l) + Result.ret (st1, opt) + else + match msg with + | betree.Message.Insert v => + do + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + (betree.List.Cons (k, betree.Message.Insert v) l) + Result.ret (st0, Option.some v) + | betree.Message.Delete => + do + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + (betree.List.Cons (k, betree.Message.Delete) l) + Result.ret (st0, Option.none) + | betree.Message.Upsert ufs => + do + let (st1, v) ← + betree.Internal.lookup_in_children (betree.Internal.mk i i0 n + n0) key st0 + let (st2, v0) ← + betree.Node.apply_upserts (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 + let node0 ← + betree.Internal.lookup_in_children_back (betree.Internal.mk i + i0 n n0) key st0 + let ⟨ i1, _, _, _ ⟩ := node0 + let pending0 ← + betree.Node.apply_upserts_back (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 + let msgs0 ← + betree.Node.lookup_first_message_for_key_back key msgs pending0 + let (st3, _) ← betree.store_internal_node i1 msgs0 st2 + Result.ret (st3, Option.some v0) + | betree.List.Nil => + do + let (st1, opt) ← + betree.Internal.lookup_in_children (betree.Internal.mk i i0 n n0) + key st0 + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + betree.List.Nil + Result.ret (st1, opt) + | betree.Node.Leaf node => + do + let (st0, bindings) ← betree.load_leaf_node node.id st + let opt ← betree.Node.lookup_in_bindings key bindings + Result.ret (st0, opt) + +/- [betree_main::betree::Node::{5}::lookup]: backward function 0 -/ +divergent def betree.Node.lookup_back + (self : betree.Node) (key : U64) (st : State) : Result betree.Node := + match self with + | betree.Node.Internal node => + do + let ⟨ i, i0, n, n0 ⟩ := node + let (st0, msgs) ← betree.load_internal_node i st + let pending ← betree.Node.lookup_first_message_for_key key msgs + match pending with + | betree.List.Cons p l => + let (k, msg) := p + if k != key + then + do + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + (betree.List.Cons (k, msg) l) + let node0 ← + betree.Internal.lookup_in_children_back (betree.Internal.mk i i0 + n n0) key st0 + Result.ret (betree.Node.Internal node0) + else + match msg with + | betree.Message.Insert v => + do + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + (betree.List.Cons (k, betree.Message.Insert v) l) + Result.ret (betree.Node.Internal (betree.Internal.mk i i0 n n0)) + | betree.Message.Delete => + do + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + (betree.List.Cons (k, betree.Message.Delete) l) + Result.ret (betree.Node.Internal (betree.Internal.mk i i0 n n0)) + | betree.Message.Upsert ufs => + do + let (st1, v) ← + betree.Internal.lookup_in_children (betree.Internal.mk i i0 n + n0) key st0 + let (st2, _) ← + betree.Node.apply_upserts (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 + let node0 ← + betree.Internal.lookup_in_children_back (betree.Internal.mk i + i0 n n0) key st0 + let ⟨ i1, i2, n1, n2 ⟩ := node0 + let pending0 ← + betree.Node.apply_upserts_back (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 + let msgs0 ← + betree.Node.lookup_first_message_for_key_back key msgs pending0 + let _ ← betree.store_internal_node i1 msgs0 st2 + Result.ret (betree.Node.Internal (betree.Internal.mk i1 i2 n1 + n2)) + | betree.List.Nil => + do + let _ ← + betree.Node.lookup_first_message_for_key_back key msgs + betree.List.Nil + let node0 ← + betree.Internal.lookup_in_children_back (betree.Internal.mk i i0 n + n0) key st0 + Result.ret (betree.Node.Internal node0) + | betree.Node.Leaf node => + do + let (_, bindings) ← betree.load_leaf_node node.id st + let _ ← betree.Node.lookup_in_bindings key bindings + Result.ret (betree.Node.Leaf node) + +/- [betree_main::betree::Internal::{4}::lookup_in_children]: forward function -/ +divergent def betree.Internal.lookup_in_children + (self : betree.Internal) (key : U64) (st : State) : + Result (State × (Option U64)) + := + let ⟨ _, i, n, n0 ⟩ := self + if key < i + then betree.Node.lookup n key st + else betree.Node.lookup n0 key st + +/- [betree_main::betree::Internal::{4}::lookup_in_children]: backward function 0 -/ +divergent def betree.Internal.lookup_in_children_back + (self : betree.Internal) (key : U64) (st : State) : Result betree.Internal := + let ⟨ i, i0, n, n0 ⟩ := self + if key < i0 + then + do + let n1 ← betree.Node.lookup_back n key st + Result.ret (betree.Internal.mk i i0 n1 n0) + else + do + let n1 ← betree.Node.lookup_back n0 key st + Result.ret (betree.Internal.mk i i0 n n1) + +end + +/- [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: forward function -/ +divergent def betree.Node.lookup_mut_in_bindings + (key : U64) (bindings : betree.List (U64 × U64)) : + Result (betree.List (U64 × U64)) + := + match bindings with + | betree.List.Cons hd tl => + let (i, i0) := hd + if i >= key + then Result.ret (betree.List.Cons (i, i0) tl) + else betree.Node.lookup_mut_in_bindings key tl + | betree.List.Nil => Result.ret betree.List.Nil + +/- [betree_main::betree::Node::{5}::lookup_mut_in_bindings]: backward function 0 -/ +divergent def betree.Node.lookup_mut_in_bindings_back + (key : U64) (bindings : betree.List (U64 × U64)) + (ret0 : betree.List (U64 × U64)) : + Result (betree.List (U64 × U64)) + := + match bindings with + | betree.List.Cons hd tl => + let (i, i0) := hd + if i >= key + then Result.ret ret0 + else + do + let tl0 ← betree.Node.lookup_mut_in_bindings_back key tl ret0 + Result.ret (betree.List.Cons (i, i0) tl0) + | betree.List.Nil => Result.ret ret0 + +/- [betree_main::betree::Node::{5}::apply_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def betree.Node.apply_to_leaf + (bindings : betree.List (U64 × U64)) (key : U64) (new_msg : betree.Message) + : + Result (betree.List (U64 × U64)) + := + do + let bindings0 ← betree.Node.lookup_mut_in_bindings key bindings + let b ← betree.List.head_has_key U64 bindings0 key + if b + then + do + let hd ← betree.List.pop_front (U64 × U64) bindings0 + match new_msg with + | betree.Message.Insert v => + do + let bindings1 ← betree.List.pop_front_back (U64 × U64) bindings0 + let bindings2 ← + betree.List.push_front (U64 × U64) bindings1 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings2 + | betree.Message.Delete => + do + let bindings1 ← betree.List.pop_front_back (U64 × U64) bindings0 + betree.Node.lookup_mut_in_bindings_back key bindings bindings1 + | betree.Message.Upsert s => + do + let (_, i) := hd + let v ← betree.upsert_update (Option.some i) s + let bindings1 ← betree.List.pop_front_back (U64 × U64) bindings0 + let bindings2 ← + betree.List.push_front (U64 × U64) bindings1 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings2 + else + match new_msg with + | betree.Message.Insert v => + do + let bindings1 ← + betree.List.push_front (U64 × U64) bindings0 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings1 + | betree.Message.Delete => + betree.Node.lookup_mut_in_bindings_back key bindings bindings0 + | betree.Message.Upsert s => + do + let v ← betree.upsert_update Option.none s + let bindings1 ← + betree.List.push_front (U64 × U64) bindings0 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings1 + +/- [betree_main::betree::Node::{5}::apply_messages_to_leaf]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def betree.Node.apply_messages_to_leaf + (bindings : betree.List (U64 × U64)) + (new_msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × U64)) + := + match new_msgs with + | betree.List.Cons new_msg new_msgs_tl => + do + let (i, m) := new_msg + let bindings0 ← betree.Node.apply_to_leaf bindings i m + betree.Node.apply_messages_to_leaf bindings0 new_msgs_tl + | betree.List.Nil => Result.ret bindings + +/- [betree_main::betree::Node::{5}::filter_messages_for_key]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def betree.Node.filter_messages_for_key + (key : U64) (msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) + := + match msgs with + | betree.List.Cons p l => + let (k, m) := p + if k = key + then + do + let msgs0 ← + betree.List.pop_front_back (U64 × betree.Message) (betree.List.Cons + (k, m) l) + betree.Node.filter_messages_for_key key msgs0 + else Result.ret (betree.List.Cons (k, m) l) + | betree.List.Nil => Result.ret betree.List.Nil + +/- [betree_main::betree::Node::{5}::lookup_first_message_after_key]: forward function -/ +divergent def betree.Node.lookup_first_message_after_key + (key : U64) (msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) + := + match msgs with + | betree.List.Cons p next_msgs => + let (k, m) := p + if k = key + then betree.Node.lookup_first_message_after_key key next_msgs + else Result.ret (betree.List.Cons (k, m) next_msgs) + | betree.List.Nil => Result.ret betree.List.Nil + +/- [betree_main::betree::Node::{5}::lookup_first_message_after_key]: backward function 0 -/ +divergent def betree.Node.lookup_first_message_after_key_back + (key : U64) (msgs : betree.List (U64 × betree.Message)) + (ret0 : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) + := + match msgs with + | betree.List.Cons p next_msgs => + let (k, m) := p + if k = key + then + do + let next_msgs0 ← + betree.Node.lookup_first_message_after_key_back key next_msgs ret0 + Result.ret (betree.List.Cons (k, m) next_msgs0) + else Result.ret ret0 + | betree.List.Nil => Result.ret ret0 + +/- [betree_main::betree::Node::{5}::apply_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def betree.Node.apply_to_internal + (msgs : betree.List (U64 × betree.Message)) (key : U64) + (new_msg : betree.Message) : + Result (betree.List (U64 × betree.Message)) + := + do + let msgs0 ← betree.Node.lookup_first_message_for_key key msgs + let b ← betree.List.head_has_key betree.Message msgs0 key + if b + then + match new_msg with + | betree.Message.Insert i => + do + let msgs1 ← betree.Node.filter_messages_for_key key msgs0 + let msgs2 ← + betree.List.push_front (U64 × betree.Message) msgs1 (key, + betree.Message.Insert i) + betree.Node.lookup_first_message_for_key_back key msgs msgs2 + | betree.Message.Delete => + do + let msgs1 ← betree.Node.filter_messages_for_key key msgs0 + let msgs2 ← + betree.List.push_front (U64 × betree.Message) msgs1 (key, + betree.Message.Delete) + betree.Node.lookup_first_message_for_key_back key msgs msgs2 + | betree.Message.Upsert s => + do + let p ← betree.List.hd (U64 × betree.Message) msgs0 + let (_, m) := p + match m with + | betree.Message.Insert prev => + do + let v ← betree.upsert_update (Option.some prev) s + let msgs1 ← + betree.List.pop_front_back (U64 × betree.Message) msgs0 + let msgs2 ← + betree.List.push_front (U64 × betree.Message) msgs1 (key, + betree.Message.Insert v) + betree.Node.lookup_first_message_for_key_back key msgs msgs2 + | betree.Message.Delete => + do + let v ← betree.upsert_update Option.none s + let msgs1 ← + betree.List.pop_front_back (U64 × betree.Message) msgs0 + let msgs2 ← + betree.List.push_front (U64 × betree.Message) msgs1 (key, + betree.Message.Insert v) + betree.Node.lookup_first_message_for_key_back key msgs msgs2 + | betree.Message.Upsert ufs => + do + let msgs1 ← + betree.Node.lookup_first_message_after_key key msgs0 + let msgs2 ← + betree.List.push_front (U64 × betree.Message) msgs1 (key, + betree.Message.Upsert s) + let msgs3 ← + betree.Node.lookup_first_message_after_key_back key msgs0 msgs2 + betree.Node.lookup_first_message_for_key_back key msgs msgs3 + else + do + let msgs1 ← + betree.List.push_front (U64 × betree.Message) msgs0 (key, new_msg) + betree.Node.lookup_first_message_for_key_back key msgs msgs1 + +/- [betree_main::betree::Node::{5}::apply_messages_to_internal]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def betree.Node.apply_messages_to_internal + (msgs : betree.List (U64 × betree.Message)) + (new_msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) + := + match new_msgs with + | betree.List.Cons new_msg new_msgs_tl => + do + let (i, m) := new_msg + let msgs0 ← betree.Node.apply_to_internal msgs i m + betree.Node.apply_messages_to_internal msgs0 new_msgs_tl + | betree.List.Nil => Result.ret msgs + +/- [betree_main::betree::Node::{5}::apply_messages]: forward function -/ +mutual divergent def betree.Node.apply_messages + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (msgs : betree.List (U64 × betree.Message)) (st : State) : + Result (State × Unit) + := + match self with + | betree.Node.Internal node => + do + let ⟨ i, i0, n, n0 ⟩ := node + let (st0, content) ← betree.load_internal_node i st + let content0 ← betree.Node.apply_messages_to_internal content msgs + let num_msgs ← betree.List.len (U64 × betree.Message) content0 + if num_msgs >= params.min_flush_size + then + do + let (st1, content1) ← + betree.Internal.flush (betree.Internal.mk i i0 n n0) params + node_id_cnt content0 st0 + let (node0, _) ← + betree.Internal.flush_back (betree.Internal.mk i i0 n n0) params + node_id_cnt content0 st0 + let ⟨ i1, _, _, _ ⟩ := node0 + let (st2, _) ← betree.store_internal_node i1 content1 st1 + Result.ret (st2, ()) + else + do + let (st1, _) ← betree.store_internal_node i content0 st0 + Result.ret (st1, ()) + | betree.Node.Leaf node => + do + let (st0, content) ← betree.load_leaf_node node.id st + let content0 ← betree.Node.apply_messages_to_leaf content msgs + let len ← betree.List.len (U64 × U64) content0 + let i ← (U64.ofInt 2) * params.split_size + if len >= i + then + do + let (st1, _) ← + betree.Leaf.split node content0 params node_id_cnt st0 + let (st2, _) ← betree.store_leaf_node node.id betree.List.Nil st1 + Result.ret (st2, ()) + else + do + let (st1, _) ← betree.store_leaf_node node.id content0 st0 + Result.ret (st1, ()) + +/- [betree_main::betree::Node::{5}::apply_messages]: backward function 0 -/ +divergent def betree.Node.apply_messages_back + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (msgs : betree.List (U64 × betree.Message)) (st : State) : + Result (betree.Node × betree.NodeIdCounter) + := + match self with + | betree.Node.Internal node => + do + let ⟨ i, i0, n, n0 ⟩ := node + let (st0, content) ← betree.load_internal_node i st + let content0 ← betree.Node.apply_messages_to_internal content msgs + let num_msgs ← betree.List.len (U64 × betree.Message) content0 + if num_msgs >= params.min_flush_size + then + do + let (st1, content1) ← + betree.Internal.flush (betree.Internal.mk i i0 n n0) params + node_id_cnt content0 st0 + let (node0, node_id_cnt0) ← + betree.Internal.flush_back (betree.Internal.mk i i0 n n0) params + node_id_cnt content0 st0 + let ⟨ i1, i2, n1, n2 ⟩ := node0 + let _ ← betree.store_internal_node i1 content1 st1 + Result.ret (betree.Node.Internal (betree.Internal.mk i1 i2 n1 n2), + node_id_cnt0) + else + do + let _ ← betree.store_internal_node i content0 st0 + Result.ret (betree.Node.Internal (betree.Internal.mk i i0 n n0), + node_id_cnt) + | betree.Node.Leaf node => + do + let (st0, content) ← betree.load_leaf_node node.id st + let content0 ← betree.Node.apply_messages_to_leaf content msgs + let len ← betree.List.len (U64 × U64) content0 + let i ← (U64.ofInt 2) * params.split_size + if len >= i + then + do + let (st1, new_node) ← + betree.Leaf.split node content0 params node_id_cnt st0 + let _ ← betree.store_leaf_node node.id betree.List.Nil st1 + let node_id_cnt0 ← + betree.Leaf.split_back node content0 params node_id_cnt st0 + Result.ret (betree.Node.Internal new_node, node_id_cnt0) + else + do + let _ ← betree.store_leaf_node node.id content0 st0 + Result.ret (betree.Node.Leaf { node with size := len }, node_id_cnt) + +/- [betree_main::betree::Internal::{4}::flush]: forward function -/ +divergent def betree.Internal.flush + (self : betree.Internal) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (content : betree.List (U64 × betree.Message)) (st : State) : + Result (State × (betree.List (U64 × betree.Message))) + := + do + let ⟨ _, i, n, n0 ⟩ := self + let p ← betree.List.partition_at_pivot betree.Message content i + let (msgs_left, msgs_right) := p + let len_left ← betree.List.len (U64 × betree.Message) msgs_left + if len_left >= params.min_flush_size + then + do + let (st0, _) ← + betree.Node.apply_messages n params node_id_cnt msgs_left st + let (_, node_id_cnt0) ← + betree.Node.apply_messages_back n params node_id_cnt msgs_left st + let len_right ← betree.List.len (U64 × betree.Message) msgs_right + if len_right >= params.min_flush_size + then + do + let (st1, _) ← + betree.Node.apply_messages n0 params node_id_cnt0 msgs_right st0 + let _ ← + betree.Node.apply_messages_back n0 params node_id_cnt0 msgs_right + st0 + Result.ret (st1, betree.List.Nil) + else Result.ret (st0, msgs_right) + else + do + let (st0, _) ← + betree.Node.apply_messages n0 params node_id_cnt msgs_right st + let _ ← + betree.Node.apply_messages_back n0 params node_id_cnt msgs_right st + Result.ret (st0, msgs_left) + +/- [betree_main::betree::Internal::{4}::flush]: backward function 0 -/ +divergent def betree.Internal.flush_back + (self : betree.Internal) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (content : betree.List (U64 × betree.Message)) (st : State) : + Result (betree.Internal × betree.NodeIdCounter) + := + do + let ⟨ i, i0, n, n0 ⟩ := self + let p ← betree.List.partition_at_pivot betree.Message content i0 + let (msgs_left, msgs_right) := p + let len_left ← betree.List.len (U64 × betree.Message) msgs_left + if len_left >= params.min_flush_size + then + do + let (st0, _) ← + betree.Node.apply_messages n params node_id_cnt msgs_left st + let (n1, node_id_cnt0) ← + betree.Node.apply_messages_back n params node_id_cnt msgs_left st + let len_right ← betree.List.len (U64 × betree.Message) msgs_right + if len_right >= params.min_flush_size + then + do + let (n2, node_id_cnt1) ← + betree.Node.apply_messages_back n0 params node_id_cnt0 msgs_right + st0 + Result.ret (betree.Internal.mk i i0 n1 n2, node_id_cnt1) + else Result.ret (betree.Internal.mk i i0 n1 n0, node_id_cnt0) + else + do + let (n1, node_id_cnt0) ← + betree.Node.apply_messages_back n0 params node_id_cnt msgs_right st + Result.ret (betree.Internal.mk i i0 n n1, node_id_cnt0) + +end + +/- [betree_main::betree::Node::{5}::apply]: forward function -/ +def betree.Node.apply + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) (key : U64) (new_msg : betree.Message) + (st : State) : + Result (State × Unit) + := + do + let l := betree.List.Nil + let (st0, _) ← + betree.Node.apply_messages self params node_id_cnt (betree.List.Cons + (key, new_msg) l) st + let _ ← + betree.Node.apply_messages_back self params node_id_cnt (betree.List.Cons + (key, new_msg) l) st + Result.ret (st0, ()) + +/- [betree_main::betree::Node::{5}::apply]: backward function 0 -/ +def betree.Node.apply_back + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) (key : U64) (new_msg : betree.Message) + (st : State) : + Result (betree.Node × betree.NodeIdCounter) + := + let l := betree.List.Nil + betree.Node.apply_messages_back self params node_id_cnt (betree.List.Cons + (key, new_msg) l) st + +/- [betree_main::betree::BeTree::{6}::new]: forward function -/ +def betree.BeTree.new + (min_flush_size : U64) (split_size : U64) (st : State) : + Result (State × betree.BeTree) + := + do + let node_id_cnt ← betree.NodeIdCounter.new + let id ← betree.NodeIdCounter.fresh_id node_id_cnt + let (st0, _) ← betree.store_leaf_node id betree.List.Nil st + let node_id_cnt0 ← betree.NodeIdCounter.fresh_id_back node_id_cnt + Result.ret (st0, + { + params := + { min_flush_size := min_flush_size, split_size := split_size }, + node_id_cnt := node_id_cnt0, + root := (betree.Node.Leaf { id := id, size := (U64.ofInt 0) }) + }) + +/- [betree_main::betree::BeTree::{6}::apply]: forward function -/ +def betree.BeTree.apply + (self : betree.BeTree) (key : U64) (msg : betree.Message) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + betree.Node.apply self.root self.params self.node_id_cnt key msg st + let _ ← + betree.Node.apply_back self.root self.params self.node_id_cnt key msg st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::apply]: backward function 0 -/ +def betree.BeTree.apply_back + (self : betree.BeTree) (key : U64) (msg : betree.Message) (st : State) : + Result betree.BeTree + := + do + let (n, nic) ← + betree.Node.apply_back self.root self.params self.node_id_cnt key msg st + Result.ret { self with node_id_cnt := nic, root := n } + +/- [betree_main::betree::BeTree::{6}::insert]: forward function -/ +def betree.BeTree.insert + (self : betree.BeTree) (key : U64) (value : U64) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + betree.BeTree.apply self key (betree.Message.Insert value) st + let _ ← + betree.BeTree.apply_back self key (betree.Message.Insert value) st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::insert]: backward function 0 -/ +def betree.BeTree.insert_back + (self : betree.BeTree) (key : U64) (value : U64) (st : State) : + Result betree.BeTree + := + betree.BeTree.apply_back self key (betree.Message.Insert value) st + +/- [betree_main::betree::BeTree::{6}::delete]: forward function -/ +def betree.BeTree.delete + (self : betree.BeTree) (key : U64) (st : State) : Result (State × Unit) := + do + let (st0, _) ← betree.BeTree.apply self key betree.Message.Delete st + let _ ← betree.BeTree.apply_back self key betree.Message.Delete st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::delete]: backward function 0 -/ +def betree.BeTree.delete_back + (self : betree.BeTree) (key : U64) (st : State) : Result betree.BeTree := + betree.BeTree.apply_back self key betree.Message.Delete st + +/- [betree_main::betree::BeTree::{6}::upsert]: forward function -/ +def betree.BeTree.upsert + (self : betree.BeTree) (key : U64) (upd : betree.UpsertFunState) (st : State) + : + Result (State × Unit) + := + do + let (st0, _) ← + betree.BeTree.apply self key (betree.Message.Upsert upd) st + let _ ← betree.BeTree.apply_back self key (betree.Message.Upsert upd) st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::upsert]: backward function 0 -/ +def betree.BeTree.upsert_back + (self : betree.BeTree) (key : U64) (upd : betree.UpsertFunState) (st : State) + : + Result betree.BeTree + := + betree.BeTree.apply_back self key (betree.Message.Upsert upd) st + +/- [betree_main::betree::BeTree::{6}::lookup]: forward function -/ +def betree.BeTree.lookup + (self : betree.BeTree) (key : U64) (st : State) : + Result (State × (Option U64)) + := + betree.Node.lookup self.root key st + +/- [betree_main::betree::BeTree::{6}::lookup]: backward function 0 -/ +def betree.BeTree.lookup_back + (self : betree.BeTree) (key : U64) (st : State) : Result betree.BeTree := + do + let n ← betree.Node.lookup_back self.root key st + Result.ret { self with root := n } + +/- [betree_main::main]: forward function -/ +def main : Result Unit := + Result.ret () + +/- Unit test for [betree_main::main] -/ +#assert (main == .ret ()) + +end betree_main diff --git a/tests/lean/BetreeMain/FunsExternal.lean b/tests/lean/BetreeMain/FunsExternal.lean new file mode 100644 index 00000000..71d26da4 --- /dev/null +++ b/tests/lean/BetreeMain/FunsExternal.lean @@ -0,0 +1,35 @@ +-- [betree_main]: external functions. +import Base +import BetreeMain.Types +open Primitives +open betree_main + +-- TODO: fill those bodies + +/- [betree_main::betree_utils::load_internal_node] -/ +def betree_utils.load_internal_node + : + U64 → State → Result (State × (betree.List (U64 × betree.Message))) := + fun _ _ => .fail .panic + +/- [betree_main::betree_utils::store_internal_node] -/ +def betree_utils.store_internal_node + : + U64 → betree.List (U64 × betree.Message) → State → Result (State + × Unit) := + fun _ _ _ => .fail .panic + +/- [betree_main::betree_utils::load_leaf_node] -/ +def betree_utils.load_leaf_node + : U64 → State → Result (State × (betree.List (U64 × U64))) := + fun _ _ => .fail .panic + +/- [betree_main::betree_utils::store_leaf_node] -/ +def betree_utils.store_leaf_node + : U64 → betree.List (U64 × U64) → State → Result (State × Unit) := + fun _ _ _ => .fail .panic + +/- [core::option::Option::{0}::unwrap] -/ +def core.option.Option.unwrap + (T : Type) : Option T → State → Result (State × T) := + fun _ _ => .fail .panic diff --git a/tests/lean/BetreeMain/FunsExternal_Template.lean b/tests/lean/BetreeMain/FunsExternal_Template.lean new file mode 100644 index 00000000..430d2dda --- /dev/null +++ b/tests/lean/BetreeMain/FunsExternal_Template.lean @@ -0,0 +1,30 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import BetreeMain.Types +open Primitives +open betree_main + +/- [betree_main::betree_utils::load_internal_node]: forward function -/ +axiom betree_utils.load_internal_node + : U64 → State → Result (State × (betree.List (U64 × betree.Message))) + +/- [betree_main::betree_utils::store_internal_node]: forward function -/ +axiom betree_utils.store_internal_node + : + U64 → betree.List (U64 × betree.Message) → State → Result (State × + Unit) + +/- [betree_main::betree_utils::load_leaf_node]: forward function -/ +axiom betree_utils.load_leaf_node + : U64 → State → Result (State × (betree.List (U64 × U64))) + +/- [betree_main::betree_utils::store_leaf_node]: forward function -/ +axiom betree_utils.store_leaf_node + : U64 → betree.List (U64 × U64) → State → Result (State × Unit) + +/- [core::option::Option::{0}::unwrap]: forward function -/ +axiom core.option.Option.unwrap + (T : Type) : Option T → State → Result (State × T) + diff --git a/tests/lean/BetreeMain/Types.lean b/tests/lean/BetreeMain/Types.lean new file mode 100644 index 00000000..783ade64 --- /dev/null +++ b/tests/lean/BetreeMain/Types.lean @@ -0,0 +1,59 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: type definitions +import Base +open Primitives +namespace betree_main + +/- [betree_main::betree::List] -/ +inductive betree.List (T : Type) := +| Cons : T → betree.List T → betree.List T +| Nil : betree.List T + +/- [betree_main::betree::UpsertFunState] -/ +inductive betree.UpsertFunState := +| Add : U64 → betree.UpsertFunState +| Sub : U64 → betree.UpsertFunState + +/- [betree_main::betree::Message] -/ +inductive betree.Message := +| Insert : U64 → betree.Message +| Delete : betree.Message +| Upsert : betree.UpsertFunState → betree.Message + +/- [betree_main::betree::Leaf] -/ +structure betree.Leaf where + id : U64 + size : U64 + +mutual + +/- [betree_main::betree::Node] -/ +inductive betree.Node := +| Internal : betree.Internal → betree.Node +| Leaf : betree.Leaf → betree.Node + +/- [betree_main::betree::Internal] -/ +inductive betree.Internal := +| mk : U64 → U64 → betree.Node → betree.Node → betree.Internal + +end + +/- [betree_main::betree::Params] -/ +structure betree.Params where + min_flush_size : U64 + split_size : U64 + +/- [betree_main::betree::NodeIdCounter] -/ +structure betree.NodeIdCounter where + next_node_id : U64 + +/- [betree_main::betree::BeTree] -/ +structure betree.BeTree where + params : betree.Params + node_id_cnt : betree.NodeIdCounter + root : betree.Node + +/- The state type used in the state-error monad -/ +axiom State : Type + +end betree_main diff --git a/tests/lean/Constants.lean b/tests/lean/Constants.lean new file mode 100644 index 00000000..4a5a7b8f --- /dev/null +++ b/tests/lean/Constants.lean @@ -0,0 +1,128 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [constants] +import Base +open Primitives +namespace constants + +/- [constants::X0] -/ +def x0_body : Result U32 := Result.ret (U32.ofInt 0) +def x0_c : U32 := eval_global x0_body (by simp) + +/- [core::num::u32::{9}::MAX] -/ +def core_num_u32_max_body : Result U32 := Result.ret (U32.ofInt 4294967295) +def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) + +/- [constants::X1] -/ +def x1_body : Result U32 := Result.ret core_num_u32_max_c +def x1_c : U32 := eval_global x1_body (by simp) + +/- [constants::X2] -/ +def x2_body : Result U32 := Result.ret (U32.ofInt 3) +def x2_c : U32 := eval_global x2_body (by simp) + +/- [constants::incr]: forward function -/ +def incr (n : U32) : Result U32 := + n + (U32.ofInt 1) + +/- [constants::X3] -/ +def x3_body : Result U32 := incr (U32.ofInt 32) +def x3_c : U32 := eval_global x3_body (by simp) + +/- [constants::mk_pair0]: forward function -/ +def mk_pair0 (x : U32) (y : U32) : Result (U32 × U32) := + Result.ret (x, y) + +/- [constants::Pair] -/ +structure Pair (T1 T2 : Type) where + x : T1 + y : T2 + +/- [constants::mk_pair1]: forward function -/ +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_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_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_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_c : Pair U32 U32 := eval_global p3_body (by simp) + +/- [constants::Wrap] -/ +structure Wrap (T : Type) where + val : T + +/- [constants::Wrap::{0}::new]: forward function -/ +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_c : Wrap I32 := eval_global y_body (by simp) + +/- [constants::unwrap_y]: forward function -/ +def unwrap_y : Result I32 := + Result.ret y_c.val + +/- [constants::YVAL] -/ +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_c : I32 := eval_global get_z1_z1_body (by simp) + +/- [constants::get_z1]: forward function -/ +def get_z1 : Result I32 := + Result.ret get_z1_z1_c + +/- [constants::add]: forward function -/ +def add (a : I32) (b : I32) : Result I32 := + a + b + +/- [constants::Q1] -/ +def q1_body : Result I32 := Result.ret (I32.ofInt 5) +def q1_c : I32 := eval_global q1_body (by simp) + +/- [constants::Q2] -/ +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_c : I32 := eval_global q3_body (by simp) + +/- [constants::get_z2]: forward function -/ +def get_z2 : Result I32 := + do + let i ← get_z1 + let i0 ← add i q3_c + add q1_c i0 + +/- [constants::S1] -/ +def s1_body : Result U32 := Result.ret (U32.ofInt 6) +def s1_c : U32 := eval_global s1_body (by simp) + +/- [constants::S2] -/ +def s2_body : Result U32 := incr s1_c +def s2_c : U32 := eval_global s2_body (by simp) + +/- [constants::S3] -/ +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_c : Pair U32 U32 := eval_global s4_body (by simp) + +end constants diff --git a/tests/lean/misc-external/External.lean b/tests/lean/External.lean index b95db309..b95db309 100644 --- a/tests/lean/misc-external/External.lean +++ b/tests/lean/External.lean diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean new file mode 100644 index 00000000..674aaebd --- /dev/null +++ b/tests/lean/External/Funs.lean @@ -0,0 +1,88 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: function definitions +import Base +import External.Types +import External.FunsExternal +open Primitives +namespace external + +/- [external::swap]: forward function -/ +def swap (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := + do + let (st0, _) ← core.mem.swap T x y st + let (st1, _) ← core.mem.swap_back0 T x y st st0 + let (st2, _) ← core.mem.swap_back1 T x y st st1 + Result.ret (st2, ()) + +/- [external::swap]: backward function 0 -/ +def swap_back + (T : Type) (x : T) (y : T) (st : State) (st0 : State) : + Result (State × (T × T)) + := + do + let (st1, _) ← core.mem.swap T x y st + let (st2, x0) ← core.mem.swap_back0 T x y st st1 + let (_, y0) ← core.mem.swap_back1 T x y st st2 + Result.ret (st0, (x0, y0)) + +/- [external::test_new_non_zero_u32]: forward function -/ +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 + +/- [external::test_vec]: forward function -/ +def test_vec : Result Unit := + do + let v := Vec.new U32 + let _ ← Vec.push U32 v (U32.ofInt 0) + Result.ret () + +/- Unit test for [external::test_vec] -/ +#assert (test_vec == .ret ()) + +/- [external::custom_swap]: forward function -/ +def custom_swap + (T : Type) (x : T) (y : T) (st : State) : Result (State × T) := + do + let (st0, _) ← core.mem.swap T x y st + let (st1, x0) ← core.mem.swap_back0 T x y st st0 + let (st2, _) ← core.mem.swap_back1 T x y st st1 + Result.ret (st2, x0) + +/- [external::custom_swap]: backward function 0 -/ +def custom_swap_back + (T : Type) (x : T) (y : T) (st : State) (ret0 : T) (st0 : State) : + Result (State × (T × T)) + := + do + let (st1, _) ← core.mem.swap T x y st + let (st2, _) ← core.mem.swap_back0 T x y st st1 + let (_, y0) ← core.mem.swap_back1 T x y st st2 + Result.ret (st0, (ret0, y0)) + +/- [external::test_custom_swap]: forward function -/ +def test_custom_swap + (x : U32) (y : U32) (st : State) : Result (State × Unit) := + do + let (st0, _) ← custom_swap U32 x y st + Result.ret (st0, ()) + +/- [external::test_custom_swap]: backward function 0 -/ +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 + +/- [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) + then Result.fail Error.panic + else Result.ret (st1, x0) + +end external diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean new file mode 100644 index 00000000..aae11ba1 --- /dev/null +++ b/tests/lean/External/FunsExternal.lean @@ -0,0 +1,33 @@ +-- [external]: templates for the external functions. +import Base +import External.Types +open Primitives +open external + +-- TODO: fill those bodies + +/- [core::mem::swap] -/ +def core.mem.swap + (T : Type) : T → T → State → Result (State × Unit) := + fun _x _y s => .ret (s, ()) + +/- [core::mem::swap] -/ +def core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) := + fun _x y _s0 s1 => .ret (s1, y) + +/- [core::mem::swap] -/ +def core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) := + fun x _y _s0 s1 => .ret (s1, x) + +/- [core::num::nonzero::NonZeroU32::{14}::new] -/ +def core.num.nonzero.NonZeroU32.new + : + U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) := + fun _ _ => .fail .panic + +/- [core::option::Option::{0}::unwrap] -/ +def core.option.Option.unwrap + (T : Type) : Option T → State → Result (State × T) := + fun _ _ => .fail .panic diff --git a/tests/lean/External/FunsExternal_Template.lean b/tests/lean/External/FunsExternal_Template.lean new file mode 100644 index 00000000..c8bc397f --- /dev/null +++ b/tests/lean/External/FunsExternal_Template.lean @@ -0,0 +1,27 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import External.Types +open Primitives +open external + +/- [core::mem::swap]: forward function -/ +axiom core.mem.swap (T : Type) : T → T → State → Result (State × Unit) + +/- [core::mem::swap]: backward function 0 -/ +axiom core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) + +/- [core::mem::swap]: backward function 1 -/ +axiom core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) + +/- [core::num::nonzero::NonZeroU32::{14}::new]: forward function -/ +axiom core.num.nonzero.NonZeroU32.new + : U32 → State → Result (State × (Option core.num.nonzero.NonZeroU32)) + +/- [core::option::Option::{0}::unwrap]: forward function -/ +axiom core.option.Option.unwrap + (T : Type) : Option T → State → Result (State × T) + diff --git a/tests/lean/External/Opaque.lean b/tests/lean/External/Opaque.lean new file mode 100644 index 00000000..d0297523 --- /dev/null +++ b/tests/lean/External/Opaque.lean @@ -0,0 +1,32 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: opaque function definitions +import Base +import External.Types +open Primitives + +namespace external + +structure OpaqueDefs where + + /- [core::mem::swap] -/ + core.mem.swap_fwd (T : Type) : T → T → State → Result (State × Unit) + + /- [core::mem::swap] -/ + core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) + + /- [core::mem::swap] -/ + core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) + + /- [core::num::nonzero::NonZeroU32::{14}::new] -/ + core.num.nonzero.NonZeroU32.new_fwd + : + U32 → State → Result (State × (Option + core_num_nonzero_non_zero_u32_t)) + + /- [core::option::Option::{0}::unwrap] -/ + core.option.Option.unwrap_fwd + (T : Type) : Option T → State → Result (State × T) + +end external diff --git a/tests/lean/misc-external/External/Types.lean b/tests/lean/External/Types.lean index ed1842be..ba984e2a 100644 --- a/tests/lean/misc-external/External/Types.lean +++ b/tests/lean/External/Types.lean @@ -1,10 +1,13 @@ -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS -- [external]: type definitions -import Base.Primitives +import Base +open Primitives +namespace external /- [core::num::nonzero::NonZeroU32] -/ -axiom core_num_nonzero_non_zero_u32_t : Type +axiom core.num.nonzero.NonZeroU32 : Type /- The state type used in the state-error monad -/ axiom State : Type +end external diff --git a/tests/lean/Hashmap.lean b/tests/lean/Hashmap.lean new file mode 100644 index 00000000..35034754 --- /dev/null +++ b/tests/lean/Hashmap.lean @@ -0,0 +1,2 @@ +import Hashmap.Funs +import Hashmap.Properties diff --git a/tests/lean/Hashmap/Funs.lean b/tests/lean/Hashmap/Funs.lean new file mode 100644 index 00000000..870693b5 --- /dev/null +++ b/tests/lean/Hashmap/Funs.lean @@ -0,0 +1,449 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [hashmap]: function definitions +import Base +import Hashmap.Types +open Primitives +namespace hashmap + +/- [hashmap::hash_key]: forward function -/ +def hash_key (k : Usize) : Result Usize := + Result.ret k + +/- [hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function -/ +divergent def HashMap.allocate_slots_loop + (T : Type) (slots : Vec (List T)) (n : Usize) : Result (Vec (List T)) := + if n > (Usize.ofInt 0) + then + do + let slots0 ← Vec.push (List T) slots List.Nil + let n0 ← n - (Usize.ofInt 1) + HashMap.allocate_slots_loop T slots0 n0 + else Result.ret slots + +/- [hashmap::HashMap::{0}::allocate_slots]: forward function -/ +def HashMap.allocate_slots + (T : Type) (slots : Vec (List T)) (n : Usize) : Result (Vec (List T)) := + HashMap.allocate_slots_loop T slots n + +/- [hashmap::HashMap::{0}::new_with_capacity]: forward function -/ +def HashMap.new_with_capacity + (T : Type) (capacity : Usize) (max_load_dividend : Usize) + (max_load_divisor : Usize) : + Result (HashMap T) + := + do + let v := Vec.new (List T) + let slots ← HashMap.allocate_slots T v capacity + let i ← capacity * max_load_dividend + let i0 ← i / max_load_divisor + Result.ret + { + num_entries := (Usize.ofInt 0), + max_load_factor := (max_load_dividend, max_load_divisor), + max_load := i0, + slots := slots + } + +/- [hashmap::HashMap::{0}::new]: forward function -/ +def HashMap.new (T : Type) : Result (HashMap T) := + HashMap.new_with_capacity T (Usize.ofInt 32) (Usize.ofInt 4) (Usize.ofInt 5) + +/- [hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def HashMap.clear_loop + (T : Type) (slots : Vec (List T)) (i : Usize) : Result (Vec (List T)) := + let i0 := Vec.len (List T) slots + if i < i0 + then + do + let i1 ← i + (Usize.ofInt 1) + let slots0 ← Vec.index_mut_back (List T) slots i List.Nil + HashMap.clear_loop T slots0 i1 + else Result.ret slots + +/- [hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def HashMap.clear (T : Type) (self : HashMap T) : Result (HashMap T) := + do + let v ← HashMap.clear_loop T self.slots (Usize.ofInt 0) + Result.ret { self with num_entries := (Usize.ofInt 0), slots := v } + +/- [hashmap::HashMap::{0}::len]: forward function -/ +def HashMap.len (T : Type) (self : HashMap T) : Result Usize := + Result.ret self.num_entries + +/- [hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function -/ +divergent def HashMap.insert_in_list_loop + (T : Type) (key : Usize) (value : T) (ls : List T) : Result Bool := + match ls with + | List.Cons ckey cvalue tl => + if ckey = key + then Result.ret false + else HashMap.insert_in_list_loop T key value tl + | List.Nil => Result.ret true + +/- [hashmap::HashMap::{0}::insert_in_list]: forward function -/ +def HashMap.insert_in_list + (T : Type) (key : Usize) (value : T) (ls : List T) : Result Bool := + HashMap.insert_in_list_loop T key value ls + +/- [hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 -/ +divergent def HashMap.insert_in_list_loop_back + (T : Type) (key : Usize) (value : T) (ls : List T) : Result (List T) := + match ls with + | List.Cons ckey cvalue tl => + if ckey = key + then Result.ret (List.Cons ckey value tl) + else + do + let tl0 ← HashMap.insert_in_list_loop_back T key value tl + Result.ret (List.Cons ckey cvalue tl0) + | List.Nil => let l := List.Nil + Result.ret (List.Cons key value l) + +/- [hashmap::HashMap::{0}::insert_in_list]: backward function 0 -/ +def HashMap.insert_in_list_back + (T : Type) (key : Usize) (value : T) (ls : List T) : Result (List T) := + HashMap.insert_in_list_loop_back T key value ls + +/- [hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def HashMap.insert_no_resize + (T : Type) (self : HashMap T) (key : Usize) (value : T) : + Result (HashMap T) + := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (List T) self.slots hash_mod + let inserted ← HashMap.insert_in_list T key value l + if inserted + then + do + let i0 ← self.num_entries + (Usize.ofInt 1) + let l0 ← HashMap.insert_in_list_back T key value l + let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 + Result.ret { self with num_entries := i0, slots := v } + else + do + let l0 ← HashMap.insert_in_list_back T key value l + let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 + Result.ret { self with slots := v } + +/- [core::num::u32::{9}::MAX] -/ +def core_num_u32_max_body : Result U32 := Result.ret (U32.ofInt 4294967295) +def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) + +/- [hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def HashMap.move_elements_from_list_loop + (T : Type) (ntable : HashMap T) (ls : List T) : Result (HashMap T) := + match ls with + | List.Cons k v tl => + do + let ntable0 ← HashMap.insert_no_resize T ntable k v + HashMap.move_elements_from_list_loop T ntable0 tl + | List.Nil => Result.ret ntable + +/- [hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def HashMap.move_elements_from_list + (T : Type) (ntable : HashMap T) (ls : List T) : Result (HashMap T) := + HashMap.move_elements_from_list_loop T ntable ls + +/- [hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def HashMap.move_elements_loop + (T : Type) (ntable : HashMap T) (slots : Vec (List T)) (i : Usize) : + Result ((HashMap T) × (Vec (List T))) + := + let i0 := Vec.len (List T) slots + if i < i0 + then + do + let l ← Vec.index_mut (List T) slots i + let ls := mem.replace (List T) l List.Nil + let ntable0 ← HashMap.move_elements_from_list T ntable ls + let i1 ← i + (Usize.ofInt 1) + let l0 := mem.replace_back (List T) l List.Nil + let slots0 ← Vec.index_mut_back (List T) slots i l0 + HashMap.move_elements_loop T ntable0 slots0 i1 + else Result.ret (ntable, slots) + +/- [hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def HashMap.move_elements + (T : Type) (ntable : HashMap T) (slots : Vec (List T)) (i : Usize) : + Result ((HashMap T) × (Vec (List T))) + := + HashMap.move_elements_loop T ntable slots i + +/- [hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def HashMap.try_resize (T : Type) (self : HashMap T) : Result (HashMap T) := + do + let max_usize ← Scalar.cast .Usize core_num_u32_max_c + let capacity := Vec.len (List T) self.slots + let n1 ← max_usize / (Usize.ofInt 2) + let (i, i0) := self.max_load_factor + let i1 ← n1 / i + if capacity <= i1 + then + do + let i2 ← capacity * (Usize.ofInt 2) + let ntable ← HashMap.new_with_capacity T i2 i i0 + let (ntable0, _) ← + HashMap.move_elements T ntable self.slots (Usize.ofInt 0) + Result.ret + { + ntable0 + with + num_entries := self.num_entries, max_load_factor := (i, i0) + } + else Result.ret { self with max_load_factor := (i, i0) } + +/- [hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def HashMap.insert + (T : Type) (self : HashMap T) (key : Usize) (value : T) : + Result (HashMap T) + := + do + let self0 ← HashMap.insert_no_resize T self key value + let i ← HashMap.len T self0 + if i > self0.max_load + then HashMap.try_resize T self0 + else Result.ret self0 + +/- [hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function -/ +divergent def HashMap.contains_key_in_list_loop + (T : Type) (key : Usize) (ls : List T) : Result Bool := + match ls with + | List.Cons ckey t tl => + if ckey = key + then Result.ret true + else HashMap.contains_key_in_list_loop T key tl + | List.Nil => Result.ret false + +/- [hashmap::HashMap::{0}::contains_key_in_list]: forward function -/ +def HashMap.contains_key_in_list + (T : Type) (key : Usize) (ls : List T) : Result Bool := + HashMap.contains_key_in_list_loop T key ls + +/- [hashmap::HashMap::{0}::contains_key]: forward function -/ +def HashMap.contains_key + (T : Type) (self : HashMap T) (key : Usize) : Result Bool := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index (List T) self.slots hash_mod + HashMap.contains_key_in_list T key l + +/- [hashmap::HashMap::{0}::get_in_list]: loop 0: forward function -/ +divergent def HashMap.get_in_list_loop + (T : Type) (key : Usize) (ls : List T) : Result T := + match ls with + | List.Cons ckey cvalue tl => + if ckey = key + then Result.ret cvalue + else HashMap.get_in_list_loop T key tl + | List.Nil => Result.fail Error.panic + +/- [hashmap::HashMap::{0}::get_in_list]: forward function -/ +def HashMap.get_in_list (T : Type) (key : Usize) (ls : List T) : Result T := + HashMap.get_in_list_loop T key ls + +/- [hashmap::HashMap::{0}::get]: forward function -/ +def HashMap.get (T : Type) (self : HashMap T) (key : Usize) : Result T := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index (List T) self.slots hash_mod + HashMap.get_in_list T key l + +/- [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function -/ +divergent def HashMap.get_mut_in_list_loop + (T : Type) (ls : List T) (key : Usize) : Result T := + match ls with + | List.Cons ckey cvalue tl => + if ckey = key + then Result.ret cvalue + else HashMap.get_mut_in_list_loop T tl key + | List.Nil => Result.fail Error.panic + +/- [hashmap::HashMap::{0}::get_mut_in_list]: forward function -/ +def HashMap.get_mut_in_list + (T : Type) (ls : List T) (key : Usize) : Result T := + HashMap.get_mut_in_list_loop T ls key + +/- [hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 -/ +divergent def HashMap.get_mut_in_list_loop_back + (T : Type) (ls : List T) (key : Usize) (ret0 : T) : Result (List T) := + match ls with + | List.Cons ckey cvalue tl => + if ckey = key + then Result.ret (List.Cons ckey ret0 tl) + else + do + let tl0 ← HashMap.get_mut_in_list_loop_back T tl key ret0 + Result.ret (List.Cons ckey cvalue tl0) + | List.Nil => Result.fail Error.panic + +/- [hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 -/ +def HashMap.get_mut_in_list_back + (T : Type) (ls : List T) (key : Usize) (ret0 : T) : Result (List T) := + HashMap.get_mut_in_list_loop_back T ls key ret0 + +/- [hashmap::HashMap::{0}::get_mut]: forward function -/ +def HashMap.get_mut (T : Type) (self : HashMap T) (key : Usize) : Result T := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (List T) self.slots hash_mod + HashMap.get_mut_in_list T l key + +/- [hashmap::HashMap::{0}::get_mut]: backward function 0 -/ +def HashMap.get_mut_back + (T : Type) (self : HashMap T) (key : Usize) (ret0 : T) : + Result (HashMap T) + := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (List T) self.slots hash_mod + let l0 ← HashMap.get_mut_in_list_back T l key ret0 + let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 + Result.ret { self with slots := v } + +/- [hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function -/ +divergent def HashMap.remove_from_list_loop + (T : Type) (key : Usize) (ls : List T) : Result (Option T) := + match ls with + | List.Cons ckey t tl => + if ckey = key + then + let mv_ls := mem.replace (List T) (List.Cons ckey t tl) List.Nil + match mv_ls with + | List.Cons i cvalue tl0 => Result.ret (Option.some cvalue) + | List.Nil => Result.fail Error.panic + else HashMap.remove_from_list_loop T key tl + | List.Nil => Result.ret Option.none + +/- [hashmap::HashMap::{0}::remove_from_list]: forward function -/ +def HashMap.remove_from_list + (T : Type) (key : Usize) (ls : List T) : Result (Option T) := + HashMap.remove_from_list_loop T key ls + +/- [hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 -/ +divergent def HashMap.remove_from_list_loop_back + (T : Type) (key : Usize) (ls : List T) : Result (List T) := + match ls with + | List.Cons ckey t tl => + if ckey = key + then + let mv_ls := mem.replace (List T) (List.Cons ckey t tl) List.Nil + match mv_ls with + | List.Cons i cvalue tl0 => Result.ret tl0 + | List.Nil => Result.fail Error.panic + else + do + let tl0 ← HashMap.remove_from_list_loop_back T key tl + Result.ret (List.Cons ckey t tl0) + | List.Nil => Result.ret List.Nil + +/- [hashmap::HashMap::{0}::remove_from_list]: backward function 1 -/ +def HashMap.remove_from_list_back + (T : Type) (key : Usize) (ls : List T) : Result (List T) := + HashMap.remove_from_list_loop_back T key ls + +/- [hashmap::HashMap::{0}::remove]: forward function -/ +def HashMap.remove + (T : Type) (self : HashMap T) (key : Usize) : Result (Option T) := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (List T) self.slots hash_mod + let x ← HashMap.remove_from_list T key l + match x with + | Option.none => Result.ret Option.none + | Option.some x0 => + do + let _ ← self.num_entries - (Usize.ofInt 1) + Result.ret (Option.some x0) + +/- [hashmap::HashMap::{0}::remove]: backward function 0 -/ +def HashMap.remove_back + (T : Type) (self : HashMap T) (key : Usize) : Result (HashMap T) := + do + let hash ← hash_key key + let i := Vec.len (List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (List T) self.slots hash_mod + let x ← HashMap.remove_from_list T key l + match x with + | Option.none => + do + let l0 ← HashMap.remove_from_list_back T key l + let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 + Result.ret { self with slots := v } + | Option.some x0 => + do + let i0 ← self.num_entries - (Usize.ofInt 1) + let l0 ← HashMap.remove_from_list_back T key l + let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 + Result.ret { self with num_entries := i0, slots := v } + +/- [hashmap::test1]: forward function -/ +def test1 : Result Unit := + do + let hm ← HashMap.new U64 + let hm0 ← HashMap.insert U64 hm (Usize.ofInt 0) (U64.ofInt 42) + let hm1 ← HashMap.insert U64 hm0 (Usize.ofInt 128) (U64.ofInt 18) + let hm2 ← HashMap.insert U64 hm1 (Usize.ofInt 1024) (U64.ofInt 138) + let hm3 ← HashMap.insert U64 hm2 (Usize.ofInt 1056) (U64.ofInt 256) + let i ← HashMap.get U64 hm3 (Usize.ofInt 128) + if not (i = (U64.ofInt 18)) + then Result.fail Error.panic + else + do + let hm4 ← + HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024) (U64.ofInt 56) + let i0 ← HashMap.get U64 hm4 (Usize.ofInt 1024) + if not (i0 = (U64.ofInt 56)) + then Result.fail Error.panic + else + do + let x ← HashMap.remove U64 hm4 (Usize.ofInt 1024) + match x with + | Option.none => Result.fail Error.panic + | Option.some x0 => + if not (x0 = (U64.ofInt 56)) + then Result.fail Error.panic + else + do + let hm5 ← HashMap.remove_back U64 hm4 (Usize.ofInt 1024) + let i1 ← HashMap.get U64 hm5 (Usize.ofInt 0) + if not (i1 = (U64.ofInt 42)) + then Result.fail Error.panic + else + do + let i2 ← HashMap.get U64 hm5 (Usize.ofInt 128) + if not (i2 = (U64.ofInt 18)) + then Result.fail Error.panic + else + do + let i3 ← HashMap.get U64 hm5 (Usize.ofInt 1056) + if not (i3 = (U64.ofInt 256)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [hashmap::test1] -/ +#assert (test1 == .ret ()) + +end hashmap diff --git a/tests/lean/Hashmap/Properties.lean b/tests/lean/Hashmap/Properties.lean new file mode 100644 index 00000000..3652f608 --- /dev/null +++ b/tests/lean/Hashmap/Properties.lean @@ -0,0 +1,439 @@ +import Hashmap.Funs + +open Primitives +open Result + +namespace List + +-- TODO: we don't want to use the original List.lookup because it uses BEq +-- TODO: rewrite rule: match x == y with ... -> if x = y then ... else ... ? (actually doesn't work because of sugar) +-- TODO: move? +@[simp] +def lookup' {α : Type} (ls: _root_.List (Usize × α)) (key: Usize) : Option α := + match ls with + | [] => none + | (k, x) :: tl => if k = key then some x else lookup' tl key + +end List + +namespace hashmap + +namespace List + +def v {α : Type} (ls: List α) : _root_.List (Usize × α) := + match ls with + | Nil => [] + | Cons k x tl => (k, x) :: v tl + +@[simp] theorem v_nil (α : Type) : (Nil : List α).v = [] := by rfl +@[simp] theorem v_cons {α : Type} k x (tl: List α) : (Cons k x tl).v = (k, x) :: v tl := by rfl + +@[simp] +abbrev lookup {α : Type} (ls: List α) (key: Usize) : Option α := + ls.v.lookup' key + +@[simp] +abbrev len {α : Type} (ls : List α) : Int := ls.v.len + +end List + +namespace HashMap + +abbrev Core.List := _root_.List + +namespace List + +end List + +-- TODO: move +@[simp] theorem neq_imp_nbeq [BEq α] [LawfulBEq α] (x y : α) (heq : ¬ x = y) : ¬ x == y := by simp [*] +@[simp] theorem neq_imp_nbeq_rev [BEq α] [LawfulBEq α] (x y : α) (heq : ¬ x = y) : ¬ y == x := by simp [*] + +-- TODO: move +-- TODO: this doesn't work because of sugar +theorem match_lawful_beq [BEq α] [LawfulBEq α] [DecidableEq α] (x y : α) : + (x == y) = (if x = y then true else false) := by + split <;> simp_all + +@[pspec] +theorem insert_in_list_spec0 {α : Type} (key: Usize) (value: α) (ls: List α) : + ∃ b, + insert_in_list α key value ls = ret b ∧ + (b ↔ ls.lookup key = none) + := match ls with + | .Nil => by simp [insert_in_list, insert_in_list_loop] + | .Cons k v tl => + if h: k = key then -- TODO: The order of k/key matters + by + simp [insert_in_list] + rw [insert_in_list_loop] + simp [h] + else + have ⟨ b, hi ⟩ := insert_in_list_spec0 key value tl + by + exists b + simp [insert_in_list] + rw [insert_in_list_loop] -- TODO: Using simp leads to infinite recursion + simp only [insert_in_list] at hi + simp [*] + +-- Variation: use progress +theorem insert_in_list_spec1 {α : Type} (key: Usize) (value: α) (ls: List α) : + ∃ b, + insert_in_list α key value ls = ret b ∧ + (b ↔ ls.lookup key = none) + := match ls with + | .Nil => by simp [insert_in_list, insert_in_list_loop] + | .Cons k v tl => + if h: k = key then -- TODO: The order of k/key matters + by + simp [insert_in_list] + rw [insert_in_list_loop] + simp [h] + else + by + simp only [insert_in_list] + rw [insert_in_list_loop] + conv => rhs; ext; simp [*] + progress keep heq as ⟨ b, hi ⟩ + simp only [insert_in_list] at heq + exists b + +-- Variation: use tactics from the beginning +theorem insert_in_list_spec2 {α : Type} (key: Usize) (value: α) (ls: List α) : + ∃ b, + insert_in_list α key value ls = ret b ∧ + (b ↔ (ls.lookup key = none)) + := by + induction ls + case Nil => simp [insert_in_list, insert_in_list_loop] + case Cons k v tl ih => + simp only [insert_in_list] + rw [insert_in_list_loop] + simp only + if h: k = key then + simp [h] + else + conv => rhs; ext; left; simp [h] -- TODO: Simplify + simp only [insert_in_list] at ih; + -- TODO: give the possibility of using underscores + progress as ⟨ b, h ⟩ + simp [*] + +def distinct_keys (ls : Core.List (Usize × α)) := ls.pairwise_rel (λ x y => x.fst ≠ y.fst) + +def hash_mod_key (k : Usize) (l : Int) : Int := + match hash_key k with + | .ret k => k.val % l + | _ => 0 + +@[simp] +theorem hash_mod_key_eq : hash_mod_key k l = k.val % l := by + simp [hash_mod_key, hash_key] + +def slot_s_inv_hash (l i : Int) (ls : Core.List (Usize × α)) : Prop := + ls.allP (λ (k, _) => hash_mod_key k l = i) + +@[simp] +def slot_s_inv (l i : Int) (ls : Core.List (Usize × α)) : Prop := + distinct_keys ls ∧ + slot_s_inv_hash l i ls + +def slot_t_inv (l i : Int) (s : List α) : Prop := slot_s_inv l i s.v + +-- Interpret the hashmap as a list of lists +def v (hm : HashMap α) : Core.List (Core.List (Usize × α)) := + hm.slots.val.map List.v + +-- Interpret the hashmap as an associative list +def al_v (hm : HashMap α) : Core.List (Usize × α) := + hm.v.flatten + +-- TODO: automatic derivation +instance : Inhabited (List α) where + default := .Nil + +@[simp] +def slots_s_inv (s : Core.List (List α)) : Prop := + ∀ (i : Int), 0 ≤ i → i < s.len → slot_t_inv s.len i (s.index i) + +def slots_t_inv (s : Vec (List α)) : Prop := + slots_s_inv s.v + +@[simp] +def base_inv (hm : HashMap α) : Prop := + -- [num_entries] correctly tracks the number of entries + hm.num_entries.val = hm.al_v.len ∧ + -- Slots invariant + slots_t_inv hm.slots ∧ + -- The capacity must be > 0 (otherwise we can't resize) + 0 < hm.slots.length + -- TODO: load computation + +def inv (hm : HashMap α) : Prop := + -- Base invariant + base_inv hm + -- TODO: either the hashmap is not overloaded, or we can't resize it + +theorem insert_in_list_back_spec_aux {α : Type} (l : Int) (key: Usize) (value: α) (l0: List α) + (hinv : slot_s_inv_hash l (hash_mod_key key l) l0.v) + (hdk : distinct_keys l0.v) : + ∃ l1, + insert_in_list_back α key value l0 = ret l1 ∧ + -- We update the binding + l1.lookup key = value ∧ + (∀ k, k ≠ key → l1.lookup k = l0.lookup k) ∧ + -- We preserve part of the key invariant + slot_s_inv_hash l (hash_mod_key key l) l1.v ∧ + -- Reasoning about the length + (match l0.lookup key with + | none => l1.len = l0.len + 1 + | some _ => l1.len = l0.len) ∧ + -- The keys are distinct + distinct_keys l1.v ∧ + -- We need this auxiliary property to prove that the keys distinct properties is preserved + (∀ k, k ≠ key → l0.v.allP (λ (k1, _) => k ≠ k1) → l1.v.allP (λ (k1, _) => k ≠ k1)) + := match l0 with + | .Nil => by checkpoint + simp (config := {contextual := true}) + [insert_in_list_back, insert_in_list_loop_back, + List.v, slot_s_inv_hash, distinct_keys, List.pairwise_rel] + | .Cons k v tl0 => + if h: k = key then by checkpoint + simp [insert_in_list_back] + rw [insert_in_list_loop_back] + simp [h] + split_conjs + . intros; simp [*] + . simp [List.v, slot_s_inv_hash] at * + simp [*] + . simp [*, distinct_keys] at * + apply hdk + . tauto + else by checkpoint + simp [insert_in_list_back] + rw [insert_in_list_loop_back] + simp [h] + have : slot_s_inv_hash l (hash_mod_key key l) (List.v tl0) := by checkpoint + simp_all [List.v, slot_s_inv_hash] + have : distinct_keys (List.v tl0) := by checkpoint + simp [distinct_keys] at hdk + simp [hdk, distinct_keys] + progress keep heq as ⟨ tl1 .. ⟩ + simp only [insert_in_list_back] at heq + have : slot_s_inv_hash l (hash_mod_key key l) (List.v (List.Cons k v tl1)) := by checkpoint + simp [List.v, slot_s_inv_hash] at * + simp [*] + have : distinct_keys ((k, v) :: List.v tl1) := by checkpoint + simp [distinct_keys] at * + simp [*] + -- TODO: canonize addition by default? + simp_all [Int.add_assoc, Int.add_comm, Int.add_left_comm] + +@[pspec] +theorem insert_in_list_back_spec {α : Type} (l : Int) (key: Usize) (value: α) (l0: List α) + (hinv : slot_s_inv_hash l (hash_mod_key key l) l0.v) + (hdk : distinct_keys l0.v) : + ∃ l1, + insert_in_list_back α key value l0 = ret l1 ∧ + -- We update the binding + l1.lookup key = value ∧ + (∀ k, k ≠ key → l1.lookup k = l0.lookup k) ∧ + -- We preserve part of the key invariant + slot_s_inv_hash l (hash_mod_key key l) l1.v ∧ + -- Reasoning about the length + (match l0.lookup key with + | none => l1.len = l0.len + 1 + | some _ => l1.len = l0.len) ∧ + -- The keys are distinct + distinct_keys l1.v + := by + progress with insert_in_list_back_spec_aux as ⟨ l1 .. ⟩ + exists l1 + +@[simp] +def slots_t_lookup (s : Core.List (List α)) (k : Usize) : Option α := + let i := hash_mod_key k s.len + let slot := s.index i + slot.lookup k + +def lookup (hm : HashMap α) (k : Usize) : Option α := + slots_t_lookup hm.slots.val k + +@[simp] +abbrev len_s (hm : HashMap α) : Int := hm.al_v.len + +-- Remark: α and β must live in the same universe, otherwise the +-- bind doesn't work +theorem if_update_eq + {α β : Type u} (b : Bool) (y : α) (e : Result α) (f : α → Result β) : + (if b then Bind.bind e f else f y) = Bind.bind (if b then e else pure y) f + := by + split <;> simp [Pure.pure] + +-- Small helper +-- TODO: move, and introduce a better solution with nice syntax +def mk_opaque {α : Sort u} (x : α) : { y : α // y = x} := + ⟨ x, by simp ⟩ + +--set_option profiler true +--set_option profiler.threshold 10 +--set_option trace.profiler true + +-- For pretty printing (useful when copy-pasting goals) +attribute [pp_dot] List.length -- use the dot notation when printing +set_option pp.coercions false -- do not print coercions with ↑ (this doesn't parse) + +theorem insert_no_resize_spec {α : Type} (hm : HashMap α) (key : Usize) (value : α) + (hinv : hm.inv) (hnsat : hm.lookup key = none → hm.len_s < Usize.max) : + ∃ nhm, hm.insert_no_resize α key value = ret nhm ∧ + -- We preserve the invariant + nhm.inv ∧ + -- We updated the binding for key + nhm.lookup key = some value ∧ + -- We left the other bindings unchanged + (∀ k, ¬ k = key → nhm.lookup k = hm.lookup k) ∧ + -- Reasoning about the length + (match hm.lookup key with + | none => nhm.len_s = hm.len_s + 1 + | some _ => nhm.len_s = hm.len_s) := by + rw [insert_no_resize] + simp only [hash_key, bind_tc_ret] -- TODO: annoying + have _ : (Vec.len (List α) hm.slots).val ≠ 0 := by checkpoint + intro + simp_all [inv] + progress keep _ as ⟨ hash_mod, hhm ⟩ + have _ : 0 ≤ hash_mod.val := by checkpoint scalar_tac + have _ : hash_mod.val < Vec.length hm.slots := by + have : 0 < hm.slots.val.len := by + simp [inv] at hinv + simp [hinv] + -- TODO: we want to automate that + simp [*, Int.emod_lt_of_pos] + -- TODO: change the spec of Vec.index_mut to introduce a let-binding. + -- or: make progress introduce the let-binding by itself (this is clearer) + progress as ⟨ l, h_leq ⟩ + -- TODO: make progress use the names written in the goal + progress as ⟨ inserted ⟩ + rw [if_update_eq] -- TODO: necessary because we don't have a join + -- TODO: progress to ... + have hipost : + ∃ i0, (if inserted = true then hm.num_entries + Usize.ofInt 1 else pure hm.num_entries) = ret i0 ∧ + i0.val = if inserted then hm.num_entries.val + 1 else hm.num_entries.val + := by + if inserted then + simp [*] + have hbounds : hm.num_entries.val + (Usize.ofInt 1).val ≤ Usize.max := by + simp [lookup] at hnsat + simp_all + simp [inv] at hinv + int_tac + -- TODO: progress fails in command line mode with "index out of bounds" + -- and I have no idea how to fix this. The error happens after progress + -- introduced the new goals. It must be when we exit the "withApp", etc. + -- helpers. + -- progress as ⟨ z, hp ⟩ + have ⟨ z, hp ⟩ := Usize.add_spec hbounds + simp [hp] + else + simp [*, Pure.pure] + progress as ⟨ i0 ⟩ + have h_slot : slot_s_inv_hash hm.slots.length (hash_mod_key key hm.slots.length) l.v + := by + simp [inv] at hinv + have h := (hinv.right.left hash_mod.val (by assumption) (by assumption)).right + simp [slot_t_inv, hhm] at h + simp [h, hhm, h_leq] + have hd : distinct_keys l.v := by checkpoint + simp [inv, slots_t_inv, slot_t_inv] at hinv + have h := hinv.right.left hash_mod.val (by assumption) (by assumption) + simp [h, h_leq] + -- TODO: hide the variables and only keep the props + -- TODO: allow providing terms to progress to instantiate the meta variables + -- which are not propositions + progress as ⟨ l0, _, _, _, hlen .. ⟩ + progress keep hv as ⟨ v, h_veq ⟩ + -- TODO: update progress to automate that + -- TODO: later I don't want to inline nhm - we need to control simp: deactivate + -- zeta reduction? For now I have to do this peculiar manipulation + have ⟨ nhm, nhm_eq ⟩ := @mk_opaque (HashMap α) { num_entries := i0, max_load_factor := hm.max_load_factor, max_load := hm.max_load, slots := v } + exists nhm + have hupdt : lookup nhm key = some value := by checkpoint + simp [lookup, List.lookup] at * + simp_all + have hlkp : ∀ k, ¬ k = key → nhm.lookup k = hm.lookup k := by + simp [lookup, List.lookup] at * + intro k hk + -- We have to make a case disjunction: either the hashes are different, + -- in which case we don't even lookup the same slots, or the hashes + -- are the same, in which case we have to reason about what happens + -- in one slot + let k_hash_mod := k.val % v.val.len + have : 0 < hm.slots.val.len := by simp_all [inv] + have hvpos : 0 < v.val.len := by simp_all + have hvnz: v.val.len ≠ 0 := by + simp_all + have _ : 0 ≤ k_hash_mod := by + -- TODO: we want to automate this + simp + apply Int.emod_nonneg k.val hvnz + have _ : k_hash_mod < Vec.length hm.slots := by + -- TODO: we want to automate this + simp + have h := Int.emod_lt_of_pos k.val hvpos + simp_all + if h_hm : k_hash_mod = hash_mod.val then + simp_all + else + simp_all + have _ : + match hm.lookup key with + | none => nhm.len_s = hm.len_s + 1 + | some _ => nhm.len_s = hm.len_s := by checkpoint + simp only [lookup, List.lookup, len_s, al_v, HashMap.v, slots_t_lookup] at * + -- We have to do a case disjunction + simp_all + simp [_root_.List.update_map_eq] + -- TODO: dependent rewrites + have _ : key.val % hm.slots.val.len < (List.map List.v hm.slots.val).len := by + simp [*] + simp [_root_.List.len_flatten_update_eq, *] + split <;> + rename_i heq <;> + simp [heq] at hlen <;> + -- TODO: canonize addition by default? We need a tactic to simplify arithmetic equalities + -- with addition and substractions ((ℤ, +) is a group or something - there should exist a tactic + -- somewhere in mathlib?) + simp [Int.add_assoc, Int.add_comm, Int.add_left_comm] <;> + int_tac + have hinv : inv nhm := by + simp [inv] at * + split_conjs + . match h: lookup hm key with + | none => + simp [h, lookup] at * + simp_all + | some _ => + simp_all [lookup] + . simp [slots_t_inv, slot_t_inv] at * + intro i hipos _ + have _ := hinv.right.left i hipos (by simp_all) + simp [hhm, h_veq, nhm_eq] at * -- TODO: annoying, we do that because simp_all fails below + -- We need a case disjunction + if h_ieq : i = key.val % _root_.List.len hm.slots.val then + -- TODO: simp_all fails: "(deterministic) timeout at 'whnf'" + -- Also, it is annoying to do this kind + -- of rewritings by hand. We could have a different simp + -- which safely substitutes variables when we have an + -- equality `x = ...` and `x` doesn't appear in the rhs + simp [h_ieq] at * + simp [*] + else + simp [*] + . -- TODO: simp[*] fails: "(deterministic) timeout at 'whnf'" + simp [hinv, h_veq, nhm_eq] + simp_all + +end HashMap + +end hashmap diff --git a/tests/lean/Hashmap/Types.lean b/tests/lean/Hashmap/Types.lean new file mode 100644 index 00000000..6606cf9e --- /dev/null +++ b/tests/lean/Hashmap/Types.lean @@ -0,0 +1,19 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [hashmap]: type definitions +import Base +open Primitives +namespace hashmap + +/- [hashmap::List] -/ +inductive List (T : Type) := +| Cons : Usize → T → List T → List T +| Nil : List T + +/- [hashmap::HashMap] -/ +structure HashMap (T : Type) where + num_entries : Usize + max_load_factor : (Usize × Usize) + max_load : Usize + slots : Vec (List T) + +end hashmap diff --git a/tests/lean/hashmap_on_disk/HashmapMain.lean b/tests/lean/HashmapMain.lean index 1a4e7f82..1a4e7f82 100644 --- a/tests/lean/hashmap_on_disk/HashmapMain.lean +++ b/tests/lean/HashmapMain.lean diff --git a/tests/lean/HashmapMain/Funs.lean b/tests/lean/HashmapMain/Funs.lean new file mode 100644 index 00000000..610bae46 --- /dev/null +++ b/tests/lean/HashmapMain/Funs.lean @@ -0,0 +1,505 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [hashmap_main]: function definitions +import Base +import HashmapMain.Types +import HashmapMain.FunsExternal +open Primitives +namespace hashmap_main + +/- [hashmap_main::hashmap::hash_key]: forward function -/ +def hashmap.hash_key (k : Usize) : Result Usize := + Result.ret k + +/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function -/ +divergent def hashmap.HashMap.allocate_slots_loop + (T : Type) (slots : Vec (hashmap.List T)) (n : Usize) : + Result (Vec (hashmap.List T)) + := + if n > (Usize.ofInt 0) + then + do + let slots0 ← Vec.push (hashmap.List T) slots hashmap.List.Nil + let n0 ← n - (Usize.ofInt 1) + hashmap.HashMap.allocate_slots_loop T slots0 n0 + else Result.ret slots + +/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: forward function -/ +def hashmap.HashMap.allocate_slots + (T : Type) (slots : Vec (hashmap.List T)) (n : Usize) : + Result (Vec (hashmap.List T)) + := + hashmap.HashMap.allocate_slots_loop T slots n + +/- [hashmap_main::hashmap::HashMap::{0}::new_with_capacity]: forward function -/ +def hashmap.HashMap.new_with_capacity + (T : Type) (capacity : Usize) (max_load_dividend : Usize) + (max_load_divisor : Usize) : + Result (hashmap.HashMap T) + := + do + let v := Vec.new (hashmap.List T) + let slots ← hashmap.HashMap.allocate_slots T v capacity + let i ← capacity * max_load_dividend + let i0 ← i / max_load_divisor + Result.ret + { + num_entries := (Usize.ofInt 0), + max_load_factor := (max_load_dividend, max_load_divisor), + max_load := i0, + slots := slots + } + +/- [hashmap_main::hashmap::HashMap::{0}::new]: forward function -/ +def hashmap.HashMap.new (T : Type) : Result (hashmap.HashMap T) := + hashmap.HashMap.new_with_capacity T (Usize.ofInt 32) (Usize.ofInt 4) + (Usize.ofInt 5) + +/- [hashmap_main::hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def hashmap.HashMap.clear_loop + (T : Type) (slots : Vec (hashmap.List T)) (i : Usize) : + Result (Vec (hashmap.List T)) + := + let i0 := Vec.len (hashmap.List T) slots + if i < i0 + then + do + let i1 ← i + (Usize.ofInt 1) + let slots0 ← + Vec.index_mut_back (hashmap.List T) slots i hashmap.List.Nil + hashmap.HashMap.clear_loop T slots0 i1 + else Result.ret slots + +/- [hashmap_main::hashmap::HashMap::{0}::clear]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def hashmap.HashMap.clear + (T : Type) (self : hashmap.HashMap T) : Result (hashmap.HashMap T) := + do + let v ← hashmap.HashMap.clear_loop T self.slots (Usize.ofInt 0) + Result.ret { self with num_entries := (Usize.ofInt 0), slots := v } + +/- [hashmap_main::hashmap::HashMap::{0}::len]: forward function -/ +def hashmap.HashMap.len (T : Type) (self : hashmap.HashMap T) : Result Usize := + Result.ret self.num_entries + +/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: forward function -/ +divergent def hashmap.HashMap.insert_in_list_loop + (T : Type) (key : Usize) (value : T) (ls : hashmap.List T) : Result Bool := + match ls with + | hashmap.List.Cons ckey cvalue tl => + if ckey = key + then Result.ret false + else hashmap.HashMap.insert_in_list_loop T key value tl + | hashmap.List.Nil => Result.ret true + +/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: forward function -/ +def hashmap.HashMap.insert_in_list + (T : Type) (key : Usize) (value : T) (ls : hashmap.List T) : Result Bool := + hashmap.HashMap.insert_in_list_loop T key value ls + +/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: loop 0: backward function 0 -/ +divergent def hashmap.HashMap.insert_in_list_loop_back + (T : Type) (key : Usize) (value : T) (ls : hashmap.List T) : + Result (hashmap.List T) + := + match ls with + | hashmap.List.Cons ckey cvalue tl => + if ckey = key + then Result.ret (hashmap.List.Cons ckey value tl) + else + do + let tl0 ← hashmap.HashMap.insert_in_list_loop_back T key value tl + Result.ret (hashmap.List.Cons ckey cvalue tl0) + | hashmap.List.Nil => + let l := hashmap.List.Nil + Result.ret (hashmap.List.Cons key value l) + +/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: backward function 0 -/ +def hashmap.HashMap.insert_in_list_back + (T : Type) (key : Usize) (value : T) (ls : hashmap.List T) : + Result (hashmap.List T) + := + hashmap.HashMap.insert_in_list_loop_back T key value ls + +/- [hashmap_main::hashmap::HashMap::{0}::insert_no_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def hashmap.HashMap.insert_no_resize + (T : Type) (self : hashmap.HashMap T) (key : Usize) (value : T) : + Result (hashmap.HashMap T) + := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (hashmap.List T) self.slots hash_mod + let inserted ← hashmap.HashMap.insert_in_list T key value l + if inserted + then + do + let i0 ← self.num_entries + (Usize.ofInt 1) + let l0 ← hashmap.HashMap.insert_in_list_back T key value l + let v ← Vec.index_mut_back (hashmap.List T) self.slots hash_mod l0 + Result.ret { self with num_entries := i0, slots := v } + else + do + let l0 ← hashmap.HashMap.insert_in_list_back T key value l + let v ← Vec.index_mut_back (hashmap.List T) self.slots hash_mod l0 + Result.ret { self with slots := v } + +/- [core::num::u32::{9}::MAX] -/ +def core_num_u32_max_body : Result U32 := Result.ret (U32.ofInt 4294967295) +def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) + +/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def hashmap.HashMap.move_elements_from_list_loop + (T : Type) (ntable : hashmap.HashMap T) (ls : hashmap.List T) : + Result (hashmap.HashMap T) + := + match ls with + | hashmap.List.Cons k v tl => + do + let ntable0 ← hashmap.HashMap.insert_no_resize T ntable k v + hashmap.HashMap.move_elements_from_list_loop T ntable0 tl + | hashmap.List.Nil => Result.ret ntable + +/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def hashmap.HashMap.move_elements_from_list + (T : Type) (ntable : hashmap.HashMap T) (ls : hashmap.List T) : + Result (hashmap.HashMap T) + := + hashmap.HashMap.move_elements_from_list_loop T ntable ls + +/- [hashmap_main::hashmap::HashMap::{0}::move_elements]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def hashmap.HashMap.move_elements_loop + (T : Type) (ntable : hashmap.HashMap T) (slots : Vec (hashmap.List T)) + (i : Usize) : + Result ((hashmap.HashMap T) × (Vec (hashmap.List T))) + := + let i0 := Vec.len (hashmap.List T) slots + if i < i0 + then + do + let l ← Vec.index_mut (hashmap.List T) slots i + let ls := mem.replace (hashmap.List T) l hashmap.List.Nil + let ntable0 ← hashmap.HashMap.move_elements_from_list T ntable ls + let i1 ← i + (Usize.ofInt 1) + let l0 := mem.replace_back (hashmap.List T) l hashmap.List.Nil + let slots0 ← Vec.index_mut_back (hashmap.List T) slots i l0 + hashmap.HashMap.move_elements_loop T ntable0 slots0 i1 + else Result.ret (ntable, slots) + +/- [hashmap_main::hashmap::HashMap::{0}::move_elements]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def hashmap.HashMap.move_elements + (T : Type) (ntable : hashmap.HashMap T) (slots : Vec (hashmap.List T)) + (i : Usize) : + Result ((hashmap.HashMap T) × (Vec (hashmap.List T))) + := + hashmap.HashMap.move_elements_loop T ntable slots i + +/- [hashmap_main::hashmap::HashMap::{0}::try_resize]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def hashmap.HashMap.try_resize + (T : Type) (self : hashmap.HashMap T) : Result (hashmap.HashMap T) := + do + let max_usize ← Scalar.cast .Usize core_num_u32_max_c + let capacity := Vec.len (hashmap.List T) self.slots + let n1 ← max_usize / (Usize.ofInt 2) + let (i, i0) := self.max_load_factor + let i1 ← n1 / i + if capacity <= i1 + then + do + let i2 ← capacity * (Usize.ofInt 2) + let ntable ← hashmap.HashMap.new_with_capacity T i2 i i0 + let (ntable0, _) ← + hashmap.HashMap.move_elements T ntable self.slots (Usize.ofInt 0) + Result.ret + { + ntable0 + with + num_entries := self.num_entries, max_load_factor := (i, i0) + } + else Result.ret { self with max_load_factor := (i, i0) } + +/- [hashmap_main::hashmap::HashMap::{0}::insert]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def hashmap.HashMap.insert + (T : Type) (self : hashmap.HashMap T) (key : Usize) (value : T) : + Result (hashmap.HashMap T) + := + do + let self0 ← hashmap.HashMap.insert_no_resize T self key value + let i ← hashmap.HashMap.len T self0 + if i > self0.max_load + then hashmap.HashMap.try_resize T self0 + else Result.ret self0 + +/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: loop 0: forward function -/ +divergent def hashmap.HashMap.contains_key_in_list_loop + (T : Type) (key : Usize) (ls : hashmap.List T) : Result Bool := + match ls with + | hashmap.List.Cons ckey t tl => + if ckey = key + then Result.ret true + else hashmap.HashMap.contains_key_in_list_loop T key tl + | hashmap.List.Nil => Result.ret false + +/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: forward function -/ +def hashmap.HashMap.contains_key_in_list + (T : Type) (key : Usize) (ls : hashmap.List T) : Result Bool := + hashmap.HashMap.contains_key_in_list_loop T key ls + +/- [hashmap_main::hashmap::HashMap::{0}::contains_key]: forward function -/ +def hashmap.HashMap.contains_key + (T : Type) (self : hashmap.HashMap T) (key : Usize) : Result Bool := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index (hashmap.List T) self.slots hash_mod + hashmap.HashMap.contains_key_in_list T key l + +/- [hashmap_main::hashmap::HashMap::{0}::get_in_list]: loop 0: forward function -/ +divergent def hashmap.HashMap.get_in_list_loop + (T : Type) (key : Usize) (ls : hashmap.List T) : Result T := + match ls with + | hashmap.List.Cons ckey cvalue tl => + if ckey = key + then Result.ret cvalue + else hashmap.HashMap.get_in_list_loop T key tl + | hashmap.List.Nil => Result.fail Error.panic + +/- [hashmap_main::hashmap::HashMap::{0}::get_in_list]: forward function -/ +def hashmap.HashMap.get_in_list + (T : Type) (key : Usize) (ls : hashmap.List T) : Result T := + hashmap.HashMap.get_in_list_loop T key ls + +/- [hashmap_main::hashmap::HashMap::{0}::get]: forward function -/ +def hashmap.HashMap.get + (T : Type) (self : hashmap.HashMap T) (key : Usize) : Result T := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index (hashmap.List T) self.slots hash_mod + hashmap.HashMap.get_in_list T key l + +/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: forward function -/ +divergent def hashmap.HashMap.get_mut_in_list_loop + (T : Type) (ls : hashmap.List T) (key : Usize) : Result T := + match ls with + | hashmap.List.Cons ckey cvalue tl => + if ckey = key + then Result.ret cvalue + else hashmap.HashMap.get_mut_in_list_loop T tl key + | hashmap.List.Nil => Result.fail Error.panic + +/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: forward function -/ +def hashmap.HashMap.get_mut_in_list + (T : Type) (ls : hashmap.List T) (key : Usize) : Result T := + hashmap.HashMap.get_mut_in_list_loop T ls key + +/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: loop 0: backward function 0 -/ +divergent def hashmap.HashMap.get_mut_in_list_loop_back + (T : Type) (ls : hashmap.List T) (key : Usize) (ret0 : T) : + Result (hashmap.List T) + := + match ls with + | hashmap.List.Cons ckey cvalue tl => + if ckey = key + then Result.ret (hashmap.List.Cons ckey ret0 tl) + else + do + let tl0 ← hashmap.HashMap.get_mut_in_list_loop_back T tl key ret0 + Result.ret (hashmap.List.Cons ckey cvalue tl0) + | hashmap.List.Nil => Result.fail Error.panic + +/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: backward function 0 -/ +def hashmap.HashMap.get_mut_in_list_back + (T : Type) (ls : hashmap.List T) (key : Usize) (ret0 : T) : + Result (hashmap.List T) + := + hashmap.HashMap.get_mut_in_list_loop_back T ls key ret0 + +/- [hashmap_main::hashmap::HashMap::{0}::get_mut]: forward function -/ +def hashmap.HashMap.get_mut + (T : Type) (self : hashmap.HashMap T) (key : Usize) : Result T := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (hashmap.List T) self.slots hash_mod + hashmap.HashMap.get_mut_in_list T l key + +/- [hashmap_main::hashmap::HashMap::{0}::get_mut]: backward function 0 -/ +def hashmap.HashMap.get_mut_back + (T : Type) (self : hashmap.HashMap T) (key : Usize) (ret0 : T) : + Result (hashmap.HashMap T) + := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (hashmap.List T) self.slots hash_mod + let l0 ← hashmap.HashMap.get_mut_in_list_back T l key ret0 + let v ← Vec.index_mut_back (hashmap.List T) self.slots hash_mod l0 + Result.ret { self with slots := v } + +/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: forward function -/ +divergent def hashmap.HashMap.remove_from_list_loop + (T : Type) (key : Usize) (ls : hashmap.List T) : Result (Option T) := + match ls with + | hashmap.List.Cons ckey t tl => + if ckey = key + then + let mv_ls := + mem.replace (hashmap.List T) (hashmap.List.Cons ckey t tl) + hashmap.List.Nil + match mv_ls with + | hashmap.List.Cons i cvalue tl0 => Result.ret (Option.some cvalue) + | hashmap.List.Nil => Result.fail Error.panic + else hashmap.HashMap.remove_from_list_loop T key tl + | hashmap.List.Nil => Result.ret Option.none + +/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: forward function -/ +def hashmap.HashMap.remove_from_list + (T : Type) (key : Usize) (ls : hashmap.List T) : Result (Option T) := + hashmap.HashMap.remove_from_list_loop T key ls + +/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: loop 0: backward function 1 -/ +divergent def hashmap.HashMap.remove_from_list_loop_back + (T : Type) (key : Usize) (ls : hashmap.List T) : Result (hashmap.List T) := + match ls with + | hashmap.List.Cons ckey t tl => + if ckey = key + then + let mv_ls := + mem.replace (hashmap.List T) (hashmap.List.Cons ckey t tl) + hashmap.List.Nil + match mv_ls with + | hashmap.List.Cons i cvalue tl0 => Result.ret tl0 + | hashmap.List.Nil => Result.fail Error.panic + else + do + let tl0 ← hashmap.HashMap.remove_from_list_loop_back T key tl + Result.ret (hashmap.List.Cons ckey t tl0) + | hashmap.List.Nil => Result.ret hashmap.List.Nil + +/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: backward function 1 -/ +def hashmap.HashMap.remove_from_list_back + (T : Type) (key : Usize) (ls : hashmap.List T) : Result (hashmap.List T) := + hashmap.HashMap.remove_from_list_loop_back T key ls + +/- [hashmap_main::hashmap::HashMap::{0}::remove]: forward function -/ +def hashmap.HashMap.remove + (T : Type) (self : hashmap.HashMap T) (key : Usize) : Result (Option T) := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (hashmap.List T) self.slots hash_mod + let x ← hashmap.HashMap.remove_from_list T key l + match x with + | Option.none => Result.ret Option.none + | Option.some x0 => + do + let _ ← self.num_entries - (Usize.ofInt 1) + Result.ret (Option.some x0) + +/- [hashmap_main::hashmap::HashMap::{0}::remove]: backward function 0 -/ +def hashmap.HashMap.remove_back + (T : Type) (self : hashmap.HashMap T) (key : Usize) : + Result (hashmap.HashMap T) + := + do + let hash ← hashmap.hash_key key + let i := Vec.len (hashmap.List T) self.slots + let hash_mod ← hash % i + let l ← Vec.index_mut (hashmap.List T) self.slots hash_mod + let x ← hashmap.HashMap.remove_from_list T key l + match x with + | Option.none => + do + let l0 ← hashmap.HashMap.remove_from_list_back T key l + let v ← Vec.index_mut_back (hashmap.List T) self.slots hash_mod l0 + Result.ret { self with slots := v } + | Option.some x0 => + do + let i0 ← self.num_entries - (Usize.ofInt 1) + let l0 ← hashmap.HashMap.remove_from_list_back T key l + let v ← Vec.index_mut_back (hashmap.List T) self.slots hash_mod l0 + Result.ret { self with num_entries := i0, slots := v } + +/- [hashmap_main::hashmap::test1]: forward function -/ +def hashmap.test1 : Result Unit := + do + let hm ← hashmap.HashMap.new U64 + let hm0 ← hashmap.HashMap.insert U64 hm (Usize.ofInt 0) (U64.ofInt 42) + let hm1 ← hashmap.HashMap.insert U64 hm0 (Usize.ofInt 128) (U64.ofInt 18) + let hm2 ← + hashmap.HashMap.insert U64 hm1 (Usize.ofInt 1024) (U64.ofInt 138) + let hm3 ← + hashmap.HashMap.insert U64 hm2 (Usize.ofInt 1056) (U64.ofInt 256) + let i ← hashmap.HashMap.get U64 hm3 (Usize.ofInt 128) + if not (i = (U64.ofInt 18)) + then Result.fail Error.panic + else + do + let hm4 ← + hashmap.HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024) + (U64.ofInt 56) + let i0 ← hashmap.HashMap.get U64 hm4 (Usize.ofInt 1024) + if not (i0 = (U64.ofInt 56)) + then Result.fail Error.panic + else + do + let x ← hashmap.HashMap.remove U64 hm4 (Usize.ofInt 1024) + match x with + | Option.none => Result.fail Error.panic + | Option.some x0 => + if not (x0 = (U64.ofInt 56)) + then Result.fail Error.panic + else + do + let hm5 ← + hashmap.HashMap.remove_back U64 hm4 (Usize.ofInt 1024) + let i1 ← hashmap.HashMap.get U64 hm5 (Usize.ofInt 0) + if not (i1 = (U64.ofInt 42)) + then Result.fail Error.panic + else + do + let i2 ← hashmap.HashMap.get U64 hm5 (Usize.ofInt 128) + if not (i2 = (U64.ofInt 18)) + then Result.fail Error.panic + else + do + let i3 ← + hashmap.HashMap.get U64 hm5 (Usize.ofInt 1056) + if not (i3 = (U64.ofInt 256)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [hashmap_main::hashmap::test1] -/ +#assert (hashmap.test1 == .ret ()) + +/- [hashmap_main::insert_on_disk]: forward function -/ +def insert_on_disk + (key : Usize) (value : U64) (st : State) : Result (State × Unit) := + do + let (st0, hm) ← hashmap_utils.deserialize st + let hm0 ← hashmap.HashMap.insert U64 hm key value + let (st1, _) ← hashmap_utils.serialize hm0 st0 + Result.ret (st1, ()) + +/- [hashmap_main::main]: forward function -/ +def main : Result Unit := + Result.ret () + +/- Unit test for [hashmap_main::main] -/ +#assert (main == .ret ()) + +end hashmap_main diff --git a/tests/lean/HashmapMain/FunsExternal.lean b/tests/lean/HashmapMain/FunsExternal.lean new file mode 100644 index 00000000..b394b32b --- /dev/null +++ b/tests/lean/HashmapMain/FunsExternal.lean @@ -0,0 +1,17 @@ +-- [hashmap_main]: templates for the external functions. +import Base +import HashmapMain.Types +open Primitives +open hashmap_main + +-- TODO: fill those bodies + +/- [hashmap_main::hashmap_utils::deserialize] -/ +def hashmap_utils.deserialize + : State → Result (State × (hashmap.HashMap U64)) := + fun _ => .fail .panic + +/- [hashmap_main::hashmap_utils::serialize] -/ +def hashmap_utils.serialize + : hashmap.HashMap U64 → State → Result (State × Unit) := + fun _ _ => .fail .panic diff --git a/tests/lean/HashmapMain/FunsExternal_Template.lean b/tests/lean/HashmapMain/FunsExternal_Template.lean new file mode 100644 index 00000000..f537fc8f --- /dev/null +++ b/tests/lean/HashmapMain/FunsExternal_Template.lean @@ -0,0 +1,16 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [hashmap_main]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import HashmapMain.Types +open Primitives +open hashmap_main + +/- [hashmap_main::hashmap_utils::deserialize]: forward function -/ +axiom hashmap_utils.deserialize + : State → Result (State × (hashmap.HashMap U64)) + +/- [hashmap_main::hashmap_utils::serialize]: forward function -/ +axiom hashmap_utils.serialize + : hashmap.HashMap U64 → State → Result (State × Unit) + diff --git a/tests/lean/hashmap_on_disk/HashmapMain/Opaque.lean b/tests/lean/HashmapMain/Opaque.lean index d98f431a..abf04c94 100644 --- a/tests/lean/hashmap_on_disk/HashmapMain/Opaque.lean +++ b/tests/lean/HashmapMain/Opaque.lean @@ -1,15 +1,19 @@ -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS -- [hashmap_main]: opaque function definitions -import Base.Primitives +import Base import HashmapMain.Types +open Primitives + +namespace hashmap_main structure OpaqueDefs where /- [hashmap_main::hashmap_utils::deserialize] -/ - hashmap_utils_deserialize_fwd - : State -> Result (State × (hashmap_hash_map_t U64)) + hashmap_utils.deserialize_fwd + : State → Result (State × (hashmap_hash_map_t U64)) /- [hashmap_main::hashmap_utils::serialize] -/ - hashmap_utils_serialize_fwd - : hashmap_hash_map_t U64 -> State -> Result (State × Unit) + hashmap_utils.serialize_fwd + : hashmap_hash_map_t U64 → State → Result (State × Unit) +end hashmap_main diff --git a/tests/lean/HashmapMain/Types.lean b/tests/lean/HashmapMain/Types.lean new file mode 100644 index 00000000..3b3d0d7c --- /dev/null +++ b/tests/lean/HashmapMain/Types.lean @@ -0,0 +1,22 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [hashmap_main]: type definitions +import Base +open Primitives +namespace hashmap_main + +/- [hashmap_main::hashmap::List] -/ +inductive hashmap.List (T : Type) := +| Cons : Usize → T → hashmap.List T → hashmap.List T +| Nil : hashmap.List T + +/- [hashmap_main::hashmap::HashMap] -/ +structure hashmap.HashMap (T : Type) where + num_entries : Usize + max_load_factor : (Usize × Usize) + max_load : Usize + slots : Vec (hashmap.List T) + +/- The state type used in the state-error monad -/ +axiom State : Type + +end hashmap_main diff --git a/tests/lean/misc-loops/Loops.lean b/tests/lean/Loops.lean index 60c73776..60c73776 100644 --- a/tests/lean/misc-loops/Loops.lean +++ b/tests/lean/Loops.lean diff --git a/tests/lean/Loops/Funs.lean b/tests/lean/Loops/Funs.lean new file mode 100644 index 00000000..f7e6603d --- /dev/null +++ b/tests/lean/Loops/Funs.lean @@ -0,0 +1,611 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [loops]: function definitions +import Base +import Loops.Types +open Primitives +namespace loops + +/- [loops::sum]: loop 0: forward function -/ +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) + sum_loop max i0 s0 + else s * (U32.ofInt 2) + +/- [loops::sum]: forward function -/ +def sum (max : U32) : Result U32 := + sum_loop max (U32.ofInt 0) (U32.ofInt 0) + +/- [loops::sum_with_mut_borrows]: loop 0: forward function -/ +divergent def sum_with_mut_borrows_loop + (max : U32) (mi : U32) (ms : U32) : Result U32 := + if mi < max + then + do + let ms0 ← ms + mi + let mi0 ← mi + (U32.ofInt 1) + sum_with_mut_borrows_loop max mi0 ms0 + else ms * (U32.ofInt 2) + +/- [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) + +/- [loops::sum_with_shared_borrows]: loop 0: forward function -/ +divergent def sum_with_shared_borrows_loop + (max : U32) (i : U32) (s : U32) : Result U32 := + if i < max + then + do + let i0 ← i + (U32.ofInt 1) + let s0 ← s + i0 + sum_with_shared_borrows_loop max i0 s0 + else s * (U32.ofInt 2) + +/- [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) + +/- [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 + if i < i0 + then + do + let i1 ← i + (Usize.ofInt 1) + let v0 ← Vec.index_mut_back U32 v i (U32.ofInt 0) + 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) + +/- [loops::list_mem]: loop 0: forward function -/ +divergent def list_mem_loop (x : U32) (ls : List U32) : Result Bool := + match ls with + | List.Cons y tl => if y = x + then Result.ret true + else list_mem_loop x tl + | List.Nil => Result.ret false + +/- [loops::list_mem]: forward function -/ +def list_mem (x : U32) (ls : List U32) : Result Bool := + list_mem_loop x ls + +/- [loops::list_nth_mut_loop]: loop 0: forward function -/ +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) + then Result.ret x + else do + let i0 ← i - (U32.ofInt 1) + list_nth_mut_loop_loop T tl i0 + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop]: forward function -/ +def list_nth_mut_loop (T : Type) (ls : List T) (i : U32) : Result T := + list_nth_mut_loop_loop T ls i + +/- [loops::list_nth_mut_loop]: loop 0: backward function 0 -/ +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) + then Result.ret (List.Cons ret0 tl) + else + do + let i0 ← i - (U32.ofInt 1) + let tl0 ← list_nth_mut_loop_loop_back T tl i0 ret0 + Result.ret (List.Cons x tl0) + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop]: backward function 0 -/ +def list_nth_mut_loop_back + (T : Type) (ls : List T) (i : U32) (ret0 : T) : Result (List T) := + list_nth_mut_loop_loop_back T ls i ret0 + +/- [loops::list_nth_shared_loop]: loop 0: forward function -/ +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) + then Result.ret x + else do + let i0 ← i - (U32.ofInt 1) + list_nth_shared_loop_loop T tl i0 + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_loop]: forward function -/ +def list_nth_shared_loop (T : Type) (ls : List T) (i : U32) : Result T := + list_nth_shared_loop_loop T ls i + +/- [loops::get_elem_mut]: loop 0: forward function -/ +divergent def get_elem_mut_loop (x : Usize) (ls : List Usize) : Result Usize := + match ls with + | List.Cons y tl => if y = x + then Result.ret y + else get_elem_mut_loop x tl + | List.Nil => Result.fail Error.panic + +/- [loops::get_elem_mut]: forward function -/ +def get_elem_mut (slots : Vec (List Usize)) (x : Usize) : Result Usize := + do + let l ← Vec.index_mut (List Usize) slots (Usize.ofInt 0) + get_elem_mut_loop x l + +/- [loops::get_elem_mut]: loop 0: backward function 0 -/ +divergent def get_elem_mut_loop_back + (x : Usize) (ls : List Usize) (ret0 : Usize) : Result (List Usize) := + match ls with + | List.Cons y tl => + if y = x + then Result.ret (List.Cons ret0 tl) + else + do + let tl0 ← get_elem_mut_loop_back x tl ret0 + Result.ret (List.Cons y tl0) + | List.Nil => Result.fail Error.panic + +/- [loops::get_elem_mut]: backward function 0 -/ +def get_elem_mut_back + (slots : Vec (List Usize)) (x : Usize) (ret0 : Usize) : + Result (Vec (List Usize)) + := + do + let l ← Vec.index_mut (List Usize) slots (Usize.ofInt 0) + let l0 ← get_elem_mut_loop_back x l ret0 + Vec.index_mut_back (List Usize) slots (Usize.ofInt 0) l0 + +/- [loops::get_elem_shared]: loop 0: forward function -/ +divergent def get_elem_shared_loop + (x : Usize) (ls : List Usize) : Result Usize := + match ls with + | List.Cons y tl => if y = x + then Result.ret y + else get_elem_shared_loop x tl + | List.Nil => Result.fail Error.panic + +/- [loops::get_elem_shared]: forward function -/ +def get_elem_shared (slots : Vec (List Usize)) (x : Usize) : Result Usize := + do + let l ← Vec.index (List Usize) slots (Usize.ofInt 0) + get_elem_shared_loop x l + +/- [loops::id_mut]: forward function -/ +def id_mut (T : Type) (ls : List T) : Result (List T) := + Result.ret ls + +/- [loops::id_mut]: backward function 0 -/ +def id_mut_back (T : Type) (ls : List T) (ret0 : List T) : Result (List T) := + Result.ret ret0 + +/- [loops::id_shared]: forward function -/ +def id_shared (T : Type) (ls : List T) : Result (List T) := + Result.ret ls + +/- [loops::list_nth_mut_loop_with_id]: loop 0: forward function -/ +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) + then Result.ret x + else do + let i0 ← i - (U32.ofInt 1) + list_nth_mut_loop_with_id_loop T i0 tl + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop_with_id]: forward function -/ +def list_nth_mut_loop_with_id (T : Type) (ls : List T) (i : U32) : Result T := + do + let ls0 ← id_mut T ls + list_nth_mut_loop_with_id_loop T i ls0 + +/- [loops::list_nth_mut_loop_with_id]: loop 0: backward function 0 -/ +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) + then Result.ret (List.Cons ret0 tl) + else + do + let i0 ← i - (U32.ofInt 1) + 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 + +/- [loops::list_nth_mut_loop_with_id]: backward function 0 -/ +def list_nth_mut_loop_with_id_back + (T : Type) (ls : List T) (i : U32) (ret0 : T) : Result (List T) := + do + let ls0 ← id_mut T ls + let l ← list_nth_mut_loop_with_id_loop_back T i ls0 ret0 + id_mut_back T ls l + +/- [loops::list_nth_shared_loop_with_id]: loop 0: forward function -/ +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) + then Result.ret x + else + do + let i0 ← i - (U32.ofInt 1) + 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 -/ +def list_nth_shared_loop_with_id + (T : Type) (ls : List T) (i : U32) : Result T := + do + let ls0 ← id_shared T ls + list_nth_shared_loop_with_id_loop T i ls0 + +/- [loops::list_nth_mut_loop_pair]: loop 0: forward function -/ +divergent def list_nth_mut_loop_pair_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_mut_loop_pair_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop_pair]: forward function -/ +def list_nth_mut_loop_pair + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_mut_loop_pair_loop T ls0 ls1 i + +/- [loops::list_nth_mut_loop_pair]: loop 0: backward function 0 -/ +divergent def list_nth_mut_loop_pair_loop_back'a + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (List.Cons ret0 tl0) + else + do + let i0 ← i - (U32.ofInt 1) + 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 + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop_pair]: backward function 0 -/ +def list_nth_mut_loop_pair_back'a + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + list_nth_mut_loop_pair_loop_back'a T ls0 ls1 i ret0 + +/- [loops::list_nth_mut_loop_pair]: loop 0: backward function 1 -/ +divergent def list_nth_mut_loop_pair_loop_back'b + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (List.Cons ret0 tl1) + else + do + let i0 ← i - (U32.ofInt 1) + 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 + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop_pair]: backward function 1 -/ +def list_nth_mut_loop_pair_back'b + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + list_nth_mut_loop_pair_loop_back'b T ls0 ls1 i ret0 + +/- [loops::list_nth_shared_loop_pair]: loop 0: forward function -/ +divergent def list_nth_shared_loop_pair_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_shared_loop_pair_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_loop_pair]: forward function -/ +def list_nth_shared_loop_pair + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_shared_loop_pair_loop T ls0 ls1 i + +/- [loops::list_nth_mut_loop_pair_merge]: loop 0: forward function -/ +divergent def list_nth_mut_loop_pair_merge_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_mut_loop_pair_merge_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop_pair_merge]: forward function -/ +def list_nth_mut_loop_pair_merge + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_mut_loop_pair_merge_loop T ls0 ls1 i + +/- [loops::list_nth_mut_loop_pair_merge]: loop 0: backward function 0 -/ +divergent def list_nth_mut_loop_pair_merge_loop_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : (T × T)) : + Result ((List T) × (List T)) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then let (t, t0) := ret0 + Result.ret (List.Cons t tl0, List.Cons t0 tl1) + else + do + let i0 ← i - (U32.ofInt 1) + 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) + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_loop_pair_merge]: backward function 0 -/ +def list_nth_mut_loop_pair_merge_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : (T × T)) : + Result ((List T) × (List T)) + := + list_nth_mut_loop_pair_merge_loop_back T ls0 ls1 i ret0 + +/- [loops::list_nth_shared_loop_pair_merge]: loop 0: forward function -/ +divergent def list_nth_shared_loop_pair_merge_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_shared_loop_pair_merge_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_loop_pair_merge]: forward function -/ +def list_nth_shared_loop_pair_merge + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_shared_loop_pair_merge_loop T ls0 ls1 i + +/- [loops::list_nth_mut_shared_loop_pair]: loop 0: forward function -/ +divergent def list_nth_mut_shared_loop_pair_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_mut_shared_loop_pair_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_shared_loop_pair]: forward function -/ +def list_nth_mut_shared_loop_pair + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_mut_shared_loop_pair_loop T ls0 ls1 i + +/- [loops::list_nth_mut_shared_loop_pair]: loop 0: backward function 0 -/ +divergent def list_nth_mut_shared_loop_pair_loop_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (List.Cons ret0 tl0) + else + do + let i0 ← i - (U32.ofInt 1) + let tl00 ← + list_nth_mut_shared_loop_pair_loop_back T tl0 tl1 i0 ret0 + Result.ret (List.Cons x0 tl00) + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_shared_loop_pair]: backward function 0 -/ +def list_nth_mut_shared_loop_pair_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + list_nth_mut_shared_loop_pair_loop_back T ls0 ls1 i ret0 + +/- [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: forward function -/ +divergent def list_nth_mut_shared_loop_pair_merge_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_mut_shared_loop_pair_merge_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_shared_loop_pair_merge]: forward function -/ +def list_nth_mut_shared_loop_pair_merge + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_mut_shared_loop_pair_merge_loop T ls0 ls1 i + +/- [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: backward function 0 -/ +divergent def list_nth_mut_shared_loop_pair_merge_loop_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (List.Cons ret0 tl0) + else + do + let i0 ← i - (U32.ofInt 1) + let tl00 ← + list_nth_mut_shared_loop_pair_merge_loop_back T tl0 tl1 i0 ret0 + Result.ret (List.Cons x0 tl00) + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_mut_shared_loop_pair_merge]: backward function 0 -/ +def list_nth_mut_shared_loop_pair_merge_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + list_nth_mut_shared_loop_pair_merge_loop_back T ls0 ls1 i ret0 + +/- [loops::list_nth_shared_mut_loop_pair]: loop 0: forward function -/ +divergent def list_nth_shared_mut_loop_pair_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_shared_mut_loop_pair_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_mut_loop_pair]: forward function -/ +def list_nth_shared_mut_loop_pair + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_shared_mut_loop_pair_loop T ls0 ls1 i + +/- [loops::list_nth_shared_mut_loop_pair]: loop 0: backward function 1 -/ +divergent def list_nth_shared_mut_loop_pair_loop_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (List.Cons ret0 tl1) + else + do + let i0 ← i - (U32.ofInt 1) + let tl10 ← + list_nth_shared_mut_loop_pair_loop_back T tl0 tl1 i0 ret0 + Result.ret (List.Cons x1 tl10) + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_mut_loop_pair]: backward function 1 -/ +def list_nth_shared_mut_loop_pair_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + list_nth_shared_mut_loop_pair_loop_back T ls0 ls1 i ret0 + +/- [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: forward function -/ +divergent def list_nth_shared_mut_loop_pair_merge_loop + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (x0, x1) + else + do + let i0 ← i - (U32.ofInt 1) + list_nth_shared_mut_loop_pair_merge_loop T tl0 tl1 i0 + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_mut_loop_pair_merge]: forward function -/ +def list_nth_shared_mut_loop_pair_merge + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := + list_nth_shared_mut_loop_pair_merge_loop T ls0 ls1 i + +/- [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: backward function 0 -/ +divergent def list_nth_shared_mut_loop_pair_merge_loop_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + match ls0 with + | List.Cons x0 tl0 => + match ls1 with + | List.Cons x1 tl1 => + if i = (U32.ofInt 0) + then Result.ret (List.Cons ret0 tl1) + else + do + let i0 ← i - (U32.ofInt 1) + let tl10 ← + list_nth_shared_mut_loop_pair_merge_loop_back T tl0 tl1 i0 ret0 + Result.ret (List.Cons x1 tl10) + | List.Nil => Result.fail Error.panic + | List.Nil => Result.fail Error.panic + +/- [loops::list_nth_shared_mut_loop_pair_merge]: backward function 0 -/ +def list_nth_shared_mut_loop_pair_merge_back + (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) (ret0 : T) : + Result (List T) + := + list_nth_shared_mut_loop_pair_merge_loop_back T ls0 ls1 i ret0 + +end loops diff --git a/tests/lean/Loops/Types.lean b/tests/lean/Loops/Types.lean new file mode 100644 index 00000000..f8bc193b --- /dev/null +++ b/tests/lean/Loops/Types.lean @@ -0,0 +1,12 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [loops]: type definitions +import Base +open Primitives +namespace loops + +/- [loops::List] -/ +inductive List (T : Type) := +| Cons : T → List T → List T +| Nil : List T + +end loops diff --git a/tests/lean/Makefile b/tests/lean/Makefile index ed3b3e3b..3ccfbec2 100644 --- a/tests/lean/Makefile +++ b/tests/lean/Makefile @@ -1,40 +1,35 @@ ALL_DIRS ?= $(filter-out %~ lean-toolchain% Makefile%, $(wildcard *)) +# TODO: remove UPDATE_DIRS = $(addprefix update-,$(ALL_DIRS)) +# TODO: remove VERIFY_DIRS = $(addprefix verif-,$(ALL_DIRS)) +# TODO: remove CLEAN_DIRS = $(addprefix clean-,$(ALL_DIRS)) +# TODO: remove COPY_LEAN_TOOLCHAIN = $(addprefix copy-lean-toolchain-,$(ALL_DIRS)) .PHONY: all all: prepare-projects verify .PHONY: prepare-projects -prepare-projects: $(COPY_LEAN_TOOLCHAIN) +prepare-projects: copy-lean-toolchain .PHONY: prepare-projects -copy-lean-toolchain-%: - cp lean-toolchain $* +copy-lean-toolchain: + cp ../../backends/lean/lean-toolchain . .PHONY: update -update: $(UPDATE_DIRS) - -.PHONY: update-% -update-%: - cd $* && lake update +update: + lake update .PHONY: verify -verify: $(VERIFY_DIRS) - -.PHONY: verif-% -verif-%: - cd $* && lake build +verify: + lake build .PHONY: clean -clean: $(CLEAN_DIRS) - -.PHONY: clean-% -clean-%: - cd $* && lake clean +clean: + lake clean diff --git a/tests/lean/NoNestedBorrows.lean b/tests/lean/NoNestedBorrows.lean new file mode 100644 index 00000000..bc707fd9 --- /dev/null +++ b/tests/lean/NoNestedBorrows.lean @@ -0,0 +1,511 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [no_nested_borrows] +import Base +open Primitives +namespace no_nested_borrows + +/- [no_nested_borrows::Pair] -/ +structure Pair (T1 T2 : Type) where + x : T1 + y : T2 + +/- [no_nested_borrows::List] -/ +inductive List (T : Type) := +| Cons : T → List T → List T +| Nil : List T + +/- [no_nested_borrows::One] -/ +inductive One (T1 : Type) := +| One : T1 → One T1 + +/- [no_nested_borrows::EmptyEnum] -/ +inductive EmptyEnum := +| Empty : EmptyEnum + +/- [no_nested_borrows::Enum] -/ +inductive Enum := +| Variant1 : Enum +| Variant2 : Enum + +/- [no_nested_borrows::EmptyStruct] -/ +structure EmptyStruct where + +/- [no_nested_borrows::Sum] -/ +inductive Sum (T1 T2 : Type) := +| Left : T1 → Sum T1 T2 +| Right : T2 → Sum T1 T2 + +/- [no_nested_borrows::neg_test]: forward function -/ +def neg_test (x : I32) : Result I32 := + - x + +/- [no_nested_borrows::add_test]: forward function -/ +def add_test (x : U32) (y : U32) : Result U32 := + x + y + +/- [no_nested_borrows::subs_test]: forward function -/ +def subs_test (x : U32) (y : U32) : Result U32 := + x - y + +/- [no_nested_borrows::div_test]: forward function -/ +def div_test (x : U32) (y : U32) : Result U32 := + x / y + +/- [no_nested_borrows::div_test1]: forward function -/ +def div_test1 (x : U32) : Result U32 := + x / (U32.ofInt 2) + +/- [no_nested_borrows::rem_test]: forward function -/ +def rem_test (x : U32) (y : U32) : Result U32 := + x % y + +/- [no_nested_borrows::cast_test]: forward function -/ +def cast_test (x : U32) : Result I32 := + Scalar.cast .I32 x + +/- [no_nested_borrows::test2]: forward function -/ +def test2 : Result Unit := + do + let _ ← (U32.ofInt 23) + (U32.ofInt 44) + Result.ret () + +/- Unit test for [no_nested_borrows::test2] -/ +#assert (test2 == .ret ()) + +/- [no_nested_borrows::get_max]: forward function -/ +def get_max (x : U32) (y : U32) : Result U32 := + if x >= y + then Result.ret x + else Result.ret y + +/- [no_nested_borrows::test3]: forward function -/ +def test3 : Result Unit := + do + let x ← get_max (U32.ofInt 4) (U32.ofInt 3) + let y ← get_max (U32.ofInt 10) (U32.ofInt 11) + let z ← x + y + if not (z = (U32.ofInt 15)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test3] -/ +#assert (test3 == .ret ()) + +/- [no_nested_borrows::test_neg1]: forward function -/ +def test_neg1 : Result Unit := + do + let y ← - (I32.ofInt 3) + if not (y = (I32.ofInt (-(3:Int)))) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_neg1] -/ +#assert (test_neg1 == .ret ()) + +/- [no_nested_borrows::refs_test1]: forward function -/ +def refs_test1 : Result Unit := + if not ((I32.ofInt 1) = (I32.ofInt 1)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::refs_test1] -/ +#assert (refs_test1 == .ret ()) + +/- [no_nested_borrows::refs_test2]: forward function -/ +def refs_test2 : Result Unit := + if not ((I32.ofInt 2) = (I32.ofInt 2)) + then Result.fail Error.panic + else + if not ((I32.ofInt 0) = (I32.ofInt 0)) + then Result.fail Error.panic + else + if not ((I32.ofInt 2) = (I32.ofInt 2)) + then Result.fail Error.panic + else + if not ((I32.ofInt 2) = (I32.ofInt 2)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::refs_test2] -/ +#assert (refs_test2 == .ret ()) + +/- [no_nested_borrows::test_list1]: forward function -/ +def test_list1 : Result Unit := + Result.ret () + +/- Unit test for [no_nested_borrows::test_list1] -/ +#assert (test_list1 == .ret ()) + +/- [no_nested_borrows::test_box1]: forward function -/ +def test_box1 : Result Unit := + let b := (I32.ofInt 1) + let x := b + if not (x = (I32.ofInt 1)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_box1] -/ +#assert (test_box1 == .ret ()) + +/- [no_nested_borrows::copy_int]: forward function -/ +def copy_int (x : I32) : Result I32 := + Result.ret x + +/- [no_nested_borrows::test_unreachable]: forward function -/ +def test_unreachable (b : Bool) : Result Unit := + if b + then Result.fail Error.panic + else Result.ret () + +/- [no_nested_borrows::test_panic]: forward function -/ +def test_panic (b : Bool) : Result Unit := + if b + then Result.fail Error.panic + else Result.ret () + +/- [no_nested_borrows::test_copy_int]: forward function -/ +def test_copy_int : Result Unit := + do + let y ← copy_int (I32.ofInt 0) + if not ((I32.ofInt 0) = y) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_copy_int] -/ +#assert (test_copy_int == .ret ()) + +/- [no_nested_borrows::is_cons]: forward function -/ +def is_cons (T : Type) (l : List T) : Result Bool := + match l with + | List.Cons t l0 => Result.ret true + | List.Nil => Result.ret false + +/- [no_nested_borrows::test_is_cons]: forward function -/ +def test_is_cons : Result Unit := + do + let l := List.Nil + let b ← is_cons I32 (List.Cons (I32.ofInt 0) l) + if not b + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_is_cons] -/ +#assert (test_is_cons == .ret ()) + +/- [no_nested_borrows::split_list]: forward function -/ +def split_list (T : Type) (l : List T) : Result (T × (List T)) := + match l with + | List.Cons hd tl => Result.ret (hd, tl) + | List.Nil => Result.fail Error.panic + +/- [no_nested_borrows::test_split_list]: forward function -/ +def test_split_list : Result Unit := + do + let l := List.Nil + let p ← split_list I32 (List.Cons (I32.ofInt 0) l) + let (hd, _) := p + if not (hd = (I32.ofInt 0)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_split_list] -/ +#assert (test_split_list == .ret ()) + +/- [no_nested_borrows::choose]: forward function -/ +def choose (T : Type) (b : Bool) (x : T) (y : T) : Result T := + if b + then Result.ret x + else Result.ret y + +/- [no_nested_borrows::choose]: backward function 0 -/ +def choose_back + (T : Type) (b : Bool) (x : T) (y : T) (ret0 : T) : Result (T × T) := + if b + then Result.ret (ret0, y) + else Result.ret (x, ret0) + +/- [no_nested_borrows::choose_test]: forward function -/ +def choose_test : 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)) + 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)) + then Result.fail Error.panic + else + if not (y = (I32.ofInt 0)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::choose_test] -/ +#assert (choose_test == .ret ()) + +/- [no_nested_borrows::test_char]: forward function -/ +def test_char : Result Char := + Result.ret 'a' + +mutual + +/- [no_nested_borrows::NodeElem] -/ +inductive NodeElem (T : Type) := +| Cons : Tree T → NodeElem T → NodeElem T +| Nil : NodeElem T + +/- [no_nested_borrows::Tree] -/ +inductive Tree (T : Type) := +| Leaf : T → Tree T +| Node : T → NodeElem T → Tree T → Tree T + +end + +/- [no_nested_borrows::list_length]: forward function -/ +divergent def list_length (T : Type) (l : List T) : Result U32 := + match l with + | List.Cons t l1 => do + let i ← list_length T l1 + (U32.ofInt 1) + i + | List.Nil => Result.ret (U32.ofInt 0) + +/- [no_nested_borrows::list_nth_shared]: forward function -/ +divergent def list_nth_shared (T : Type) (l : List T) (i : U32) : Result T := + match l with + | List.Cons x tl => + if i = (U32.ofInt 0) + then Result.ret x + else do + let i0 ← i - (U32.ofInt 1) + list_nth_shared T tl i0 + | List.Nil => Result.fail Error.panic + +/- [no_nested_borrows::list_nth_mut]: forward function -/ +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) + then Result.ret x + else do + let i0 ← i - (U32.ofInt 1) + list_nth_mut T tl i0 + | List.Nil => Result.fail Error.panic + +/- [no_nested_borrows::list_nth_mut]: backward function 0 -/ +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) + then Result.ret (List.Cons ret0 tl) + else + do + let i0 ← i - (U32.ofInt 1) + let tl0 ← list_nth_mut_back T tl i0 ret0 + Result.ret (List.Cons x tl0) + | List.Nil => Result.fail Error.panic + +/- [no_nested_borrows::list_rev_aux]: forward function -/ +divergent def list_rev_aux + (T : Type) (li : List T) (lo : List T) : Result (List T) := + match li with + | List.Cons hd tl => list_rev_aux T tl (List.Cons hd lo) + | List.Nil => Result.ret lo + +/- [no_nested_borrows::list_rev]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def list_rev (T : Type) (l : List T) : Result (List T) := + let li := mem.replace (List T) l List.Nil + list_rev_aux T li List.Nil + +/- [no_nested_borrows::test_list_functions]: forward function -/ +def test_list_functions : Result Unit := + do + let l := List.Nil + let l0 := List.Cons (I32.ofInt 2) l + let l1 := List.Cons (I32.ofInt 1) l0 + let i ← list_length I32 (List.Cons (I32.ofInt 0) l1) + if not (i = (U32.ofInt 3)) + then Result.fail Error.panic + else + do + let i0 ← + list_nth_shared I32 (List.Cons (I32.ofInt 0) l1) (U32.ofInt 0) + if not (i0 = (I32.ofInt 0)) + then Result.fail Error.panic + else + do + let i1 ← + list_nth_shared I32 (List.Cons (I32.ofInt 0) l1) (U32.ofInt 1) + if not (i1 = (I32.ofInt 1)) + then Result.fail Error.panic + else + do + let i2 ← + list_nth_shared I32 (List.Cons (I32.ofInt 0) l1) + (U32.ofInt 2) + if not (i2 = (I32.ofInt 2)) + then Result.fail Error.panic + else + do + let ls ← + list_nth_mut_back I32 (List.Cons (I32.ofInt 0) l1) + (U32.ofInt 1) (I32.ofInt 3) + let i3 ← list_nth_shared I32 ls (U32.ofInt 0) + if not (i3 = (I32.ofInt 0)) + then Result.fail Error.panic + else + do + let i4 ← list_nth_shared I32 ls (U32.ofInt 1) + if not (i4 = (I32.ofInt 3)) + then Result.fail Error.panic + else + do + let i5 ← list_nth_shared I32 ls (U32.ofInt 2) + if not (i5 = (I32.ofInt 2)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_list_functions] -/ +#assert (test_list_functions == .ret ()) + +/- [no_nested_borrows::id_mut_pair1]: forward function -/ +def id_mut_pair1 (T1 T2 : Type) (x : T1) (y : T2) : Result (T1 × T2) := + Result.ret (x, y) + +/- [no_nested_borrows::id_mut_pair1]: backward function 0 -/ +def id_mut_pair1_back + (T1 T2 : Type) (x : T1) (y : T2) (ret0 : (T1 × T2)) : Result (T1 × T2) := + let (t, t0) := ret0 + Result.ret (t, t0) + +/- [no_nested_borrows::id_mut_pair2]: forward function -/ +def id_mut_pair2 (T1 T2 : Type) (p : (T1 × T2)) : Result (T1 × T2) := + let (t, t0) := p + Result.ret (t, t0) + +/- [no_nested_borrows::id_mut_pair2]: backward function 0 -/ +def id_mut_pair2_back + (T1 T2 : Type) (p : (T1 × T2)) (ret0 : (T1 × T2)) : Result (T1 × T2) := + let (t, t0) := ret0 + Result.ret (t, t0) + +/- [no_nested_borrows::id_mut_pair3]: forward function -/ +def id_mut_pair3 (T1 T2 : Type) (x : T1) (y : T2) : Result (T1 × T2) := + Result.ret (x, y) + +/- [no_nested_borrows::id_mut_pair3]: backward function 0 -/ +def id_mut_pair3_back'a + (T1 T2 : Type) (x : T1) (y : T2) (ret0 : T1) : Result T1 := + Result.ret ret0 + +/- [no_nested_borrows::id_mut_pair3]: backward function 1 -/ +def id_mut_pair3_back'b + (T1 T2 : Type) (x : T1) (y : T2) (ret0 : T2) : Result T2 := + Result.ret ret0 + +/- [no_nested_borrows::id_mut_pair4]: forward function -/ +def id_mut_pair4 (T1 T2 : Type) (p : (T1 × T2)) : Result (T1 × T2) := + let (t, t0) := p + Result.ret (t, t0) + +/- [no_nested_borrows::id_mut_pair4]: backward function 0 -/ +def id_mut_pair4_back'a + (T1 T2 : Type) (p : (T1 × T2)) (ret0 : T1) : Result T1 := + Result.ret ret0 + +/- [no_nested_borrows::id_mut_pair4]: backward function 1 -/ +def id_mut_pair4_back'b + (T1 T2 : Type) (p : (T1 × T2)) (ret0 : T2) : Result T2 := + Result.ret ret0 + +/- [no_nested_borrows::StructWithTuple] -/ +structure StructWithTuple (T1 T2 : Type) where + p : (T1 × T2) + +/- [no_nested_borrows::new_tuple1]: forward function -/ +def new_tuple1 : Result (StructWithTuple U32 U32) := + Result.ret { p := ((U32.ofInt 1), (U32.ofInt 2)) } + +/- [no_nested_borrows::new_tuple2]: forward function -/ +def new_tuple2 : Result (StructWithTuple I16 I16) := + Result.ret { p := ((I16.ofInt 1), (I16.ofInt 2)) } + +/- [no_nested_borrows::new_tuple3]: forward function -/ +def new_tuple3 : Result (StructWithTuple U64 I64) := + Result.ret { p := ((U64.ofInt 1), (I64.ofInt 2)) } + +/- [no_nested_borrows::StructWithPair] -/ +structure StructWithPair (T1 T2 : Type) where + p : Pair T1 T2 + +/- [no_nested_borrows::new_pair1]: forward function -/ +def new_pair1 : Result (StructWithPair U32 U32) := + Result.ret { p := { x := (U32.ofInt 1), y := (U32.ofInt 2) } } + +/- [no_nested_borrows::test_constants]: forward function -/ +def test_constants : Result Unit := + do + let swt ← new_tuple1 + let (i, _) := swt.p + if not (i = (U32.ofInt 1)) + then Result.fail Error.panic + else + do + let swt0 ← new_tuple2 + let (i0, _) := swt0.p + if not (i0 = (I16.ofInt 1)) + then Result.fail Error.panic + else + do + let swt1 ← new_tuple3 + let (i1, _) := swt1.p + if not (i1 = (U64.ofInt 1)) + then Result.fail Error.panic + else + do + let swp ← new_pair1 + if not (swp.p.x = (U32.ofInt 1)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [no_nested_borrows::test_constants] -/ +#assert (test_constants == .ret ()) + +/- [no_nested_borrows::test_weird_borrows1]: forward function -/ +def test_weird_borrows1 : Result Unit := + Result.ret () + +/- Unit test for [no_nested_borrows::test_weird_borrows1] -/ +#assert (test_weird_borrows1 == .ret ()) + +/- [no_nested_borrows::test_mem_replace]: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +def test_mem_replace (px : U32) : Result U32 := + let y := mem.replace U32 px (U32.ofInt 1) + if not (y = (U32.ofInt 0)) + then Result.fail Error.panic + else Result.ret (U32.ofInt 2) + +/- [no_nested_borrows::test_shared_borrow_bool1]: forward function -/ +def test_shared_borrow_bool1 (b : Bool) : Result U32 := + if b + then Result.ret (U32.ofInt 0) + else Result.ret (U32.ofInt 1) + +/- [no_nested_borrows::test_shared_borrow_bool2]: forward function -/ +def test_shared_borrow_bool2 : Result U32 := + Result.ret (U32.ofInt 0) + +/- [no_nested_borrows::test_shared_borrow_enum1]: forward function -/ +def test_shared_borrow_enum1 (l : List U32) : Result U32 := + match l with + | List.Cons i l0 => Result.ret (U32.ofInt 1) + | List.Nil => Result.ret (U32.ofInt 0) + +/- [no_nested_borrows::test_shared_borrow_enum2]: forward function -/ +def test_shared_borrow_enum2 : Result U32 := + Result.ret (U32.ofInt 0) + +end no_nested_borrows diff --git a/tests/lean/Paper.lean b/tests/lean/Paper.lean new file mode 100644 index 00000000..cee7128a --- /dev/null +++ b/tests/lean/Paper.lean @@ -0,0 +1,121 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [paper] +import Base +open Primitives +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) + +/- [paper::test_incr]: forward function -/ +def test_incr : Result Unit := + do + let x ← ref_incr (I32.ofInt 0) + if not (x = (I32.ofInt 1)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [paper::test_incr] -/ +#assert (test_incr == .ret ()) + +/- [paper::choose]: forward function -/ +def choose (T : Type) (b : Bool) (x : T) (y : T) : Result T := + if b + then Result.ret x + else Result.ret y + +/- [paper::choose]: backward function 0 -/ +def choose_back + (T : Type) (b : Bool) (x : T) (y : T) (ret0 : T) : Result (T × T) := + if b + then Result.ret (ret0, y) + else Result.ret (x, ret0) + +/- [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)) + 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)) + then Result.fail Error.panic + else + if not (y = (I32.ofInt 0)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [paper::test_choose] -/ +#assert (test_choose == .ret ()) + +/- [paper::List] -/ +inductive List (T : Type) := +| Cons : T → List T → List T +| Nil : List T + +/- [paper::list_nth_mut]: forward function -/ +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) + then Result.ret x + else do + let i0 ← i - (U32.ofInt 1) + list_nth_mut T tl i0 + | List.Nil => Result.fail Error.panic + +/- [paper::list_nth_mut]: backward function 0 -/ +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) + then Result.ret (List.Cons ret0 tl) + else + do + let i0 ← i - (U32.ofInt 1) + let tl0 ← list_nth_mut_back T tl i0 ret0 + Result.ret (List.Cons x tl0) + | List.Nil => Result.fail Error.panic + +/- [paper::sum]: forward function -/ +divergent def sum (l : List I32) : Result I32 := + match l with + | List.Cons x tl => do + let i ← sum tl + x + i + | List.Nil => Result.ret (I32.ofInt 0) + +/- [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 i ← sum l2 + if not (i = (I32.ofInt 7)) + then Result.fail Error.panic + else Result.ret () + +/- Unit test for [paper::test_nth] -/ +#assert (test_nth == .ret ()) + +/- [paper::call_choose]: forward function -/ +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 (px0, _) ← choose_back U32 true px py pz0 + Result.ret px0 + +end paper diff --git a/tests/lean/PoloniusList.lean b/tests/lean/PoloniusList.lean new file mode 100644 index 00000000..1453c275 --- /dev/null +++ b/tests/lean/PoloniusList.lean @@ -0,0 +1,34 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [polonius_list] +import Base +open Primitives +namespace polonius_list + +/- [polonius_list::List] -/ +inductive List (T : Type) := +| Cons : T → List T → List T +| Nil : List T + +/- [polonius_list::get_list_at_x]: forward function -/ +divergent def get_list_at_x (ls : List U32) (x : U32) : Result (List U32) := + match ls with + | List.Cons hd tl => + if hd = x + then Result.ret (List.Cons hd tl) + else get_list_at_x tl x + | List.Nil => Result.ret List.Nil + +/- [polonius_list::get_list_at_x]: backward function 0 -/ +divergent def get_list_at_x_back + (ls : List U32) (x : U32) (ret0 : List U32) : Result (List U32) := + match ls with + | List.Cons hd tl => + if hd = x + then Result.ret ret0 + else + do + let tl0 ← get_list_at_x_back tl x ret0 + Result.ret (List.Cons hd tl0) + | List.Nil => Result.ret ret0 + +end polonius_list diff --git a/tests/lean/hashmap/Base/Primitives.lean b/tests/lean/hashmap/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/hashmap/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/hashmap/Hashmap.lean b/tests/lean/hashmap/Hashmap.lean deleted file mode 100644 index 41630205..00000000 --- a/tests/lean/hashmap/Hashmap.lean +++ /dev/null @@ -1 +0,0 @@ -import Hashmap.Funs diff --git a/tests/lean/hashmap/Hashmap/Clauses/Clauses.lean b/tests/lean/hashmap/Hashmap/Clauses/Clauses.lean deleted file mode 100644 index 197b0a6a..00000000 --- a/tests/lean/hashmap/Hashmap/Clauses/Clauses.lean +++ /dev/null @@ -1,107 +0,0 @@ --- [hashmap]: templates for the decreases clauses -import Base.Primitives -import Hashmap.Types - -/- [hashmap::HashMap::{0}::allocate_slots]: termination measure -/ -@[simp] -def hash_map_allocate_slots_loop_terminates (T : Type) (slots : Vec (list_t T)) - (n : Usize) := - (slots, n) - -/- [hashmap::HashMap::{0}::allocate_slots]: decreases_by tactic -/ -syntax "hash_map_allocate_slots_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_allocate_slots_loop_decreases $slots $n) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::clear]: termination measure -/ -@[simp] -def hash_map_clear_loop_terminates (T : Type) (slots : Vec (list_t T)) - (i : Usize) := - (slots, i) - -/- [hashmap::HashMap::{0}::clear]: decreases_by tactic -/ -syntax "hash_map_clear_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_clear_loop_decreases $slots $i) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::insert_in_list]: termination measure -/ -@[simp] -def hash_map_insert_in_list_loop_terminates (T : Type) (key : Usize) - (value : T) (ls : list_t T) := - (key, value, ls) - -/- [hashmap::HashMap::{0}::insert_in_list]: decreases_by tactic -/ -syntax "hash_map_insert_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_insert_in_list_loop_decreases $key $value $ls) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::move_elements_from_list]: termination measure -/ -@[simp] -def hash_map_move_elements_from_list_loop_terminates (T : Type) - (ntable : hash_map_t T) (ls : list_t T) := - (ntable, ls) - -/- [hashmap::HashMap::{0}::move_elements_from_list]: decreases_by tactic -/ -syntax "hash_map_move_elements_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_move_elements_from_list_loop_decreases $ntable $ls) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::move_elements]: termination measure -/ -@[simp] -def hash_map_move_elements_loop_terminates (T : Type) (ntable : hash_map_t T) - (slots : Vec (list_t T)) (i : Usize) := - (ntable, slots, i) - -/- [hashmap::HashMap::{0}::move_elements]: decreases_by tactic -/ -syntax "hash_map_move_elements_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_move_elements_loop_decreases $ntable $slots $i) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::contains_key_in_list]: termination measure -/ -@[simp] -def hash_map_contains_key_in_list_loop_terminates (T : Type) (key : Usize) - (ls : list_t T) := - (key, ls) - -/- [hashmap::HashMap::{0}::contains_key_in_list]: decreases_by tactic -/ -syntax "hash_map_contains_key_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_contains_key_in_list_loop_decreases $key $ls) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::get_in_list]: termination measure -/ -@[simp] -def hash_map_get_in_list_loop_terminates (T : Type) (key : Usize) - (ls : list_t T) := - (key, ls) - -/- [hashmap::HashMap::{0}::get_in_list]: decreases_by tactic -/ -syntax "hash_map_get_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_get_in_list_loop_decreases $key $ls) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::get_mut_in_list]: termination measure -/ -@[simp] -def hash_map_get_mut_in_list_loop_terminates (T : Type) (ls : list_t T) - (key : Usize) := - (ls, key) - -/- [hashmap::HashMap::{0}::get_mut_in_list]: decreases_by tactic -/ -syntax "hash_map_get_mut_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_get_mut_in_list_loop_decreases $ls $key) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::remove_from_list]: termination measure -/ -@[simp] -def hash_map_remove_from_list_loop_terminates (T : Type) (key : Usize) - (ls : list_t T) := - (key, ls) - -/- [hashmap::HashMap::{0}::remove_from_list]: decreases_by tactic -/ -syntax "hash_map_remove_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_remove_from_list_loop_decreases $key $ls) =>`(tactic| sorry) - diff --git a/tests/lean/hashmap/Hashmap/Clauses/Template.lean b/tests/lean/hashmap/Hashmap/Clauses/Template.lean deleted file mode 100644 index 560592c8..00000000 --- a/tests/lean/hashmap/Hashmap/Clauses/Template.lean +++ /dev/null @@ -1,108 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [hashmap]: templates for the decreases clauses -import Base.Primitives -import Hashmap.Types - -/- [hashmap::HashMap::{0}::allocate_slots]: termination measure -/ -@[simp] -def hash_map_allocate_slots_loop_terminates (T : Type) (slots : Vec (list_t T)) - (n : Usize) := - (slots, n) - -/- [hashmap::HashMap::{0}::allocate_slots]: decreases_by tactic -/ -syntax "hash_map_allocate_slots_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_allocate_slots_loop_decreases $slots $n) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::clear]: termination measure -/ -@[simp] -def hash_map_clear_loop_terminates (T : Type) (slots : Vec (list_t T)) - (i : Usize) := - (slots, i) - -/- [hashmap::HashMap::{0}::clear]: decreases_by tactic -/ -syntax "hash_map_clear_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_clear_loop_decreases $slots $i) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::insert_in_list]: termination measure -/ -@[simp] -def hash_map_insert_in_list_loop_terminates (T : Type) (key : Usize) - (value : T) (ls : list_t T) := - (key, value, ls) - -/- [hashmap::HashMap::{0}::insert_in_list]: decreases_by tactic -/ -syntax "hash_map_insert_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_insert_in_list_loop_decreases $key $value $ls) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::move_elements_from_list]: termination measure -/ -@[simp] -def hash_map_move_elements_from_list_loop_terminates (T : Type) - (ntable : hash_map_t T) (ls : list_t T) := - (ntable, ls) - -/- [hashmap::HashMap::{0}::move_elements_from_list]: decreases_by tactic -/ -syntax "hash_map_move_elements_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_move_elements_from_list_loop_decreases $ntable $ls) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::move_elements]: termination measure -/ -@[simp] -def hash_map_move_elements_loop_terminates (T : Type) (ntable : hash_map_t T) - (slots : Vec (list_t T)) (i : Usize) := - (ntable, slots, i) - -/- [hashmap::HashMap::{0}::move_elements]: decreases_by tactic -/ -syntax "hash_map_move_elements_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_move_elements_loop_decreases $ntable $slots $i) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::contains_key_in_list]: termination measure -/ -@[simp] -def hash_map_contains_key_in_list_loop_terminates (T : Type) (key : Usize) - (ls : list_t T) := - (key, ls) - -/- [hashmap::HashMap::{0}::contains_key_in_list]: decreases_by tactic -/ -syntax "hash_map_contains_key_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_contains_key_in_list_loop_decreases $key $ls) => - `(tactic| sorry) - -/- [hashmap::HashMap::{0}::get_in_list]: termination measure -/ -@[simp] -def hash_map_get_in_list_loop_terminates (T : Type) (key : Usize) - (ls : list_t T) := - (key, ls) - -/- [hashmap::HashMap::{0}::get_in_list]: decreases_by tactic -/ -syntax "hash_map_get_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_get_in_list_loop_decreases $key $ls) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::get_mut_in_list]: termination measure -/ -@[simp] -def hash_map_get_mut_in_list_loop_terminates (T : Type) (ls : list_t T) - (key : Usize) := - (ls, key) - -/- [hashmap::HashMap::{0}::get_mut_in_list]: decreases_by tactic -/ -syntax "hash_map_get_mut_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_get_mut_in_list_loop_decreases $ls $key) =>`(tactic| sorry) - -/- [hashmap::HashMap::{0}::remove_from_list]: termination measure -/ -@[simp] -def hash_map_remove_from_list_loop_terminates (T : Type) (key : Usize) - (ls : list_t T) := - (key, ls) - -/- [hashmap::HashMap::{0}::remove_from_list]: decreases_by tactic -/ -syntax "hash_map_remove_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hash_map_remove_from_list_loop_decreases $key $ls) =>`(tactic| sorry) - diff --git a/tests/lean/hashmap/Hashmap/Funs.lean b/tests/lean/hashmap/Hashmap/Funs.lean deleted file mode 100644 index 77b1a157..00000000 --- a/tests/lean/hashmap/Hashmap/Funs.lean +++ /dev/null @@ -1,513 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [hashmap]: function definitions -import Base.Primitives -import Hashmap.Types -import Hashmap.Clauses.Clauses - -/- [hashmap::hash_key] -/ -def hash_key_fwd (k : Usize) : Result Usize := - Result.ret k - -/- [hashmap::HashMap::{0}::allocate_slots] -/ -def hash_map_allocate_slots_loop_fwd - (T : Type) (slots : Vec (list_t T)) (n : Usize) : - (Result (Vec (list_t T))) - := - if h: n > (Usize.ofInt 0 (by intlit)) - then - do - let slots0 ← vec_push_back (list_t T) slots list_t.Nil - let n0 ← n - (Usize.ofInt 1 (by intlit)) - hash_map_allocate_slots_loop_fwd T slots0 n0 - else Result.ret slots -termination_by hash_map_allocate_slots_loop_fwd slots n => - hash_map_allocate_slots_loop_terminates T slots n -decreasing_by hash_map_allocate_slots_loop_decreases slots n - -/- [hashmap::HashMap::{0}::allocate_slots] -/ -def hash_map_allocate_slots_fwd - (T : Type) (slots : Vec (list_t T)) (n : Usize) : Result (Vec (list_t T)) := - hash_map_allocate_slots_loop_fwd T slots n - -/- [hashmap::HashMap::{0}::new_with_capacity] -/ -def hash_map_new_with_capacity_fwd - (T : Type) (capacity : Usize) (max_load_dividend : Usize) - (max_load_divisor : Usize) : - Result (hash_map_t T) - := - do - let v := vec_new (list_t T) - let slots ← hash_map_allocate_slots_fwd T v capacity - let i ← capacity * max_load_dividend - let i0 ← i / max_load_divisor - Result.ret - { - hash_map_num_entries := (Usize.ofInt 0 (by intlit)), - hash_map_max_load_factor := (max_load_dividend, max_load_divisor), - hash_map_max_load := i0, - hash_map_slots := slots - } - -/- [hashmap::HashMap::{0}::new] -/ -def hash_map_new_fwd (T : Type) : Result (hash_map_t T) := - hash_map_new_with_capacity_fwd T (Usize.ofInt 32 (by intlit)) - (Usize.ofInt 4 (by intlit)) (Usize.ofInt 5 (by intlit)) - -/- [hashmap::HashMap::{0}::clear] -/ -def hash_map_clear_loop_fwd_back - (T : Type) (slots : Vec (list_t T)) (i : Usize) : - (Result (Vec (list_t T))) - := - let i0 := vec_len (list_t T) slots - if h: i < i0 - then - do - let i1 ← i + (Usize.ofInt 1 (by intlit)) - let slots0 ← vec_index_mut_back (list_t T) slots i list_t.Nil - hash_map_clear_loop_fwd_back T slots0 i1 - else Result.ret slots -termination_by hash_map_clear_loop_fwd_back slots i => - hash_map_clear_loop_terminates T slots i -decreasing_by hash_map_clear_loop_decreases slots i - -/- [hashmap::HashMap::{0}::clear] -/ -def hash_map_clear_fwd_back - (T : Type) (self : hash_map_t T) : Result (hash_map_t T) := - do - let v ← - hash_map_clear_loop_fwd_back T self.hash_map_slots - (Usize.ofInt 0 (by intlit)) - Result.ret - { - self - with - hash_map_num_entries := (Usize.ofInt 0 (by intlit)), - hash_map_slots := v - } - -/- [hashmap::HashMap::{0}::len] -/ -def hash_map_len_fwd (T : Type) (self : hash_map_t T) : Result Usize := - Result.ret self.hash_map_num_entries - -/- [hashmap::HashMap::{0}::insert_in_list] -/ -def hash_map_insert_in_list_loop_fwd - (T : Type) (key : Usize) (value : T) (ls : list_t T) : (Result Bool) := - match h: ls with - | list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret false - else hash_map_insert_in_list_loop_fwd T key value tl - | list_t.Nil => Result.ret true -termination_by hash_map_insert_in_list_loop_fwd key value ls => - hash_map_insert_in_list_loop_terminates T key value ls -decreasing_by hash_map_insert_in_list_loop_decreases key value ls - -/- [hashmap::HashMap::{0}::insert_in_list] -/ -def hash_map_insert_in_list_fwd - (T : Type) (key : Usize) (value : T) (ls : list_t T) : Result Bool := - hash_map_insert_in_list_loop_fwd T key value ls - -/- [hashmap::HashMap::{0}::insert_in_list] -/ -def hash_map_insert_in_list_loop_back - (T : Type) (key : Usize) (value : T) (ls : list_t T) : (Result (list_t T)) := - match h: ls with - | list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret (list_t.Cons ckey value tl) - else - do - let tl0 ← hash_map_insert_in_list_loop_back T key value tl - Result.ret (list_t.Cons ckey cvalue tl0) - | list_t.Nil => let l := list_t.Nil - Result.ret (list_t.Cons key value l) -termination_by hash_map_insert_in_list_loop_back key value ls => - hash_map_insert_in_list_loop_terminates T key value ls -decreasing_by hash_map_insert_in_list_loop_decreases key value ls - -/- [hashmap::HashMap::{0}::insert_in_list] -/ -def hash_map_insert_in_list_back - (T : Type) (key : Usize) (value : T) (ls : list_t T) : Result (list_t T) := - hash_map_insert_in_list_loop_back T key value ls - -/- [hashmap::HashMap::{0}::insert_no_resize] -/ -def hash_map_insert_no_resize_fwd_back - (T : Type) (self : hash_map_t T) (key : Usize) (value : T) : - Result (hash_map_t T) - := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_mut_fwd (list_t T) self.hash_map_slots hash_mod - let inserted ← hash_map_insert_in_list_fwd T key value l - if h: inserted - then - do - let i0 ← self.hash_map_num_entries + (Usize.ofInt 1 (by intlit)) - let l0 ← hash_map_insert_in_list_back T key value l - let v ← vec_index_mut_back (list_t T) self.hash_map_slots hash_mod l0 - Result.ret - { self with hash_map_num_entries := i0, hash_map_slots := v } - else - do - let l0 ← hash_map_insert_in_list_back T key value l - let v ← vec_index_mut_back (list_t T) self.hash_map_slots hash_mod l0 - Result.ret { self with hash_map_slots := v } - -/- [core::num::u32::{9}::MAX] -/ -def core_num_u32_max_body : Result U32 := - Result.ret (U32.ofInt 4294967295 (by intlit)) -def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) - -/- [hashmap::HashMap::{0}::move_elements_from_list] -/ -def hash_map_move_elements_from_list_loop_fwd_back - (T : Type) (ntable : hash_map_t T) (ls : list_t T) : - (Result (hash_map_t T)) - := - match h: ls with - | list_t.Cons k v tl => - do - let ntable0 ← hash_map_insert_no_resize_fwd_back T ntable k v - hash_map_move_elements_from_list_loop_fwd_back T ntable0 tl - | list_t.Nil => Result.ret ntable -termination_by hash_map_move_elements_from_list_loop_fwd_back ntable ls => - hash_map_move_elements_from_list_loop_terminates T ntable ls -decreasing_by hash_map_move_elements_from_list_loop_decreases ntable ls - -/- [hashmap::HashMap::{0}::move_elements_from_list] -/ -def hash_map_move_elements_from_list_fwd_back - (T : Type) (ntable : hash_map_t T) (ls : list_t T) : Result (hash_map_t T) := - hash_map_move_elements_from_list_loop_fwd_back T ntable ls - -/- [hashmap::HashMap::{0}::move_elements] -/ -def hash_map_move_elements_loop_fwd_back - (T : Type) (ntable : hash_map_t T) (slots : Vec (list_t T)) (i : Usize) : - (Result ((hash_map_t T) × (Vec (list_t T)))) - := - let i0 := vec_len (list_t T) slots - if h: i < i0 - then - do - let l ← vec_index_mut_fwd (list_t T) slots i - let ls := mem_replace_fwd (list_t T) l list_t.Nil - let ntable0 ← hash_map_move_elements_from_list_fwd_back T ntable ls - let i1 ← i + (Usize.ofInt 1 (by intlit)) - let l0 := mem_replace_back (list_t T) l list_t.Nil - let slots0 ← vec_index_mut_back (list_t T) slots i l0 - hash_map_move_elements_loop_fwd_back T ntable0 slots0 i1 - else Result.ret (ntable, slots) -termination_by hash_map_move_elements_loop_fwd_back ntable slots i => - hash_map_move_elements_loop_terminates T ntable slots i -decreasing_by hash_map_move_elements_loop_decreases ntable slots i - -/- [hashmap::HashMap::{0}::move_elements] -/ -def hash_map_move_elements_fwd_back - (T : Type) (ntable : hash_map_t T) (slots : Vec (list_t T)) (i : Usize) : - Result ((hash_map_t T) × (Vec (list_t T))) - := - hash_map_move_elements_loop_fwd_back T ntable slots i - -/- [hashmap::HashMap::{0}::try_resize] -/ -def hash_map_try_resize_fwd_back - (T : Type) (self : hash_map_t T) : Result (hash_map_t T) := - do - let max_usize ← Scalar.cast .Usize core_num_u32_max_c - let capacity := vec_len (list_t T) self.hash_map_slots - let n1 ← max_usize / (Usize.ofInt 2 (by intlit)) - let (i, i0) := self.hash_map_max_load_factor - let i1 ← n1 / i - if h: capacity <= i1 - then - do - let i2 ← capacity * (Usize.ofInt 2 (by intlit)) - let ntable ← hash_map_new_with_capacity_fwd T i2 i i0 - let (ntable0, _) ← - hash_map_move_elements_fwd_back T ntable self.hash_map_slots - (Usize.ofInt 0 (by intlit)) - Result.ret - { - ntable0 - with - hash_map_num_entries := self.hash_map_num_entries, - hash_map_max_load_factor := (i, i0) - } - else Result.ret { self with hash_map_max_load_factor := (i, i0) } - -/- [hashmap::HashMap::{0}::insert] -/ -def hash_map_insert_fwd_back - (T : Type) (self : hash_map_t T) (key : Usize) (value : T) : - Result (hash_map_t T) - := - do - let self0 ← hash_map_insert_no_resize_fwd_back T self key value - let i ← hash_map_len_fwd T self0 - if h: i > self0.hash_map_max_load - then hash_map_try_resize_fwd_back T self0 - else Result.ret self0 - -/- [hashmap::HashMap::{0}::contains_key_in_list] -/ -def hash_map_contains_key_in_list_loop_fwd - (T : Type) (key : Usize) (ls : list_t T) : (Result Bool) := - match h: ls with - | list_t.Cons ckey t tl => - if h: ckey = key - then Result.ret true - else hash_map_contains_key_in_list_loop_fwd T key tl - | list_t.Nil => Result.ret false -termination_by hash_map_contains_key_in_list_loop_fwd key ls => - hash_map_contains_key_in_list_loop_terminates T key ls -decreasing_by hash_map_contains_key_in_list_loop_decreases key ls - -/- [hashmap::HashMap::{0}::contains_key_in_list] -/ -def hash_map_contains_key_in_list_fwd - (T : Type) (key : Usize) (ls : list_t T) : Result Bool := - hash_map_contains_key_in_list_loop_fwd T key ls - -/- [hashmap::HashMap::{0}::contains_key] -/ -def hash_map_contains_key_fwd - (T : Type) (self : hash_map_t T) (key : Usize) : Result Bool := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_fwd (list_t T) self.hash_map_slots hash_mod - hash_map_contains_key_in_list_fwd T key l - -/- [hashmap::HashMap::{0}::get_in_list] -/ -def hash_map_get_in_list_loop_fwd - (T : Type) (key : Usize) (ls : list_t T) : (Result T) := - match h: ls with - | list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret cvalue - else hash_map_get_in_list_loop_fwd T key tl - | list_t.Nil => Result.fail Error.panic -termination_by hash_map_get_in_list_loop_fwd key ls => - hash_map_get_in_list_loop_terminates T key ls -decreasing_by hash_map_get_in_list_loop_decreases key ls - -/- [hashmap::HashMap::{0}::get_in_list] -/ -def hash_map_get_in_list_fwd - (T : Type) (key : Usize) (ls : list_t T) : Result T := - hash_map_get_in_list_loop_fwd T key ls - -/- [hashmap::HashMap::{0}::get] -/ -def hash_map_get_fwd - (T : Type) (self : hash_map_t T) (key : Usize) : Result T := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_fwd (list_t T) self.hash_map_slots hash_mod - hash_map_get_in_list_fwd T key l - -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ -def hash_map_get_mut_in_list_loop_fwd - (T : Type) (ls : list_t T) (key : Usize) : (Result T) := - match h: ls with - | list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret cvalue - else hash_map_get_mut_in_list_loop_fwd T tl key - | list_t.Nil => Result.fail Error.panic -termination_by hash_map_get_mut_in_list_loop_fwd ls key => - hash_map_get_mut_in_list_loop_terminates T ls key -decreasing_by hash_map_get_mut_in_list_loop_decreases ls key - -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ -def hash_map_get_mut_in_list_fwd - (T : Type) (ls : list_t T) (key : Usize) : Result T := - hash_map_get_mut_in_list_loop_fwd T ls key - -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ -def hash_map_get_mut_in_list_loop_back - (T : Type) (ls : list_t T) (key : Usize) (ret0 : T) : (Result (list_t T)) := - match h: ls with - | list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret (list_t.Cons ckey ret0 tl) - else - do - let tl0 ← hash_map_get_mut_in_list_loop_back T tl key ret0 - Result.ret (list_t.Cons ckey cvalue tl0) - | list_t.Nil => Result.fail Error.panic -termination_by hash_map_get_mut_in_list_loop_back ls key ret0 => - hash_map_get_mut_in_list_loop_terminates T ls key -decreasing_by hash_map_get_mut_in_list_loop_decreases ls key - -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ -def hash_map_get_mut_in_list_back - (T : Type) (ls : list_t T) (key : Usize) (ret0 : T) : Result (list_t T) := - hash_map_get_mut_in_list_loop_back T ls key ret0 - -/- [hashmap::HashMap::{0}::get_mut] -/ -def hash_map_get_mut_fwd - (T : Type) (self : hash_map_t T) (key : Usize) : Result T := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_mut_fwd (list_t T) self.hash_map_slots hash_mod - hash_map_get_mut_in_list_fwd T l key - -/- [hashmap::HashMap::{0}::get_mut] -/ -def hash_map_get_mut_back - (T : Type) (self : hash_map_t T) (key : Usize) (ret0 : T) : - Result (hash_map_t T) - := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_mut_fwd (list_t T) self.hash_map_slots hash_mod - let l0 ← hash_map_get_mut_in_list_back T l key ret0 - let v ← vec_index_mut_back (list_t T) self.hash_map_slots hash_mod l0 - Result.ret { self with hash_map_slots := v } - -/- [hashmap::HashMap::{0}::remove_from_list] -/ -def hash_map_remove_from_list_loop_fwd - (T : Type) (key : Usize) (ls : list_t T) : (Result (Option T)) := - match h: ls with - | list_t.Cons ckey t tl => - if h: ckey = key - then - let mv_ls := - mem_replace_fwd (list_t T) (list_t.Cons ckey t tl) list_t.Nil - match h: mv_ls with - | list_t.Cons i cvalue tl0 => Result.ret (Option.some cvalue) - | list_t.Nil => Result.fail Error.panic - else hash_map_remove_from_list_loop_fwd T key tl - | list_t.Nil => Result.ret Option.none -termination_by hash_map_remove_from_list_loop_fwd key ls => - hash_map_remove_from_list_loop_terminates T key ls -decreasing_by hash_map_remove_from_list_loop_decreases key ls - -/- [hashmap::HashMap::{0}::remove_from_list] -/ -def hash_map_remove_from_list_fwd - (T : Type) (key : Usize) (ls : list_t T) : Result (Option T) := - hash_map_remove_from_list_loop_fwd T key ls - -/- [hashmap::HashMap::{0}::remove_from_list] -/ -def hash_map_remove_from_list_loop_back - (T : Type) (key : Usize) (ls : list_t T) : (Result (list_t T)) := - match h: ls with - | list_t.Cons ckey t tl => - if h: ckey = key - then - let mv_ls := - mem_replace_fwd (list_t T) (list_t.Cons ckey t tl) list_t.Nil - match h: mv_ls with - | list_t.Cons i cvalue tl0 => Result.ret tl0 - | list_t.Nil => Result.fail Error.panic - else - do - let tl0 ← hash_map_remove_from_list_loop_back T key tl - Result.ret (list_t.Cons ckey t tl0) - | list_t.Nil => Result.ret list_t.Nil -termination_by hash_map_remove_from_list_loop_back key ls => - hash_map_remove_from_list_loop_terminates T key ls -decreasing_by hash_map_remove_from_list_loop_decreases key ls - -/- [hashmap::HashMap::{0}::remove_from_list] -/ -def hash_map_remove_from_list_back - (T : Type) (key : Usize) (ls : list_t T) : Result (list_t T) := - hash_map_remove_from_list_loop_back T key ls - -/- [hashmap::HashMap::{0}::remove] -/ -def hash_map_remove_fwd - (T : Type) (self : hash_map_t T) (key : Usize) : Result (Option T) := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_mut_fwd (list_t T) self.hash_map_slots hash_mod - let x ← hash_map_remove_from_list_fwd T key l - match h: x with - | Option.none => Result.ret Option.none - | Option.some x0 => - do - let _ ← self.hash_map_num_entries - (Usize.ofInt 1 (by intlit)) - Result.ret (Option.some x0) - -/- [hashmap::HashMap::{0}::remove] -/ -def hash_map_remove_back - (T : Type) (self : hash_map_t T) (key : Usize) : Result (hash_map_t T) := - do - let hash ← hash_key_fwd key - let i := vec_len (list_t T) self.hash_map_slots - let hash_mod ← hash % i - let l ← vec_index_mut_fwd (list_t T) self.hash_map_slots hash_mod - let x ← hash_map_remove_from_list_fwd T key l - match h: x with - | Option.none => - do - let l0 ← hash_map_remove_from_list_back T key l - let v ← vec_index_mut_back (list_t T) self.hash_map_slots hash_mod l0 - Result.ret { self with hash_map_slots := v } - | Option.some x0 => - do - let i0 ← self.hash_map_num_entries - (Usize.ofInt 1 (by intlit)) - let l0 ← hash_map_remove_from_list_back T key l - let v ← vec_index_mut_back (list_t T) self.hash_map_slots hash_mod l0 - Result.ret - { self with hash_map_num_entries := i0, hash_map_slots := v } - -/- [hashmap::test1] -/ -def test1_fwd : Result Unit := - do - let hm ← hash_map_new_fwd U64 - let hm0 ← - hash_map_insert_fwd_back U64 hm (Usize.ofInt 0 (by intlit)) - (U64.ofInt 42 (by intlit)) - let hm1 ← - hash_map_insert_fwd_back U64 hm0 (Usize.ofInt 128 (by intlit)) - (U64.ofInt 18 (by intlit)) - let hm2 ← - hash_map_insert_fwd_back U64 hm1 (Usize.ofInt 1024 (by intlit)) - (U64.ofInt 138 (by intlit)) - let hm3 ← - hash_map_insert_fwd_back U64 hm2 (Usize.ofInt 1056 (by intlit)) - (U64.ofInt 256 (by intlit)) - let i ← hash_map_get_fwd U64 hm3 (Usize.ofInt 128 (by intlit)) - if h: not (i = (U64.ofInt 18 (by intlit))) - then Result.fail Error.panic - else - do - let hm4 ← - hash_map_get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) - (U64.ofInt 56 (by intlit)) - let i0 ← hash_map_get_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) - if h: not (i0 = (U64.ofInt 56 (by intlit))) - then Result.fail Error.panic - else - do - let x ← - hash_map_remove_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) - match h: x with - | Option.none => Result.fail Error.panic - | Option.some x0 => - if h: not (x0 = (U64.ofInt 56 (by intlit))) - then Result.fail Error.panic - else - do - let hm5 ← - hash_map_remove_back U64 hm4 (Usize.ofInt 1024 (by intlit)) - let i1 ← - hash_map_get_fwd U64 hm5 (Usize.ofInt 0 (by intlit)) - if h: not (i1 = (U64.ofInt 42 (by intlit))) - then Result.fail Error.panic - else - do - let i2 ← - hash_map_get_fwd U64 hm5 (Usize.ofInt 128 (by intlit)) - if h: not (i2 = (U64.ofInt 18 (by intlit))) - then Result.fail Error.panic - else - do - let i3 ← - hash_map_get_fwd U64 hm5 - (Usize.ofInt 1056 (by intlit)) - if h: not (i3 = (U64.ofInt 256 (by intlit))) - then Result.fail Error.panic - else Result.ret () - diff --git a/tests/lean/hashmap/Hashmap/Types.lean b/tests/lean/hashmap/Hashmap/Types.lean deleted file mode 100644 index 6eabf7da..00000000 --- a/tests/lean/hashmap/Hashmap/Types.lean +++ /dev/null @@ -1,16 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [hashmap]: type definitions -import Base.Primitives - -/- [hashmap::List] -/ -inductive list_t (T : Type) := -| Cons : Usize -> T -> list_t T -> list_t T -| Nil : list_t T - -/- [hashmap::HashMap] -/ -structure hash_map_t (T : Type) where - hash_map_num_entries : Usize - hash_map_max_load_factor : (Usize × Usize) - hash_map_max_load : Usize - hash_map_slots : Vec (list_t T) - diff --git a/tests/lean/hashmap/lake-manifest.json b/tests/lean/hashmap/lake-manifest.json deleted file mode 100644 index 88e446e5..00000000 --- a/tests/lean/hashmap/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "1c5ed7840906e29e1f8ca7dbf088cf155e5397e9", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/hashmap/lakefile.lean b/tests/lean/hashmap/lakefile.lean deleted file mode 100644 index 713785f6..00000000 --- a/tests/lean/hashmap/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «hashmap» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «Hashmap» {} diff --git a/tests/lean/hashmap/lean-toolchain b/tests/lean/hashmap/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/hashmap/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/hashmap_on_disk/.gitignore b/tests/lean/hashmap_on_disk/.gitignore deleted file mode 100644 index a1735e7c..00000000 --- a/tests/lean/hashmap_on_disk/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/build -/lean_packages/* -!/lean_packages/manifest.json -/build -/lake-packages/* diff --git a/tests/lean/hashmap_on_disk/Base/Primitives.lean b/tests/lean/hashmap_on_disk/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/hashmap_on_disk/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/hashmap_on_disk/HashmapMain/Clauses/Clauses.lean b/tests/lean/hashmap_on_disk/HashmapMain/Clauses/Clauses.lean deleted file mode 100644 index a4dc996a..00000000 --- a/tests/lean/hashmap_on_disk/HashmapMain/Clauses/Clauses.lean +++ /dev/null @@ -1,110 +0,0 @@ -import Base.Primitives -import HashmapMain.Types - -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: termination measure -/ -@[simp] -def hashmap_hash_map_allocate_slots_loop_terminates (T : Type) - (slots : Vec (hashmap_list_t T)) (n : Usize) := - (slots, n) - -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: decreases_by tactic -/ -syntax "hashmap_hash_map_allocate_slots_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_allocate_slots_loop_decreases $slots $n) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::clear]: termination measure -/ -@[simp] -def hashmap_hash_map_clear_loop_terminates (T : Type) - (slots : Vec (hashmap_list_t T)) (i : Usize) := - (slots, i) - -/- [hashmap_main::hashmap::HashMap::{0}::clear]: decreases_by tactic -/ -syntax "hashmap_hash_map_clear_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_clear_loop_decreases $slots $i) =>`(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_insert_in_list_loop_terminates (T : Type) (key : Usize) - (value : T) (ls : hashmap_list_t T) := - (key, value, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_insert_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_insert_in_list_loop_decreases $key $value $ls) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: termination measure -/ -@[simp] -def hashmap_hash_map_move_elements_from_list_loop_terminates (T : Type) - (ntable : hashmap_hash_map_t T) (ls : hashmap_list_t T) := - (ntable, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_move_elements_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_move_elements_from_list_loop_decreases $ntable -$ls) =>`(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements]: termination measure -/ -@[simp] -def hashmap_hash_map_move_elements_loop_terminates (T : Type) - (ntable : hashmap_hash_map_t T) (slots : Vec (hashmap_list_t T)) (i : Usize) - := - (ntable, slots, i) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements]: decreases_by tactic -/ -syntax "hashmap_hash_map_move_elements_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_move_elements_loop_decreases $ntable $slots $i) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_contains_key_in_list_loop_terminates (T : Type) - (key : Usize) (ls : hashmap_list_t T) := - (key, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_contains_key_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_contains_key_in_list_loop_decreases $key $ls) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_get_in_list_loop_terminates (T : Type) (key : Usize) - (ls : hashmap_list_t T) := - (key, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_get_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_get_in_list_loop_decreases $key $ls) =>`(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_get_mut_in_list_loop_terminates (T : Type) - (ls : hashmap_list_t T) (key : Usize) := - (ls, key) - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_get_mut_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_get_mut_in_list_loop_decreases $ls $key) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: termination measure -/ -@[simp] -def hashmap_hash_map_remove_from_list_loop_terminates (T : Type) (key : Usize) - (ls : hashmap_list_t T) := - (key, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_remove_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_remove_from_list_loop_decreases $key $ls) => - `(tactic| sorry) - diff --git a/tests/lean/hashmap_on_disk/HashmapMain/Clauses/Template.lean b/tests/lean/hashmap_on_disk/HashmapMain/Clauses/Template.lean deleted file mode 100644 index 33802597..00000000 --- a/tests/lean/hashmap_on_disk/HashmapMain/Clauses/Template.lean +++ /dev/null @@ -1,112 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [hashmap_main]: templates for the decreases clauses -import Base.Primitives -import HashmapMain.Types - -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: termination measure -/ -@[simp] -def hashmap_hash_map_allocate_slots_loop_terminates (T : Type) - (slots : Vec (hashmap_list_t T)) (n : Usize) := - (slots, n) - -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots]: decreases_by tactic -/ -syntax "hashmap_hash_map_allocate_slots_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_allocate_slots_loop_decreases $slots $n) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::clear]: termination measure -/ -@[simp] -def hashmap_hash_map_clear_loop_terminates (T : Type) - (slots : Vec (hashmap_list_t T)) (i : Usize) := - (slots, i) - -/- [hashmap_main::hashmap::HashMap::{0}::clear]: decreases_by tactic -/ -syntax "hashmap_hash_map_clear_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_clear_loop_decreases $slots $i) =>`(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_insert_in_list_loop_terminates (T : Type) (key : Usize) - (value : T) (ls : hashmap_list_t T) := - (key, value, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_insert_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_insert_in_list_loop_decreases $key $value $ls) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: termination measure -/ -@[simp] -def hashmap_hash_map_move_elements_from_list_loop_terminates (T : Type) - (ntable : hashmap_hash_map_t T) (ls : hashmap_list_t T) := - (ntable, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_move_elements_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_move_elements_from_list_loop_decreases $ntable -$ls) =>`(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements]: termination measure -/ -@[simp] -def hashmap_hash_map_move_elements_loop_terminates (T : Type) - (ntable : hashmap_hash_map_t T) (slots : Vec (hashmap_list_t T)) (i : Usize) - := - (ntable, slots, i) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements]: decreases_by tactic -/ -syntax "hashmap_hash_map_move_elements_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_move_elements_loop_decreases $ntable $slots $i) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_contains_key_in_list_loop_terminates (T : Type) - (key : Usize) (ls : hashmap_list_t T) := - (key, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_contains_key_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_contains_key_in_list_loop_decreases $key $ls) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_get_in_list_loop_terminates (T : Type) (key : Usize) - (ls : hashmap_list_t T) := - (key, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_get_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_get_in_list_loop_decreases $key $ls) =>`(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: termination measure -/ -@[simp] -def hashmap_hash_map_get_mut_in_list_loop_terminates (T : Type) - (ls : hashmap_list_t T) (key : Usize) := - (ls, key) - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_get_mut_in_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_get_mut_in_list_loop_decreases $ls $key) => - `(tactic| sorry) - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: termination measure -/ -@[simp] -def hashmap_hash_map_remove_from_list_loop_terminates (T : Type) (key : Usize) - (ls : hashmap_list_t T) := - (key, ls) - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list]: decreases_by tactic -/ -syntax "hashmap_hash_map_remove_from_list_loop_decreases" term+ : tactic -macro_rules -| `(tactic| hashmap_hash_map_remove_from_list_loop_decreases $key $ls) => - `(tactic| sorry) - diff --git a/tests/lean/hashmap_on_disk/HashmapMain/ExternalFuns.lean b/tests/lean/hashmap_on_disk/HashmapMain/ExternalFuns.lean deleted file mode 100644 index a5103acc..00000000 --- a/tests/lean/hashmap_on_disk/HashmapMain/ExternalFuns.lean +++ /dev/null @@ -1,5 +0,0 @@ -import Base.Primitives -import HashmapMain.Types -import HashmapMain.Opaque - -def opaque_defs : OpaqueDefs := by sorry diff --git a/tests/lean/hashmap_on_disk/HashmapMain/Funs.lean b/tests/lean/hashmap_on_disk/HashmapMain/Funs.lean deleted file mode 100644 index 342c3833..00000000 --- a/tests/lean/hashmap_on_disk/HashmapMain/Funs.lean +++ /dev/null @@ -1,590 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [hashmap_main]: function definitions -import Base.Primitives -import HashmapMain.Types -import HashmapMain.ExternalFuns -import HashmapMain.Clauses.Clauses - -/- [hashmap_main::hashmap::hash_key] -/ -def hashmap_hash_key_fwd (k : Usize) : Result Usize := - Result.ret k - -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots] -/ -def hashmap_hash_map_allocate_slots_loop_fwd - (T : Type) (slots : Vec (hashmap_list_t T)) (n : Usize) : - (Result (Vec (hashmap_list_t T))) - := - if h: n > (Usize.ofInt 0 (by intlit)) - then - do - let slots0 ← vec_push_back (hashmap_list_t T) slots hashmap_list_t.Nil - let n0 ← n - (Usize.ofInt 1 (by intlit)) - hashmap_hash_map_allocate_slots_loop_fwd T slots0 n0 - else Result.ret slots -termination_by hashmap_hash_map_allocate_slots_loop_fwd slots n => - hashmap_hash_map_allocate_slots_loop_terminates T slots n -decreasing_by hashmap_hash_map_allocate_slots_loop_decreases slots n - -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots] -/ -def hashmap_hash_map_allocate_slots_fwd - (T : Type) (slots : Vec (hashmap_list_t T)) (n : Usize) : - Result (Vec (hashmap_list_t T)) - := - hashmap_hash_map_allocate_slots_loop_fwd T slots n - -/- [hashmap_main::hashmap::HashMap::{0}::new_with_capacity] -/ -def hashmap_hash_map_new_with_capacity_fwd - (T : Type) (capacity : Usize) (max_load_dividend : Usize) - (max_load_divisor : Usize) : - Result (hashmap_hash_map_t T) - := - do - let v := vec_new (hashmap_list_t T) - let slots ← hashmap_hash_map_allocate_slots_fwd T v capacity - let i ← capacity * max_load_dividend - let i0 ← i / max_load_divisor - Result.ret - { - hashmap_hash_map_num_entries := (Usize.ofInt 0 (by intlit)), - hashmap_hash_map_max_load_factor := - (max_load_dividend, max_load_divisor), - hashmap_hash_map_max_load := i0, - hashmap_hash_map_slots := slots - } - -/- [hashmap_main::hashmap::HashMap::{0}::new] -/ -def hashmap_hash_map_new_fwd (T : Type) : Result (hashmap_hash_map_t T) := - hashmap_hash_map_new_with_capacity_fwd T (Usize.ofInt 32 (by intlit)) - (Usize.ofInt 4 (by intlit)) (Usize.ofInt 5 (by intlit)) - -/- [hashmap_main::hashmap::HashMap::{0}::clear] -/ -def hashmap_hash_map_clear_loop_fwd_back - (T : Type) (slots : Vec (hashmap_list_t T)) (i : Usize) : - (Result (Vec (hashmap_list_t T))) - := - let i0 := vec_len (hashmap_list_t T) slots - if h: i < i0 - then - do - let i1 ← i + (Usize.ofInt 1 (by intlit)) - let slots0 ← - vec_index_mut_back (hashmap_list_t T) slots i hashmap_list_t.Nil - hashmap_hash_map_clear_loop_fwd_back T slots0 i1 - else Result.ret slots -termination_by hashmap_hash_map_clear_loop_fwd_back slots i => - hashmap_hash_map_clear_loop_terminates T slots i -decreasing_by hashmap_hash_map_clear_loop_decreases slots i - -/- [hashmap_main::hashmap::HashMap::{0}::clear] -/ -def hashmap_hash_map_clear_fwd_back - (T : Type) (self : hashmap_hash_map_t T) : Result (hashmap_hash_map_t T) := - do - let v ← - hashmap_hash_map_clear_loop_fwd_back T self.hashmap_hash_map_slots - (Usize.ofInt 0 (by intlit)) - Result.ret - { - self - with - hashmap_hash_map_num_entries := (Usize.ofInt 0 (by intlit)), - hashmap_hash_map_slots := v - } - -/- [hashmap_main::hashmap::HashMap::{0}::len] -/ -def hashmap_hash_map_len_fwd - (T : Type) (self : hashmap_hash_map_t T) : Result Usize := - Result.ret self.hashmap_hash_map_num_entries - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -def hashmap_hash_map_insert_in_list_loop_fwd - (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : - (Result Bool) - := - match h: ls with - | hashmap_list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret false - else hashmap_hash_map_insert_in_list_loop_fwd T key value tl - | hashmap_list_t.Nil => Result.ret true -termination_by hashmap_hash_map_insert_in_list_loop_fwd key value ls => - hashmap_hash_map_insert_in_list_loop_terminates T key value ls -decreasing_by hashmap_hash_map_insert_in_list_loop_decreases key value ls - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -def hashmap_hash_map_insert_in_list_fwd - (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : Result Bool := - hashmap_hash_map_insert_in_list_loop_fwd T key value ls - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -def hashmap_hash_map_insert_in_list_loop_back - (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : - (Result (hashmap_list_t T)) - := - match h: ls with - | hashmap_list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret (hashmap_list_t.Cons ckey value tl) - else - do - let tl0 ← hashmap_hash_map_insert_in_list_loop_back T key value tl - Result.ret (hashmap_list_t.Cons ckey cvalue tl0) - | hashmap_list_t.Nil => - let l := hashmap_list_t.Nil - Result.ret (hashmap_list_t.Cons key value l) -termination_by hashmap_hash_map_insert_in_list_loop_back key value ls => - hashmap_hash_map_insert_in_list_loop_terminates T key value ls -decreasing_by hashmap_hash_map_insert_in_list_loop_decreases key value ls - -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -def hashmap_hash_map_insert_in_list_back - (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : - Result (hashmap_list_t T) - := - hashmap_hash_map_insert_in_list_loop_back T key value ls - -/- [hashmap_main::hashmap::HashMap::{0}::insert_no_resize] -/ -def hashmap_hash_map_insert_no_resize_fwd_back - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) (value : T) : - Result (hashmap_hash_map_t T) - := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let inserted ← hashmap_hash_map_insert_in_list_fwd T key value l - if h: inserted - then - do - let i0 ← self.hashmap_hash_map_num_entries + - (Usize.ofInt 1 (by intlit)) - let l0 ← hashmap_hash_map_insert_in_list_back T key value l - let v ← - vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots - hash_mod l0 - Result.ret - { - self - with - hashmap_hash_map_num_entries := i0, hashmap_hash_map_slots := v - } - else - do - let l0 ← hashmap_hash_map_insert_in_list_back T key value l - let v ← - vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots - hash_mod l0 - Result.ret { self with hashmap_hash_map_slots := v } - -/- [core::num::u32::{9}::MAX] -/ -def core_num_u32_max_body : Result U32 := - Result.ret (U32.ofInt 4294967295 (by intlit)) -def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] -/ -def hashmap_hash_map_move_elements_from_list_loop_fwd_back - (T : Type) (ntable : hashmap_hash_map_t T) (ls : hashmap_list_t T) : - (Result (hashmap_hash_map_t T)) - := - match h: ls with - | hashmap_list_t.Cons k v tl => - do - let ntable0 ← hashmap_hash_map_insert_no_resize_fwd_back T ntable k v - hashmap_hash_map_move_elements_from_list_loop_fwd_back T ntable0 tl - | hashmap_list_t.Nil => Result.ret ntable -termination_by hashmap_hash_map_move_elements_from_list_loop_fwd_back ntable ls - => - hashmap_hash_map_move_elements_from_list_loop_terminates T ntable ls -decreasing_by hashmap_hash_map_move_elements_from_list_loop_decreases ntable ls - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] -/ -def hashmap_hash_map_move_elements_from_list_fwd_back - (T : Type) (ntable : hashmap_hash_map_t T) (ls : hashmap_list_t T) : - Result (hashmap_hash_map_t T) - := - hashmap_hash_map_move_elements_from_list_loop_fwd_back T ntable ls - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements] -/ -def hashmap_hash_map_move_elements_loop_fwd_back - (T : Type) (ntable : hashmap_hash_map_t T) (slots : Vec (hashmap_list_t T)) - (i : Usize) : - (Result ((hashmap_hash_map_t T) × (Vec (hashmap_list_t T)))) - := - let i0 := vec_len (hashmap_list_t T) slots - if h: i < i0 - then - do - let l ← vec_index_mut_fwd (hashmap_list_t T) slots i - let ls := mem_replace_fwd (hashmap_list_t T) l hashmap_list_t.Nil - let ntable0 ← - hashmap_hash_map_move_elements_from_list_fwd_back T ntable ls - let i1 ← i + (Usize.ofInt 1 (by intlit)) - let l0 := mem_replace_back (hashmap_list_t T) l hashmap_list_t.Nil - let slots0 ← vec_index_mut_back (hashmap_list_t T) slots i l0 - hashmap_hash_map_move_elements_loop_fwd_back T ntable0 slots0 i1 - else Result.ret (ntable, slots) -termination_by hashmap_hash_map_move_elements_loop_fwd_back ntable slots i => - hashmap_hash_map_move_elements_loop_terminates T ntable slots i -decreasing_by hashmap_hash_map_move_elements_loop_decreases ntable slots i - -/- [hashmap_main::hashmap::HashMap::{0}::move_elements] -/ -def hashmap_hash_map_move_elements_fwd_back - (T : Type) (ntable : hashmap_hash_map_t T) (slots : Vec (hashmap_list_t T)) - (i : Usize) : - Result ((hashmap_hash_map_t T) × (Vec (hashmap_list_t T))) - := - hashmap_hash_map_move_elements_loop_fwd_back T ntable slots i - -/- [hashmap_main::hashmap::HashMap::{0}::try_resize] -/ -def hashmap_hash_map_try_resize_fwd_back - (T : Type) (self : hashmap_hash_map_t T) : Result (hashmap_hash_map_t T) := - do - let max_usize ← Scalar.cast .Usize core_num_u32_max_c - let capacity := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let n1 ← max_usize / (Usize.ofInt 2 (by intlit)) - let (i, i0) := self.hashmap_hash_map_max_load_factor - let i1 ← n1 / i - if h: capacity <= i1 - then - do - let i2 ← capacity * (Usize.ofInt 2 (by intlit)) - let ntable ← hashmap_hash_map_new_with_capacity_fwd T i2 i i0 - let (ntable0, _) ← - hashmap_hash_map_move_elements_fwd_back T ntable - self.hashmap_hash_map_slots (Usize.ofInt 0 (by intlit)) - Result.ret - { - ntable0 - with - hashmap_hash_map_num_entries := self.hashmap_hash_map_num_entries, - hashmap_hash_map_max_load_factor := (i, i0) - } - else Result.ret { self with hashmap_hash_map_max_load_factor := (i, i0) } - -/- [hashmap_main::hashmap::HashMap::{0}::insert] -/ -def hashmap_hash_map_insert_fwd_back - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) (value : T) : - Result (hashmap_hash_map_t T) - := - do - let self0 ← hashmap_hash_map_insert_no_resize_fwd_back T self key value - let i ← hashmap_hash_map_len_fwd T self0 - if h: i > self0.hashmap_hash_map_max_load - then hashmap_hash_map_try_resize_fwd_back T self0 - else Result.ret self0 - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] -/ -def hashmap_hash_map_contains_key_in_list_loop_fwd - (T : Type) (key : Usize) (ls : hashmap_list_t T) : (Result Bool) := - match h: ls with - | hashmap_list_t.Cons ckey t tl => - if h: ckey = key - then Result.ret true - else hashmap_hash_map_contains_key_in_list_loop_fwd T key tl - | hashmap_list_t.Nil => Result.ret false -termination_by hashmap_hash_map_contains_key_in_list_loop_fwd key ls => - hashmap_hash_map_contains_key_in_list_loop_terminates T key ls -decreasing_by hashmap_hash_map_contains_key_in_list_loop_decreases key ls - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] -/ -def hashmap_hash_map_contains_key_in_list_fwd - (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result Bool := - hashmap_hash_map_contains_key_in_list_loop_fwd T key ls - -/- [hashmap_main::hashmap::HashMap::{0}::contains_key] -/ -def hashmap_hash_map_contains_key_fwd - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result Bool := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - hashmap_hash_map_contains_key_in_list_fwd T key l - -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list] -/ -def hashmap_hash_map_get_in_list_loop_fwd - (T : Type) (key : Usize) (ls : hashmap_list_t T) : (Result T) := - match h: ls with - | hashmap_list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret cvalue - else hashmap_hash_map_get_in_list_loop_fwd T key tl - | hashmap_list_t.Nil => Result.fail Error.panic -termination_by hashmap_hash_map_get_in_list_loop_fwd key ls => - hashmap_hash_map_get_in_list_loop_terminates T key ls -decreasing_by hashmap_hash_map_get_in_list_loop_decreases key ls - -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list] -/ -def hashmap_hash_map_get_in_list_fwd - (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result T := - hashmap_hash_map_get_in_list_loop_fwd T key ls - -/- [hashmap_main::hashmap::HashMap::{0}::get] -/ -def hashmap_hash_map_get_fwd - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result T := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - hashmap_hash_map_get_in_list_fwd T key l - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -def hashmap_hash_map_get_mut_in_list_loop_fwd - (T : Type) (ls : hashmap_list_t T) (key : Usize) : (Result T) := - match h: ls with - | hashmap_list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret cvalue - else hashmap_hash_map_get_mut_in_list_loop_fwd T tl key - | hashmap_list_t.Nil => Result.fail Error.panic -termination_by hashmap_hash_map_get_mut_in_list_loop_fwd ls key => - hashmap_hash_map_get_mut_in_list_loop_terminates T ls key -decreasing_by hashmap_hash_map_get_mut_in_list_loop_decreases ls key - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -def hashmap_hash_map_get_mut_in_list_fwd - (T : Type) (ls : hashmap_list_t T) (key : Usize) : Result T := - hashmap_hash_map_get_mut_in_list_loop_fwd T ls key - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -def hashmap_hash_map_get_mut_in_list_loop_back - (T : Type) (ls : hashmap_list_t T) (key : Usize) (ret0 : T) : - (Result (hashmap_list_t T)) - := - match h: ls with - | hashmap_list_t.Cons ckey cvalue tl => - if h: ckey = key - then Result.ret (hashmap_list_t.Cons ckey ret0 tl) - else - do - let tl0 ← hashmap_hash_map_get_mut_in_list_loop_back T tl key ret0 - Result.ret (hashmap_list_t.Cons ckey cvalue tl0) - | hashmap_list_t.Nil => Result.fail Error.panic -termination_by hashmap_hash_map_get_mut_in_list_loop_back ls key ret0 => - hashmap_hash_map_get_mut_in_list_loop_terminates T ls key -decreasing_by hashmap_hash_map_get_mut_in_list_loop_decreases ls key - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -def hashmap_hash_map_get_mut_in_list_back - (T : Type) (ls : hashmap_list_t T) (key : Usize) (ret0 : T) : - Result (hashmap_list_t T) - := - hashmap_hash_map_get_mut_in_list_loop_back T ls key ret0 - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut] -/ -def hashmap_hash_map_get_mut_fwd - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result T := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - hashmap_hash_map_get_mut_in_list_fwd T l key - -/- [hashmap_main::hashmap::HashMap::{0}::get_mut] -/ -def hashmap_hash_map_get_mut_back - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) (ret0 : T) : - Result (hashmap_hash_map_t T) - := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let l0 ← hashmap_hash_map_get_mut_in_list_back T l key ret0 - let v ← - vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots - hash_mod l0 - Result.ret { self with hashmap_hash_map_slots := v } - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -def hashmap_hash_map_remove_from_list_loop_fwd - (T : Type) (key : Usize) (ls : hashmap_list_t T) : (Result (Option T)) := - match h: ls with - | hashmap_list_t.Cons ckey t tl => - if h: ckey = key - then - let mv_ls := - mem_replace_fwd (hashmap_list_t T) (hashmap_list_t.Cons ckey t tl) - hashmap_list_t.Nil - match h: mv_ls with - | hashmap_list_t.Cons i cvalue tl0 => Result.ret (Option.some cvalue) - | hashmap_list_t.Nil => Result.fail Error.panic - else hashmap_hash_map_remove_from_list_loop_fwd T key tl - | hashmap_list_t.Nil => Result.ret Option.none -termination_by hashmap_hash_map_remove_from_list_loop_fwd key ls => - hashmap_hash_map_remove_from_list_loop_terminates T key ls -decreasing_by hashmap_hash_map_remove_from_list_loop_decreases key ls - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -def hashmap_hash_map_remove_from_list_fwd - (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result (Option T) := - hashmap_hash_map_remove_from_list_loop_fwd T key ls - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -def hashmap_hash_map_remove_from_list_loop_back - (T : Type) (key : Usize) (ls : hashmap_list_t T) : - (Result (hashmap_list_t T)) - := - match h: ls with - | hashmap_list_t.Cons ckey t tl => - if h: ckey = key - then - let mv_ls := - mem_replace_fwd (hashmap_list_t T) (hashmap_list_t.Cons ckey t tl) - hashmap_list_t.Nil - match h: mv_ls with - | hashmap_list_t.Cons i cvalue tl0 => Result.ret tl0 - | hashmap_list_t.Nil => Result.fail Error.panic - else - do - let tl0 ← hashmap_hash_map_remove_from_list_loop_back T key tl - Result.ret (hashmap_list_t.Cons ckey t tl0) - | hashmap_list_t.Nil => Result.ret hashmap_list_t.Nil -termination_by hashmap_hash_map_remove_from_list_loop_back key ls => - hashmap_hash_map_remove_from_list_loop_terminates T key ls -decreasing_by hashmap_hash_map_remove_from_list_loop_decreases key ls - -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -def hashmap_hash_map_remove_from_list_back - (T : Type) (key : Usize) (ls : hashmap_list_t T) : - Result (hashmap_list_t T) - := - hashmap_hash_map_remove_from_list_loop_back T key ls - -/- [hashmap_main::hashmap::HashMap::{0}::remove] -/ -def hashmap_hash_map_remove_fwd - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result (Option T) := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let x ← hashmap_hash_map_remove_from_list_fwd T key l - match h: x with - | Option.none => Result.ret Option.none - | Option.some x0 => - do - let _ ← self.hashmap_hash_map_num_entries - - (Usize.ofInt 1 (by intlit)) - Result.ret (Option.some x0) - -/- [hashmap_main::hashmap::HashMap::{0}::remove] -/ -def hashmap_hash_map_remove_back - (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : - Result (hashmap_hash_map_t T) - := - do - let hash ← hashmap_hash_key_fwd key - let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots - let hash_mod ← hash % i - let l ← - vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let x ← hashmap_hash_map_remove_from_list_fwd T key l - match h: x with - | Option.none => - do - let l0 ← hashmap_hash_map_remove_from_list_back T key l - let v ← - vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots - hash_mod l0 - Result.ret { self with hashmap_hash_map_slots := v } - | Option.some x0 => - do - let i0 ← self.hashmap_hash_map_num_entries - - (Usize.ofInt 1 (by intlit)) - let l0 ← hashmap_hash_map_remove_from_list_back T key l - let v ← - vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots - hash_mod l0 - Result.ret - { - self - with - hashmap_hash_map_num_entries := i0, hashmap_hash_map_slots := v - } - -/- [hashmap_main::hashmap::test1] -/ -def hashmap_test1_fwd : Result Unit := - do - let hm ← hashmap_hash_map_new_fwd U64 - let hm0 ← - hashmap_hash_map_insert_fwd_back U64 hm (Usize.ofInt 0 (by intlit)) - (U64.ofInt 42 (by intlit)) - let hm1 ← - hashmap_hash_map_insert_fwd_back U64 hm0 (Usize.ofInt 128 (by intlit)) - (U64.ofInt 18 (by intlit)) - let hm2 ← - hashmap_hash_map_insert_fwd_back U64 hm1 (Usize.ofInt 1024 (by intlit)) - (U64.ofInt 138 (by intlit)) - let hm3 ← - hashmap_hash_map_insert_fwd_back U64 hm2 (Usize.ofInt 1056 (by intlit)) - (U64.ofInt 256 (by intlit)) - let i ← hashmap_hash_map_get_fwd U64 hm3 (Usize.ofInt 128 (by intlit)) - if h: not (i = (U64.ofInt 18 (by intlit))) - then Result.fail Error.panic - else - do - let hm4 ← - hashmap_hash_map_get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) - (U64.ofInt 56 (by intlit)) - let i0 ← - hashmap_hash_map_get_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) - if h: not (i0 = (U64.ofInt 56 (by intlit))) - then Result.fail Error.panic - else - do - let x ← - hashmap_hash_map_remove_fwd U64 hm4 - (Usize.ofInt 1024 (by intlit)) - match h: x with - | Option.none => Result.fail Error.panic - | Option.some x0 => - if h: not (x0 = (U64.ofInt 56 (by intlit))) - then Result.fail Error.panic - else - do - let hm5 ← - hashmap_hash_map_remove_back U64 hm4 - (Usize.ofInt 1024 (by intlit)) - let i1 ← - hashmap_hash_map_get_fwd U64 hm5 - (Usize.ofInt 0 (by intlit)) - if h: not (i1 = (U64.ofInt 42 (by intlit))) - then Result.fail Error.panic - else - do - let i2 ← - hashmap_hash_map_get_fwd U64 hm5 - (Usize.ofInt 128 (by intlit)) - if h: not (i2 = (U64.ofInt 18 (by intlit))) - then Result.fail Error.panic - else - do - let i3 ← - hashmap_hash_map_get_fwd U64 hm5 - (Usize.ofInt 1056 (by intlit)) - if h: not (i3 = (U64.ofInt 256 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- [hashmap_main::insert_on_disk] -/ -def insert_on_disk_fwd - (key : Usize) (value : U64) (st : State) : Result (State × Unit) := - do - let (st0, hm) ← opaque_defs.hashmap_utils_deserialize_fwd st - let hm0 ← hashmap_hash_map_insert_fwd_back U64 hm key value - let (st1, _) ← opaque_defs.hashmap_utils_serialize_fwd hm0 st0 - Result.ret (st1, ()) - -/- [hashmap_main::main] -/ -def main_fwd : Result Unit := - Result.ret () - diff --git a/tests/lean/hashmap_on_disk/HashmapMain/Types.lean b/tests/lean/hashmap_on_disk/HashmapMain/Types.lean deleted file mode 100644 index 0509fbbd..00000000 --- a/tests/lean/hashmap_on_disk/HashmapMain/Types.lean +++ /dev/null @@ -1,19 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [hashmap_main]: type definitions -import Base.Primitives - -/- [hashmap_main::hashmap::List] -/ -inductive hashmap_list_t (T : Type) := -| Cons : Usize -> T -> hashmap_list_t T -> hashmap_list_t T -| Nil : hashmap_list_t T - -/- [hashmap_main::hashmap::HashMap] -/ -structure hashmap_hash_map_t (T : Type) where - hashmap_hash_map_num_entries : Usize - hashmap_hash_map_max_load_factor : (Usize × Usize) - hashmap_hash_map_max_load : Usize - hashmap_hash_map_slots : Vec (hashmap_list_t T) - -/- The state type used in the state-error monad -/ -axiom State : Type - diff --git a/tests/lean/hashmap_on_disk/lake-manifest.json b/tests/lean/hashmap_on_disk/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/hashmap_on_disk/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/hashmap_on_disk/lakefile.lean b/tests/lean/hashmap_on_disk/lakefile.lean deleted file mode 100644 index 70daf427..00000000 --- a/tests/lean/hashmap_on_disk/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «hashmap_main» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «HashmapMain» {} diff --git a/tests/lean/hashmap_on_disk/lean-toolchain b/tests/lean/hashmap_on_disk/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/hashmap_on_disk/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/lake-manifest.json b/tests/lean/lake-manifest.json new file mode 100644 index 00000000..94030cb6 --- /dev/null +++ b/tests/lean/lake-manifest.json @@ -0,0 +1,40 @@ +{"version": 4, + "packagesDir": "lake-packages", + "packages": + [{"git": + {"url": "https://github.com/EdAyers/ProofWidgets4", + "subDir?": null, + "rev": "c43db94a8f495dad37829e9d7ad65483d68c86b8", + "name": "proofwidgets", + "inputRev?": "v0.0.11"}}, + {"path": {"name": "Base", "dir": "./../../backends/lean"}}, + {"git": + {"url": "https://github.com/mhuisi/lean4-cli.git", + "subDir?": null, + "rev": "5a858c32963b6b19be0d477a30a1f4b6c120be7e", + "name": "Cli", + "inputRev?": "nightly"}}, + {"git": + {"url": "https://github.com/leanprover-community/mathlib4.git", + "subDir?": null, + "rev": "fa05951a270fef2873666c46f138e90338cd48d6", + "name": "mathlib", + "inputRev?": null}}, + {"git": + {"url": "https://github.com/gebner/quote4", + "subDir?": null, + "rev": "c0d9516f44d07feee01c1103c8f2f7c24a822b55", + "name": "Qq", + "inputRev?": "master"}}, + {"git": + {"url": "https://github.com/JLimperg/aesop", + "subDir?": null, + "rev": "f04538ab6ad07642368cf11d2702acc0a9b4bcee", + "name": "aesop", + "inputRev?": "master"}}, + {"git": + {"url": "https://github.com/leanprover/std4", + "subDir?": null, + "rev": "dff883c55395438ae2a5c65ad5ddba084b600feb", + "name": "std", + "inputRev?": "main"}}]} diff --git a/tests/lean/lakefile.lean b/tests/lean/lakefile.lean new file mode 100644 index 00000000..ae63b129 --- /dev/null +++ b/tests/lean/lakefile.lean @@ -0,0 +1,19 @@ +import Lake +open Lake DSL + +require mathlib from git + "https://github.com/leanprover-community/mathlib4.git" + +require Base from "../../backends/lean" + +package «tests» {} + +@[default_target] lean_lib betreeMain +@[default_target] lean_lib constants +@[default_target] lean_lib external +@[default_target] lean_lib hashmap +@[default_target] lean_lib hashmapMain +@[default_target] lean_lib loops +@[default_target] lean_lib noNestedBorrows +@[default_target] lean_lib paper +@[default_target] lean_lib poloniusList diff --git a/tests/lean/lean-toolchain b/tests/lean/lean-toolchain index bbf57f10..334c5053 100644 --- a/tests/lean/lean-toolchain +++ b/tests/lean/lean-toolchain @@ -1 +1 @@ -leanprover/lean4:nightly-2023-01-21 +leanprover/lean4:nightly-2023-07-12
\ No newline at end of file diff --git a/tests/lean/misc-constants/Base/Primitives.lean b/tests/lean/misc-constants/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/misc-constants/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/misc-constants/Constants.lean b/tests/lean/misc-constants/Constants.lean deleted file mode 100644 index 8306ed85..00000000 --- a/tests/lean/misc-constants/Constants.lean +++ /dev/null @@ -1,131 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [constants] -import Base.Primitives - -/- [constants::X0] -/ -def x0_body : Result U32 := Result.ret (U32.ofInt 0 (by intlit)) -def x0_c : U32 := eval_global x0_body (by simp) - -/- [core::num::u32::{9}::MAX] -/ -def core_num_u32_max_body : Result U32 := - Result.ret (U32.ofInt 4294967295 (by intlit)) -def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) - -/- [constants::X1] -/ -def x1_body : Result U32 := Result.ret core_num_u32_max_c -def x1_c : U32 := eval_global x1_body (by simp) - -/- [constants::X2] -/ -def x2_body : Result U32 := Result.ret (U32.ofInt 3 (by intlit)) -def x2_c : U32 := eval_global x2_body (by simp) - -/- [constants::incr] -/ -def incr_fwd (n : U32) : Result U32 := - n + (U32.ofInt 1 (by intlit)) - -/- [constants::X3] -/ -def x3_body : Result U32 := incr_fwd (U32.ofInt 32 (by intlit)) -def x3_c : U32 := eval_global x3_body (by simp) - -/- [constants::mk_pair0] -/ -def mk_pair0_fwd (x : U32) (y : U32) : Result (U32 × U32) := - Result.ret (x, y) - -/- [constants::Pair] -/ -structure pair_t (T1 T2 : Type) where - pair_x : T1 - pair_y : T2 - -/- [constants::mk_pair1] -/ -def mk_pair1_fwd (x : U32) (y : U32) : Result (pair_t U32 U32) := - Result.ret { pair_x := x, pair_y := y } - -/- [constants::P0] -/ -def p0_body : Result (U32 × U32) := - mk_pair0_fwd (U32.ofInt 0 (by intlit)) (U32.ofInt 1 (by intlit)) -def p0_c : (U32 × U32) := eval_global p0_body (by simp) - -/- [constants::P1] -/ -def p1_body : Result (pair_t U32 U32) := - mk_pair1_fwd (U32.ofInt 0 (by intlit)) (U32.ofInt 1 (by intlit)) -def p1_c : pair_t U32 U32 := eval_global p1_body (by simp) - -/- [constants::P2] -/ -def p2_body : Result (U32 × U32) := - Result.ret ((U32.ofInt 0 (by intlit)), (U32.ofInt 1 (by intlit))) -def p2_c : (U32 × U32) := eval_global p2_body (by simp) - -/- [constants::P3] -/ -def p3_body : Result (pair_t U32 U32) := - Result.ret - { pair_x := (U32.ofInt 0 (by intlit)), pair_y := (U32.ofInt 1 (by intlit)) } -def p3_c : pair_t U32 U32 := eval_global p3_body (by simp) - -/- [constants::Wrap] -/ -structure wrap_t (T : Type) where - wrap_val : T - -/- [constants::Wrap::{0}::new] -/ -def wrap_new_fwd (T : Type) (val : T) : Result (wrap_t T) := - Result.ret { wrap_val := val } - -/- [constants::Y] -/ -def y_body : Result (wrap_t I32) := wrap_new_fwd I32 (I32.ofInt 2 (by intlit)) -def y_c : wrap_t I32 := eval_global y_body (by simp) - -/- [constants::unwrap_y] -/ -def unwrap_y_fwd : Result I32 := - Result.ret y_c.wrap_val - -/- [constants::YVAL] -/ -def yval_body : Result I32 := unwrap_y_fwd -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 (by intlit)) -def get_z1_z1_c : I32 := eval_global get_z1_z1_body (by simp) - -/- [constants::get_z1] -/ -def get_z1_fwd : Result I32 := - Result.ret get_z1_z1_c - -/- [constants::add] -/ -def add_fwd (a : I32) (b : I32) : Result I32 := - a + b - -/- [constants::Q1] -/ -def q1_body : Result I32 := Result.ret (I32.ofInt 5 (by intlit)) -def q1_c : I32 := eval_global q1_body (by simp) - -/- [constants::Q2] -/ -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_fwd q2_c (I32.ofInt 3 (by intlit)) -def q3_c : I32 := eval_global q3_body (by simp) - -/- [constants::get_z2] -/ -def get_z2_fwd : Result I32 := - do - let i ← get_z1_fwd - let i0 ← add_fwd i q3_c - add_fwd q1_c i0 - -/- [constants::S1] -/ -def s1_body : Result U32 := Result.ret (U32.ofInt 6 (by intlit)) -def s1_c : U32 := eval_global s1_body (by simp) - -/- [constants::S2] -/ -def s2_body : Result U32 := incr_fwd s1_c -def s2_c : U32 := eval_global s2_body (by simp) - -/- [constants::S3] -/ -def s3_body : Result (pair_t U32 U32) := Result.ret p3_c -def s3_c : pair_t U32 U32 := eval_global s3_body (by simp) - -/- [constants::S4] -/ -def s4_body : Result (pair_t U32 U32) := - mk_pair1_fwd (U32.ofInt 7 (by intlit)) (U32.ofInt 8 (by intlit)) -def s4_c : pair_t U32 U32 := eval_global s4_body (by simp) - diff --git a/tests/lean/misc-constants/lake-manifest.json b/tests/lean/misc-constants/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/misc-constants/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/misc-constants/lakefile.lean b/tests/lean/misc-constants/lakefile.lean deleted file mode 100644 index 01aacb90..00000000 --- a/tests/lean/misc-constants/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «constants» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «Constants» {} diff --git a/tests/lean/misc-constants/lean-toolchain b/tests/lean/misc-constants/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/misc-constants/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/misc-external/Base/Primitives.lean b/tests/lean/misc-external/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/misc-external/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/misc-external/External/ExternalFuns.lean b/tests/lean/misc-external/External/ExternalFuns.lean deleted file mode 100644 index 6bd4f4a9..00000000 --- a/tests/lean/misc-external/External/ExternalFuns.lean +++ /dev/null @@ -1,5 +0,0 @@ -import Base.Primitives -import External.Types -import External.Opaque - -def opaque_defs : OpaqueDefs := sorry diff --git a/tests/lean/misc-external/External/Funs.lean b/tests/lean/misc-external/External/Funs.lean deleted file mode 100644 index eeb83989..00000000 --- a/tests/lean/misc-external/External/Funs.lean +++ /dev/null @@ -1,84 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [external]: function definitions -import Base.Primitives -import External.Types -import External.ExternalFuns - -/- [external::swap] -/ -def swap_fwd - (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := - do - let (st0, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st1, _) ← opaque_defs.core_mem_swap_back0 T x y st st0 - let (st2, _) ← opaque_defs.core_mem_swap_back1 T x y st st1 - Result.ret (st2, ()) - -/- [external::swap] -/ -def swap_back - (T : Type) (x : T) (y : T) (st : State) (st0 : State) : - Result (State × (T × T)) - := - do - let (st1, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st2, x0) ← opaque_defs.core_mem_swap_back0 T x y st st1 - let (_, y0) ← opaque_defs.core_mem_swap_back1 T x y st st2 - Result.ret (st0, (x0, y0)) - -/- [external::test_new_non_zero_u32] -/ -def test_new_non_zero_u32_fwd - (x : U32) (st : State) : Result (State × core_num_nonzero_non_zero_u32_t) := - do - let (st0, opt) ← opaque_defs.core_num_nonzero_non_zero_u32_new_fwd x st - opaque_defs.core_option_option_unwrap_fwd core_num_nonzero_non_zero_u32_t - opt st0 - -/- [external::test_vec] -/ -def test_vec_fwd : Result Unit := - do - let v := vec_new U32 - let _ ← vec_push_back U32 v (U32.ofInt 0 (by intlit)) - Result.ret () - -/- [external::custom_swap] -/ -def custom_swap_fwd - (T : Type) (x : T) (y : T) (st : State) : Result (State × T) := - do - let (st0, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st1, x0) ← opaque_defs.core_mem_swap_back0 T x y st st0 - let (st2, _) ← opaque_defs.core_mem_swap_back1 T x y st st1 - Result.ret (st2, x0) - -/- [external::custom_swap] -/ -def custom_swap_back - (T : Type) (x : T) (y : T) (st : State) (ret0 : T) (st0 : State) : - Result (State × (T × T)) - := - do - let (st1, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st2, _) ← opaque_defs.core_mem_swap_back0 T x y st st1 - let (_, y0) ← opaque_defs.core_mem_swap_back1 T x y st st2 - Result.ret (st0, (ret0, y0)) - -/- [external::test_custom_swap] -/ -def test_custom_swap_fwd - (x : U32) (y : U32) (st : State) : Result (State × Unit) := - do - let (st0, _) ← custom_swap_fwd U32 x y st - Result.ret (st0, ()) - -/- [external::test_custom_swap] -/ -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 (by intlit)) st0 - -/- [external::test_swap_non_zero] -/ -def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := - do - let (st0, _) ← swap_fwd U32 x (U32.ofInt 0 (by intlit)) st - let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0 (by intlit)) st st0 - if h: x0 = (U32.ofInt 0 (by intlit)) - then Result.fail Error.panic - else Result.ret (st1, x0) - diff --git a/tests/lean/misc-external/External/Opaque.lean b/tests/lean/misc-external/External/Opaque.lean deleted file mode 100644 index d641912b..00000000 --- a/tests/lean/misc-external/External/Opaque.lean +++ /dev/null @@ -1,27 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [external]: opaque function definitions -import Base.Primitives -import External.Types - -structure OpaqueDefs where - - /- [core::mem::swap] -/ - core_mem_swap_fwd (T : Type) : T -> T -> State -> Result (State × Unit) - - /- [core::mem::swap] -/ - core_mem_swap_back0 - (T : Type) : T -> T -> State -> State -> Result (State × T) - - /- [core::mem::swap] -/ - core_mem_swap_back1 - (T : Type) : T -> T -> State -> State -> Result (State × T) - - /- [core::num::nonzero::NonZeroU32::{14}::new] -/ - core_num_nonzero_non_zero_u32_new_fwd - : - U32 -> State -> Result (State × (Option core_num_nonzero_non_zero_u32_t)) - - /- [core::option::Option::{0}::unwrap] -/ - core_option_option_unwrap_fwd - (T : Type) : Option T -> State -> Result (State × T) - diff --git a/tests/lean/misc-external/lake-manifest.json b/tests/lean/misc-external/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/misc-external/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/misc-external/lakefile.lean b/tests/lean/misc-external/lakefile.lean deleted file mode 100644 index 6cc4aae4..00000000 --- a/tests/lean/misc-external/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «external» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «External» {} diff --git a/tests/lean/misc-external/lean-toolchain b/tests/lean/misc-external/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/misc-external/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/misc-loops/Base/Primitives.lean b/tests/lean/misc-loops/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/misc-loops/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/misc-loops/Loops/Clauses/Clauses.lean b/tests/lean/misc-loops/Loops/Clauses/Clauses.lean deleted file mode 100644 index 89a7ce34..00000000 --- a/tests/lean/misc-loops/Loops/Clauses/Clauses.lean +++ /dev/null @@ -1,205 +0,0 @@ --- [loops]: decreases clauses -import Base.Primitives -import Loops.Types - -/- [loops::sum]: termination measure -/ -@[simp] -def sum_loop_terminates (max : U32) (i : U32) (s : U32) := (max, i, s) - -syntax "sum_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| sum_loop_decreases $max $i $s) =>`(tactic| sorry) - -/- [loops::sum_with_mut_borrows]: termination measure -/ -@[simp] -def sum_with_mut_borrows_loop_terminates (max : U32) (mi : U32) (ms : U32) := - (max, mi, ms) - -syntax "sum_with_mut_borrows_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| sum_with_mut_borrows_loop_decreases $max $mi $ms) =>`(tactic| sorry) - -/- [loops::sum_with_shared_borrows]: termination measure -/ -@[simp] -def sum_with_shared_borrows_loop_terminates (max : U32) (i : U32) (s : U32) := - (max, i, s) - -syntax "sum_with_shared_borrows_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| sum_with_shared_borrows_loop_decreases $max $i $s) =>`(tactic| sorry) - -/- [loops::clear]: termination measure -/ -@[simp] def clear_loop_terminates (v : Vec U32) (i : Usize) := (v, i) - -syntax "clear_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| clear_loop_decreases $v $i) =>`(tactic| sorry) - -/- [loops::list_mem]: termination measure -/ -@[simp] -def list_mem_loop_terminates (x : U32) (ls : list_t U32) := (x, ls) - -syntax "list_mem_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_mem_loop_decreases $x $ls) =>`(tactic| sorry) - -/- [loops::list_nth_mut_loop]: termination measure -/ -@[simp] -def list_nth_mut_loop_loop_terminates (T : Type) (ls : list_t T) (i : U32) := - (ls, i) - -syntax "list_nth_mut_loop_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_mut_loop_loop_decreases $ls $i) =>`(tactic| sorry) - -/- [loops::list_nth_shared_loop]: termination measure -/ -@[simp] -def list_nth_shared_loop_loop_terminates (T : Type) (ls : list_t T) (i : U32) := - (ls, i) - -syntax "list_nth_shared_loop_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_shared_loop_loop_decreases $ls $i) =>`(tactic| sorry) - -/- [loops::get_elem_mut]: termination measure -/ -@[simp] -def get_elem_mut_loop_terminates (x : Usize) (ls : list_t Usize) := (x, ls) - -syntax "get_elem_mut_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| get_elem_mut_loop_decreases $x $ls) =>`(tactic| sorry) - -/- [loops::get_elem_shared]: termination measure -/ -@[simp] -def get_elem_shared_loop_terminates (x : Usize) (ls : list_t Usize) := (x, ls) - -syntax "get_elem_shared_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| get_elem_shared_loop_decreases $x $ls) =>`(tactic| sorry) - -/- [loops::list_nth_mut_loop_with_id]: termination measure -/ -@[simp] -def list_nth_mut_loop_with_id_loop_terminates (T : Type) (i : U32) - (ls : list_t T) := - (i, ls) - -syntax "list_nth_mut_loop_with_id_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_mut_loop_with_id_loop_decreases $i $ls) =>`(tactic| sorry) - -/- [loops::list_nth_shared_loop_with_id]: termination measure -/ -@[simp] -def list_nth_shared_loop_with_id_loop_terminates (T : Type) (i : U32) - (ls : list_t T) := - (i, ls) - -syntax "list_nth_shared_loop_with_id_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_shared_loop_with_id_loop_decreases $i $ls) =>`(tactic| sorry) - -/- [loops::list_nth_mut_loop_pair]: termination measure -/ -@[simp] -def list_nth_mut_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_mut_loop_pair_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_mut_loop_pair_loop_decreases $ls0 $ls1 $i) =>`(tactic| sorry) - -/- [loops::list_nth_shared_loop_pair]: termination measure -/ -@[simp] -def list_nth_shared_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_shared_loop_pair_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_shared_loop_pair_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_mut_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_mut_loop_pair_merge_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_mut_loop_pair_merge_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_mut_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_shared_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_shared_loop_pair_merge_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_shared_loop_pair_merge_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_shared_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_mut_shared_loop_pair]: termination measure -/ -@[simp] -def list_nth_mut_shared_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_mut_shared_loop_pair_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_mut_shared_loop_pair_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_mut_shared_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_mut_shared_loop_pair_merge_loop_terminates (T : Type) - (ls0 : list_t T) (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_mut_shared_loop_pair_merge_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_mut_shared_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_shared_mut_loop_pair]: termination measure -/ -@[simp] -def list_nth_shared_mut_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_shared_mut_loop_pair_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_shared_mut_loop_pair_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_shared_mut_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_shared_mut_loop_pair_merge_loop_terminates (T : Type) - (ls0 : list_t T) (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -syntax "list_nth_shared_mut_loop_pair_merge_loop_decreases" term+ : tactic - -macro_rules -| `(tactic| list_nth_shared_mut_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - diff --git a/tests/lean/misc-loops/Loops/Clauses/Template.lean b/tests/lean/misc-loops/Loops/Clauses/Template.lean deleted file mode 100644 index 2e28a6c0..00000000 --- a/tests/lean/misc-loops/Loops/Clauses/Template.lean +++ /dev/null @@ -1,205 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [loops]: templates for the decreases clauses -import Base.Primitives -import Loops.Types - -/- [loops::sum]: termination measure -/ -@[simp] def sum_loop_terminates (max : U32) (i : U32) (s : U32) := (max, i, s) - -/- [loops::sum]: decreases_by tactic -/ -syntax "sum_loop_decreases" term+ : tactic -macro_rules -| `(tactic| sum_loop_decreases $max $i $s) =>`(tactic| sorry) - -/- [loops::sum_with_mut_borrows]: termination measure -/ -@[simp] -def sum_with_mut_borrows_loop_terminates (max : U32) (mi : U32) (ms : U32) := - (max, mi, ms) - -/- [loops::sum_with_mut_borrows]: decreases_by tactic -/ -syntax "sum_with_mut_borrows_loop_decreases" term+ : tactic -macro_rules -| `(tactic| sum_with_mut_borrows_loop_decreases $max $mi $ms) =>`(tactic| sorry) - -/- [loops::sum_with_shared_borrows]: termination measure -/ -@[simp] -def sum_with_shared_borrows_loop_terminates (max : U32) (i : U32) (s : U32) := - (max, i, s) - -/- [loops::sum_with_shared_borrows]: decreases_by tactic -/ -syntax "sum_with_shared_borrows_loop_decreases" term+ : tactic -macro_rules -| `(tactic| sum_with_shared_borrows_loop_decreases $max $i $s) =>`(tactic| sorry) - -/- [loops::clear]: termination measure -/ -@[simp] def clear_loop_terminates (v : Vec U32) (i : Usize) := (v, i) - -/- [loops::clear]: decreases_by tactic -/ -syntax "clear_loop_decreases" term+ : tactic -macro_rules -| `(tactic| clear_loop_decreases $v $i) =>`(tactic| sorry) - -/- [loops::list_mem]: termination measure -/ -@[simp] def list_mem_loop_terminates (x : U32) (ls : list_t U32) := (x, ls) - -/- [loops::list_mem]: decreases_by tactic -/ -syntax "list_mem_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_mem_loop_decreases $x $ls) =>`(tactic| sorry) - -/- [loops::list_nth_mut_loop]: termination measure -/ -@[simp] -def list_nth_mut_loop_loop_terminates (T : Type) (ls : list_t T) (i : U32) := - (ls, i) - -/- [loops::list_nth_mut_loop]: decreases_by tactic -/ -syntax "list_nth_mut_loop_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_mut_loop_loop_decreases $ls $i) =>`(tactic| sorry) - -/- [loops::list_nth_shared_loop]: termination measure -/ -@[simp] -def list_nth_shared_loop_loop_terminates (T : Type) (ls : list_t T) (i : U32) - := - (ls, i) - -/- [loops::list_nth_shared_loop]: decreases_by tactic -/ -syntax "list_nth_shared_loop_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_shared_loop_loop_decreases $ls $i) =>`(tactic| sorry) - -/- [loops::get_elem_mut]: termination measure -/ -@[simp] -def get_elem_mut_loop_terminates (x : Usize) (ls : list_t Usize) := (x, ls) - -/- [loops::get_elem_mut]: decreases_by tactic -/ -syntax "get_elem_mut_loop_decreases" term+ : tactic -macro_rules -| `(tactic| get_elem_mut_loop_decreases $x $ls) =>`(tactic| sorry) - -/- [loops::get_elem_shared]: termination measure -/ -@[simp] -def get_elem_shared_loop_terminates (x : Usize) (ls : list_t Usize) := (x, ls) - -/- [loops::get_elem_shared]: decreases_by tactic -/ -syntax "get_elem_shared_loop_decreases" term+ : tactic -macro_rules -| `(tactic| get_elem_shared_loop_decreases $x $ls) =>`(tactic| sorry) - -/- [loops::list_nth_mut_loop_with_id]: termination measure -/ -@[simp] -def list_nth_mut_loop_with_id_loop_terminates (T : Type) (i : U32) - (ls : list_t T) := - (i, ls) - -/- [loops::list_nth_mut_loop_with_id]: decreases_by tactic -/ -syntax "list_nth_mut_loop_with_id_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_mut_loop_with_id_loop_decreases $i $ls) =>`(tactic| sorry) - -/- [loops::list_nth_shared_loop_with_id]: termination measure -/ -@[simp] -def list_nth_shared_loop_with_id_loop_terminates (T : Type) (i : U32) - (ls : list_t T) := - (i, ls) - -/- [loops::list_nth_shared_loop_with_id]: decreases_by tactic -/ -syntax "list_nth_shared_loop_with_id_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_shared_loop_with_id_loop_decreases $i $ls) =>`(tactic| sorry) - -/- [loops::list_nth_mut_loop_pair]: termination measure -/ -@[simp] -def list_nth_mut_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_mut_loop_pair]: decreases_by tactic -/ -syntax "list_nth_mut_loop_pair_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_mut_loop_pair_loop_decreases $ls0 $ls1 $i) =>`(tactic| sorry) - -/- [loops::list_nth_shared_loop_pair]: termination measure -/ -@[simp] -def list_nth_shared_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_shared_loop_pair]: decreases_by tactic -/ -syntax "list_nth_shared_loop_pair_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_shared_loop_pair_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_mut_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_mut_loop_pair_merge_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_mut_loop_pair_merge]: decreases_by tactic -/ -syntax "list_nth_mut_loop_pair_merge_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_mut_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_shared_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_shared_loop_pair_merge_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_shared_loop_pair_merge]: decreases_by tactic -/ -syntax "list_nth_shared_loop_pair_merge_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_shared_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_mut_shared_loop_pair]: termination measure -/ -@[simp] -def list_nth_mut_shared_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_mut_shared_loop_pair]: decreases_by tactic -/ -syntax "list_nth_mut_shared_loop_pair_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_mut_shared_loop_pair_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_mut_shared_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_mut_shared_loop_pair_merge_loop_terminates (T : Type) - (ls0 : list_t T) (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_mut_shared_loop_pair_merge]: decreases_by tactic -/ -syntax "list_nth_mut_shared_loop_pair_merge_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_mut_shared_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_shared_mut_loop_pair]: termination measure -/ -@[simp] -def list_nth_shared_mut_loop_pair_loop_terminates (T : Type) (ls0 : list_t T) - (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_shared_mut_loop_pair]: decreases_by tactic -/ -syntax "list_nth_shared_mut_loop_pair_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_shared_mut_loop_pair_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - -/- [loops::list_nth_shared_mut_loop_pair_merge]: termination measure -/ -@[simp] -def list_nth_shared_mut_loop_pair_merge_loop_terminates (T : Type) - (ls0 : list_t T) (ls1 : list_t T) (i : U32) := - (ls0, ls1, i) - -/- [loops::list_nth_shared_mut_loop_pair_merge]: decreases_by tactic -/ -syntax "list_nth_shared_mut_loop_pair_merge_loop_decreases" term+ : tactic -macro_rules -| `(tactic| list_nth_shared_mut_loop_pair_merge_loop_decreases $ls0 $ls1 $i) => - `(tactic| sorry) - diff --git a/tests/lean/misc-loops/Loops/Funs.lean b/tests/lean/misc-loops/Loops/Funs.lean deleted file mode 100644 index fd8d62d7..00000000 --- a/tests/lean/misc-loops/Loops/Funs.lean +++ /dev/null @@ -1,705 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [loops]: function definitions -import Base.Primitives -import Loops.Types -import Loops.Clauses.Clauses - -/- [loops::sum] -/ -def sum_loop_fwd (max : U32) (i : U32) (s : U32) : (Result U32) := - if h: i < max - then - do - let s0 ← s + i - let i0 ← i + (U32.ofInt 1 (by intlit)) - sum_loop_fwd max i0 s0 - else s * (U32.ofInt 2 (by intlit)) -termination_by sum_loop_fwd max i s => sum_loop_terminates max i s -decreasing_by sum_loop_decreases max i s - -/- [loops::sum] -/ -def sum_fwd (max : U32) : Result U32 := - sum_loop_fwd max (U32.ofInt 0 (by intlit)) (U32.ofInt 0 (by intlit)) - -/- [loops::sum_with_mut_borrows] -/ -def sum_with_mut_borrows_loop_fwd - (max : U32) (mi : U32) (ms : U32) : (Result U32) := - if h: mi < max - then - do - let ms0 ← ms + mi - let mi0 ← mi + (U32.ofInt 1 (by intlit)) - sum_with_mut_borrows_loop_fwd max mi0 ms0 - else ms * (U32.ofInt 2 (by intlit)) -termination_by sum_with_mut_borrows_loop_fwd max mi ms => - sum_with_mut_borrows_loop_terminates max mi ms -decreasing_by sum_with_mut_borrows_loop_decreases max mi ms - -/- [loops::sum_with_mut_borrows] -/ -def sum_with_mut_borrows_fwd (max : U32) : Result U32 := - sum_with_mut_borrows_loop_fwd max (U32.ofInt 0 (by intlit)) - (U32.ofInt 0 (by intlit)) - -/- [loops::sum_with_shared_borrows] -/ -def sum_with_shared_borrows_loop_fwd - (max : U32) (i : U32) (s : U32) : (Result U32) := - if h: i < max - then - do - let i0 ← i + (U32.ofInt 1 (by intlit)) - let s0 ← s + i0 - sum_with_shared_borrows_loop_fwd max i0 s0 - else s * (U32.ofInt 2 (by intlit)) -termination_by sum_with_shared_borrows_loop_fwd max i s => - sum_with_shared_borrows_loop_terminates max i s -decreasing_by sum_with_shared_borrows_loop_decreases max i s - -/- [loops::sum_with_shared_borrows] -/ -def sum_with_shared_borrows_fwd (max : U32) : Result U32 := - sum_with_shared_borrows_loop_fwd max (U32.ofInt 0 (by intlit)) - (U32.ofInt 0 (by intlit)) - -/- [loops::clear] -/ -def clear_loop_fwd_back (v : Vec U32) (i : Usize) : (Result (Vec U32)) := - let i0 := vec_len U32 v - if h: i < i0 - then - do - let i1 ← i + (Usize.ofInt 1 (by intlit)) - let v0 ← vec_index_mut_back U32 v i (U32.ofInt 0 (by intlit)) - clear_loop_fwd_back v0 i1 - else Result.ret v -termination_by clear_loop_fwd_back v i => clear_loop_terminates v i -decreasing_by clear_loop_decreases v i - -/- [loops::clear] -/ -def clear_fwd_back (v : Vec U32) : Result (Vec U32) := - clear_loop_fwd_back v (Usize.ofInt 0 (by intlit)) - -/- [loops::list_mem] -/ -def list_mem_loop_fwd (x : U32) (ls : list_t U32) : (Result Bool) := - match h: ls with - | list_t.Cons y tl => - if h: y = x - then Result.ret true - else list_mem_loop_fwd x tl - | list_t.Nil => Result.ret false -termination_by list_mem_loop_fwd x ls => list_mem_loop_terminates x ls -decreasing_by list_mem_loop_decreases x ls - -/- [loops::list_mem] -/ -def list_mem_fwd (x : U32) (ls : list_t U32) : Result Bool := - list_mem_loop_fwd x ls - -/- [loops::list_nth_mut_loop] -/ -def list_nth_mut_loop_loop_fwd - (T : Type) (ls : list_t T) (i : U32) : (Result T) := - match h: ls with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_loop_fwd T tl i0 - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_loop_fwd ls i => - list_nth_mut_loop_loop_terminates T ls i -decreasing_by list_nth_mut_loop_loop_decreases ls i - -/- [loops::list_nth_mut_loop] -/ -def list_nth_mut_loop_fwd (T : Type) (ls : list_t T) (i : U32) : Result T := - list_nth_mut_loop_loop_fwd T ls i - -/- [loops::list_nth_mut_loop] -/ -def list_nth_mut_loop_loop_back - (T : Type) (ls : list_t T) (i : U32) (ret0 : T) : (Result (list_t T)) := - match h: ls with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl0 ← list_nth_mut_loop_loop_back T tl i0 ret0 - Result.ret (list_t.Cons x tl0) - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_loop_back ls i ret0 => - list_nth_mut_loop_loop_terminates T ls i -decreasing_by list_nth_mut_loop_loop_decreases ls i - -/- [loops::list_nth_mut_loop] -/ -def list_nth_mut_loop_back - (T : Type) (ls : list_t T) (i : U32) (ret0 : T) : Result (list_t T) := - list_nth_mut_loop_loop_back T ls i ret0 - -/- [loops::list_nth_shared_loop] -/ -def list_nth_shared_loop_loop_fwd - (T : Type) (ls : list_t T) (i : U32) : (Result T) := - match h: ls with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_loop_fwd T tl i0 - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_loop_loop_fwd ls i => - list_nth_shared_loop_loop_terminates T ls i -decreasing_by list_nth_shared_loop_loop_decreases ls i - -/- [loops::list_nth_shared_loop] -/ -def list_nth_shared_loop_fwd (T : Type) (ls : list_t T) (i : U32) : Result T := - list_nth_shared_loop_loop_fwd T ls i - -/- [loops::get_elem_mut] -/ -def get_elem_mut_loop_fwd (x : Usize) (ls : list_t Usize) : (Result Usize) := - match h: ls with - | list_t.Cons y tl => - if h: y = x - then Result.ret y - else get_elem_mut_loop_fwd x tl - | list_t.Nil => Result.fail Error.panic -termination_by get_elem_mut_loop_fwd x ls => get_elem_mut_loop_terminates x ls -decreasing_by get_elem_mut_loop_decreases x ls - -/- [loops::get_elem_mut] -/ -def get_elem_mut_fwd (slots : Vec (list_t Usize)) (x : Usize) : Result Usize := - do - let l ← - vec_index_mut_fwd (list_t Usize) slots (Usize.ofInt 0 (by intlit)) - get_elem_mut_loop_fwd x l - -/- [loops::get_elem_mut] -/ -def get_elem_mut_loop_back - (x : Usize) (ls : list_t Usize) (ret0 : Usize) : (Result (list_t Usize)) := - match h: ls with - | list_t.Cons y tl => - if h: y = x - then Result.ret (list_t.Cons ret0 tl) - else - do - let tl0 ← get_elem_mut_loop_back x tl ret0 - Result.ret (list_t.Cons y tl0) - | list_t.Nil => Result.fail Error.panic -termination_by get_elem_mut_loop_back x ls ret0 => - get_elem_mut_loop_terminates x ls -decreasing_by get_elem_mut_loop_decreases x ls - -/- [loops::get_elem_mut] -/ -def get_elem_mut_back - (slots : Vec (list_t Usize)) (x : Usize) (ret0 : Usize) : - Result (Vec (list_t Usize)) - := - do - let l ← - vec_index_mut_fwd (list_t Usize) slots (Usize.ofInt 0 (by intlit)) - let l0 ← get_elem_mut_loop_back x l ret0 - vec_index_mut_back (list_t Usize) slots (Usize.ofInt 0 (by intlit)) l0 - -/- [loops::get_elem_shared] -/ -def get_elem_shared_loop_fwd - (x : Usize) (ls : list_t Usize) : (Result Usize) := - match h: ls with - | list_t.Cons y tl => - if h: y = x - then Result.ret y - else get_elem_shared_loop_fwd x tl - | list_t.Nil => Result.fail Error.panic -termination_by get_elem_shared_loop_fwd x ls => - get_elem_shared_loop_terminates x ls -decreasing_by get_elem_shared_loop_decreases x ls - -/- [loops::get_elem_shared] -/ -def get_elem_shared_fwd - (slots : Vec (list_t Usize)) (x : Usize) : Result Usize := - do - let l ← vec_index_fwd (list_t Usize) slots (Usize.ofInt 0 (by intlit)) - get_elem_shared_loop_fwd x l - -/- [loops::id_mut] -/ -def id_mut_fwd (T : Type) (ls : list_t T) : Result (list_t T) := - Result.ret ls - -/- [loops::id_mut] -/ -def id_mut_back - (T : Type) (ls : list_t T) (ret0 : list_t T) : Result (list_t T) := - Result.ret ret0 - -/- [loops::id_shared] -/ -def id_shared_fwd (T : Type) (ls : list_t T) : Result (list_t T) := - Result.ret ls - -/- [loops::list_nth_mut_loop_with_id] -/ -def list_nth_mut_loop_with_id_loop_fwd - (T : Type) (i : U32) (ls : list_t T) : (Result T) := - match h: ls with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_with_id_loop_fwd T i0 tl - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_with_id_loop_fwd i ls => - list_nth_mut_loop_with_id_loop_terminates T i ls -decreasing_by list_nth_mut_loop_with_id_loop_decreases i ls - -/- [loops::list_nth_mut_loop_with_id] -/ -def list_nth_mut_loop_with_id_fwd - (T : Type) (ls : list_t T) (i : U32) : Result T := - do - let ls0 ← id_mut_fwd T ls - list_nth_mut_loop_with_id_loop_fwd T i ls0 - -/- [loops::list_nth_mut_loop_with_id] -/ -def list_nth_mut_loop_with_id_loop_back - (T : Type) (i : U32) (ls : list_t T) (ret0 : T) : (Result (list_t T)) := - match h: ls with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl0 ← list_nth_mut_loop_with_id_loop_back T i0 tl ret0 - Result.ret (list_t.Cons x tl0) - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_with_id_loop_back i ls ret0 => - list_nth_mut_loop_with_id_loop_terminates T i ls -decreasing_by list_nth_mut_loop_with_id_loop_decreases i ls - -/- [loops::list_nth_mut_loop_with_id] -/ -def list_nth_mut_loop_with_id_back - (T : Type) (ls : list_t T) (i : U32) (ret0 : T) : Result (list_t T) := - do - let ls0 ← id_mut_fwd T ls - let l ← list_nth_mut_loop_with_id_loop_back T i ls0 ret0 - id_mut_back T ls l - -/- [loops::list_nth_shared_loop_with_id] -/ -def list_nth_shared_loop_with_id_loop_fwd - (T : Type) (i : U32) (ls : list_t T) : (Result T) := - match h: ls with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_with_id_loop_fwd T i0 tl - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_loop_with_id_loop_fwd i ls => - list_nth_shared_loop_with_id_loop_terminates T i ls -decreasing_by list_nth_shared_loop_with_id_loop_decreases i ls - -/- [loops::list_nth_shared_loop_with_id] -/ -def list_nth_shared_loop_with_id_fwd - (T : Type) (ls : list_t T) (i : U32) : Result T := - do - let ls0 ← id_shared_fwd T ls - list_nth_shared_loop_with_id_loop_fwd T i ls0 - -/- [loops::list_nth_mut_loop_pair] -/ -def list_nth_mut_loop_pair_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_pair_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_pair_loop_fwd ls0 ls1 i => - list_nth_mut_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair] -/ -def list_nth_mut_loop_pair_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_mut_loop_pair_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair] -/ -def list_nth_mut_loop_pair_loop_back'a - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - (Result (list_t T)) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl0) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl00 ← list_nth_mut_loop_pair_loop_back'a T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x0 tl00) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_pair_loop_back'a ls0 ls1 i ret0 => - list_nth_mut_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair] -/ -def list_nth_mut_loop_pair_back'a - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - Result (list_t T) - := - list_nth_mut_loop_pair_loop_back'a T ls0 ls1 i ret0 - -/- [loops::list_nth_mut_loop_pair] -/ -def list_nth_mut_loop_pair_loop_back'b - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - (Result (list_t T)) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl10 ← list_nth_mut_loop_pair_loop_back'b T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x1 tl10) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_pair_loop_back'b ls0 ls1 i ret0 => - list_nth_mut_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair] -/ -def list_nth_mut_loop_pair_back'b - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - Result (list_t T) - := - list_nth_mut_loop_pair_loop_back'b T ls0 ls1 i ret0 - -/- [loops::list_nth_shared_loop_pair] -/ -def list_nth_shared_loop_pair_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_pair_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_loop_pair_loop_fwd ls0 ls1 i => - list_nth_shared_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_shared_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_shared_loop_pair] -/ -def list_nth_shared_loop_pair_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_shared_loop_pair_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair_merge] -/ -def list_nth_mut_loop_pair_merge_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_pair_merge_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_pair_merge_loop_fwd ls0 ls1 i => - list_nth_mut_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair_merge] -/ -def list_nth_mut_loop_pair_merge_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_mut_loop_pair_merge_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair_merge] -/ -def list_nth_mut_loop_pair_merge_loop_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : (T × T)) : - (Result ((list_t T) × (list_t T))) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then - let (t, t0) := ret0 - Result.ret (list_t.Cons t tl0, list_t.Cons t0 tl1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let (tl00, tl10) ← - list_nth_mut_loop_pair_merge_loop_back T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x0 tl00, list_t.Cons x1 tl10) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_loop_pair_merge_loop_back ls0 ls1 i ret0 => - list_nth_mut_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_loop_pair_merge] -/ -def list_nth_mut_loop_pair_merge_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : (T × T)) : - Result ((list_t T) × (list_t T)) - := - list_nth_mut_loop_pair_merge_loop_back T ls0 ls1 i ret0 - -/- [loops::list_nth_shared_loop_pair_merge] -/ -def list_nth_shared_loop_pair_merge_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_pair_merge_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_loop_pair_merge_loop_fwd ls0 ls1 i => - list_nth_shared_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_shared_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_shared_loop_pair_merge] -/ -def list_nth_shared_loop_pair_merge_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_shared_loop_pair_merge_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair] -/ -def list_nth_mut_shared_loop_pair_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_shared_loop_pair_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_shared_loop_pair_loop_fwd ls0 ls1 i => - list_nth_mut_shared_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_shared_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair] -/ -def list_nth_mut_shared_loop_pair_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_mut_shared_loop_pair_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair] -/ -def list_nth_mut_shared_loop_pair_loop_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - (Result (list_t T)) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl0) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl00 ← - list_nth_mut_shared_loop_pair_loop_back T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x0 tl00) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_shared_loop_pair_loop_back ls0 ls1 i ret0 => - list_nth_mut_shared_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_shared_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair] -/ -def list_nth_mut_shared_loop_pair_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - Result (list_t T) - := - list_nth_mut_shared_loop_pair_loop_back T ls0 ls1 i ret0 - -/- [loops::list_nth_mut_shared_loop_pair_merge] -/ -def list_nth_mut_shared_loop_pair_merge_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_shared_loop_pair_merge_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_shared_loop_pair_merge_loop_fwd ls0 ls1 i => - list_nth_mut_shared_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_shared_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair_merge] -/ -def list_nth_mut_shared_loop_pair_merge_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_mut_shared_loop_pair_merge_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair_merge] -/ -def list_nth_mut_shared_loop_pair_merge_loop_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - (Result (list_t T)) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl0) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl00 ← - list_nth_mut_shared_loop_pair_merge_loop_back T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x0 tl00) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_mut_shared_loop_pair_merge_loop_back ls0 ls1 i ret0 => - list_nth_mut_shared_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_mut_shared_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_mut_shared_loop_pair_merge] -/ -def list_nth_mut_shared_loop_pair_merge_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - Result (list_t T) - := - list_nth_mut_shared_loop_pair_merge_loop_back T ls0 ls1 i ret0 - -/- [loops::list_nth_shared_mut_loop_pair] -/ -def list_nth_shared_mut_loop_pair_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_mut_loop_pair_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_mut_loop_pair_loop_fwd ls0 ls1 i => - list_nth_shared_mut_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_shared_mut_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_shared_mut_loop_pair] -/ -def list_nth_shared_mut_loop_pair_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_shared_mut_loop_pair_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_shared_mut_loop_pair] -/ -def list_nth_shared_mut_loop_pair_loop_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - (Result (list_t T)) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl10 ← - list_nth_shared_mut_loop_pair_loop_back T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x1 tl10) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_mut_loop_pair_loop_back ls0 ls1 i ret0 => - list_nth_shared_mut_loop_pair_loop_terminates T ls0 ls1 i -decreasing_by list_nth_shared_mut_loop_pair_loop_decreases ls0 ls1 i - -/- [loops::list_nth_shared_mut_loop_pair] -/ -def list_nth_shared_mut_loop_pair_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - Result (list_t T) - := - list_nth_shared_mut_loop_pair_loop_back T ls0 ls1 i ret0 - -/- [loops::list_nth_shared_mut_loop_pair_merge] -/ -def list_nth_shared_mut_loop_pair_merge_loop_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : (Result (T × T)) := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (x0, x1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_mut_loop_pair_merge_loop_fwd T tl0 tl1 i0 - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_mut_loop_pair_merge_loop_fwd ls0 ls1 i => - list_nth_shared_mut_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_shared_mut_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_shared_mut_loop_pair_merge] -/ -def list_nth_shared_mut_loop_pair_merge_fwd - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) : Result (T × T) := - list_nth_shared_mut_loop_pair_merge_loop_fwd T ls0 ls1 i - -/- [loops::list_nth_shared_mut_loop_pair_merge] -/ -def list_nth_shared_mut_loop_pair_merge_loop_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - (Result (list_t T)) - := - match h: ls0 with - | list_t.Cons x0 tl0 => - match h: ls1 with - | list_t.Cons x1 tl1 => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl1) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl10 ← - list_nth_shared_mut_loop_pair_merge_loop_back T tl0 tl1 i0 ret0 - Result.ret (list_t.Cons x1 tl10) - | list_t.Nil => Result.fail Error.panic - | list_t.Nil => Result.fail Error.panic -termination_by list_nth_shared_mut_loop_pair_merge_loop_back ls0 ls1 i ret0 => - list_nth_shared_mut_loop_pair_merge_loop_terminates T ls0 ls1 i -decreasing_by list_nth_shared_mut_loop_pair_merge_loop_decreases ls0 ls1 i - -/- [loops::list_nth_shared_mut_loop_pair_merge] -/ -def list_nth_shared_mut_loop_pair_merge_back - (T : Type) (ls0 : list_t T) (ls1 : list_t T) (i : U32) (ret0 : T) : - Result (list_t T) - := - list_nth_shared_mut_loop_pair_merge_loop_back T ls0 ls1 i ret0 - diff --git a/tests/lean/misc-loops/Loops/Types.lean b/tests/lean/misc-loops/Loops/Types.lean deleted file mode 100644 index ca43f4c8..00000000 --- a/tests/lean/misc-loops/Loops/Types.lean +++ /dev/null @@ -1,9 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [loops]: type definitions -import Base.Primitives - -/- [loops::List] -/ -inductive list_t (T : Type) := -| Cons : T -> list_t T -> list_t T -| Nil : list_t T - diff --git a/tests/lean/misc-loops/lake-manifest.json b/tests/lean/misc-loops/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/misc-loops/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/misc-loops/lakefile.lean b/tests/lean/misc-loops/lakefile.lean deleted file mode 100644 index 097c0a7d..00000000 --- a/tests/lean/misc-loops/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «loops» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «Loops» {} diff --git a/tests/lean/misc-loops/lean-toolchain b/tests/lean/misc-loops/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/misc-loops/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/misc-no_nested_borrows/Base/Primitives.lean b/tests/lean/misc-no_nested_borrows/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/misc-no_nested_borrows/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean b/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean deleted file mode 100644 index 12c7d8f7..00000000 --- a/tests/lean/misc-no_nested_borrows/NoNestedBorrows.lean +++ /dev/null @@ -1,538 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [no_nested_borrows] -import Base.Primitives - -/- [no_nested_borrows::Pair] -/ -structure pair_t (T1 T2 : Type) where - pair_x : T1 - pair_y : T2 - -/- [no_nested_borrows::List] -/ -inductive list_t (T : Type) := -| Cons : T -> list_t T -> list_t T -| Nil : list_t T - -/- [no_nested_borrows::One] -/ -inductive one_t (T1 : Type) := -| One : T1 -> one_t T1 - -/- [no_nested_borrows::EmptyEnum] -/ -inductive empty_enum_t := -| Empty : empty_enum_t - -/- [no_nested_borrows::Enum] -/ -inductive enum_t := -| Variant1 : enum_t -| Variant2 : enum_t - -/- [no_nested_borrows::EmptyStruct] -/ -structure empty_struct_t where - -/- [no_nested_borrows::Sum] -/ -inductive sum_t (T1 T2 : Type) := -| Left : T1 -> sum_t T1 T2 -| Right : T2 -> sum_t T1 T2 - -/- [no_nested_borrows::neg_test] -/ -def neg_test_fwd (x : I32) : Result I32 := - - x - -/- [no_nested_borrows::add_test] -/ -def add_test_fwd (x : U32) (y : U32) : Result U32 := - x + y - -/- [no_nested_borrows::subs_test] -/ -def subs_test_fwd (x : U32) (y : U32) : Result U32 := - x - y - -/- [no_nested_borrows::div_test] -/ -def div_test_fwd (x : U32) (y : U32) : Result U32 := - x / y - -/- [no_nested_borrows::div_test1] -/ -def div_test1_fwd (x : U32) : Result U32 := - x / (U32.ofInt 2 (by intlit)) - -/- [no_nested_borrows::rem_test] -/ -def rem_test_fwd (x : U32) (y : U32) : Result U32 := - x % y - -/- [no_nested_borrows::cast_test] -/ -def cast_test_fwd (x : U32) : Result I32 := - Scalar.cast .I32 x - -/- [no_nested_borrows::test2] -/ -def test2_fwd : Result Unit := - do - let _ ← (U32.ofInt 23 (by intlit)) + (U32.ofInt 44 (by intlit)) - Result.ret () - -/- Unit test for [no_nested_borrows::test2] -/ -#assert (test2_fwd == .ret ()) - -/- [no_nested_borrows::get_max] -/ -def get_max_fwd (x : U32) (y : U32) : Result U32 := - if h: x >= y - then Result.ret x - else Result.ret y - -/- [no_nested_borrows::test3] -/ -def test3_fwd : Result Unit := - do - let x ← get_max_fwd (U32.ofInt 4 (by intlit)) (U32.ofInt 3 (by intlit)) - let y ← get_max_fwd (U32.ofInt 10 (by intlit)) (U32.ofInt 11 (by intlit)) - let z ← x + y - if h: not (z = (U32.ofInt 15 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test3] -/ -#assert (test3_fwd == .ret ()) - -/- [no_nested_borrows::test_neg1] -/ -def test_neg1_fwd : Result Unit := - do - let y ← - (I32.ofInt 3 (by intlit)) - if h: not (y = (I32.ofInt (-(3:Int)) (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_neg1] -/ -#assert (test_neg1_fwd == .ret ()) - -/- [no_nested_borrows::refs_test1] -/ -def refs_test1_fwd : Result Unit := - if h: not ((I32.ofInt 1 (by intlit)) = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::refs_test1] -/ -#assert (refs_test1_fwd == .ret ()) - -/- [no_nested_borrows::refs_test2] -/ -def refs_test2_fwd : Result Unit := - if h: not ((I32.ofInt 2 (by intlit)) = (I32.ofInt 2 (by intlit))) - then Result.fail Error.panic - else - if h: not ((I32.ofInt 0 (by intlit)) = (I32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else - if h: not ((I32.ofInt 2 (by intlit)) = (I32.ofInt 2 (by intlit))) - then Result.fail Error.panic - else - if h: not ((I32.ofInt 2 (by intlit)) = (I32.ofInt 2 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::refs_test2] -/ -#assert (refs_test2_fwd == .ret ()) - -/- [no_nested_borrows::test_list1] -/ -def test_list1_fwd : Result Unit := - Result.ret () - -/- Unit test for [no_nested_borrows::test_list1] -/ -#assert (test_list1_fwd == .ret ()) - -/- [no_nested_borrows::test_box1] -/ -def test_box1_fwd : Result Unit := - let b := (I32.ofInt 1 (by intlit)) - let x := b - if h: not (x = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_box1] -/ -#assert (test_box1_fwd == .ret ()) - -/- [no_nested_borrows::copy_int] -/ -def copy_int_fwd (x : I32) : Result I32 := - Result.ret x - -/- [no_nested_borrows::test_unreachable] -/ -def test_unreachable_fwd (b : Bool) : Result Unit := - if h: b - then Result.fail Error.panic - else Result.ret () - -/- [no_nested_borrows::test_panic] -/ -def test_panic_fwd (b : Bool) : Result Unit := - if h: b - then Result.fail Error.panic - else Result.ret () - -/- [no_nested_borrows::test_copy_int] -/ -def test_copy_int_fwd : Result Unit := - do - let y ← copy_int_fwd (I32.ofInt 0 (by intlit)) - if h: not ((I32.ofInt 0 (by intlit)) = y) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_copy_int] -/ -#assert (test_copy_int_fwd == .ret ()) - -/- [no_nested_borrows::is_cons] -/ -def is_cons_fwd (T : Type) (l : list_t T) : Result Bool := - match h: l with - | list_t.Cons t l0 => Result.ret true - | list_t.Nil => Result.ret false - -/- [no_nested_borrows::test_is_cons] -/ -def test_is_cons_fwd : Result Unit := - do - let l := list_t.Nil - let b ← is_cons_fwd I32 (list_t.Cons (I32.ofInt 0 (by intlit)) l) - if h: not b - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_is_cons] -/ -#assert (test_is_cons_fwd == .ret ()) - -/- [no_nested_borrows::split_list] -/ -def split_list_fwd (T : Type) (l : list_t T) : Result (T × (list_t T)) := - match h: l with - | list_t.Cons hd tl => Result.ret (hd, tl) - | list_t.Nil => Result.fail Error.panic - -/- [no_nested_borrows::test_split_list] -/ -def test_split_list_fwd : Result Unit := - do - let l := list_t.Nil - let p ← split_list_fwd I32 (list_t.Cons (I32.ofInt 0 (by intlit)) l) - let (hd, _) := p - if h: not (hd = (I32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_split_list] -/ -#assert (test_split_list_fwd == .ret ()) - -/- [no_nested_borrows::choose] -/ -def choose_fwd (T : Type) (b : Bool) (x : T) (y : T) : Result T := - if h: b - then Result.ret x - else Result.ret y - -/- [no_nested_borrows::choose] -/ -def choose_back - (T : Type) (b : Bool) (x : T) (y : T) (ret0 : T) : Result (T × T) := - if h: b - then Result.ret (ret0, y) - else Result.ret (x, ret0) - -/- [no_nested_borrows::choose_test] -/ -def choose_test_fwd : Result Unit := - do - let z ← - choose_fwd I32 true (I32.ofInt 0 (by intlit)) (I32.ofInt 0 (by intlit)) - let z0 ← z + (I32.ofInt 1 (by intlit)) - if h: not (z0 = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - do - let (x, y) ← - choose_back I32 true (I32.ofInt 0 (by intlit)) - (I32.ofInt 0 (by intlit)) z0 - if h: not (x = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - if h: not (y = (I32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::choose_test] -/ -#assert (choose_test_fwd == .ret ()) - -/- [no_nested_borrows::test_char] -/ -def test_char_fwd : Result Char := - Result.ret 'a' - -mutual - -/- [no_nested_borrows::NodeElem] -/ -inductive node_elem_t (T : Type) := -| Cons : tree_t T -> node_elem_t T -> node_elem_t T -| Nil : node_elem_t T - -/- [no_nested_borrows::Tree] -/ -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] -/ -def list_length_fwd (T : Type) (l : list_t T) : Result U32 := - match h: l with - | list_t.Cons t l1 => - do - let i ← list_length_fwd T l1 - (U32.ofInt 1 (by intlit)) + i - | list_t.Nil => Result.ret (U32.ofInt 0 (by intlit)) - -/- [no_nested_borrows::list_nth_shared] -/ -def list_nth_shared_fwd (T : Type) (l : list_t T) (i : U32) : Result T := - match h: l with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_fwd T tl i0 - | list_t.Nil => Result.fail Error.panic - -/- [no_nested_borrows::list_nth_mut] -/ -def list_nth_mut_fwd (T : Type) (l : list_t T) (i : U32) : Result T := - match h: l with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_fwd T tl i0 - | list_t.Nil => Result.fail Error.panic - -/- [no_nested_borrows::list_nth_mut] -/ -def list_nth_mut_back - (T : Type) (l : list_t T) (i : U32) (ret0 : T) : Result (list_t T) := - match h: l with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl0 ← list_nth_mut_back T tl i0 ret0 - Result.ret (list_t.Cons x tl0) - | list_t.Nil => Result.fail Error.panic - -/- [no_nested_borrows::list_rev_aux] -/ -def list_rev_aux_fwd - (T : Type) (li : list_t T) (lo : list_t T) : Result (list_t T) := - match h: li with - | list_t.Cons hd tl => list_rev_aux_fwd T tl (list_t.Cons hd lo) - | list_t.Nil => Result.ret lo - -/- [no_nested_borrows::list_rev] -/ -def list_rev_fwd_back (T : Type) (l : list_t T) : Result (list_t T) := - let li := mem_replace_fwd (list_t T) l list_t.Nil - list_rev_aux_fwd T li list_t.Nil - -/- [no_nested_borrows::test_list_functions] -/ -def test_list_functions_fwd : Result Unit := - do - let l := list_t.Nil - let l0 := list_t.Cons (I32.ofInt 2 (by intlit)) l - let l1 := list_t.Cons (I32.ofInt 1 (by intlit)) l0 - let i ← list_length_fwd I32 (list_t.Cons (I32.ofInt 0 (by intlit)) l1) - if h: not (i = (U32.ofInt 3 (by intlit))) - then Result.fail Error.panic - else - do - let i0 ← - list_nth_shared_fwd I32 (list_t.Cons (I32.ofInt 0 (by intlit)) l1) - (U32.ofInt 0 (by intlit)) - if h: not (i0 = (I32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else - do - let i1 ← - list_nth_shared_fwd I32 (list_t.Cons (I32.ofInt 0 (by intlit)) - l1) (U32.ofInt 1 (by intlit)) - if h: not (i1 = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - do - let i2 ← - list_nth_shared_fwd I32 (list_t.Cons - (I32.ofInt 0 (by intlit)) l1) (U32.ofInt 2 (by intlit)) - if h: not (i2 = (I32.ofInt 2 (by intlit))) - then Result.fail Error.panic - else - do - let ls ← - list_nth_mut_back I32 (list_t.Cons - (I32.ofInt 0 (by intlit)) l1) (U32.ofInt 1 (by intlit)) - (I32.ofInt 3 (by intlit)) - let i3 ← - list_nth_shared_fwd I32 ls (U32.ofInt 0 (by intlit)) - if h: not (i3 = (I32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else - do - let i4 ← - list_nth_shared_fwd I32 ls (U32.ofInt 1 (by intlit)) - if h: not (i4 = (I32.ofInt 3 (by intlit))) - then Result.fail Error.panic - else - do - let i5 ← - list_nth_shared_fwd I32 ls - (U32.ofInt 2 (by intlit)) - if h: not (i5 = (I32.ofInt 2 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_list_functions] -/ -#assert (test_list_functions_fwd == .ret ()) - -/- [no_nested_borrows::id_mut_pair1] -/ -def id_mut_pair1_fwd (T1 T2 : Type) (x : T1) (y : T2) : Result (T1 × T2) := - Result.ret (x, y) - -/- [no_nested_borrows::id_mut_pair1] -/ -def id_mut_pair1_back - (T1 T2 : Type) (x : T1) (y : T2) (ret0 : (T1 × T2)) : Result (T1 × T2) := - let (t, t0) := ret0 - Result.ret (t, t0) - -/- [no_nested_borrows::id_mut_pair2] -/ -def id_mut_pair2_fwd (T1 T2 : Type) (p : (T1 × T2)) : Result (T1 × T2) := - let (t, t0) := p - Result.ret (t, t0) - -/- [no_nested_borrows::id_mut_pair2] -/ -def id_mut_pair2_back - (T1 T2 : Type) (p : (T1 × T2)) (ret0 : (T1 × T2)) : Result (T1 × T2) := - let (t, t0) := ret0 - Result.ret (t, t0) - -/- [no_nested_borrows::id_mut_pair3] -/ -def id_mut_pair3_fwd (T1 T2 : Type) (x : T1) (y : T2) : Result (T1 × T2) := - Result.ret (x, y) - -/- [no_nested_borrows::id_mut_pair3] -/ -def id_mut_pair3_back'a - (T1 T2 : Type) (x : T1) (y : T2) (ret0 : T1) : Result T1 := - Result.ret ret0 - -/- [no_nested_borrows::id_mut_pair3] -/ -def id_mut_pair3_back'b - (T1 T2 : Type) (x : T1) (y : T2) (ret0 : T2) : Result T2 := - Result.ret ret0 - -/- [no_nested_borrows::id_mut_pair4] -/ -def id_mut_pair4_fwd (T1 T2 : Type) (p : (T1 × T2)) : Result (T1 × T2) := - let (t, t0) := p - Result.ret (t, t0) - -/- [no_nested_borrows::id_mut_pair4] -/ -def id_mut_pair4_back'a - (T1 T2 : Type) (p : (T1 × T2)) (ret0 : T1) : Result T1 := - Result.ret ret0 - -/- [no_nested_borrows::id_mut_pair4] -/ -def id_mut_pair4_back'b - (T1 T2 : Type) (p : (T1 × T2)) (ret0 : T2) : Result T2 := - Result.ret ret0 - -/- [no_nested_borrows::StructWithTuple] -/ -structure struct_with_tuple_t (T1 T2 : Type) where - struct_with_tuple_p : (T1 × T2) - -/- [no_nested_borrows::new_tuple1] -/ -def new_tuple1_fwd : Result (struct_with_tuple_t U32 U32) := - Result.ret - { - struct_with_tuple_p := - ((U32.ofInt 1 (by intlit)), (U32.ofInt 2 (by intlit))) - } - -/- [no_nested_borrows::new_tuple2] -/ -def new_tuple2_fwd : Result (struct_with_tuple_t I16 I16) := - Result.ret - { - struct_with_tuple_p := - ((I16.ofInt 1 (by intlit)), (I16.ofInt 2 (by intlit))) - } - -/- [no_nested_borrows::new_tuple3] -/ -def new_tuple3_fwd : Result (struct_with_tuple_t U64 I64) := - Result.ret - { - struct_with_tuple_p := - ((U64.ofInt 1 (by intlit)), (I64.ofInt 2 (by intlit))) - } - -/- [no_nested_borrows::StructWithPair] -/ -structure struct_with_pair_t (T1 T2 : Type) where - struct_with_pair_p : pair_t T1 T2 - -/- [no_nested_borrows::new_pair1] -/ -def new_pair1_fwd : Result (struct_with_pair_t U32 U32) := - Result.ret - { - struct_with_pair_p := - { - pair_x := (U32.ofInt 1 (by intlit)), - pair_y := (U32.ofInt 2 (by intlit)) - } - } - -/- [no_nested_borrows::test_constants] -/ -def test_constants_fwd : Result Unit := - do - let swt ← new_tuple1_fwd - let (i, _) := swt.struct_with_tuple_p - if h: not (i = (U32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - do - let swt0 ← new_tuple2_fwd - let (i0, _) := swt0.struct_with_tuple_p - if h: not (i0 = (I16.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - do - let swt1 ← new_tuple3_fwd - let (i1, _) := swt1.struct_with_tuple_p - if h: not (i1 = (U64.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - do - let swp ← new_pair1_fwd - if h: not (swp.struct_with_pair_p.pair_x = - (U32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [no_nested_borrows::test_constants] -/ -#assert (test_constants_fwd == .ret ()) - -/- [no_nested_borrows::test_weird_borrows1] -/ -def test_weird_borrows1_fwd : Result Unit := - Result.ret () - -/- Unit test for [no_nested_borrows::test_weird_borrows1] -/ -#assert (test_weird_borrows1_fwd == .ret ()) - -/- [no_nested_borrows::test_mem_replace] -/ -def test_mem_replace_fwd_back (px : U32) : Result U32 := - let y := mem_replace_fwd U32 px (U32.ofInt 1 (by intlit)) - if h: not (y = (U32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else Result.ret (U32.ofInt 2 (by intlit)) - -/- [no_nested_borrows::test_shared_borrow_bool1] -/ -def test_shared_borrow_bool1_fwd (b : Bool) : Result U32 := - if h: b - then Result.ret (U32.ofInt 0 (by intlit)) - else Result.ret (U32.ofInt 1 (by intlit)) - -/- [no_nested_borrows::test_shared_borrow_bool2] -/ -def test_shared_borrow_bool2_fwd : Result U32 := - Result.ret (U32.ofInt 0 (by intlit)) - -/- [no_nested_borrows::test_shared_borrow_enum1] -/ -def test_shared_borrow_enum1_fwd (l : list_t U32) : Result U32 := - match h: l with - | list_t.Cons i l0 => Result.ret (U32.ofInt 1 (by intlit)) - | list_t.Nil => Result.ret (U32.ofInt 0 (by intlit)) - -/- [no_nested_borrows::test_shared_borrow_enum2] -/ -def test_shared_borrow_enum2_fwd : Result U32 := - Result.ret (U32.ofInt 0 (by intlit)) - diff --git a/tests/lean/misc-no_nested_borrows/lake-manifest.json b/tests/lean/misc-no_nested_borrows/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/misc-no_nested_borrows/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/misc-no_nested_borrows/lakefile.lean b/tests/lean/misc-no_nested_borrows/lakefile.lean deleted file mode 100644 index 58619110..00000000 --- a/tests/lean/misc-no_nested_borrows/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «no_nested_borrows» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «NoNestedBorrows» {} diff --git a/tests/lean/misc-no_nested_borrows/lean-toolchain b/tests/lean/misc-no_nested_borrows/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/misc-no_nested_borrows/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/misc-paper/Base/Primitives.lean b/tests/lean/misc-paper/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/misc-paper/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/misc-paper/Paper.lean b/tests/lean/misc-paper/Paper.lean deleted file mode 100644 index 0b16fb8e..00000000 --- a/tests/lean/misc-paper/Paper.lean +++ /dev/null @@ -1,123 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [paper] -import Base.Primitives - -/- [paper::ref_incr] -/ -def ref_incr_fwd_back (x : I32) : Result I32 := - x + (I32.ofInt 1 (by intlit)) - -/- [paper::test_incr] -/ -def test_incr_fwd : Result Unit := - do - let x ← ref_incr_fwd_back (I32.ofInt 0 (by intlit)) - if h: not (x = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [paper::test_incr] -/ -#assert (test_incr_fwd == .ret ()) - -/- [paper::choose] -/ -def choose_fwd (T : Type) (b : Bool) (x : T) (y : T) : Result T := - if h: b - then Result.ret x - else Result.ret y - -/- [paper::choose] -/ -def choose_back - (T : Type) (b : Bool) (x : T) (y : T) (ret0 : T) : Result (T × T) := - if h: b - then Result.ret (ret0, y) - else Result.ret (x, ret0) - -/- [paper::test_choose] -/ -def test_choose_fwd : Result Unit := - do - let z ← - choose_fwd I32 true (I32.ofInt 0 (by intlit)) (I32.ofInt 0 (by intlit)) - let z0 ← z + (I32.ofInt 1 (by intlit)) - if h: not (z0 = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - do - let (x, y) ← - choose_back I32 true (I32.ofInt 0 (by intlit)) - (I32.ofInt 0 (by intlit)) z0 - if h: not (x = (I32.ofInt 1 (by intlit))) - then Result.fail Error.panic - else - if h: not (y = (I32.ofInt 0 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [paper::test_choose] -/ -#assert (test_choose_fwd == .ret ()) - -/- [paper::List] -/ -inductive list_t (T : Type) := -| Cons : T -> list_t T -> list_t T -| Nil : list_t T - -/- [paper::list_nth_mut] -/ -def list_nth_mut_fwd (T : Type) (l : list_t T) (i : U32) : Result T := - match h: l with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret x - else do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_fwd T tl i0 - | list_t.Nil => Result.fail Error.panic - -/- [paper::list_nth_mut] -/ -def list_nth_mut_back - (T : Type) (l : list_t T) (i : U32) (ret0 : T) : Result (list_t T) := - match h: l with - | list_t.Cons x tl => - if h: i = (U32.ofInt 0 (by intlit)) - then Result.ret (list_t.Cons ret0 tl) - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - let tl0 ← list_nth_mut_back T tl i0 ret0 - Result.ret (list_t.Cons x tl0) - | list_t.Nil => Result.fail Error.panic - -/- [paper::sum] -/ -def sum_fwd (l : list_t I32) : Result I32 := - match h: l with - | list_t.Cons x tl => do - let i ← sum_fwd tl - x + i - | list_t.Nil => Result.ret (I32.ofInt 0 (by intlit)) - -/- [paper::test_nth] -/ -def test_nth_fwd : Result Unit := - do - let l := list_t.Nil - let l0 := list_t.Cons (I32.ofInt 3 (by intlit)) l - let l1 := list_t.Cons (I32.ofInt 2 (by intlit)) l0 - let x ← - list_nth_mut_fwd I32 (list_t.Cons (I32.ofInt 1 (by intlit)) l1) - (U32.ofInt 2 (by intlit)) - let x0 ← x + (I32.ofInt 1 (by intlit)) - let l2 ← - list_nth_mut_back I32 (list_t.Cons (I32.ofInt 1 (by intlit)) l1) - (U32.ofInt 2 (by intlit)) x0 - let i ← sum_fwd l2 - if h: not (i = (I32.ofInt 7 (by intlit))) - then Result.fail Error.panic - else Result.ret () - -/- Unit test for [paper::test_nth] -/ -#assert (test_nth_fwd == .ret ()) - -/- [paper::call_choose] -/ -def call_choose_fwd (p : (U32 × U32)) : Result U32 := - do - let (px, py) := p - let pz ← choose_fwd U32 true px py - let pz0 ← pz + (U32.ofInt 1 (by intlit)) - let (px0, _) ← choose_back U32 true px py pz0 - Result.ret px0 - diff --git a/tests/lean/misc-paper/lake-manifest.json b/tests/lean/misc-paper/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/misc-paper/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/misc-paper/lakefile.lean b/tests/lean/misc-paper/lakefile.lean deleted file mode 100644 index 75d7208e..00000000 --- a/tests/lean/misc-paper/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «paper» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «Paper» {} diff --git a/tests/lean/misc-paper/lean-toolchain b/tests/lean/misc-paper/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/misc-paper/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 diff --git a/tests/lean/misc-polonius_list/Base/Primitives.lean b/tests/lean/misc-polonius_list/Base/Primitives.lean deleted file mode 100644 index 4a66a453..00000000 --- a/tests/lean/misc-polonius_list/Base/Primitives.lean +++ /dev/null @@ -1,583 +0,0 @@ -import Lean -import Lean.Meta.Tactic.Simp -import Init.Data.List.Basic -import Mathlib.Tactic.RunCmd - --------------------- --- ASSERT COMMAND -- --------------------- - -open Lean Elab Command Term Meta - -syntax (name := assert) "#assert" term: command - -@[command_elab assert] -unsafe -def assertImpl : CommandElab := fun (_stx: Syntax) => do - runTermElabM (fun _ => do - let r ← evalTerm Bool (mkConst ``Bool) _stx[1] - if not r then - logInfo "Assertion failed for: " - logInfo _stx[1] - logError "Expression reduced to false" - pure ()) - -#eval 2 == 2 -#assert (2 == 2) - -------------- --- PRELUDE -- -------------- - --- Results & monadic combinators - -inductive Error where - | assertionFailure: Error - | integerOverflow: Error - | divisionByZero: Error - | arrayOutOfBounds: Error - | maximumSizeExceeded: Error - | panic: Error -deriving Repr, BEq - -open Error - -inductive Result (α : Type u) where - | ret (v: α): Result α - | fail (e: Error): Result α -deriving Repr, BEq - -open Result - -instance Result_Inhabited (α : Type u) : Inhabited (Result α) := - Inhabited.mk (fail panic) - -/- HELPERS -/ - -def ret? {α: Type} (r: Result α): Bool := - match r with - | Result.ret _ => true - | Result.fail _ => false - -def massert (b:Bool) : Result Unit := - if b then .ret () else fail assertionFailure - -def eval_global {α: Type} (x: Result α) (_: ret? x): α := - match x with - | Result.fail _ => by contradiction - | Result.ret x => x - -/- DO-DSL SUPPORT -/ - -def bind (x: Result α) (f: α -> Result β) : Result β := - match x with - | ret v => f v - | fail v => fail v - --- Allows using Result in do-blocks -instance : Bind Result where - bind := bind - --- Allows using return x in do-blocks -instance : Pure Result where - pure := fun x => ret x - -/- CUSTOM-DSL SUPPORT -/ - --- Let-binding the Result of a monadic operation is oftentimes not sufficient, --- because we may need a hypothesis for equational reasoning in the scope. We --- rely on subtype, and a custom let-binding operator, in effect recreating our --- own variant of the do-dsl - -def Result.attach {α: Type} (o : Result α): Result { x : α // o = ret x } := - match o with - | .ret x => .ret ⟨x, rfl⟩ - | .fail e => .fail e - -macro "let" e:term " ⟵ " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- TODO: any way to factorize both definitions? -macro "let" e:term " <-- " f:term : doElem => - `(doElem| let ⟨$e, h⟩ ← Result.attach $f) - --- We call the hypothesis `h`, in effect making it unavailable to the user --- (because too much shadowing). But in practice, once can use the French single --- quote notation (input with f< and f>), where `‹ h ›` finds a suitable --- hypothesis in the context, this is equivalent to `have x: h := by assumption in x` -#eval do - let y <-- .ret (0: Nat) - let _: y = 0 := by cases ‹ ret 0 = ret y › ; decide - let r: { x: Nat // x = 0 } := ⟨ y, by assumption ⟩ - .ret r - ----------------------- --- MACHINE INTEGERS -- ----------------------- - --- We redefine our machine integers types. - --- For Isize/Usize, we reuse `getNumBits` from `USize`. You cannot reduce `getNumBits` --- using the simplifier, meaning that proofs do not depend on the compile-time value of --- USize.size. (Lean assumes 32 or 64-bit platforms, and Rust doesn't really support, at --- least officially, 16-bit microcontrollers, so this seems like a fine design decision --- for now.) - --- Note from Chris Bailey: "If there's more than one salient property of your --- definition then the subtyping strategy might get messy, and the property part --- of a subtype is less discoverable by the simplifier or tactics like --- library_search." So, we will not add refinements on the return values of the --- operations defined on Primitives, but will rather rely on custom lemmas to --- invert on possible return values of the primitive operations. - --- Machine integer constants, done via `ofNatCore`, which requires a proof that --- the `Nat` fits within the desired integer type. We provide a custom tactic. - -open System.Platform.getNumBits - --- TODO: is there a way of only importing System.Platform.getNumBits? --- -@[simp] def size_num_bits : Nat := (System.Platform.getNumBits ()).val - --- Remark: Lean seems to use < for the comparisons with the upper bounds by convention. --- We keep the F* convention for now. -@[simp] def Isize.min : Int := - (HPow.hPow 2 (size_num_bits - 1)) -@[simp] def Isize.max : Int := (HPow.hPow 2 (size_num_bits - 1)) - 1 -@[simp] def I8.min : Int := - (HPow.hPow 2 7) -@[simp] def I8.max : Int := HPow.hPow 2 7 - 1 -@[simp] def I16.min : Int := - (HPow.hPow 2 15) -@[simp] def I16.max : Int := HPow.hPow 2 15 - 1 -@[simp] def I32.min : Int := -(HPow.hPow 2 31) -@[simp] def I32.max : Int := HPow.hPow 2 31 - 1 -@[simp] def I64.min : Int := -(HPow.hPow 2 63) -@[simp] def I64.max : Int := HPow.hPow 2 63 - 1 -@[simp] def I128.min : Int := -(HPow.hPow 2 127) -@[simp] def I128.max : Int := HPow.hPow 2 127 - 1 -@[simp] def Usize.min : Int := 0 -@[simp] def Usize.max : Int := HPow.hPow 2 size_num_bits - 1 -@[simp] def U8.min : Int := 0 -@[simp] def U8.max : Int := HPow.hPow 2 8 - 1 -@[simp] def U16.min : Int := 0 -@[simp] def U16.max : Int := HPow.hPow 2 16 - 1 -@[simp] def U32.min : Int := 0 -@[simp] def U32.max : Int := HPow.hPow 2 32 - 1 -@[simp] def U64.min : Int := 0 -@[simp] def U64.max : Int := HPow.hPow 2 64 - 1 -@[simp] def U128.min : Int := 0 -@[simp] def U128.max : Int := HPow.hPow 2 128 - 1 - -#assert (I8.min == -128) -#assert (I8.max == 127) -#assert (I16.min == -32768) -#assert (I16.max == 32767) -#assert (I32.min == -2147483648) -#assert (I32.max == 2147483647) -#assert (I64.min == -9223372036854775808) -#assert (I64.max == 9223372036854775807) -#assert (I128.min == -170141183460469231731687303715884105728) -#assert (I128.max == 170141183460469231731687303715884105727) -#assert (U8.min == 0) -#assert (U8.max == 255) -#assert (U16.min == 0) -#assert (U16.max == 65535) -#assert (U32.min == 0) -#assert (U32.max == 4294967295) -#assert (U64.min == 0) -#assert (U64.max == 18446744073709551615) -#assert (U128.min == 0) -#assert (U128.max == 340282366920938463463374607431768211455) - -inductive ScalarTy := -| Isize -| I8 -| I16 -| I32 -| I64 -| I128 -| Usize -| U8 -| U16 -| U32 -| U64 -| U128 - -def Scalar.min (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.min - | .I8 => I8.min - | .I16 => I16.min - | .I32 => I32.min - | .I64 => I64.min - | .I128 => I128.min - | .Usize => Usize.min - | .U8 => U8.min - | .U16 => U16.min - | .U32 => U32.min - | .U64 => U64.min - | .U128 => U128.min - -def Scalar.max (ty : ScalarTy) : Int := - match ty with - | .Isize => Isize.max - | .I8 => I8.max - | .I16 => I16.max - | .I32 => I32.max - | .I64 => I64.max - | .I128 => I128.max - | .Usize => Usize.max - | .U8 => U8.max - | .U16 => U16.max - | .U32 => U32.max - | .U64 => U64.max - | .U128 => U128.max - --- "Conservative" bounds --- We use those because we can't compare to the isize bounds (which can't --- reduce at compile-time). Whenever we perform an arithmetic operation like --- addition we need to check that the result is in bounds: we first compare --- to the conservative bounds, which reduce, then compare to the real bounds. --- This is useful for the various #asserts that we want to reduce at --- type-checking time. -def Scalar.cMin (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.min - | _ => Scalar.min ty - -def Scalar.cMax (ty : ScalarTy) : Int := - match ty with - | .Isize => I32.max - | .Usize => U32.max - | _ => Scalar.max ty - -theorem Scalar.cMin_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry -theorem Scalar.cMax_bound ty : Scalar.min ty <= Scalar.cMin ty := by sorry - -structure Scalar (ty : ScalarTy) where - val : Int - hmin : Scalar.min ty <= val - hmax : val <= Scalar.max ty - -theorem Scalar.bound_suffices (ty : ScalarTy) (x : Int) : - Scalar.cMin ty <= x && x <= Scalar.cMax ty -> - (decide (Scalar.min ty ≤ x) && decide (x ≤ Scalar.max ty)) = true - := by sorry - -def Scalar.ofIntCore {ty : ScalarTy} (x : Int) - (hmin : Scalar.min ty <= x) (hmax : x <= Scalar.max ty) : Scalar ty := - { val := x, hmin := hmin, hmax := hmax } - -def Scalar.ofInt {ty : ScalarTy} (x : Int) - (h : Scalar.min ty <= x && x <= Scalar.max ty) : Scalar ty := - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - Scalar.ofIntCore x hmin hmax - --- Further thoughts: look at what has been done here: --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/Fin/Basic.lean --- and --- https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Data/UInt.lean --- which both contain a fair amount of reasoning already! -def Scalar.tryMk (ty : ScalarTy) (x : Int) : Result (Scalar ty) := - -- TODO: write this with only one if then else - if hmin_cons: Scalar.cMin ty <= x || Scalar.min ty <= x then - if hmax_cons: x <= Scalar.cMax ty || x <= Scalar.max ty then - let hmin: Scalar.min ty <= x := by sorry - let hmax: x <= Scalar.max ty := by sorry - return Scalar.ofIntCore x hmin hmax - else fail integerOverflow - else fail integerOverflow - -def Scalar.neg {ty : ScalarTy} (x : Scalar ty) : Result (Scalar ty) := Scalar.tryMk ty (- x.val) - -def Scalar.div {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val / y.val) else fail divisionByZero - --- Checking that the % operation in Lean computes the same as the remainder operation in Rust -#assert 1 % 2 = (1:Int) -#assert (-1) % 2 = -1 -#assert 1 % (-2) = 1 -#assert (-1) % (-2) = -1 - -def Scalar.rem {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - if y.val != 0 then Scalar.tryMk ty (x.val % y.val) else fail divisionByZero - -def Scalar.add {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val + y.val) - -def Scalar.sub {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val - y.val) - -def Scalar.mul {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Result (Scalar ty) := - Scalar.tryMk ty (x.val * y.val) - --- TODO: instances of +, -, * etc. for scalars - --- Cast an integer from a [src_ty] to a [tgt_ty] --- TODO: check the semantics of casts in Rust -def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) := - Scalar.tryMk tgt_ty x.val - --- The scalar types --- We declare the definitions as reducible so that Lean can unfold them (useful --- for type class resolution for instance). -@[reducible] def Isize := Scalar .Isize -@[reducible] def I8 := Scalar .I8 -@[reducible] def I16 := Scalar .I16 -@[reducible] def I32 := Scalar .I32 -@[reducible] def I64 := Scalar .I64 -@[reducible] def I128 := Scalar .I128 -@[reducible] def Usize := Scalar .Usize -@[reducible] def U8 := Scalar .U8 -@[reducible] def U16 := Scalar .U16 -@[reducible] def U32 := Scalar .U32 -@[reducible] def U64 := Scalar .U64 -@[reducible] def U128 := Scalar .U128 - --- TODO: below: not sure this is the best way. --- Should we rather overload operations like +, -, etc.? --- Also, it is possible to automate the generation of those definitions --- with macros (but would it be a good idea? It would be less easy to --- read the file, which is not supposed to change a lot) - --- Negation - -/-- -Remark: there is no heterogeneous negation in the Lean prelude: we thus introduce -one here. - -The notation typeclass for heterogeneous addition. -This enables the notation `- a : β` where `a : α`. --/ -class HNeg (α : Type u) (β : outParam (Type v)) where - /-- `- a` computes the negation of `a`. - The meaning of this notation is type-dependent. -/ - hNeg : α → β - -prefix:75 "-" => HNeg.hNeg - -instance : HNeg Isize (Result Isize) where hNeg x := Scalar.neg x -instance : HNeg I8 (Result I8) where hNeg x := Scalar.neg x -instance : HNeg I16 (Result I16) where hNeg x := Scalar.neg x -instance : HNeg I32 (Result I32) where hNeg x := Scalar.neg x -instance : HNeg I64 (Result I64) where hNeg x := Scalar.neg x -instance : HNeg I128 (Result I128) where hNeg x := Scalar.neg x - --- Addition -instance {ty} : HAdd (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hAdd x y := Scalar.add x y - --- Substraction -instance {ty} : HSub (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hSub x y := Scalar.sub x y - --- Multiplication -instance {ty} : HMul (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMul x y := Scalar.mul x y - --- Division -instance {ty} : HDiv (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hDiv x y := Scalar.div x y - --- Remainder -instance {ty} : HMod (Scalar ty) (Scalar ty) (Result (Scalar ty)) where - hMod x y := Scalar.rem x y - --- ofIntCore --- TODO: typeclass? -def Isize.ofIntCore := @Scalar.ofIntCore .Isize -def I8.ofIntCore := @Scalar.ofIntCore .I8 -def I16.ofIntCore := @Scalar.ofIntCore .I16 -def I32.ofIntCore := @Scalar.ofIntCore .I32 -def I64.ofIntCore := @Scalar.ofIntCore .I64 -def I128.ofIntCore := @Scalar.ofIntCore .I128 -def Usize.ofIntCore := @Scalar.ofIntCore .Usize -def U8.ofIntCore := @Scalar.ofIntCore .U8 -def U16.ofIntCore := @Scalar.ofIntCore .U16 -def U32.ofIntCore := @Scalar.ofIntCore .U32 -def U64.ofIntCore := @Scalar.ofIntCore .U64 -def U128.ofIntCore := @Scalar.ofIntCore .U128 - --- ofInt --- TODO: typeclass? -def Isize.ofInt := @Scalar.ofInt .Isize -def I8.ofInt := @Scalar.ofInt .I8 -def I16.ofInt := @Scalar.ofInt .I16 -def I32.ofInt := @Scalar.ofInt .I32 -def I64.ofInt := @Scalar.ofInt .I64 -def I128.ofInt := @Scalar.ofInt .I128 -def Usize.ofInt := @Scalar.ofInt .Usize -def U8.ofInt := @Scalar.ofInt .U8 -def U16.ofInt := @Scalar.ofInt .U16 -def U32.ofInt := @Scalar.ofInt .U32 -def U64.ofInt := @Scalar.ofInt .U64 -def U128.ofInt := @Scalar.ofInt .U128 - --- Comparisons -instance {ty} : LT (Scalar ty) where - lt a b := LT.lt a.val b.val - -instance {ty} : LE (Scalar ty) where le a b := LE.le a.val b.val - -instance Scalar.decLt {ty} (a b : Scalar ty) : Decidable (LT.lt a b) := Int.decLt .. -instance Scalar.decLe {ty} (a b : Scalar ty) : Decidable (LE.le a b) := Int.decLe .. - -theorem Scalar.eq_of_val_eq {ty} : ∀ {i j : Scalar ty}, Eq i.val j.val → Eq i j - | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl - -theorem Scalar.val_eq_of_eq {ty} {i j : Scalar ty} (h : Eq i j) : Eq i.val j.val := - h ▸ rfl - -theorem Scalar.ne_of_val_ne {ty} {i j : Scalar ty} (h : Not (Eq i.val j.val)) : Not (Eq i j) := - fun h' => absurd (val_eq_of_eq h') h - -instance (ty : ScalarTy) : DecidableEq (Scalar ty) := - fun i j => - match decEq i.val j.val with - | isTrue h => isTrue (Scalar.eq_of_val_eq h) - | isFalse h => isFalse (Scalar.ne_of_val_ne h) - -def Scalar.toInt {ty} (n : Scalar ty) : Int := n.val - --- Tactic to prove that integers are in bounds -syntax "intlit" : tactic - -macro_rules - | `(tactic| intlit) => `(tactic| apply Scalar.bound_suffices ; decide) - --- -- We now define a type class that subsumes the various machine integer types, so --- -- as to write a concise definition for scalar_cast, rather than exhaustively --- -- enumerating all of the possible pairs. We remark that Rust has sane semantics --- -- and fails if a cast operation would involve a truncation or modulo. - --- class MachineInteger (t: Type) where --- size: Nat --- val: t -> Fin size --- ofNatCore: (n:Nat) -> LT.lt n size -> t - --- set_option hygiene false in --- run_cmd --- for typeName in [`UInt8, `UInt16, `UInt32, `UInt64, `USize].map Lean.mkIdent do --- Lean.Elab.Command.elabCommand (← `( --- namespace $typeName --- instance: MachineInteger $typeName where --- size := size --- val := val --- ofNatCore := ofNatCore --- end $typeName --- )) - --- -- Aeneas only instantiates the destination type (`src` is implicit). We rely on --- -- Lean to infer `src`. - --- def scalar_cast { src: Type } (dst: Type) [ MachineInteger src ] [ MachineInteger dst ] (x: src): Result dst := --- if h: MachineInteger.val x < MachineInteger.size dst then --- .ret (MachineInteger.ofNatCore (MachineInteger.val x).val h) --- else --- .fail integerOverflow - -------------- --- VECTORS -- -------------- - -def Vec (α : Type u) := { l : List α // List.length l <= Usize.max } - -def vec_new (α : Type u): Vec α := ⟨ [], by sorry ⟩ - -def vec_len (α : Type u) (v : Vec α) : Usize := - let ⟨ v, l ⟩ := v - Usize.ofIntCore (List.length v) (by sorry) l - -def vec_push_fwd (α : Type u) (_ : Vec α) (_ : α) : Unit := () - -def vec_push_back (α : Type u) (v : Vec α) (x : α) : Result (Vec α) - := - if h : List.length v.val <= U32.max || List.length v.val <= Usize.max then - return ⟨ List.concat v.val x, by sorry ⟩ - else - fail maximumSizeExceeded - -def vec_insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_insert_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - -- TODO: maybe we should redefine a list library which uses integers - -- (instead of natural numbers) - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - -def vec_index_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_back (α : Type u) (v: Vec α) (i: Usize) (_: α): Result Unit := - if i.val < List.length v.val then - .ret () - else - .fail arrayOutOfBounds - -def vec_index_mut_fwd (α : Type u) (v: Vec α) (i: Usize): Result α := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - let h: i < List.length v.val := by sorry - .ret (List.get v.val ⟨i.val, h⟩) - else - .fail arrayOutOfBounds - -def vec_index_mut_back (α : Type u) (v: Vec α) (i: Usize) (x: α): Result (Vec α) := - if i.val < List.length v.val then - let i : Nat := - match i.val with - | .ofNat n => n - | .negSucc n => by sorry -- TODO: we can't get here - let isLt: i < USize.size := by sorry - let i : Fin USize.size := { val := i, isLt := isLt } - .ret ⟨ List.set v.val i.val x, by - have h: List.length v.val <= Usize.max := v.property - rewrite [ List.length_set v.val i.val x ] - assumption - ⟩ - else - .fail arrayOutOfBounds - ----------- --- MISC -- ----------- - -def mem_replace_fwd (a : Type) (x : a) (_ : a) : a := - x - -def mem_replace_back (a : Type) (_ : a) (y : a) : a := - y - -/-- Aeneas-translated function -- useful to reduce non-recursive definitions. - Use with `simp [ aeneas ]` -/ -register_simp_attr aeneas diff --git a/tests/lean/misc-polonius_list/PoloniusList.lean b/tests/lean/misc-polonius_list/PoloniusList.lean deleted file mode 100644 index 79696996..00000000 --- a/tests/lean/misc-polonius_list/PoloniusList.lean +++ /dev/null @@ -1,31 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [polonius_list] -import Base.Primitives - -/- [polonius_list::List] -/ -inductive list_t (T : Type) := -| Cons : T -> list_t T -> list_t T -| Nil : list_t T - -/- [polonius_list::get_list_at_x] -/ -def get_list_at_x_fwd (ls : list_t U32) (x : U32) : Result (list_t U32) := - match h: ls with - | list_t.Cons hd tl => - if h: hd = x - then Result.ret (list_t.Cons hd tl) - else get_list_at_x_fwd tl x - | list_t.Nil => Result.ret list_t.Nil - -/- [polonius_list::get_list_at_x] -/ -def get_list_at_x_back - (ls : list_t U32) (x : U32) (ret0 : list_t U32) : Result (list_t U32) := - match h: ls with - | list_t.Cons hd tl => - if h: hd = x - then Result.ret ret0 - else - do - let tl0 ← get_list_at_x_back tl x ret0 - Result.ret (list_t.Cons hd tl0) - | list_t.Nil => Result.ret ret0 - diff --git a/tests/lean/misc-polonius_list/lake-manifest.json b/tests/lean/misc-polonius_list/lake-manifest.json deleted file mode 100644 index 57b071ca..00000000 --- a/tests/lean/misc-polonius_list/lake-manifest.json +++ /dev/null @@ -1,27 +0,0 @@ -{"version": 4, - "packagesDir": "./lake-packages", - "packages": - [{"git": - {"url": "https://github.com/leanprover-community/mathlib4.git", - "subDir?": null, - "rev": "4037792ead804d7bfa8868e2c4684d4223c15ece", - "name": "mathlib", - "inputRev?": null}}, - {"git": - {"url": "https://github.com/gebner/quote4", - "subDir?": null, - "rev": "2412c4fdf4a8b689f4467618e5e7b371ae5014aa", - "name": "Qq", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/JLimperg/aesop", - "subDir?": null, - "rev": "7fe9ecd9339b0e1796e89d243b776849c305c690", - "name": "aesop", - "inputRev?": "master"}}, - {"git": - {"url": "https://github.com/leanprover/std4", - "subDir?": null, - "rev": "24897887905b3a1254b244369f5dd2cf6174b0ee", - "name": "std", - "inputRev?": "main"}}]} diff --git a/tests/lean/misc-polonius_list/lakefile.lean b/tests/lean/misc-polonius_list/lakefile.lean deleted file mode 100644 index e89d4259..00000000 --- a/tests/lean/misc-polonius_list/lakefile.lean +++ /dev/null @@ -1,12 +0,0 @@ -import Lake -open Lake DSL - -require mathlib from git - "https://github.com/leanprover-community/mathlib4.git" - -package «polonius_list» {} - -lean_lib «Base» {} - -@[default_target] -lean_lib «PoloniusList» {} diff --git a/tests/lean/misc-polonius_list/lean-toolchain b/tests/lean/misc-polonius_list/lean-toolchain deleted file mode 100644 index bbf57f10..00000000 --- a/tests/lean/misc-polonius_list/lean-toolchain +++ /dev/null @@ -1 +0,0 @@ -leanprover/lean4:nightly-2023-01-21 |