diff options
Diffstat (limited to 'tests/lean')
-rw-r--r-- | tests/lean/BetreeMain/Funs.lean | 472 | ||||
-rw-r--r-- | tests/lean/BetreeMain/FunsExternal.lean | 10 | ||||
-rw-r--r-- | tests/lean/BetreeMain/FunsExternal_Template.lean | 20 | ||||
-rw-r--r-- | tests/lean/Constants.lean | 54 | ||||
-rw-r--r-- | tests/lean/External/Funs.lean | 49 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal.lean | 6 | ||||
-rw-r--r-- | tests/lean/External/FunsExternal_Template.lean | 17 | ||||
-rw-r--r-- | tests/lean/Hashmap/Funs.lean | 262 | ||||
-rw-r--r-- | tests/lean/HashmapMain/Funs.lean | 276 | ||||
-rw-r--r-- | tests/lean/HashmapMain/FunsExternal.lean | 4 | ||||
-rw-r--r-- | tests/lean/HashmapMain/FunsExternal_Template.lean | 8 | ||||
-rw-r--r-- | tests/lean/Loops/Funs.lean | 300 | ||||
-rw-r--r-- | tests/lean/NoNestedBorrows.lean | 292 | ||||
-rw-r--r-- | tests/lean/Paper.lean | 57 | ||||
-rw-r--r-- | tests/lean/PoloniusList.lean | 9 |
15 files changed, 916 insertions, 920 deletions
diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index 074fff5e..41e4349e 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -6,60 +6,59 @@ import BetreeMain.FunsExternal open Primitives namespace betree_main -/- [betree_main::betree::load_internal_node] -/ -def betree.load_internal_node_fwd +/- [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_fwd id st + betree_utils.load_internal_node id st -/- [betree_main::betree::store_internal_node] -/ -def betree.store_internal_node_fwd +/- [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_fwd id content st + let (st0, _) ← betree_utils.store_internal_node id content st Result.ret (st0, ()) -/- [betree_main::betree::load_leaf_node] -/ -def betree.load_leaf_node_fwd +/- [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_fwd id st + betree_utils.load_leaf_node id st -/- [betree_main::betree::store_leaf_node] -/ -def betree.store_leaf_node_fwd +/- [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_fwd id content st + let (st0, _) ← betree_utils.store_leaf_node id content st Result.ret (st0, ()) -/- [betree_main::betree::fresh_node_id] -/ -def betree.fresh_node_id_fwd (counter : U64) : Result U64 := +/- [betree_main::betree::fresh_node_id]: forward function -/ +def betree.fresh_node_id (counter : U64) : Result U64 := do let _ ← counter + (U64.ofInt 1 (by intlit)) Result.ret counter -/- [betree_main::betree::fresh_node_id] -/ +/- [betree_main::betree::fresh_node_id]: backward function 0 -/ def betree.fresh_node_id_back (counter : U64) : Result U64 := counter + (U64.ofInt 1 (by intlit)) -/- [betree_main::betree::NodeIdCounter::{0}::new] -/ -def betree.NodeIdCounter.new_fwd : Result betree.NodeIdCounter := +/- [betree_main::betree::NodeIdCounter::{0}::new]: forward function -/ +def betree.NodeIdCounter.new : Result betree.NodeIdCounter := Result.ret { betree_node_id_counter_next_node_id := (U64.ofInt 0 (by intlit)) } -/- [betree_main::betree::NodeIdCounter::{0}::fresh_id] -/ -def betree.NodeIdCounter.fresh_id_fwd - (self : betree.NodeIdCounter) : Result U64 := +/- [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function -/ +def betree.NodeIdCounter.fresh_id (self : betree.NodeIdCounter) : Result U64 := do let _ ← self.betree_node_id_counter_next_node_id + (U64.ofInt 1 (by intlit)) Result.ret 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 -/ def betree.NodeIdCounter.fresh_id_back (self : betree.NodeIdCounter) : Result betree.NodeIdCounter := do @@ -72,8 +71,8 @@ def core_num_u64_max_body : Result U64 := Result.ret (U64.ofInt 18446744073709551615 (by intlit)) def core_num_u64_max_c : U64 := eval_global core_num_u64_max_body (by simp) -/- [betree_main::betree::upsert_update] -/ -def betree.upsert_update_fwd +/- [betree_main::betree::upsert_update]: forward function -/ +def betree.upsert_update (prev : Option U64) (st : betree.UpsertFunState) : Result U64 := match prev with | Option.none => @@ -93,18 +92,17 @@ def betree.upsert_update_fwd then prev0 - v else Result.ret (U64.ofInt 0 (by intlit)) -/- [betree_main::betree::List::{1}::len] -/ -divergent def betree.List.len_fwd - (T : Type) (self : betree.List T) : Result U64 := +/- [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_fwd T tl + let i ← betree.List.len T tl (U64.ofInt 1 (by intlit)) + i | betree.List.Nil => Result.ret (U64.ofInt 0 (by intlit)) -/- [betree_main::betree::List::{1}::split_at] -/ -divergent def betree.List.split_at_fwd +/- [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)) := @@ -115,50 +113,51 @@ divergent def betree.List.split_at_fwd | betree.List.Cons hd tl => do let i ← n - (U64.ofInt 1 (by intlit)) - let p ← betree.List.split_at_fwd T tl i + 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] -/ -def betree.List.push_front_fwd_back +/- [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_fwd (betree.List T) self betree.List.Nil + 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] -/ -def betree.List.pop_front_fwd (T : Type) (self : betree.List T) : Result T := - let ls := mem.replace_fwd (betree.List T) self betree.List.Nil +/- [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] -/ +/- [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_fwd (betree.List T) self betree.List.Nil + 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] -/ -def betree.List.hd_fwd (T : Type) (self : betree.List T) : Result T := +/- [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] -/ -def betree.List.head_has_key_fwd +/- [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] -/ -divergent def betree.List.partition_at_pivot_fwd +/- [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))) := @@ -169,30 +168,29 @@ divergent def betree.List.partition_at_pivot_fwd then Result.ret (betree.List.Nil, betree.List.Cons (i, t) tl) else do - let p ← betree.List.partition_at_pivot_fwd T tl pivot + 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] -/ -def betree.Leaf.split_fwd +/- [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_fwd (U64 × U64) content - params.betree_params_split_size + betree.List.split_at (U64 × U64) content params.betree_params_split_size let (content0, content1) := p - let p0 ← betree.List.hd_fwd (U64 × U64) content1 + let p0 ← betree.List.hd (U64 × U64) content1 let (pivot, _) := p0 - let id0 ← betree.NodeIdCounter.fresh_id_fwd node_id_cnt + 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_fwd node_id_cnt0 - let (st0, _) ← betree.store_leaf_node_fwd id0 content0 st - let (st1, _) ← betree.store_leaf_node_fwd id1 content1 st0 + 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 { betree_leaf_id := id0, @@ -205,7 +203,7 @@ def betree.Leaf.split_fwd } Result.ret (st1, betree.Internal.mk self.betree_leaf_id pivot n n0) -/- [betree_main::betree::Leaf::{3}::split] -/ +/- [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) : @@ -213,19 +211,18 @@ def betree.Leaf.split_back := do let p ← - betree.List.split_at_fwd (U64 × U64) content - params.betree_params_split_size + betree.List.split_at (U64 × U64) content params.betree_params_split_size let (content0, content1) := p - let _ ← betree.List.hd_fwd (U64 × U64) content1 - let id0 ← betree.NodeIdCounter.fresh_id_fwd node_id_cnt + 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_fwd node_id_cnt0 - let (st0, _) ← betree.store_leaf_node_fwd id0 content0 st - let _ ← betree.store_leaf_node_fwd id1 content1 st0 + 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] -/ -divergent def betree.Node.lookup_in_bindings_fwd +/- [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 => @@ -235,11 +232,11 @@ divergent def betree.Node.lookup_in_bindings_fwd else if i > key then Result.ret Option.none - else betree.Node.lookup_in_bindings_fwd key tl + 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] -/ -divergent def betree.Node.lookup_first_message_for_key_fwd +/- [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)) := @@ -248,10 +245,10 @@ divergent def betree.Node.lookup_first_message_for_key_fwd 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_fwd key 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] -/ +/- [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)) : @@ -269,66 +266,66 @@ divergent def betree.Node.lookup_first_message_for_key_back Result.ret (betree.List.Cons (i, m) next_msgs0) | betree.List.Nil => Result.ret ret0 -/- [betree_main::betree::Node::{5}::apply_upserts] -/ -divergent def betree.Node.apply_upserts_fwd +/- [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_fwd betree.Message msgs key + let b ← betree.List.head_has_key betree.Message msgs key if b then do - let msg ← betree.List.pop_front_fwd (U64 × betree.Message) msgs + 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_fwd prev s + let v ← betree.upsert_update prev s let msgs0 ← betree.List.pop_front_back (U64 × betree.Message) msgs - betree.Node.apply_upserts_fwd msgs0 (Option.some v) key st + betree.Node.apply_upserts msgs0 (Option.some v) key st else do - let (st0, v) ← core.option.Option.unwrap_fwd U64 prev st + let (st0, v) ← core.option.Option.unwrap U64 prev st let _ ← - betree.List.push_front_fwd_back (U64 × betree.Message) msgs (key, + betree.List.push_front (U64 × betree.Message) msgs (key, betree.Message.Insert v) Result.ret (st0, v) -/- [betree_main::betree::Node::{5}::apply_upserts] -/ +/- [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_fwd betree.Message msgs key + let b ← betree.List.head_has_key betree.Message msgs key if b then do - let msg ← betree.List.pop_front_fwd (U64 × betree.Message) msgs + 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_fwd prev s + 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_fwd U64 prev st - betree.List.push_front_fwd_back (U64 × betree.Message) msgs (key, + 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] -/ -mutual divergent def betree.Node.lookup_fwd +/- [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)) := @@ -336,8 +333,8 @@ mutual divergent def betree.Node.lookup_fwd | betree.Node.Internal node => do let ⟨ i, i0, n, n0 ⟩ := node - let (st0, msgs) ← betree.load_internal_node_fwd i st - let pending ← betree.Node.lookup_first_message_for_key_fwd key msgs + 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 @@ -345,8 +342,8 @@ mutual divergent def betree.Node.lookup_fwd then do let (st1, opt) ← - betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 n - n0) key st0 + 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) @@ -368,10 +365,10 @@ mutual divergent def betree.Node.lookup_fwd | betree.Message.Upsert ufs => do let (st1, v) ← - betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 - n n0) key st0 + betree.Internal.lookup_in_children (betree.Internal.mk i i0 n + n0) key st0 let (st2, v0) ← - betree.Node.apply_upserts_fwd (betree.List.Cons (k, + 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 @@ -382,32 +379,32 @@ mutual divergent def betree.Node.lookup_fwd 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_fwd i1 msgs0 st2 + 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_fwd (betree.Internal.mk i i0 n - n0) key st0 + 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_fwd node.betree_leaf_id st - let opt ← betree.Node.lookup_in_bindings_fwd key bindings + let (st0, bindings) ← betree.load_leaf_node node.betree_leaf_id st + let opt ← betree.Node.lookup_in_bindings key bindings Result.ret (st0, opt) -/- [betree_main::betree::Node::{5}::lookup] -/ +/- [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_fwd i st - let pending ← betree.Node.lookup_first_message_for_key_fwd key msgs + 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 @@ -438,10 +435,10 @@ divergent def betree.Node.lookup_back | betree.Message.Upsert ufs => do let (st1, v) ← - betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 - n n0) key st0 + betree.Internal.lookup_in_children (betree.Internal.mk i i0 n + n0) key st0 let (st2, _) ← - betree.Node.apply_upserts_fwd (betree.List.Cons (k, + 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 @@ -452,7 +449,7 @@ divergent def betree.Node.lookup_back 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_fwd i1 msgs0 st2 + let _ ← betree.store_internal_node i1 msgs0 st2 Result.ret (betree.Node.Internal (betree.Internal.mk i1 i2 n1 n2)) | betree.List.Nil => @@ -466,21 +463,21 @@ divergent def betree.Node.lookup_back Result.ret (betree.Node.Internal node0) | betree.Node.Leaf node => do - let (_, bindings) ← betree.load_leaf_node_fwd node.betree_leaf_id st - let _ ← betree.Node.lookup_in_bindings_fwd key bindings + let (_, bindings) ← betree.load_leaf_node node.betree_leaf_id st + let _ ← betree.Node.lookup_in_bindings key bindings Result.ret (betree.Node.Leaf node) -/- [betree_main::betree::Internal::{4}::lookup_in_children] -/ -divergent def betree.Internal.lookup_in_children_fwd +/- [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_fwd n key st - else betree.Node.lookup_fwd n0 key st + then betree.Node.lookup n key st + else betree.Node.lookup n0 key st -/- [betree_main::betree::Internal::{4}::lookup_in_children] -/ +/- [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 @@ -496,8 +493,8 @@ divergent def betree.Internal.lookup_in_children_back end -/- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ -divergent def betree.Node.lookup_mut_in_bindings_fwd +/- [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)) := @@ -506,10 +503,10 @@ divergent def betree.Node.lookup_mut_in_bindings_fwd let (i, i0) := hd if i >= key then Result.ret (betree.List.Cons (i, i0) tl) - else betree.Node.lookup_mut_in_bindings_fwd key 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] -/ +/- [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)) : @@ -526,25 +523,26 @@ divergent def betree.Node.lookup_mut_in_bindings_back Result.ret (betree.List.Cons (i, i0) tl0) | betree.List.Nil => Result.ret ret0 -/- [betree_main::betree::Node::{5}::apply_to_leaf] -/ -def betree.Node.apply_to_leaf_fwd_back +/- [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_fwd key bindings - let b ← betree.List.head_has_key_fwd U64 bindings0 key + 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_fwd (U64 × U64) bindings0 + 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_fwd_back (U64 × U64) bindings1 (key, v) + betree.List.push_front (U64 × U64) bindings1 (key, v) betree.Node.lookup_mut_in_bindings_back key bindings bindings2 | betree.Message.Delete => do @@ -553,29 +551,30 @@ def betree.Node.apply_to_leaf_fwd_back | betree.Message.Upsert s => do let (_, i) := hd - let v ← betree.upsert_update_fwd (Option.some i) s + 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_fwd_back (U64 × U64) bindings1 (key, v) + 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_fwd_back (U64 × U64) bindings0 (key, v) + 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_fwd Option.none s + let v ← betree.upsert_update Option.none s let bindings1 ← - betree.List.push_front_fwd_back (U64 × U64) bindings0 (key, v) + 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] -/ -divergent def betree.Node.apply_messages_to_leaf_fwd_back +/- [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)) @@ -584,12 +583,13 @@ divergent def betree.Node.apply_messages_to_leaf_fwd_back | betree.List.Cons new_msg new_msgs_tl => do let (i, m) := new_msg - let bindings0 ← betree.Node.apply_to_leaf_fwd_back bindings i m - betree.Node.apply_messages_to_leaf_fwd_back bindings0 new_msgs_tl + 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] -/ -divergent def betree.Node.filter_messages_for_key_fwd_back +/- [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)) := @@ -602,12 +602,12 @@ divergent def betree.Node.filter_messages_for_key_fwd_back let msgs0 ← betree.List.pop_front_back (U64 × betree.Message) (betree.List.Cons (k, m) l) - betree.Node.filter_messages_for_key_fwd_back key msgs0 + 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] -/ -divergent def betree.Node.lookup_first_message_after_key_fwd +/- [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)) := @@ -615,11 +615,11 @@ divergent def betree.Node.lookup_first_message_after_key_fwd | betree.List.Cons p next_msgs => let (k, m) := p if k = key - then betree.Node.lookup_first_message_after_key_fwd key next_msgs + 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] -/ +/- [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)) : @@ -637,74 +637,75 @@ divergent def betree.Node.lookup_first_message_after_key_back else Result.ret ret0 | betree.List.Nil => Result.ret ret0 -/- [betree_main::betree::Node::{5}::apply_to_internal] -/ -def betree.Node.apply_to_internal_fwd_back +/- [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_fwd key msgs - let b ← betree.List.head_has_key_fwd betree.Message msgs0 key + 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_fwd_back key msgs0 + let msgs1 ← betree.Node.filter_messages_for_key key msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 (key, + 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_fwd_back key msgs0 + let msgs1 ← betree.Node.filter_messages_for_key key msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 (key, + 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_fwd (U64 × betree.Message) msgs0 + 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_fwd (Option.some prev) s + 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_fwd_back (U64 × betree.Message) msgs1 - (key, betree.Message.Insert v) + 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_fwd Option.none s + 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_fwd_back (U64 × betree.Message) msgs1 - (key, betree.Message.Insert v) + 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_fwd key msgs0 + betree.Node.lookup_first_message_after_key key msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 - (key, betree.Message.Upsert s) + 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_fwd_back (U64 × betree.Message) msgs0 (key, - new_msg) + 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] -/ -divergent def betree.Node.apply_messages_to_internal_fwd_back +/- [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)) @@ -713,12 +714,12 @@ divergent def betree.Node.apply_messages_to_internal_fwd_back | betree.List.Cons new_msg new_msgs_tl => do let (i, m) := new_msg - let msgs0 ← betree.Node.apply_to_internal_fwd_back msgs i m - betree.Node.apply_messages_to_internal_fwd_back msgs0 new_msgs_tl + 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] -/ -mutual divergent def betree.Node.apply_messages_fwd +/- [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) : @@ -728,47 +729,46 @@ mutual divergent def betree.Node.apply_messages_fwd | betree.Node.Internal node => do let ⟨ i, i0, n, n0 ⟩ := node - let (st0, content) ← betree.load_internal_node_fwd i st - let content0 ← - betree.Node.apply_messages_to_internal_fwd_back content msgs - let num_msgs ← betree.List.len_fwd (U64 × betree.Message) content0 + 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.betree_params_min_flush_size then do let (st1, content1) ← - betree.Internal.flush_fwd (betree.Internal.mk i i0 n n0) params + 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_fwd i1 content1 st1 + let (st2, _) ← betree.store_internal_node i1 content1 st1 Result.ret (st2, ()) else do - let (st1, _) ← betree.store_internal_node_fwd i content0 st0 + let (st1, _) ← betree.store_internal_node i content0 st0 Result.ret (st1, ()) | betree.Node.Leaf node => do - let (st0, content) ← betree.load_leaf_node_fwd node.betree_leaf_id st - let content0 ← betree.Node.apply_messages_to_leaf_fwd_back content msgs - let len ← betree.List.len_fwd (U64 × U64) content0 + let (st0, content) ← betree.load_leaf_node node.betree_leaf_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 (by intlit)) * params.betree_params_split_size if len >= i then do let (st1, _) ← - betree.Leaf.split_fwd node content0 params node_id_cnt st0 + betree.Leaf.split node content0 params node_id_cnt st0 let (st2, _) ← - betree.store_leaf_node_fwd node.betree_leaf_id betree.List.Nil st1 + betree.store_leaf_node node.betree_leaf_id betree.List.Nil st1 Result.ret (st2, ()) else do let (st1, _) ← - betree.store_leaf_node_fwd node.betree_leaf_id content0 st0 + betree.store_leaf_node node.betree_leaf_id content0 st0 Result.ret (st1, ()) -/- [betree_main::betree::Node::{5}::apply_messages] -/ +/- [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) @@ -779,52 +779,51 @@ divergent def betree.Node.apply_messages_back | betree.Node.Internal node => do let ⟨ i, i0, n, n0 ⟩ := node - let (st0, content) ← betree.load_internal_node_fwd i st - let content0 ← - betree.Node.apply_messages_to_internal_fwd_back content msgs - let num_msgs ← betree.List.len_fwd (U64 × betree.Message) content0 + 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.betree_params_min_flush_size then do let (st1, content1) ← - betree.Internal.flush_fwd (betree.Internal.mk i i0 n n0) params + 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_fwd i1 content1 st1 + 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_fwd i content0 st0 + 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_fwd node.betree_leaf_id st - let content0 ← betree.Node.apply_messages_to_leaf_fwd_back content msgs - let len ← betree.List.len_fwd (U64 × U64) content0 + let (st0, content) ← betree.load_leaf_node node.betree_leaf_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 (by intlit)) * params.betree_params_split_size if len >= i then do let (st1, new_node) ← - betree.Leaf.split_fwd node content0 params node_id_cnt st0 + betree.Leaf.split node content0 params node_id_cnt st0 let _ ← - betree.store_leaf_node_fwd node.betree_leaf_id betree.List.Nil st1 + betree.store_leaf_node node.betree_leaf_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_fwd node.betree_leaf_id content0 st0 + let _ ← betree.store_leaf_node node.betree_leaf_id content0 st0 Result.ret (betree.Node.Leaf { node with betree_leaf_size := len }, node_id_cnt) -/- [betree_main::betree::Internal::{4}::flush] -/ -divergent def betree.Internal.flush_fwd +/- [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) : @@ -832,24 +831,22 @@ divergent def betree.Internal.flush_fwd := do let ⟨ _, i, n, n0 ⟩ := self - let p ← betree.List.partition_at_pivot_fwd betree.Message content i + let p ← betree.List.partition_at_pivot betree.Message content i let (msgs_left, msgs_right) := p - let len_left ← betree.List.len_fwd (U64 × betree.Message) msgs_left + let len_left ← betree.List.len (U64 × betree.Message) msgs_left if len_left >= params.betree_params_min_flush_size then do let (st0, _) ← - betree.Node.apply_messages_fwd n params node_id_cnt msgs_left st + 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_fwd (U64 × betree.Message) msgs_right + let len_right ← betree.List.len (U64 × betree.Message) msgs_right if len_right >= params.betree_params_min_flush_size then do let (st1, _) ← - betree.Node.apply_messages_fwd n0 params node_id_cnt0 msgs_right - st0 + 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 @@ -858,12 +855,12 @@ divergent def betree.Internal.flush_fwd else do let (st0, _) ← - betree.Node.apply_messages_fwd n0 params node_id_cnt msgs_right st + 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] -/ +/- [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) @@ -872,18 +869,17 @@ divergent def betree.Internal.flush_back := do let ⟨ i, i0, n, n0 ⟩ := self - let p ← betree.List.partition_at_pivot_fwd betree.Message content i0 + let p ← betree.List.partition_at_pivot betree.Message content i0 let (msgs_left, msgs_right) := p - let len_left ← betree.List.len_fwd (U64 × betree.Message) msgs_left + let len_left ← betree.List.len (U64 × betree.Message) msgs_left if len_left >= params.betree_params_min_flush_size then do let (st0, _) ← - betree.Node.apply_messages_fwd n params node_id_cnt msgs_left st + 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_fwd (U64 × betree.Message) msgs_right + let len_right ← betree.List.len (U64 × betree.Message) msgs_right if len_right >= params.betree_params_min_flush_size then do @@ -900,8 +896,8 @@ divergent def betree.Internal.flush_back end -/- [betree_main::betree::Node::{5}::apply] -/ -def betree.Node.apply_fwd +/- [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) : @@ -910,14 +906,14 @@ def betree.Node.apply_fwd do let l := betree.List.Nil let (st0, _) ← - betree.Node.apply_messages_fwd self params node_id_cnt (betree.List.Cons + 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] -/ +/- [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) @@ -928,15 +924,15 @@ def betree.Node.apply_back betree.Node.apply_messages_back self params node_id_cnt (betree.List.Cons (key, new_msg) l) st -/- [betree_main::betree::BeTree::{6}::new] -/ -def betree.BeTree.new_fwd +/- [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_fwd - let id ← betree.NodeIdCounter.fresh_id_fwd node_id_cnt - let (st0, _) ← betree.store_leaf_node_fwd id betree.List.Nil st + 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, { @@ -954,21 +950,21 @@ def betree.BeTree.new_fwd }) }) -/- [betree_main::betree::BeTree::{6}::apply] -/ -def betree.BeTree.apply_fwd +/- [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_fwd self.betree_be_tree_root self.betree_be_tree_params + betree.Node.apply self.betree_be_tree_root self.betree_be_tree_params self.betree_be_tree_node_id_cnt key msg st let _ ← betree.Node.apply_back self.betree_be_tree_root self.betree_be_tree_params self.betree_be_tree_node_id_cnt key msg st Result.ret (st0, ()) -/- [betree_main::betree::BeTree::{6}::apply] -/ +/- [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 @@ -980,51 +976,51 @@ def betree.BeTree.apply_back Result.ret { self with betree_be_tree_node_id_cnt := nic, betree_be_tree_root := n } -/- [betree_main::betree::BeTree::{6}::insert] -/ -def betree.BeTree.insert_fwd +/- [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_fwd self key (betree.Message.Insert value) st + 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] -/ +/- [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] -/ -def betree.BeTree.delete_fwd +/- [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_fwd self key betree.Message.Delete st + 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] -/ +/- [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] -/ -def betree.BeTree.upsert_fwd +/- [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_fwd self key (betree.Message.Upsert upd) st + 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] -/ +/- [betree_main::betree::BeTree::{6}::upsert]: backward function 0 -/ def betree.BeTree.upsert_back (self : betree.BeTree) (key : U64) (upd : betree.UpsertFunState) (st : State) : @@ -1032,25 +1028,25 @@ def betree.BeTree.upsert_back := betree.BeTree.apply_back self key (betree.Message.Upsert upd) st -/- [betree_main::betree::BeTree::{6}::lookup] -/ -def betree.BeTree.lookup_fwd +/- [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_fwd self.betree_be_tree_root key st + betree.Node.lookup self.betree_be_tree_root key st -/- [betree_main::betree::BeTree::{6}::lookup] -/ +/- [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.betree_be_tree_root key st Result.ret { self with betree_be_tree_root := n } -/- [betree_main::main] -/ -def main_fwd : Result Unit := +/- [betree_main::main]: forward function -/ +def main : Result Unit := Result.ret () /- Unit test for [betree_main::main] -/ -#assert (main_fwd == .ret ()) +#assert (main == .ret ()) end betree_main diff --git a/tests/lean/BetreeMain/FunsExternal.lean b/tests/lean/BetreeMain/FunsExternal.lean index 7bcba380..71d26da4 100644 --- a/tests/lean/BetreeMain/FunsExternal.lean +++ b/tests/lean/BetreeMain/FunsExternal.lean @@ -7,29 +7,29 @@ open betree_main -- TODO: fill those bodies /- [betree_main::betree_utils::load_internal_node] -/ -def betree_utils.load_internal_node_fwd +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_fwd +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_fwd +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_fwd +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_fwd +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 index d768bb20..430d2dda 100644 --- a/tests/lean/BetreeMain/FunsExternal_Template.lean +++ b/tests/lean/BetreeMain/FunsExternal_Template.lean @@ -6,25 +6,25 @@ import BetreeMain.Types open Primitives open betree_main -/- [betree_main::betree_utils::load_internal_node] -/ -axiom betree_utils.load_internal_node_fwd +/- [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] -/ -axiom betree_utils.store_internal_node_fwd +/- [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] -/ -axiom betree_utils.load_leaf_node_fwd +/- [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] -/ -axiom betree_utils.store_leaf_node_fwd +/- [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] -/ -axiom core.option.Option.unwrap_fwd +/- [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/Constants.lean b/tests/lean/Constants.lean index 7014b0d8..f37c9204 100644 --- a/tests/lean/Constants.lean +++ b/tests/lean/Constants.lean @@ -21,16 +21,16 @@ def x1_c : U32 := eval_global x1_body (by simp) 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 := +/- [constants::incr]: forward function -/ +def incr (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_body : Result U32 := incr (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) := +/- [constants::mk_pair0]: forward function -/ +def mk_pair0 (x : U32) (y : U32) : Result (U32 × U32) := Result.ret (x, y) /- [constants::Pair] -/ @@ -38,18 +38,18 @@ structure Pair (T1 T2 : Type) where pair_x : T1 pair_y : T2 -/- [constants::mk_pair1] -/ -def mk_pair1_fwd (x : U32) (y : U32) : Result (Pair U32 U32) := +/- [constants::mk_pair1]: forward function -/ +def mk_pair1 (x : U32) (y : U32) : Result (Pair 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)) + mk_pair0 (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 U32 U32) := - mk_pair1_fwd (U32.ofInt 0 (by intlit)) (U32.ofInt 1 (by intlit)) + mk_pair1 (U32.ofInt 0 (by intlit)) (U32.ofInt 1 (by intlit)) def p1_c : Pair U32 U32 := eval_global p1_body (by simp) /- [constants::P2] -/ @@ -67,32 +67,32 @@ def p3_c : Pair U32 U32 := eval_global p3_body (by simp) structure Wrap (T : Type) where wrap_val : T -/- [constants::Wrap::{0}::new] -/ -def Wrap.new_fwd (T : Type) (val : T) : Result (Wrap T) := +/- [constants::Wrap::{0}::new]: forward function -/ +def Wrap.new (T : Type) (val : T) : Result (Wrap T) := Result.ret { wrap_val := val } /- [constants::Y] -/ -def y_body : Result (Wrap I32) := Wrap.new_fwd I32 (I32.ofInt 2 (by intlit)) +def y_body : Result (Wrap I32) := Wrap.new I32 (I32.ofInt 2 (by intlit)) def y_c : Wrap I32 := eval_global y_body (by simp) -/- [constants::unwrap_y] -/ -def unwrap_y_fwd : Result I32 := +/- [constants::unwrap_y]: forward function -/ +def unwrap_y : Result I32 := Result.ret y_c.wrap_val /- [constants::YVAL] -/ -def yval_body : Result I32 := unwrap_y_fwd +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 (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 := +/- [constants::get_z1]: forward function -/ +def get_z1 : Result I32 := Result.ret get_z1_z1_c -/- [constants::add] -/ -def add_fwd (a : I32) (b : I32) : Result I32 := +/- [constants::add]: forward function -/ +def add (a : I32) (b : I32) : Result I32 := a + b /- [constants::Q1] -/ @@ -104,22 +104,22 @@ 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_body : Result I32 := add 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 := +/- [constants::get_z2]: forward function -/ +def get_z2 : Result I32 := do - let i ← get_z1_fwd - let i0 ← add_fwd i q3_c - add_fwd q1_c i0 + 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 (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_body : Result U32 := incr s1_c def s2_c : U32 := eval_global s2_body (by simp) /- [constants::S3] -/ @@ -128,7 +128,7 @@ def s3_c : Pair U32 U32 := eval_global s3_body (by simp) /- [constants::S4] -/ def s4_body : Result (Pair U32 U32) := - mk_pair1_fwd (U32.ofInt 7 (by intlit)) (U32.ofInt 8 (by intlit)) + mk_pair1 (U32.ofInt 7 (by intlit)) (U32.ofInt 8 (by intlit)) def s4_c : Pair U32 U32 := eval_global s4_body (by simp) end constants diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 3fc21d91..122f94da 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -6,81 +6,80 @@ import External.FunsExternal open Primitives namespace external -/- [external::swap] -/ -def swap_fwd - (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := +/- [external::swap]: forward function -/ +def swap (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := do - let (st0, _) ← core.mem.swap_fwd T x y st + 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] -/ +/- [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_fwd T x y st + 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] -/ -def test_new_non_zero_u32_fwd +/- [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_fwd x st - core.option.Option.unwrap_fwd core.num.nonzero.NonZeroU32 opt st0 + let (st0, opt) ← core.num.nonzero.NonZeroU32.new x st + core.option.Option.unwrap core.num.nonzero.NonZeroU32 opt st0 -/- [external::test_vec] -/ -def test_vec_fwd : Result Unit := +/- [external::test_vec]: forward function -/ +def test_vec : Result Unit := do let v := Vec.new U32 let _ ← Vec.push U32 v (U32.ofInt 0 (by intlit)) Result.ret () /- Unit test for [external::test_vec] -/ -#assert (test_vec_fwd == .ret ()) +#assert (test_vec == .ret ()) -/- [external::custom_swap] -/ -def custom_swap_fwd +/- [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_fwd T x y st + 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] -/ +/- [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_fwd T x y st + 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] -/ -def test_custom_swap_fwd +/- [external::test_custom_swap]: forward function -/ +def test_custom_swap (x : U32) (y : U32) (st : State) : Result (State × Unit) := do - let (st0, _) ← custom_swap_fwd U32 x y st + let (st0, _) ← custom_swap U32 x y st Result.ret (st0, ()) -/- [external::test_custom_swap] -/ +/- [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 (by intlit)) st0 -/- [external::test_swap_non_zero] -/ -def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := +/- [external::test_swap_non_zero]: forward function -/ +def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) := do - let (st0, _) ← swap_fwd U32 x (U32.ofInt 0 (by intlit)) st + let (st0, _) ← swap U32 x (U32.ofInt 0 (by intlit)) st let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0 (by intlit)) st st0 if x0 = (U32.ofInt 0 (by intlit)) then Result.fail Error.panic diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean index 5326dd77..aae11ba1 100644 --- a/tests/lean/External/FunsExternal.lean +++ b/tests/lean/External/FunsExternal.lean @@ -7,7 +7,7 @@ open external -- TODO: fill those bodies /- [core::mem::swap] -/ -def core.mem.swap_fwd +def core.mem.swap (T : Type) : T → T → State → Result (State × Unit) := fun _x _y s => .ret (s, ()) @@ -22,12 +22,12 @@ def core.mem.swap_back1 fun x _y _s0 s1 => .ret (s1, x) /- [core::num::nonzero::NonZeroU32::{14}::new] -/ -def core.num.nonzero.NonZeroU32.new_fwd +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_fwd +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 index 669fe91b..c8bc397f 100644 --- a/tests/lean/External/FunsExternal_Template.lean +++ b/tests/lean/External/FunsExternal_Template.lean @@ -6,23 +6,22 @@ import External.Types open Primitives open external -/- [core::mem::swap] -/ -axiom core.mem.swap_fwd - (T : Type) : T → T → State → Result (State × Unit) +/- [core::mem::swap]: forward function -/ +axiom core.mem.swap (T : Type) : T → T → State → Result (State × Unit) -/- [core::mem::swap] -/ +/- [core::mem::swap]: backward function 0 -/ axiom core.mem.swap_back0 (T : Type) : T → T → State → State → Result (State × T) -/- [core::mem::swap] -/ +/- [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] -/ -axiom core.num.nonzero.NonZeroU32.new_fwd +/- [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] -/ -axiom core.option.Option.unwrap_fwd +/- [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/Hashmap/Funs.lean b/tests/lean/Hashmap/Funs.lean index 48038bfb..34ff1379 100644 --- a/tests/lean/Hashmap/Funs.lean +++ b/tests/lean/Hashmap/Funs.lean @@ -5,35 +5,35 @@ import Hashmap.Types open Primitives namespace hashmap -/- [hashmap::hash_key] -/ -def hash_key_fwd (k : Usize) : Result Usize := +/- [hashmap::hash_key]: forward function -/ +def hash_key (k : Usize) : Result Usize := Result.ret k -/- [hashmap::HashMap::{0}::allocate_slots] -/ -divergent def HashMap.allocate_slots_loop_fwd +/- [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 (by intlit)) then do let slots0 ← Vec.push (List T) slots List.Nil let n0 ← n - (Usize.ofInt 1 (by intlit)) - HashMap.allocate_slots_loop_fwd T slots0 n0 + HashMap.allocate_slots_loop T slots0 n0 else Result.ret slots -/- [hashmap::HashMap::{0}::allocate_slots] -/ -def HashMap.allocate_slots_fwd +/- [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_fwd T slots n + HashMap.allocate_slots_loop T slots n -/- [hashmap::HashMap::{0}::new_with_capacity] -/ -def HashMap.new_with_capacity_fwd +/- [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_fwd T v capacity + let slots ← HashMap.allocate_slots T v capacity let i ← capacity * max_load_dividend let i0 ← i / max_load_divisor Result.ret @@ -44,13 +44,14 @@ def HashMap.new_with_capacity_fwd hash_map_slots := slots } -/- [hashmap::HashMap::{0}::new] -/ -def HashMap.new_fwd (T : Type) : Result (HashMap T) := - HashMap.new_with_capacity_fwd T (Usize.ofInt 32 (by intlit)) +/- [hashmap::HashMap::{0}::new]: forward function -/ +def HashMap.new (T : Type) : Result (HashMap T) := + HashMap.new_with_capacity T (Usize.ofInt 32 (by intlit)) (Usize.ofInt 4 (by intlit)) (Usize.ofInt 5 (by intlit)) -/- [hashmap::HashMap::{0}::clear] -/ -divergent def HashMap.clear_loop_fwd_back +/- [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 @@ -58,16 +59,15 @@ divergent def HashMap.clear_loop_fwd_back do let i1 ← i + (Usize.ofInt 1 (by intlit)) let slots0 ← Vec.index_mut_back (List T) slots i List.Nil - HashMap.clear_loop_fwd_back T slots0 i1 + HashMap.clear_loop T slots0 i1 else Result.ret slots -/- [hashmap::HashMap::{0}::clear] -/ -def HashMap.clear_fwd_back - (T : Type) (self : HashMap T) : Result (HashMap T) := +/- [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_fwd_back T self.hash_map_slots - (Usize.ofInt 0 (by intlit)) + HashMap.clear_loop T self.hash_map_slots (Usize.ofInt 0 (by intlit)) Result.ret { self @@ -76,26 +76,26 @@ def HashMap.clear_fwd_back hash_map_slots := v } -/- [hashmap::HashMap::{0}::len] -/ -def HashMap.len_fwd (T : Type) (self : HashMap T) : Result Usize := +/- [hashmap::HashMap::{0}::len]: forward function -/ +def HashMap.len (T : Type) (self : HashMap T) : Result Usize := Result.ret self.hash_map_num_entries -/- [hashmap::HashMap::{0}::insert_in_list] -/ -divergent def HashMap.insert_in_list_loop_fwd +/- [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_fwd T key value tl + else HashMap.insert_in_list_loop T key value tl | List.Nil => Result.ret true -/- [hashmap::HashMap::{0}::insert_in_list] -/ -def HashMap.insert_in_list_fwd +/- [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_fwd T key value ls + HashMap.insert_in_list_loop T key value ls -/- [hashmap::HashMap::{0}::insert_in_list] -/ +/- [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 @@ -109,22 +109,23 @@ divergent def HashMap.insert_in_list_loop_back | List.Nil => let l := List.Nil Result.ret (List.Cons key value l) -/- [hashmap::HashMap::{0}::insert_in_list] -/ +/- [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] -/ -def HashMap.insert_no_resize_fwd_back +/- [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_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (List T) self.hash_map_slots hash_mod - let inserted ← HashMap.insert_in_list_fwd T key value l + let inserted ← HashMap.insert_in_list T key value l if inserted then do @@ -144,23 +145,26 @@ 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] -/ -divergent def HashMap.move_elements_from_list_loop_fwd_back +/- [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_fwd_back T ntable k v - HashMap.move_elements_from_list_loop_fwd_back T ntable0 tl + 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] -/ -def HashMap.move_elements_from_list_fwd_back +/- [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_fwd_back T ntable ls + HashMap.move_elements_from_list_loop T ntable ls -/- [hashmap::HashMap::{0}::move_elements] -/ -divergent def HashMap.move_elements_loop_fwd_back +/- [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))) := @@ -169,24 +173,25 @@ divergent def HashMap.move_elements_loop_fwd_back then do let l ← Vec.index_mut (List T) slots i - let ls := mem.replace_fwd (List T) l List.Nil - let ntable0 ← HashMap.move_elements_from_list_fwd_back T ntable ls + 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 (by intlit)) 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_fwd_back T ntable0 slots0 i1 + HashMap.move_elements_loop T ntable0 slots0 i1 else Result.ret (ntable, slots) -/- [hashmap::HashMap::{0}::move_elements] -/ -def HashMap.move_elements_fwd_back +/- [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_fwd_back T ntable slots i + HashMap.move_elements_loop T ntable slots i -/- [hashmap::HashMap::{0}::try_resize] -/ -def HashMap.try_resize_fwd_back - (T : Type) (self : HashMap T) : Result (HashMap T) := +/- [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.hash_map_slots @@ -197,9 +202,9 @@ def HashMap.try_resize_fwd_back then do let i2 ← capacity * (Usize.ofInt 2 (by intlit)) - let ntable ← HashMap.new_with_capacity_fwd T i2 i i0 + let ntable ← HashMap.new_with_capacity T i2 i i0 let (ntable0, _) ← - HashMap.move_elements_fwd_back T ntable self.hash_map_slots + HashMap.move_elements T ntable self.hash_map_slots (Usize.ofInt 0 (by intlit)) Result.ret { @@ -210,83 +215,83 @@ def HashMap.try_resize_fwd_back } else Result.ret { self with hash_map_max_load_factor := (i, i0) } -/- [hashmap::HashMap::{0}::insert] -/ -def HashMap.insert_fwd_back +/- [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_fwd_back T self key value - let i ← HashMap.len_fwd T self0 + let self0 ← HashMap.insert_no_resize T self key value + let i ← HashMap.len T self0 if i > self0.hash_map_max_load - then HashMap.try_resize_fwd_back T self0 + then HashMap.try_resize T self0 else Result.ret self0 -/- [hashmap::HashMap::{0}::contains_key_in_list] -/ -divergent def HashMap.contains_key_in_list_loop_fwd +/- [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_fwd T key tl + else HashMap.contains_key_in_list_loop T key tl | List.Nil => Result.ret false -/- [hashmap::HashMap::{0}::contains_key_in_list] -/ -def HashMap.contains_key_in_list_fwd +/- [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_fwd T key ls + HashMap.contains_key_in_list_loop T key ls -/- [hashmap::HashMap::{0}::contains_key] -/ -def HashMap.contains_key_fwd +/- [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_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index (List T) self.hash_map_slots hash_mod - HashMap.contains_key_in_list_fwd T key l + HashMap.contains_key_in_list T key l -/- [hashmap::HashMap::{0}::get_in_list] -/ -divergent def HashMap.get_in_list_loop_fwd +/- [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_fwd T key tl + else HashMap.get_in_list_loop T key tl | List.Nil => Result.fail Error.panic -/- [hashmap::HashMap::{0}::get_in_list] -/ -def HashMap.get_in_list_fwd - (T : Type) (key : Usize) (ls : List T) : Result T := - HashMap.get_in_list_loop_fwd T key ls +/- [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] -/ -def HashMap.get_fwd (T : Type) (self : HashMap T) (key : Usize) : Result T := +/- [hashmap::HashMap::{0}::get]: forward function -/ +def HashMap.get (T : Type) (self : HashMap T) (key : Usize) : Result T := do - let hash ← hash_key_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index (List T) self.hash_map_slots hash_mod - HashMap.get_in_list_fwd T key l + HashMap.get_in_list T key l -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ -divergent def HashMap.get_mut_in_list_loop_fwd +/- [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_fwd T tl key + else HashMap.get_mut_in_list_loop T tl key | List.Nil => Result.fail Error.panic -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ -def HashMap.get_mut_in_list_fwd +/- [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_fwd T ls key + HashMap.get_mut_in_list_loop T ls key -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ +/- [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 @@ -299,28 +304,27 @@ divergent def HashMap.get_mut_in_list_loop_back Result.ret (List.Cons ckey cvalue tl0) | List.Nil => Result.fail Error.panic -/- [hashmap::HashMap::{0}::get_mut_in_list] -/ +/- [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] -/ -def HashMap.get_mut_fwd - (T : Type) (self : HashMap T) (key : Usize) : Result T := +/- [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_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (List T) self.hash_map_slots hash_mod - HashMap.get_mut_in_list_fwd T l key + HashMap.get_mut_in_list T l key -/- [hashmap::HashMap::{0}::get_mut] -/ +/- [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_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (List T) self.hash_map_slots hash_mod @@ -328,33 +332,33 @@ def HashMap.get_mut_back let v ← Vec.index_mut_back (List T) self.hash_map_slots hash_mod l0 Result.ret { self with hash_map_slots := v } -/- [hashmap::HashMap::{0}::remove_from_list] -/ -divergent def HashMap.remove_from_list_loop_fwd +/- [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_fwd (List T) (List.Cons ckey t tl) List.Nil + 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_fwd T key tl + else HashMap.remove_from_list_loop T key tl | List.Nil => Result.ret Option.none -/- [hashmap::HashMap::{0}::remove_from_list] -/ -def HashMap.remove_from_list_fwd +/- [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_fwd T key ls + HashMap.remove_from_list_loop T key ls -/- [hashmap::HashMap::{0}::remove_from_list] -/ +/- [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_fwd (List T) (List.Cons ckey t tl) List.Nil + 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 @@ -364,20 +368,20 @@ divergent def HashMap.remove_from_list_loop_back Result.ret (List.Cons ckey t tl0) | List.Nil => Result.ret List.Nil -/- [hashmap::HashMap::{0}::remove_from_list] -/ +/- [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] -/ -def HashMap.remove_fwd +/- [hashmap::HashMap::{0}::remove]: forward function -/ +def HashMap.remove (T : Type) (self : HashMap T) (key : Usize) : Result (Option T) := do - let hash ← hash_key_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (List T) self.hash_map_slots hash_mod - let x ← HashMap.remove_from_list_fwd T key l + let x ← HashMap.remove_from_list T key l match x with | Option.none => Result.ret Option.none | Option.some x0 => @@ -385,15 +389,15 @@ def HashMap.remove_fwd let _ ← self.hash_map_num_entries - (Usize.ofInt 1 (by intlit)) Result.ret (Option.some x0) -/- [hashmap::HashMap::{0}::remove] -/ +/- [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_fwd key + let hash ← hash_key key let i := Vec.len (List T) self.hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (List T) self.hash_map_slots hash_mod - let x ← HashMap.remove_from_list_fwd T key l + let x ← HashMap.remove_from_list T key l match x with | Option.none => do @@ -408,23 +412,23 @@ def HashMap.remove_back Result.ret { self with hash_map_num_entries := i0, hash_map_slots := v } -/- [hashmap::test1] -/ -def test1_fwd : Result Unit := +/- [hashmap::test1]: forward function -/ +def test1 : Result Unit := do - let hm ← HashMap.new_fwd U64 + let hm ← HashMap.new U64 let hm0 ← - HashMap.insert_fwd_back U64 hm (Usize.ofInt 0 (by intlit)) + HashMap.insert U64 hm (Usize.ofInt 0 (by intlit)) (U64.ofInt 42 (by intlit)) let hm1 ← - HashMap.insert_fwd_back U64 hm0 (Usize.ofInt 128 (by intlit)) + HashMap.insert U64 hm0 (Usize.ofInt 128 (by intlit)) (U64.ofInt 18 (by intlit)) let hm2 ← - HashMap.insert_fwd_back U64 hm1 (Usize.ofInt 1024 (by intlit)) + HashMap.insert U64 hm1 (Usize.ofInt 1024 (by intlit)) (U64.ofInt 138 (by intlit)) let hm3 ← - HashMap.insert_fwd_back U64 hm2 (Usize.ofInt 1056 (by intlit)) + HashMap.insert U64 hm2 (Usize.ofInt 1056 (by intlit)) (U64.ofInt 256 (by intlit)) - let i ← HashMap.get_fwd U64 hm3 (Usize.ofInt 128 (by intlit)) + let i ← HashMap.get U64 hm3 (Usize.ofInt 128 (by intlit)) if not (i = (U64.ofInt 18 (by intlit))) then Result.fail Error.panic else @@ -432,12 +436,12 @@ def test1_fwd : Result Unit := let hm4 ← HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) (U64.ofInt 56 (by intlit)) - let i0 ← HashMap.get_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) + let i0 ← HashMap.get U64 hm4 (Usize.ofInt 1024 (by intlit)) if not (i0 = (U64.ofInt 56 (by intlit))) then Result.fail Error.panic else do - let x ← HashMap.remove_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) + let x ← HashMap.remove U64 hm4 (Usize.ofInt 1024 (by intlit)) match x with | Option.none => Result.fail Error.panic | Option.some x0 => @@ -447,26 +451,24 @@ def test1_fwd : Result Unit := do let hm5 ← HashMap.remove_back U64 hm4 (Usize.ofInt 1024 (by intlit)) - let i1 ← - HashMap.get_fwd U64 hm5 (Usize.ofInt 0 (by intlit)) + let i1 ← HashMap.get U64 hm5 (Usize.ofInt 0 (by intlit)) if not (i1 = (U64.ofInt 42 (by intlit))) then Result.fail Error.panic else do let i2 ← - HashMap.get_fwd U64 hm5 (Usize.ofInt 128 (by intlit)) + HashMap.get U64 hm5 (Usize.ofInt 128 (by intlit)) if not (i2 = (U64.ofInt 18 (by intlit))) then Result.fail Error.panic else do let i3 ← - HashMap.get_fwd U64 hm5 - (Usize.ofInt 1056 (by intlit)) + HashMap.get U64 hm5 (Usize.ofInt 1056 (by intlit)) if not (i3 = (U64.ofInt 256 (by intlit))) then Result.fail Error.panic else Result.ret () /- Unit test for [hashmap::test1] -/ -#assert (test1_fwd == .ret ()) +#assert (test1 == .ret ()) end hashmap diff --git a/tests/lean/HashmapMain/Funs.lean b/tests/lean/HashmapMain/Funs.lean index 1a741a2d..b1afcd44 100644 --- a/tests/lean/HashmapMain/Funs.lean +++ b/tests/lean/HashmapMain/Funs.lean @@ -6,12 +6,12 @@ import HashmapMain.FunsExternal open Primitives namespace hashmap_main -/- [hashmap_main::hashmap::hash_key] -/ -def hashmap.hash_key_fwd (k : Usize) : Result Usize := +/- [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] -/ -divergent def hashmap.HashMap.allocate_slots_loop_fwd +/- [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)) := @@ -20,25 +20,25 @@ divergent def hashmap.HashMap.allocate_slots_loop_fwd do let slots0 ← Vec.push (hashmap.List T) slots hashmap.List.Nil let n0 ← n - (Usize.ofInt 1 (by intlit)) - hashmap.HashMap.allocate_slots_loop_fwd T slots0 n0 + hashmap.HashMap.allocate_slots_loop T slots0 n0 else Result.ret slots -/- [hashmap_main::hashmap::HashMap::{0}::allocate_slots] -/ -def hashmap.HashMap.allocate_slots_fwd +/- [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_fwd T slots n + hashmap.HashMap.allocate_slots_loop T slots n -/- [hashmap_main::hashmap::HashMap::{0}::new_with_capacity] -/ -def hashmap.HashMap.new_with_capacity_fwd +/- [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_fwd T v capacity + let slots ← hashmap.HashMap.allocate_slots T v capacity let i ← capacity * max_load_dividend let i0 ← i / max_load_divisor Result.ret @@ -50,13 +50,14 @@ def hashmap.HashMap.new_with_capacity_fwd hashmap_hash_map_slots := slots } -/- [hashmap_main::hashmap::HashMap::{0}::new] -/ -def hashmap.HashMap.new_fwd (T : Type) : Result (hashmap.HashMap T) := - hashmap.HashMap.new_with_capacity_fwd T (Usize.ofInt 32 (by intlit)) +/- [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 (by intlit)) (Usize.ofInt 4 (by intlit)) (Usize.ofInt 5 (by intlit)) -/- [hashmap_main::hashmap::HashMap::{0}::clear] -/ -divergent def hashmap.HashMap.clear_loop_fwd_back +/- [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)) := @@ -67,15 +68,16 @@ divergent def hashmap.HashMap.clear_loop_fwd_back let i1 ← i + (Usize.ofInt 1 (by intlit)) let slots0 ← Vec.index_mut_back (hashmap.List T) slots i hashmap.List.Nil - hashmap.HashMap.clear_loop_fwd_back T slots0 i1 + hashmap.HashMap.clear_loop T slots0 i1 else Result.ret slots -/- [hashmap_main::hashmap::HashMap::{0}::clear] -/ -def hashmap.HashMap.clear_fwd_back +/- [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_fwd_back T self.hashmap_hash_map_slots + hashmap.HashMap.clear_loop T self.hashmap_hash_map_slots (Usize.ofInt 0 (by intlit)) Result.ret { @@ -85,27 +87,26 @@ def hashmap.HashMap.clear_fwd_back hashmap_hash_map_slots := v } -/- [hashmap_main::hashmap::HashMap::{0}::len] -/ -def hashmap.HashMap.len_fwd - (T : Type) (self : hashmap.HashMap T) : Result Usize := +/- [hashmap_main::hashmap::HashMap::{0}::len]: forward function -/ +def hashmap.HashMap.len (T : Type) (self : hashmap.HashMap T) : Result Usize := Result.ret self.hashmap_hash_map_num_entries -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -divergent def hashmap.HashMap.insert_in_list_loop_fwd +/- [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_fwd T key value tl + 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] -/ -def hashmap.HashMap.insert_in_list_fwd +/- [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_fwd T key value ls + hashmap.HashMap.insert_in_list_loop 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 -/ divergent def hashmap.HashMap.insert_in_list_loop_back (T : Type) (key : Usize) (value : T) (ls : hashmap.List T) : Result (hashmap.List T) @@ -122,25 +123,26 @@ divergent def hashmap.HashMap.insert_in_list_loop_back let l := hashmap.List.Nil Result.ret (hashmap.List.Cons key value l) -/- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ +/- [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] -/ -def hashmap.HashMap.insert_no_resize_fwd_back +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (hashmap.List T) self.hashmap_hash_map_slots hash_mod - let inserted ← hashmap.HashMap.insert_in_list_fwd T key value l + let inserted ← hashmap.HashMap.insert_in_list T key value l if inserted then do @@ -169,27 +171,30 @@ 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] -/ -divergent def hashmap.HashMap.move_elements_from_list_loop_fwd_back +/- [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_fwd_back T ntable k v - hashmap.HashMap.move_elements_from_list_loop_fwd_back T ntable0 tl + 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] -/ -def hashmap.HashMap.move_elements_from_list_fwd_back +/- [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_fwd_back T ntable ls + hashmap.HashMap.move_elements_from_list_loop T ntable ls -/- [hashmap_main::hashmap::HashMap::{0}::move_elements] -/ -divergent def hashmap.HashMap.move_elements_loop_fwd_back +/- [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))) @@ -199,25 +204,26 @@ divergent def hashmap.HashMap.move_elements_loop_fwd_back then do let l ← Vec.index_mut (hashmap.List T) slots i - let ls := mem.replace_fwd (hashmap.List T) l hashmap.List.Nil - let ntable0 ← - hashmap.HashMap.move_elements_from_list_fwd_back T ntable ls + 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 (by intlit)) 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_fwd_back T ntable0 slots0 i1 + hashmap.HashMap.move_elements_loop T ntable0 slots0 i1 else Result.ret (ntable, slots) -/- [hashmap_main::hashmap::HashMap::{0}::move_elements] -/ -def hashmap.HashMap.move_elements_fwd_back +/- [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_fwd_back T ntable slots i + hashmap.HashMap.move_elements_loop T ntable slots i -/- [hashmap_main::hashmap::HashMap::{0}::try_resize] -/ -def hashmap.HashMap.try_resize_fwd_back +/- [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 @@ -229,10 +235,10 @@ def hashmap.HashMap.try_resize_fwd_back then do let i2 ← capacity * (Usize.ofInt 2 (by intlit)) - let ntable ← hashmap.HashMap.new_with_capacity_fwd T i2 i i0 + let ntable ← hashmap.HashMap.new_with_capacity T i2 i i0 let (ntable0, _) ← - hashmap.HashMap.move_elements_fwd_back T ntable - self.hashmap_hash_map_slots (Usize.ofInt 0 (by intlit)) + hashmap.HashMap.move_elements T ntable self.hashmap_hash_map_slots + (Usize.ofInt 0 (by intlit)) Result.ret { ntable0 @@ -242,84 +248,85 @@ def hashmap.HashMap.try_resize_fwd_back } else Result.ret { self with hashmap_hash_map_max_load_factor := (i, i0) } -/- [hashmap_main::hashmap::HashMap::{0}::insert] -/ -def hashmap.HashMap.insert_fwd_back +/- [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_fwd_back T self key value - let i ← hashmap.HashMap.len_fwd T self0 + let self0 ← hashmap.HashMap.insert_no_resize T self key value + let i ← hashmap.HashMap.len T self0 if i > self0.hashmap_hash_map_max_load - then hashmap.HashMap.try_resize_fwd_back T self0 + then hashmap.HashMap.try_resize T self0 else Result.ret self0 -/- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] -/ -divergent def hashmap.HashMap.contains_key_in_list_loop_fwd +/- [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_fwd T key tl + 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] -/ -def hashmap.HashMap.contains_key_in_list_fwd +/- [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_fwd T key ls + hashmap.HashMap.contains_key_in_list_loop T key ls -/- [hashmap_main::hashmap::HashMap::{0}::contains_key] -/ -def hashmap.HashMap.contains_key_fwd +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← Vec.index (hashmap.List T) self.hashmap_hash_map_slots hash_mod - hashmap.HashMap.contains_key_in_list_fwd T key l + hashmap.HashMap.contains_key_in_list T key l -/- [hashmap_main::hashmap::HashMap::{0}::get_in_list] -/ -divergent def hashmap.HashMap.get_in_list_loop_fwd +/- [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_fwd T key tl + 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] -/ -def hashmap.HashMap.get_in_list_fwd +/- [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_fwd T key ls + hashmap.HashMap.get_in_list_loop T key ls -/- [hashmap_main::hashmap::HashMap::{0}::get] -/ -def hashmap.HashMap.get_fwd +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← Vec.index (hashmap.List T) self.hashmap_hash_map_slots hash_mod - hashmap.HashMap.get_in_list_fwd T key l + hashmap.HashMap.get_in_list T key l -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -divergent def hashmap.HashMap.get_mut_in_list_loop_fwd +/- [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_fwd T tl key + 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] -/ -def hashmap.HashMap.get_mut_in_list_fwd +/- [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_fwd T ls key + hashmap.HashMap.get_mut_in_list_loop 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 -/ divergent def hashmap.HashMap.get_mut_in_list_loop_back (T : Type) (ls : hashmap.List T) (key : Usize) (ret0 : T) : Result (hashmap.List T) @@ -334,31 +341,31 @@ divergent def hashmap.HashMap.get_mut_in_list_loop_back Result.ret (hashmap.List.Cons ckey cvalue tl0) | hashmap.List.Nil => Result.fail Error.panic -/- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ +/- [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] -/ -def hashmap.HashMap.get_mut_fwd +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (hashmap.List T) self.hashmap_hash_map_slots hash_mod - hashmap.HashMap.get_mut_in_list_fwd T l key + hashmap.HashMap.get_mut_in_list T l key -/- [hashmap_main::hashmap::HashMap::{0}::get_mut] -/ +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← @@ -369,28 +376,28 @@ def hashmap.HashMap.get_mut_back l0 Result.ret { self with hashmap_hash_map_slots := v } -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -divergent def hashmap.HashMap.remove_from_list_loop_fwd +/- [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_fwd (hashmap.List T) (hashmap.List.Cons ckey t tl) + 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_fwd T key tl + 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] -/ -def hashmap.HashMap.remove_from_list_fwd +/- [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_fwd T key ls + hashmap.HashMap.remove_from_list_loop T key ls -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ +/- [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 @@ -398,7 +405,7 @@ divergent def hashmap.HashMap.remove_from_list_loop_back if ckey = key then let mv_ls := - mem.replace_fwd (hashmap.List T) (hashmap.List.Cons ckey t tl) + 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 @@ -409,21 +416,21 @@ divergent def hashmap.HashMap.remove_from_list_loop_back Result.ret (hashmap.List.Cons ckey t tl0) | hashmap.List.Nil => Result.ret hashmap.List.Nil -/- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ +/- [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] -/ -def hashmap.HashMap.remove_fwd +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (hashmap.List T) self.hashmap_hash_map_slots hash_mod - let x ← hashmap.HashMap.remove_from_list_fwd T key l + let x ← hashmap.HashMap.remove_from_list T key l match x with | Option.none => Result.ret Option.none | Option.some x0 => @@ -432,18 +439,18 @@ def hashmap.HashMap.remove_fwd (Usize.ofInt 1 (by intlit)) Result.ret (Option.some x0) -/- [hashmap_main::hashmap::HashMap::{0}::remove] -/ +/- [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_fwd key + let hash ← hashmap.hash_key key let i := Vec.len (hashmap.List T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← Vec.index_mut (hashmap.List T) self.hashmap_hash_map_slots hash_mod - let x ← hashmap.HashMap.remove_from_list_fwd T key l + let x ← hashmap.HashMap.remove_from_list T key l match x with | Option.none => do @@ -467,23 +474,23 @@ def hashmap.HashMap.remove_back hashmap_hash_map_num_entries := i0, hashmap_hash_map_slots := v } -/- [hashmap_main::hashmap::test1] -/ -def hashmap.test1_fwd : Result Unit := +/- [hashmap_main::hashmap::test1]: forward function -/ +def hashmap.test1 : Result Unit := do - let hm ← hashmap.HashMap.new_fwd U64 + let hm ← hashmap.HashMap.new U64 let hm0 ← - hashmap.HashMap.insert_fwd_back U64 hm (Usize.ofInt 0 (by intlit)) + hashmap.HashMap.insert U64 hm (Usize.ofInt 0 (by intlit)) (U64.ofInt 42 (by intlit)) let hm1 ← - hashmap.HashMap.insert_fwd_back U64 hm0 (Usize.ofInt 128 (by intlit)) + hashmap.HashMap.insert U64 hm0 (Usize.ofInt 128 (by intlit)) (U64.ofInt 18 (by intlit)) let hm2 ← - hashmap.HashMap.insert_fwd_back U64 hm1 (Usize.ofInt 1024 (by intlit)) + hashmap.HashMap.insert U64 hm1 (Usize.ofInt 1024 (by intlit)) (U64.ofInt 138 (by intlit)) let hm3 ← - hashmap.HashMap.insert_fwd_back U64 hm2 (Usize.ofInt 1056 (by intlit)) + hashmap.HashMap.insert U64 hm2 (Usize.ofInt 1056 (by intlit)) (U64.ofInt 256 (by intlit)) - let i ← hashmap.HashMap.get_fwd U64 hm3 (Usize.ofInt 128 (by intlit)) + let i ← hashmap.HashMap.get U64 hm3 (Usize.ofInt 128 (by intlit)) if not (i = (U64.ofInt 18 (by intlit))) then Result.fail Error.panic else @@ -491,14 +498,13 @@ def hashmap.test1_fwd : Result Unit := let hm4 ← hashmap.HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) (U64.ofInt 56 (by intlit)) - let i0 ← - hashmap.HashMap.get_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) + let i0 ← hashmap.HashMap.get U64 hm4 (Usize.ofInt 1024 (by intlit)) if not (i0 = (U64.ofInt 56 (by intlit))) then Result.fail Error.panic else do let x ← - hashmap.HashMap.remove_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) + hashmap.HashMap.remove U64 hm4 (Usize.ofInt 1024 (by intlit)) match x with | Option.none => Result.fail Error.panic | Option.some x0 => @@ -510,42 +516,42 @@ def hashmap.test1_fwd : Result Unit := hashmap.HashMap.remove_back U64 hm4 (Usize.ofInt 1024 (by intlit)) let i1 ← - hashmap.HashMap.get_fwd U64 hm5 (Usize.ofInt 0 (by intlit)) + hashmap.HashMap.get U64 hm5 (Usize.ofInt 0 (by intlit)) if not (i1 = (U64.ofInt 42 (by intlit))) then Result.fail Error.panic else do let i2 ← - hashmap.HashMap.get_fwd U64 hm5 + hashmap.HashMap.get U64 hm5 (Usize.ofInt 128 (by intlit)) if not (i2 = (U64.ofInt 18 (by intlit))) then Result.fail Error.panic else do let i3 ← - hashmap.HashMap.get_fwd U64 hm5 + hashmap.HashMap.get U64 hm5 (Usize.ofInt 1056 (by intlit)) if not (i3 = (U64.ofInt 256 (by intlit))) then Result.fail Error.panic else Result.ret () /- Unit test for [hashmap_main::hashmap::test1] -/ -#assert (hashmap.test1_fwd == .ret ()) +#assert (hashmap.test1 == .ret ()) -/- [hashmap_main::insert_on_disk] -/ -def insert_on_disk_fwd +/- [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_fwd st - let hm0 ← hashmap.HashMap.insert_fwd_back U64 hm key value - let (st1, _) ← hashmap_utils.serialize_fwd hm0 st0 + 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] -/ -def main_fwd : Result Unit := +/- [hashmap_main::main]: forward function -/ +def main : Result Unit := Result.ret () /- Unit test for [hashmap_main::main] -/ -#assert (main_fwd == .ret ()) +#assert (main == .ret ()) end hashmap_main diff --git a/tests/lean/HashmapMain/FunsExternal.lean b/tests/lean/HashmapMain/FunsExternal.lean index 3689dd45..b394b32b 100644 --- a/tests/lean/HashmapMain/FunsExternal.lean +++ b/tests/lean/HashmapMain/FunsExternal.lean @@ -7,11 +7,11 @@ open hashmap_main -- TODO: fill those bodies /- [hashmap_main::hashmap_utils::deserialize] -/ -def hashmap_utils.deserialize_fwd +def hashmap_utils.deserialize : State → Result (State × (hashmap.HashMap U64)) := fun _ => .fail .panic /- [hashmap_main::hashmap_utils::serialize] -/ -def hashmap_utils.serialize_fwd +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 index 8853b7fc..f537fc8f 100644 --- a/tests/lean/HashmapMain/FunsExternal_Template.lean +++ b/tests/lean/HashmapMain/FunsExternal_Template.lean @@ -6,11 +6,11 @@ import HashmapMain.Types open Primitives open hashmap_main -/- [hashmap_main::hashmap_utils::deserialize] -/ -axiom hashmap_utils.deserialize_fwd +/- [hashmap_main::hashmap_utils::deserialize]: forward function -/ +axiom hashmap_utils.deserialize : State → Result (State × (hashmap.HashMap U64)) -/- [hashmap_main::hashmap_utils::serialize] -/ -axiom hashmap_utils.serialize_fwd +/- [hashmap_main::hashmap_utils::serialize]: forward function -/ +axiom hashmap_utils.serialize : hashmap.HashMap U64 → State → Result (State × Unit) diff --git a/tests/lean/Loops/Funs.lean b/tests/lean/Loops/Funs.lean index 6e6eef3b..8cac7ac0 100644 --- a/tests/lean/Loops/Funs.lean +++ b/tests/lean/Loops/Funs.lean @@ -5,82 +5,83 @@ import Loops.Types open Primitives namespace loops -/- [loops::sum] -/ -divergent def sum_loop_fwd (max : U32) (i : U32) (s : U32) : Result U32 := +/- [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 (by intlit)) - sum_loop_fwd max i0 s0 + sum_loop max i0 s0 else s * (U32.ofInt 2 (by intlit)) -/- [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]: forward function -/ +def sum (max : U32) : Result U32 := + sum_loop max (U32.ofInt 0 (by intlit)) (U32.ofInt 0 (by intlit)) -/- [loops::sum_with_mut_borrows] -/ -divergent def sum_with_mut_borrows_loop_fwd +/- [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 (by intlit)) - sum_with_mut_borrows_loop_fwd max mi0 ms0 + sum_with_mut_borrows_loop max mi0 ms0 else ms * (U32.ofInt 2 (by intlit)) -/- [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)) +/- [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 (by intlit)) (U32.ofInt 0 (by intlit)) -/- [loops::sum_with_shared_borrows] -/ -divergent def sum_with_shared_borrows_loop_fwd +/- [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 (by intlit)) let s0 ← s + i0 - sum_with_shared_borrows_loop_fwd max i0 s0 + sum_with_shared_borrows_loop max i0 s0 else s * (U32.ofInt 2 (by intlit)) -/- [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)) +/- [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 (by intlit)) (U32.ofInt 0 (by intlit)) -/- [loops::clear] -/ -divergent def clear_loop_fwd_back - (v : Vec U32) (i : Usize) : Result (Vec U32) := +/- [loops::clear]: loop 0: merged forward/backward function + (there is a single backward function, and the forward function returns ()) -/ +divergent def clear_loop (v : Vec U32) (i : Usize) : Result (Vec U32) := let i0 := Vec.len U32 v if 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 + clear_loop v0 i1 else Result.ret v -/- [loops::clear] -/ -def clear_fwd_back (v : Vec U32) : Result (Vec U32) := - clear_loop_fwd_back v (Usize.ofInt 0 (by intlit)) +/- [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 (by intlit)) -/- [loops::list_mem] -/ -divergent def list_mem_loop_fwd (x : U32) (ls : List U32) : Result Bool := +/- [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_fwd x tl + else list_mem_loop x tl | List.Nil => Result.ret false -/- [loops::list_mem] -/ -def list_mem_fwd (x : U32) (ls : List U32) : Result Bool := - list_mem_loop_fwd x ls +/- [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] -/ -divergent def list_nth_mut_loop_loop_fwd +/- [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 => @@ -89,14 +90,14 @@ divergent def list_nth_mut_loop_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_loop_fwd T tl i0 + list_nth_mut_loop_loop T tl i0 | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop] -/ -def list_nth_mut_loop_fwd (T : Type) (ls : List T) (i : U32) : Result T := - list_nth_mut_loop_loop_fwd T ls i +/- [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] -/ +/- [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 @@ -110,13 +111,13 @@ divergent def list_nth_mut_loop_loop_back Result.ret (List.Cons x tl0) | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop] -/ +/- [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] -/ -divergent def list_nth_shared_loop_loop_fwd +/- [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 => @@ -125,30 +126,28 @@ divergent def list_nth_shared_loop_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_loop_fwd T tl i0 + list_nth_shared_loop_loop T tl i0 | List.Nil => Result.fail Error.panic -/- [loops::list_nth_shared_loop] -/ -def list_nth_shared_loop_fwd (T : Type) (ls : List T) (i : U32) : Result T := - list_nth_shared_loop_loop_fwd T ls i +/- [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] -/ -divergent def get_elem_mut_loop_fwd - (x : Usize) (ls : List Usize) : Result Usize := +/- [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_fwd x tl + | 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] -/ -def get_elem_mut_fwd (slots : Vec (List Usize)) (x : Usize) : Result Usize := +/- [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 (by intlit)) - get_elem_mut_loop_fwd x l + get_elem_mut_loop x l -/- [loops::get_elem_mut] -/ +/- [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 @@ -161,7 +160,7 @@ divergent def get_elem_mut_loop_back Result.ret (List.Cons y tl0) | List.Nil => Result.fail Error.panic -/- [loops::get_elem_mut] -/ +/- [loops::get_elem_mut]: backward function 0 -/ def get_elem_mut_back (slots : Vec (List Usize)) (x : Usize) (ret0 : Usize) : Result (Vec (List Usize)) @@ -171,37 +170,35 @@ def get_elem_mut_back let l0 ← get_elem_mut_loop_back x l ret0 Vec.index_mut_back (List Usize) slots (Usize.ofInt 0 (by intlit)) l0 -/- [loops::get_elem_shared] -/ -divergent def get_elem_shared_loop_fwd +/- [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_fwd x tl + | 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] -/ -def get_elem_shared_fwd - (slots : Vec (List Usize)) (x : Usize) : Result Usize := +/- [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 (by intlit)) - get_elem_shared_loop_fwd x l + get_elem_shared_loop x l -/- [loops::id_mut] -/ -def id_mut_fwd (T : Type) (ls : List T) : Result (List T) := +/- [loops::id_mut]: forward function -/ +def id_mut (T : Type) (ls : List T) : Result (List T) := Result.ret ls -/- [loops::id_mut] -/ +/- [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] -/ -def id_shared_fwd (T : Type) (ls : List T) : Result (List T) := +/- [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] -/ -divergent def list_nth_mut_loop_with_id_loop_fwd +/- [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 => @@ -210,17 +207,16 @@ divergent def list_nth_mut_loop_with_id_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_with_id_loop_fwd T i0 tl + list_nth_mut_loop_with_id_loop T i0 tl | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop_with_id] -/ -def list_nth_mut_loop_with_id_fwd - (T : Type) (ls : List T) (i : U32) : Result T := +/- [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_fwd T ls - list_nth_mut_loop_with_id_loop_fwd T i ls0 + let ls0 ← id_mut T ls + list_nth_mut_loop_with_id_loop T i ls0 -/- [loops::list_nth_mut_loop_with_id] -/ +/- [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 @@ -234,16 +230,16 @@ divergent def list_nth_mut_loop_with_id_loop_back Result.ret (List.Cons x tl0) | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop_with_id] -/ +/- [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_fwd T ls + 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] -/ -divergent def list_nth_shared_loop_with_id_loop_fwd +/- [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 => @@ -252,18 +248,18 @@ divergent def list_nth_shared_loop_with_id_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_with_id_loop_fwd T i0 tl + list_nth_shared_loop_with_id_loop T i0 tl | List.Nil => Result.fail Error.panic -/- [loops::list_nth_shared_loop_with_id] -/ -def list_nth_shared_loop_with_id_fwd +/- [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_fwd T ls - list_nth_shared_loop_with_id_loop_fwd T i ls0 + let ls0 ← id_shared T ls + list_nth_shared_loop_with_id_loop T i ls0 -/- [loops::list_nth_mut_loop_pair] -/ -divergent def list_nth_mut_loop_pair_loop_fwd +/- [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 => @@ -274,16 +270,16 @@ divergent def list_nth_mut_loop_pair_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_pair_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_mut_loop_pair_fwd +/- [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_fwd T ls0 ls1 i + list_nth_mut_loop_pair_loop T ls0 ls1 i -/- [loops::list_nth_mut_loop_pair] -/ +/- [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) @@ -302,14 +298,14 @@ divergent def list_nth_mut_loop_pair_loop_back'a | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop_pair] -/ +/- [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] -/ +/- [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) @@ -328,15 +324,15 @@ divergent def list_nth_mut_loop_pair_loop_back'b | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop_pair] -/ +/- [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] -/ -divergent def list_nth_shared_loop_pair_loop_fwd +/- [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 => @@ -347,17 +343,17 @@ divergent def list_nth_shared_loop_pair_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_pair_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_shared_loop_pair_fwd +/- [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_fwd T ls0 ls1 i + list_nth_shared_loop_pair_loop T ls0 ls1 i -/- [loops::list_nth_mut_loop_pair_merge] -/ -divergent def list_nth_mut_loop_pair_merge_loop_fwd +/- [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 => @@ -368,16 +364,16 @@ divergent def list_nth_mut_loop_pair_merge_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_loop_pair_merge_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_mut_loop_pair_merge_fwd +/- [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_fwd T ls0 ls1 i + list_nth_mut_loop_pair_merge_loop T ls0 ls1 i -/- [loops::list_nth_mut_loop_pair_merge] -/ +/- [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)) @@ -398,15 +394,15 @@ divergent def list_nth_mut_loop_pair_merge_loop_back | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_loop_pair_merge] -/ +/- [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] -/ -divergent def list_nth_shared_loop_pair_merge_loop_fwd +/- [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 => @@ -417,17 +413,17 @@ divergent def list_nth_shared_loop_pair_merge_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_loop_pair_merge_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_shared_loop_pair_merge_fwd +/- [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_fwd T ls0 ls1 i + list_nth_shared_loop_pair_merge_loop T ls0 ls1 i -/- [loops::list_nth_mut_shared_loop_pair] -/ -divergent def list_nth_mut_shared_loop_pair_loop_fwd +/- [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 => @@ -438,16 +434,16 @@ divergent def list_nth_mut_shared_loop_pair_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_shared_loop_pair_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_mut_shared_loop_pair_fwd +/- [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_fwd T ls0 ls1 i + list_nth_mut_shared_loop_pair_loop T ls0 ls1 i -/- [loops::list_nth_mut_shared_loop_pair] -/ +/- [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) @@ -467,15 +463,15 @@ divergent def list_nth_mut_shared_loop_pair_loop_back | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_shared_loop_pair] -/ +/- [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] -/ -divergent def list_nth_mut_shared_loop_pair_merge_loop_fwd +/- [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 => @@ -486,16 +482,16 @@ divergent def list_nth_mut_shared_loop_pair_merge_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_shared_loop_pair_merge_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_mut_shared_loop_pair_merge_fwd +/- [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_fwd T ls0 ls1 i + list_nth_mut_shared_loop_pair_merge_loop 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 -/ 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) @@ -515,15 +511,15 @@ divergent def list_nth_mut_shared_loop_pair_merge_loop_back | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_mut_shared_loop_pair_merge] -/ +/- [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] -/ -divergent def list_nth_shared_mut_loop_pair_loop_fwd +/- [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 => @@ -534,16 +530,16 @@ divergent def list_nth_shared_mut_loop_pair_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_mut_loop_pair_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_shared_mut_loop_pair_fwd +/- [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_fwd T ls0 ls1 i + list_nth_shared_mut_loop_pair_loop T ls0 ls1 i -/- [loops::list_nth_shared_mut_loop_pair] -/ +/- [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) @@ -563,15 +559,15 @@ divergent def list_nth_shared_mut_loop_pair_loop_back | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_shared_mut_loop_pair] -/ +/- [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] -/ -divergent def list_nth_shared_mut_loop_pair_merge_loop_fwd +/- [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 => @@ -582,16 +578,16 @@ divergent def list_nth_shared_mut_loop_pair_merge_loop_fwd else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_mut_loop_pair_merge_loop_fwd T tl0 tl1 i0 + 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] -/ -def list_nth_shared_mut_loop_pair_merge_fwd +/- [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_fwd T ls0 ls1 i + list_nth_shared_mut_loop_pair_merge_loop 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 -/ 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) @@ -611,7 +607,7 @@ divergent def list_nth_shared_mut_loop_pair_merge_loop_back | List.Nil => Result.fail Error.panic | List.Nil => Result.fail Error.panic -/- [loops::list_nth_shared_mut_loop_pair_merge] -/ +/- [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) diff --git a/tests/lean/NoNestedBorrows.lean b/tests/lean/NoNestedBorrows.lean index e4fa7612..dc744a29 100644 --- a/tests/lean/NoNestedBorrows.lean +++ b/tests/lean/NoNestedBorrows.lean @@ -35,64 +35,64 @@ inductive Sum (T1 T2 : Type) := | Left : T1 → Sum T1 T2 | Right : T2 → Sum T1 T2 -/- [no_nested_borrows::neg_test] -/ -def neg_test_fwd (x : I32) : Result I32 := +/- [no_nested_borrows::neg_test]: forward function -/ +def neg_test (x : I32) : Result I32 := - x -/- [no_nested_borrows::add_test] -/ -def add_test_fwd (x : U32) (y : U32) : Result U32 := +/- [no_nested_borrows::add_test]: forward function -/ +def add_test (x : U32) (y : U32) : Result U32 := x + y -/- [no_nested_borrows::subs_test] -/ -def subs_test_fwd (x : U32) (y : U32) : Result U32 := +/- [no_nested_borrows::subs_test]: forward function -/ +def subs_test (x : U32) (y : U32) : Result U32 := x - y -/- [no_nested_borrows::div_test] -/ -def div_test_fwd (x : U32) (y : U32) : Result U32 := +/- [no_nested_borrows::div_test]: forward function -/ +def div_test (x : U32) (y : U32) : Result U32 := x / y -/- [no_nested_borrows::div_test1] -/ -def div_test1_fwd (x : U32) : Result U32 := +/- [no_nested_borrows::div_test1]: forward function -/ +def div_test1 (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 := +/- [no_nested_borrows::rem_test]: forward function -/ +def rem_test (x : U32) (y : U32) : Result U32 := x % y -/- [no_nested_borrows::cast_test] -/ -def cast_test_fwd (x : U32) : Result I32 := +/- [no_nested_borrows::cast_test]: forward function -/ +def cast_test (x : U32) : Result I32 := Scalar.cast .I32 x -/- [no_nested_borrows::test2] -/ -def test2_fwd : Result Unit := +/- [no_nested_borrows::test2]: forward function -/ +def test2 : 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 ()) +#assert (test2 == .ret ()) -/- [no_nested_borrows::get_max] -/ -def get_max_fwd (x : U32) (y : U32) : Result U32 := +/- [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] -/ -def test3_fwd : Result Unit := +/- [no_nested_borrows::test3]: forward function -/ +def test3 : 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 x ← get_max (U32.ofInt 4 (by intlit)) (U32.ofInt 3 (by intlit)) + let y ← get_max (U32.ofInt 10 (by intlit)) (U32.ofInt 11 (by intlit)) let z ← x + y if 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 ()) +#assert (test3 == .ret ()) -/- [no_nested_borrows::test_neg1] -/ -def test_neg1_fwd : Result Unit := +/- [no_nested_borrows::test_neg1]: forward function -/ +def test_neg1 : Result Unit := do let y ← - (I32.ofInt 3 (by intlit)) if not (y = (I32.ofInt (-(3:Int)) (by intlit))) @@ -100,19 +100,19 @@ def test_neg1_fwd : Result Unit := else Result.ret () /- Unit test for [no_nested_borrows::test_neg1] -/ -#assert (test_neg1_fwd == .ret ()) +#assert (test_neg1 == .ret ()) -/- [no_nested_borrows::refs_test1] -/ -def refs_test1_fwd : Result Unit := +/- [no_nested_borrows::refs_test1]: forward function -/ +def refs_test1 : Result Unit := if 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 ()) +#assert (refs_test1 == .ret ()) -/- [no_nested_borrows::refs_test2] -/ -def refs_test2_fwd : Result Unit := +/- [no_nested_borrows::refs_test2]: forward function -/ +def refs_test2 : Result Unit := if not ((I32.ofInt 2 (by intlit)) = (I32.ofInt 2 (by intlit))) then Result.fail Error.panic else @@ -127,17 +127,17 @@ def refs_test2_fwd : Result Unit := else Result.ret () /- Unit test for [no_nested_borrows::refs_test2] -/ -#assert (refs_test2_fwd == .ret ()) +#assert (refs_test2 == .ret ()) -/- [no_nested_borrows::test_list1] -/ -def test_list1_fwd : Result Unit := +/- [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_fwd == .ret ()) +#assert (test_list1 == .ret ()) -/- [no_nested_borrows::test_box1] -/ -def test_box1_fwd : Result Unit := +/- [no_nested_borrows::test_box1]: forward function -/ +def test_box1 : Result Unit := let b := (I32.ofInt 1 (by intlit)) let x := b if not (x = (I32.ofInt 1 (by intlit))) @@ -145,90 +145,90 @@ def test_box1_fwd : Result Unit := else Result.ret () /- Unit test for [no_nested_borrows::test_box1] -/ -#assert (test_box1_fwd == .ret ()) +#assert (test_box1 == .ret ()) -/- [no_nested_borrows::copy_int] -/ -def copy_int_fwd (x : I32) : Result I32 := +/- [no_nested_borrows::copy_int]: forward function -/ +def copy_int (x : I32) : Result I32 := Result.ret x -/- [no_nested_borrows::test_unreachable] -/ -def test_unreachable_fwd (b : Bool) : Result Unit := +/- [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] -/ -def test_panic_fwd (b : Bool) : Result Unit := +/- [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] -/ -def test_copy_int_fwd : Result Unit := +/- [no_nested_borrows::test_copy_int]: forward function -/ +def test_copy_int : Result Unit := do - let y ← copy_int_fwd (I32.ofInt 0 (by intlit)) + let y ← copy_int (I32.ofInt 0 (by intlit)) if 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 ()) +#assert (test_copy_int == .ret ()) -/- [no_nested_borrows::is_cons] -/ -def is_cons_fwd (T : Type) (l : List T) : Result Bool := +/- [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] -/ -def test_is_cons_fwd : Result Unit := +/- [no_nested_borrows::test_is_cons]: forward function -/ +def test_is_cons : Result Unit := do let l := List.Nil - let b ← is_cons_fwd I32 (List.Cons (I32.ofInt 0 (by intlit)) l) + let b ← is_cons I32 (List.Cons (I32.ofInt 0 (by intlit)) 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_fwd == .ret ()) +#assert (test_is_cons == .ret ()) -/- [no_nested_borrows::split_list] -/ -def split_list_fwd (T : Type) (l : List T) : Result (T × (List T)) := +/- [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] -/ -def test_split_list_fwd : Result Unit := +/- [no_nested_borrows::test_split_list]: forward function -/ +def test_split_list : Result Unit := do let l := List.Nil - let p ← split_list_fwd I32 (List.Cons (I32.ofInt 0 (by intlit)) l) + let p ← split_list I32 (List.Cons (I32.ofInt 0 (by intlit)) l) let (hd, _) := p if 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 ()) +#assert (test_split_list == .ret ()) -/- [no_nested_borrows::choose] -/ -def choose_fwd (T : Type) (b : Bool) (x : T) (y : T) : Result T := +/- [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] -/ +/- [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] -/ -def choose_test_fwd : Result Unit := +/- [no_nested_borrows::choose_test]: forward function -/ +def choose_test : Result Unit := do let z ← - choose_fwd I32 true (I32.ofInt 0 (by intlit)) (I32.ofInt 0 (by intlit)) + choose I32 true (I32.ofInt 0 (by intlit)) (I32.ofInt 0 (by intlit)) let z0 ← z + (I32.ofInt 1 (by intlit)) if not (z0 = (I32.ofInt 1 (by intlit))) then Result.fail Error.panic @@ -245,10 +245,10 @@ def choose_test_fwd : Result Unit := else Result.ret () /- Unit test for [no_nested_borrows::choose_test] -/ -#assert (choose_test_fwd == .ret ()) +#assert (choose_test == .ret ()) -/- [no_nested_borrows::test_char] -/ -def test_char_fwd : Result Char := +/- [no_nested_borrows::test_char]: forward function -/ +def test_char : Result Char := Result.ret 'a' mutual @@ -265,40 +265,38 @@ inductive Tree (T : Type) := end -/- [no_nested_borrows::list_length] -/ -divergent def list_length_fwd (T : Type) (l : List T) : Result U32 := +/- [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_fwd T l1 + let i ← list_length T l1 (U32.ofInt 1 (by intlit)) + i | List.Nil => Result.ret (U32.ofInt 0 (by intlit)) -/- [no_nested_borrows::list_nth_shared] -/ -divergent def list_nth_shared_fwd - (T : Type) (l : List T) (i : U32) : Result T := +/- [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 (by intlit)) then Result.ret x - else - do - let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_shared_fwd T tl i0 + else do + let i0 ← i - (U32.ofInt 1 (by intlit)) + list_nth_shared T tl i0 | List.Nil => Result.fail Error.panic -/- [no_nested_borrows::list_nth_mut] -/ -divergent def list_nth_mut_fwd (T : Type) (l : List T) (i : U32) : Result T := +/- [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 (by intlit)) then Result.ret x else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_fwd T tl i0 + list_nth_mut T tl i0 | List.Nil => Result.fail Error.panic -/- [no_nested_borrows::list_nth_mut] -/ +/- [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 @@ -312,46 +310,47 @@ divergent def list_nth_mut_back Result.ret (List.Cons x tl0) | List.Nil => Result.fail Error.panic -/- [no_nested_borrows::list_rev_aux] -/ -divergent def list_rev_aux_fwd +/- [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_fwd T tl (List.Cons hd lo) + | List.Cons hd tl => list_rev_aux T tl (List.Cons hd lo) | List.Nil => Result.ret lo -/- [no_nested_borrows::list_rev] -/ -def list_rev_fwd_back (T : Type) (l : List T) : Result (List T) := - let li := mem.replace_fwd (List T) l List.Nil - list_rev_aux_fwd T li List.Nil +/- [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] -/ -def test_list_functions_fwd : Result Unit := +/- [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 (by intlit)) l let l1 := List.Cons (I32.ofInt 1 (by intlit)) l0 - let i ← list_length_fwd I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) + let i ← list_length I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) if not (i = (U32.ofInt 3 (by intlit))) then Result.fail Error.panic else do let i0 ← - list_nth_shared_fwd I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) + list_nth_shared I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) (U32.ofInt 0 (by intlit)) if not (i0 = (I32.ofInt 0 (by intlit))) then Result.fail Error.panic else do let i1 ← - list_nth_shared_fwd I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) + list_nth_shared I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) (U32.ofInt 1 (by intlit)) if not (i1 = (I32.ofInt 1 (by intlit))) then Result.fail Error.panic else do let i2 ← - list_nth_shared_fwd I32 (List.Cons (I32.ofInt 0 (by intlit)) - l1) (U32.ofInt 2 (by intlit)) + list_nth_shared I32 (List.Cons (I32.ofInt 0 (by intlit)) l1) + (U32.ofInt 2 (by intlit)) if not (i2 = (I32.ofInt 2 (by intlit))) then Result.fail Error.panic else @@ -360,74 +359,72 @@ def test_list_functions_fwd : Result Unit := list_nth_mut_back I32 (List.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)) + let i3 ← list_nth_shared I32 ls (U32.ofInt 0 (by intlit)) if 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)) + list_nth_shared I32 ls (U32.ofInt 1 (by intlit)) if 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)) + list_nth_shared I32 ls (U32.ofInt 2 (by intlit)) if 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 ()) +#assert (test_list_functions == .ret ()) -/- [no_nested_borrows::id_mut_pair1] -/ -def id_mut_pair1_fwd (T1 T2 : Type) (x : T1) (y : T2) : Result (T1 × T2) := +/- [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] -/ +/- [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] -/ -def id_mut_pair2_fwd (T1 T2 : Type) (p : (T1 × T2)) : Result (T1 × T2) := +/- [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] -/ +/- [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] -/ -def id_mut_pair3_fwd (T1 T2 : Type) (x : T1) (y : T2) : Result (T1 × T2) := +/- [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] -/ +/- [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] -/ +/- [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] -/ -def id_mut_pair4_fwd (T1 T2 : Type) (p : (T1 × T2)) : Result (T1 × T2) := +/- [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] -/ +/- [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] -/ +/- [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 @@ -436,24 +433,24 @@ def id_mut_pair4_back'b structure StructWithTuple (T1 T2 : Type) where struct_with_tuple_p : (T1 × T2) -/- [no_nested_borrows::new_tuple1] -/ -def new_tuple1_fwd : Result (StructWithTuple U32 U32) := +/- [no_nested_borrows::new_tuple1]: forward function -/ +def new_tuple1 : Result (StructWithTuple 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 (StructWithTuple I16 I16) := +/- [no_nested_borrows::new_tuple2]: forward function -/ +def new_tuple2 : Result (StructWithTuple 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 (StructWithTuple U64 I64) := +/- [no_nested_borrows::new_tuple3]: forward function -/ +def new_tuple3 : Result (StructWithTuple U64 I64) := Result.ret { struct_with_tuple_p := @@ -464,8 +461,8 @@ def new_tuple3_fwd : Result (StructWithTuple U64 I64) := structure StructWithPair (T1 T2 : Type) where struct_with_pair_p : Pair T1 T2 -/- [no_nested_borrows::new_pair1] -/ -def new_pair1_fwd : Result (StructWithPair U32 U32) := +/- [no_nested_borrows::new_pair1]: forward function -/ +def new_pair1 : Result (StructWithPair U32 U32) := Result.ret { struct_with_pair_p := @@ -475,68 +472,69 @@ def new_pair1_fwd : Result (StructWithPair U32 U32) := } } -/- [no_nested_borrows::test_constants] -/ -def test_constants_fwd : Result Unit := +/- [no_nested_borrows::test_constants]: forward function -/ +def test_constants : Result Unit := do - let swt ← new_tuple1_fwd + let swt ← new_tuple1 let (i, _) := swt.struct_with_tuple_p if not (i = (U32.ofInt 1 (by intlit))) then Result.fail Error.panic else do - let swt0 ← new_tuple2_fwd + let swt0 ← new_tuple2 let (i0, _) := swt0.struct_with_tuple_p if not (i0 = (I16.ofInt 1 (by intlit))) then Result.fail Error.panic else do - let swt1 ← new_tuple3_fwd + let swt1 ← new_tuple3 let (i1, _) := swt1.struct_with_tuple_p if not (i1 = (U64.ofInt 1 (by intlit))) then Result.fail Error.panic else do - let swp ← new_pair1_fwd + let swp ← new_pair1 if 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 ()) +#assert (test_constants == .ret ()) -/- [no_nested_borrows::test_weird_borrows1] -/ -def test_weird_borrows1_fwd : Result Unit := +/- [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_fwd == .ret ()) +#assert (test_weird_borrows1 == .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)) +/- [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 (by intlit)) if 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 := +/- [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 (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 := +/- [no_nested_borrows::test_shared_borrow_bool2]: forward function -/ +def test_shared_borrow_bool2 : Result U32 := Result.ret (U32.ofInt 0 (by intlit)) -/- [no_nested_borrows::test_shared_borrow_enum1] -/ -def test_shared_borrow_enum1_fwd (l : List U32) : Result U32 := +/- [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 (by intlit)) | List.Nil => Result.ret (U32.ofInt 0 (by intlit)) -/- [no_nested_borrows::test_shared_borrow_enum2] -/ -def test_shared_borrow_enum2_fwd : Result U32 := +/- [no_nested_borrows::test_shared_borrow_enum2]: forward function -/ +def test_shared_borrow_enum2 : Result U32 := Result.ret (U32.ofInt 0 (by intlit)) end no_nested_borrows diff --git a/tests/lean/Paper.lean b/tests/lean/Paper.lean index 9f63b460..ade65656 100644 --- a/tests/lean/Paper.lean +++ b/tests/lean/Paper.lean @@ -4,39 +4,40 @@ import Base open Primitives namespace paper -/- [paper::ref_incr] -/ -def ref_incr_fwd_back (x : I32) : Result I32 := +/- [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 (by intlit)) -/- [paper::test_incr] -/ -def test_incr_fwd : Result Unit := +/- [paper::test_incr]: forward function -/ +def test_incr : Result Unit := do - let x ← ref_incr_fwd_back (I32.ofInt 0 (by intlit)) + let x ← ref_incr (I32.ofInt 0 (by intlit)) if 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 ()) +#assert (test_incr == .ret ()) -/- [paper::choose] -/ -def choose_fwd (T : Type) (b : Bool) (x : T) (y : T) : Result T := +/- [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] -/ +/- [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] -/ -def test_choose_fwd : Result Unit := +/- [paper::test_choose]: forward function -/ +def test_choose : Result Unit := do let z ← - choose_fwd I32 true (I32.ofInt 0 (by intlit)) (I32.ofInt 0 (by intlit)) + choose I32 true (I32.ofInt 0 (by intlit)) (I32.ofInt 0 (by intlit)) let z0 ← z + (I32.ofInt 1 (by intlit)) if not (z0 = (I32.ofInt 1 (by intlit))) then Result.fail Error.panic @@ -53,25 +54,25 @@ def test_choose_fwd : Result Unit := else Result.ret () /- Unit test for [paper::test_choose] -/ -#assert (test_choose_fwd == .ret ()) +#assert (test_choose == .ret ()) /- [paper::List] -/ inductive List (T : Type) := | Cons : T → List T → List T | Nil : List T -/- [paper::list_nth_mut] -/ -divergent def list_nth_mut_fwd (T : Type) (l : List T) (i : U32) : Result 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 (by intlit)) then Result.ret x else do let i0 ← i - (U32.ofInt 1 (by intlit)) - list_nth_mut_fwd T tl i0 + list_nth_mut T tl i0 | List.Nil => Result.fail Error.panic -/- [paper::list_nth_mut] -/ +/- [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 @@ -85,40 +86,40 @@ divergent def list_nth_mut_back Result.ret (List.Cons x tl0) | List.Nil => Result.fail Error.panic -/- [paper::sum] -/ -divergent def sum_fwd (l : List I32) : Result I32 := +/- [paper::sum]: forward function -/ +divergent def sum (l : List I32) : Result I32 := match l with | List.Cons x tl => do - let i ← sum_fwd tl + let i ← sum tl x + i | List.Nil => Result.ret (I32.ofInt 0 (by intlit)) -/- [paper::test_nth] -/ -def test_nth_fwd : Result Unit := +/- [paper::test_nth]: forward function -/ +def test_nth : Result Unit := do let l := List.Nil let l0 := List.Cons (I32.ofInt 3 (by intlit)) l let l1 := List.Cons (I32.ofInt 2 (by intlit)) l0 let x ← - list_nth_mut_fwd I32 (List.Cons (I32.ofInt 1 (by intlit)) l1) + list_nth_mut I32 (List.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.Cons (I32.ofInt 1 (by intlit)) l1) (U32.ofInt 2 (by intlit)) x0 - let i ← sum_fwd l2 + let i ← sum l2 if 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 ()) +#assert (test_nth == .ret ()) -/- [paper::call_choose] -/ -def call_choose_fwd (p : (U32 × U32)) : Result U32 := +/- [paper::call_choose]: forward function -/ +def call_choose (p : (U32 × U32)) : Result U32 := do let (px, py) := p - let pz ← choose_fwd U32 true px py + let pz ← choose 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/PoloniusList.lean b/tests/lean/PoloniusList.lean index 1d7ec99b..1453c275 100644 --- a/tests/lean/PoloniusList.lean +++ b/tests/lean/PoloniusList.lean @@ -9,17 +9,16 @@ inductive List (T : Type) := | Cons : T → List T → List T | Nil : List T -/- [polonius_list::get_list_at_x] -/ -divergent def get_list_at_x_fwd - (ls : List U32) (x : U32) : Result (List U32) := +/- [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_fwd tl x + else get_list_at_x tl x | List.Nil => Result.ret List.Nil -/- [polonius_list::get_list_at_x] -/ +/- [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 |