From 87d6f6c7c90bf7b427397d6bd2e2c70d610678e3 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 4 Jul 2023 14:57:51 +0200 Subject: Reorganize the Lean tests --- tests/lean/BetreeMain/Funs.lean | 1071 +++++++++++++++++++++++++++++++++++++ tests/lean/BetreeMain/Opaque.lean | 31 ++ tests/lean/BetreeMain/Types.lean | 62 +++ 3 files changed, 1164 insertions(+) create mode 100644 tests/lean/BetreeMain/Funs.lean create mode 100644 tests/lean/BetreeMain/Opaque.lean create mode 100644 tests/lean/BetreeMain/Types.lean (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean new file mode 100644 index 00000000..fb48b3a6 --- /dev/null +++ b/tests/lean/BetreeMain/Funs.lean @@ -0,0 +1,1071 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: function definitions +import Base +import BetreeMain.Types +import BetreeMain.ExternalFuns +open Primitives + +/- [betree_main::betree::load_internal_node] -/ +def betree_load_internal_node_fwd + (id : U64) (st : State) : + Result (State × (betree_list_t (U64 × betree_message_t))) + := + opaque_defs.betree_utils_load_internal_node_fwd id st + +/- [betree_main::betree::store_internal_node] -/ +def betree_store_internal_node_fwd + (id : U64) (content : betree_list_t (U64 × betree_message_t)) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + opaque_defs.betree_utils_store_internal_node_fwd id content st + Result.ret (st0, ()) + +/- [betree_main::betree::load_leaf_node] -/ +def betree_load_leaf_node_fwd + (id : U64) (st : State) : Result (State × (betree_list_t (U64 × U64))) := + opaque_defs.betree_utils_load_leaf_node_fwd id st + +/- [betree_main::betree::store_leaf_node] -/ +def betree_store_leaf_node_fwd + (id : U64) (content : betree_list_t (U64 × U64)) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← opaque_defs.betree_utils_store_leaf_node_fwd id content st + Result.ret (st0, ()) + +/- [betree_main::betree::fresh_node_id] -/ +def betree_fresh_node_id_fwd (counter : U64) : Result U64 := + do + let _ ← counter + (U64.ofInt 1 (by intlit)) + Result.ret counter + +/- [betree_main::betree::fresh_node_id] -/ +def betree_fresh_node_id_back (counter : U64) : Result U64 := + counter + (U64.ofInt 1 (by intlit)) + +/- [betree_main::betree::NodeIdCounter::{0}::new] -/ +def betree_node_id_counter_new_fwd : Result betree_node_id_counter_t := + Result.ret + { betree_node_id_counter_next_node_id := (U64.ofInt 0 (by intlit)) } + +/- [betree_main::betree::NodeIdCounter::{0}::fresh_id] -/ +def betree_node_id_counter_fresh_id_fwd + (self : betree_node_id_counter_t) : 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] -/ +def betree_node_id_counter_fresh_id_back + (self : betree_node_id_counter_t) : Result betree_node_id_counter_t := + do + let i ← self.betree_node_id_counter_next_node_id + + (U64.ofInt 1 (by intlit)) + Result.ret { betree_node_id_counter_next_node_id := i } + +/- [core::num::u64::{10}::MAX] -/ +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 + (prev : Option U64) (st : betree_upsert_fun_state_t) : Result U64 := + match h: prev with + | Option.none => + match h: st with + | betree_upsert_fun_state_t.Add v => Result.ret v + | betree_upsert_fun_state_t.Sub i => Result.ret (U64.ofInt 0 (by intlit)) + | Option.some prev0 => + match h: st with + | betree_upsert_fun_state_t.Add v => + do + let margin ← core_num_u64_max_c - prev0 + if margin >= v + then prev0 + v + else Result.ret core_num_u64_max_c + | betree_upsert_fun_state_t.Sub v => + if prev0 >= v + 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 T) : Result U64 := + match h: self with + | betree_list_t.Cons t tl => + do + let i ← betree_list_len_fwd T tl + (U64.ofInt 1 (by intlit)) + i + | betree_list_t.Nil => Result.ret (U64.ofInt 0 (by intlit)) + +/- [betree_main::betree::List::{1}::split_at] -/ +divergent def betree_list_split_at_fwd + (T : Type) (self : betree_list_t T) (n : U64) : + Result ((betree_list_t T) × (betree_list_t T)) + := + if n = (U64.ofInt 0 (by intlit)) + then Result.ret (betree_list_t.Nil, self) + else + match h: self with + | betree_list_t.Cons hd tl => + do + let i ← n - (U64.ofInt 1 (by intlit)) + let p ← betree_list_split_at_fwd T tl i + let (ls0, ls1) := p + let l := ls0 + Result.ret (betree_list_t.Cons hd l, ls1) + | betree_list_t.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{1}::push_front] -/ +def betree_list_push_front_fwd_back + (T : Type) (self : betree_list_t T) (x : T) : Result (betree_list_t T) := + let tl := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil + let l := tl + Result.ret (betree_list_t.Cons x l) + +/- [betree_main::betree::List::{1}::pop_front] -/ +def betree_list_pop_front_fwd (T : Type) (self : betree_list_t T) : Result T := + let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil + match h: ls with + | betree_list_t.Cons x tl => Result.ret x + | betree_list_t.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{1}::pop_front] -/ +def betree_list_pop_front_back + (T : Type) (self : betree_list_t T) : Result (betree_list_t T) := + let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil + match h: ls with + | betree_list_t.Cons x tl => Result.ret tl + | betree_list_t.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{1}::hd] -/ +def betree_list_hd_fwd (T : Type) (self : betree_list_t T) : Result T := + match h: self with + | betree_list_t.Cons hd l => Result.ret hd + | betree_list_t.Nil => Result.fail Error.panic + +/- [betree_main::betree::List::{2}::head_has_key] -/ +def betree_list_head_has_key_fwd + (T : Type) (self : betree_list_t (U64 × T)) (key : U64) : Result Bool := + match h: self with + | betree_list_t.Cons hd l => let (i, _) := hd + Result.ret (i = key) + | betree_list_t.Nil => Result.ret false + +/- [betree_main::betree::List::{2}::partition_at_pivot] -/ +divergent def betree_list_partition_at_pivot_fwd + (T : Type) (self : betree_list_t (U64 × T)) (pivot : U64) : + Result ((betree_list_t (U64 × T)) × (betree_list_t (U64 × T))) + := + match h: self with + | betree_list_t.Cons hd tl => + let (i, t) := hd + if i >= pivot + then Result.ret (betree_list_t.Nil, betree_list_t.Cons (i, t) tl) + else + do + let p ← betree_list_partition_at_pivot_fwd T tl pivot + let (ls0, ls1) := p + let l := ls0 + Result.ret (betree_list_t.Cons (i, t) l, ls1) + | betree_list_t.Nil => Result.ret (betree_list_t.Nil, betree_list_t.Nil) + +/- [betree_main::betree::Leaf::{3}::split] -/ +def betree_leaf_split_fwd + (self : betree_leaf_t) (content : betree_list_t (U64 × U64)) + (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) + (st : State) : + Result (State × betree_internal_t) + := + do + let p ← + betree_list_split_at_fwd (U64 × U64) content + params.betree_params_split_size + let (content0, content1) := p + let p0 ← betree_list_hd_fwd (U64 × U64) content1 + let (pivot, _) := p0 + let id0 ← betree_node_id_counter_fresh_id_fwd node_id_cnt + let node_id_cnt0 ← betree_node_id_counter_fresh_id_back node_id_cnt + let id1 ← betree_node_id_counter_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 n := betree_node_t.Leaf + { + betree_leaf_id := id0, + betree_leaf_size := params.betree_params_split_size + } + let n0 := betree_node_t.Leaf + { + betree_leaf_id := id1, + betree_leaf_size := params.betree_params_split_size + } + Result.ret (st1, mkbetree_internal_t self.betree_leaf_id pivot n n0) + +/- [betree_main::betree::Leaf::{3}::split] -/ +def betree_leaf_split_back + (self : betree_leaf_t) (content : betree_list_t (U64 × U64)) + (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) + (st : State) : + Result betree_node_id_counter_t + := + do + let p ← + betree_list_split_at_fwd (U64 × U64) content + params.betree_params_split_size + let (content0, content1) := p + let _ ← betree_list_hd_fwd (U64 × U64) content1 + let id0 ← betree_node_id_counter_fresh_id_fwd node_id_cnt + let node_id_cnt0 ← betree_node_id_counter_fresh_id_back node_id_cnt + let id1 ← betree_node_id_counter_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 + betree_node_id_counter_fresh_id_back node_id_cnt0 + +/- [betree_main::betree::Node::{5}::lookup_in_bindings] -/ +divergent def betree_node_lookup_in_bindings_fwd + (key : U64) (bindings : betree_list_t (U64 × U64)) : Result (Option U64) := + match h: bindings with + | betree_list_t.Cons hd tl => + let (i, i0) := hd + if i = key + then Result.ret (Option.some i0) + else + if i > key + then Result.ret Option.none + else betree_node_lookup_in_bindings_fwd key tl + | betree_list_t.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 + (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × betree_message_t)) + := + match h: msgs with + | betree_list_t.Cons x next_msgs => + let (i, m) := x + if i >= key + then Result.ret (betree_list_t.Cons (i, m) next_msgs) + else betree_node_lookup_first_message_for_key_fwd key next_msgs + | betree_list_t.Nil => Result.ret betree_list_t.Nil + +/- [betree_main::betree::Node::{5}::lookup_first_message_for_key] -/ +divergent def betree_node_lookup_first_message_for_key_back + (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) + (ret0 : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × betree_message_t)) + := + match h: msgs with + | betree_list_t.Cons x next_msgs => + let (i, m) := x + if i >= key + then Result.ret ret0 + else + do + let next_msgs0 ← + betree_node_lookup_first_message_for_key_back key next_msgs ret0 + Result.ret (betree_list_t.Cons (i, m) next_msgs0) + | betree_list_t.Nil => Result.ret ret0 + +/- [betree_main::betree::Node::{5}::apply_upserts] -/ +divergent def betree_node_apply_upserts_fwd + (msgs : betree_list_t (U64 × betree_message_t)) (prev : Option U64) + (key : U64) (st : State) : + Result (State × U64) + := + do + let b ← betree_list_head_has_key_fwd betree_message_t msgs key + if b + then + do + let msg ← betree_list_pop_front_fwd (U64 × betree_message_t) msgs + let (_, m) := msg + match h: m with + | betree_message_t.Insert i => Result.fail Error.panic + | betree_message_t.Delete => Result.fail Error.panic + | betree_message_t.Upsert s => + do + let v ← betree_upsert_update_fwd prev s + let msgs0 ← + betree_list_pop_front_back (U64 × betree_message_t) msgs + betree_node_apply_upserts_fwd msgs0 (Option.some v) key st + else + do + let (st0, v) ← opaque_defs.core_option_option_unwrap_fwd U64 prev st + let _ ← + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs (key, + betree_message_t.Insert v) + Result.ret (st0, v) + +/- [betree_main::betree::Node::{5}::apply_upserts] -/ +divergent def betree_node_apply_upserts_back + (msgs : betree_list_t (U64 × betree_message_t)) (prev : Option U64) + (key : U64) (st : State) : + Result (betree_list_t (U64 × betree_message_t)) + := + do + let b ← betree_list_head_has_key_fwd betree_message_t msgs key + if b + then + do + let msg ← betree_list_pop_front_fwd (U64 × betree_message_t) msgs + let (_, m) := msg + match h: m with + | betree_message_t.Insert i => Result.fail Error.panic + | betree_message_t.Delete => Result.fail Error.panic + | betree_message_t.Upsert s => + do + let v ← betree_upsert_update_fwd prev s + let msgs0 ← + betree_list_pop_front_back (U64 × betree_message_t) msgs + betree_node_apply_upserts_back msgs0 (Option.some v) key st + else + do + let (_, v) ← opaque_defs.core_option_option_unwrap_fwd U64 prev st + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs (key, + betree_message_t.Insert v) + +/- [betree_main::betree::Node::{5}::lookup] -/ +mutual divergent def betree_node_lookup_fwd + (self : betree_node_t) (key : U64) (st : State) : + Result (State × (Option U64)) + := + match h: self with + | betree_node_t.Internal node => + do + let (mkbetree_internal_t 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 + match h: pending with + | betree_list_t.Cons p l => + let (k, msg) := p + if k != key + then + do + let (st1, opt) ← + betree_internal_lookup_in_children_fwd (mkbetree_internal_t i i0 + n n0) key st0 + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + (betree_list_t.Cons (k, msg) l) + Result.ret (st1, opt) + else + match h: msg with + | betree_message_t.Insert v => + do + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + (betree_list_t.Cons (k, betree_message_t.Insert v) l) + Result.ret (st0, Option.some v) + | betree_message_t.Delete => + do + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + (betree_list_t.Cons (k, betree_message_t.Delete) l) + Result.ret (st0, Option.none) + | betree_message_t.Upsert ufs => + do + let (st1, v) ← + betree_internal_lookup_in_children_fwd (mkbetree_internal_t i + i0 n n0) key st0 + let (st2, v0) ← + betree_node_apply_upserts_fwd (betree_list_t.Cons (k, + betree_message_t.Upsert ufs) l) v key st1 + let node0 ← + betree_internal_lookup_in_children_back (mkbetree_internal_t i + i0 n n0) key st0 + let (mkbetree_internal_t i1 _ _ _) := node0 + let pending0 ← + betree_node_apply_upserts_back (betree_list_t.Cons (k, + betree_message_t.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 + Result.ret (st3, Option.some v0) + | betree_list_t.Nil => + do + let (st1, opt) ← + betree_internal_lookup_in_children_fwd (mkbetree_internal_t i i0 n + n0) key st0 + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + betree_list_t.Nil + Result.ret (st1, opt) + | betree_node_t.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 + Result.ret (st0, opt) + +/- [betree_main::betree::Node::{5}::lookup] -/ +divergent def betree_node_lookup_back + (self : betree_node_t) (key : U64) (st : State) : Result betree_node_t := + match h: self with + | betree_node_t.Internal node => + do + let (mkbetree_internal_t 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 + match h: pending with + | betree_list_t.Cons p l => + let (k, msg) := p + if k != key + then + do + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + (betree_list_t.Cons (k, msg) l) + let node0 ← + betree_internal_lookup_in_children_back (mkbetree_internal_t i i0 + n n0) key st0 + Result.ret (betree_node_t.Internal node0) + else + match h: msg with + | betree_message_t.Insert v => + do + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + (betree_list_t.Cons (k, betree_message_t.Insert v) l) + Result.ret (betree_node_t.Internal (mkbetree_internal_t i i0 n + n0)) + | betree_message_t.Delete => + do + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + (betree_list_t.Cons (k, betree_message_t.Delete) l) + Result.ret (betree_node_t.Internal (mkbetree_internal_t i i0 n + n0)) + | betree_message_t.Upsert ufs => + do + let (st1, v) ← + betree_internal_lookup_in_children_fwd (mkbetree_internal_t i + i0 n n0) key st0 + let (st2, _) ← + betree_node_apply_upserts_fwd (betree_list_t.Cons (k, + betree_message_t.Upsert ufs) l) v key st1 + let node0 ← + betree_internal_lookup_in_children_back (mkbetree_internal_t i + i0 n n0) key st0 + let (mkbetree_internal_t i1 i2 n1 n2) := node0 + let pending0 ← + betree_node_apply_upserts_back (betree_list_t.Cons (k, + betree_message_t.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 + Result.ret (betree_node_t.Internal (mkbetree_internal_t i1 i2 n1 + n2)) + | betree_list_t.Nil => + do + let _ ← + betree_node_lookup_first_message_for_key_back key msgs + betree_list_t.Nil + let node0 ← + betree_internal_lookup_in_children_back (mkbetree_internal_t i i0 n + n0) key st0 + Result.ret (betree_node_t.Internal node0) + | betree_node_t.Leaf node => + do + let (_, bindings) ← betree_load_leaf_node_fwd node.betree_leaf_id st + let _ ← betree_node_lookup_in_bindings_fwd key bindings + Result.ret (betree_node_t.Leaf node) + +/- [betree_main::betree::Internal::{4}::lookup_in_children] -/ +divergent def betree_internal_lookup_in_children_fwd + (self : betree_internal_t) (key : U64) (st : State) : + Result (State × (Option U64)) + := + let (mkbetree_internal_t _ i n n0) := self + if key < i + then betree_node_lookup_fwd n key st + else betree_node_lookup_fwd n0 key st + +/- [betree_main::betree::Internal::{4}::lookup_in_children] -/ +divergent def betree_internal_lookup_in_children_back + (self : betree_internal_t) (key : U64) (st : State) : + Result betree_internal_t + := + let (mkbetree_internal_t i i0 n n0) := self + if key < i0 + then + do + let n1 ← betree_node_lookup_back n key st + Result.ret (mkbetree_internal_t i i0 n1 n0) + else + do + let n1 ← betree_node_lookup_back n0 key st + Result.ret (mkbetree_internal_t i i0 n n1) + +end + +/- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ +divergent def betree_node_lookup_mut_in_bindings_fwd + (key : U64) (bindings : betree_list_t (U64 × U64)) : + Result (betree_list_t (U64 × U64)) + := + match h: bindings with + | betree_list_t.Cons hd tl => + let (i, i0) := hd + if i >= key + then Result.ret (betree_list_t.Cons (i, i0) tl) + else betree_node_lookup_mut_in_bindings_fwd key tl + | betree_list_t.Nil => Result.ret betree_list_t.Nil + +/- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ +divergent def betree_node_lookup_mut_in_bindings_back + (key : U64) (bindings : betree_list_t (U64 × U64)) + (ret0 : betree_list_t (U64 × U64)) : + Result (betree_list_t (U64 × U64)) + := + match h: bindings with + | betree_list_t.Cons hd tl => + let (i, i0) := hd + if i >= key + then Result.ret ret0 + else + do + let tl0 ← betree_node_lookup_mut_in_bindings_back key tl ret0 + Result.ret (betree_list_t.Cons (i, i0) tl0) + | betree_list_t.Nil => Result.ret ret0 + +/- [betree_main::betree::Node::{5}::apply_to_leaf] -/ +def betree_node_apply_to_leaf_fwd_back + (bindings : betree_list_t (U64 × U64)) (key : U64) + (new_msg : betree_message_t) : + Result (betree_list_t (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 + if b + then + do + let hd ← betree_list_pop_front_fwd (U64 × U64) bindings0 + match h: new_msg with + | betree_message_t.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_node_lookup_mut_in_bindings_back key bindings bindings2 + | betree_message_t.Delete => + do + let bindings1 ← betree_list_pop_front_back (U64 × U64) bindings0 + betree_node_lookup_mut_in_bindings_back key bindings bindings1 + | betree_message_t.Upsert s => + do + let (_, i) := hd + let v ← betree_upsert_update_fwd (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_node_lookup_mut_in_bindings_back key bindings bindings2 + else + match h: new_msg with + | betree_message_t.Insert v => + do + let bindings1 ← + betree_list_push_front_fwd_back (U64 × U64) bindings0 (key, v) + betree_node_lookup_mut_in_bindings_back key bindings bindings1 + | betree_message_t.Delete => + betree_node_lookup_mut_in_bindings_back key bindings bindings0 + | betree_message_t.Upsert s => + do + let v ← betree_upsert_update_fwd Option.none s + let bindings1 ← + betree_list_push_front_fwd_back (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 + (bindings : betree_list_t (U64 × U64)) + (new_msgs : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × U64)) + := + match h: new_msgs with + | betree_list_t.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 + | betree_list_t.Nil => Result.ret bindings + +/- [betree_main::betree::Node::{5}::filter_messages_for_key] -/ +divergent def betree_node_filter_messages_for_key_fwd_back + (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × betree_message_t)) + := + match h: msgs with + | betree_list_t.Cons p l => + let (k, m) := p + if k = key + then + do + let msgs0 ← + betree_list_pop_front_back (U64 × betree_message_t) + (betree_list_t.Cons (k, m) l) + betree_node_filter_messages_for_key_fwd_back key msgs0 + else Result.ret (betree_list_t.Cons (k, m) l) + | betree_list_t.Nil => Result.ret betree_list_t.Nil + +/- [betree_main::betree::Node::{5}::lookup_first_message_after_key] -/ +divergent def betree_node_lookup_first_message_after_key_fwd + (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × betree_message_t)) + := + match h: msgs with + | betree_list_t.Cons p next_msgs => + let (k, m) := p + if k = key + then betree_node_lookup_first_message_after_key_fwd key next_msgs + else Result.ret (betree_list_t.Cons (k, m) next_msgs) + | betree_list_t.Nil => Result.ret betree_list_t.Nil + +/- [betree_main::betree::Node::{5}::lookup_first_message_after_key] -/ +divergent def betree_node_lookup_first_message_after_key_back + (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) + (ret0 : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × betree_message_t)) + := + match h: msgs with + | betree_list_t.Cons p next_msgs => + let (k, m) := p + if k = key + then + do + let next_msgs0 ← + betree_node_lookup_first_message_after_key_back key next_msgs ret0 + Result.ret (betree_list_t.Cons (k, m) next_msgs0) + else Result.ret ret0 + | betree_list_t.Nil => Result.ret ret0 + +/- [betree_main::betree::Node::{5}::apply_to_internal] -/ +def betree_node_apply_to_internal_fwd_back + (msgs : betree_list_t (U64 × betree_message_t)) (key : U64) + (new_msg : betree_message_t) : + Result (betree_list_t (U64 × betree_message_t)) + := + do + let msgs0 ← betree_node_lookup_first_message_for_key_fwd key msgs + let b ← betree_list_head_has_key_fwd betree_message_t msgs0 key + if b + then + match h: new_msg with + | betree_message_t.Insert i => + do + let msgs1 ← betree_node_filter_messages_for_key_fwd_back key msgs0 + let msgs2 ← + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + (key, betree_message_t.Insert i) + betree_node_lookup_first_message_for_key_back key msgs msgs2 + | betree_message_t.Delete => + do + let msgs1 ← betree_node_filter_messages_for_key_fwd_back key msgs0 + let msgs2 ← + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + (key, betree_message_t.Delete) + betree_node_lookup_first_message_for_key_back key msgs msgs2 + | betree_message_t.Upsert s => + do + let p ← betree_list_hd_fwd (U64 × betree_message_t) msgs0 + let (_, m) := p + match h: m with + | betree_message_t.Insert prev => + do + let v ← betree_upsert_update_fwd (Option.some prev) s + let msgs1 ← + betree_list_pop_front_back (U64 × betree_message_t) msgs0 + let msgs2 ← + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + (key, betree_message_t.Insert v) + betree_node_lookup_first_message_for_key_back key msgs msgs2 + | betree_message_t.Delete => + do + let v ← betree_upsert_update_fwd Option.none s + let msgs1 ← + betree_list_pop_front_back (U64 × betree_message_t) msgs0 + let msgs2 ← + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + (key, betree_message_t.Insert v) + betree_node_lookup_first_message_for_key_back key msgs msgs2 + | betree_message_t.Upsert ufs => + do + let msgs1 ← + betree_node_lookup_first_message_after_key_fwd key msgs0 + let msgs2 ← + betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + (key, betree_message_t.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_t) 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 + (msgs : betree_list_t (U64 × betree_message_t)) + (new_msgs : betree_list_t (U64 × betree_message_t)) : + Result (betree_list_t (U64 × betree_message_t)) + := + match h: new_msgs with + | betree_list_t.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 + | betree_list_t.Nil => Result.ret msgs + +/- [betree_main::betree::Node::{5}::apply_messages] -/ +mutual divergent def betree_node_apply_messages_fwd + (self : betree_node_t) (params : betree_params_t) + (node_id_cnt : betree_node_id_counter_t) + (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : + Result (State × Unit) + := + match h: self with + | betree_node_t.Internal node => + do + let (mkbetree_internal_t 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_t) content0 + if num_msgs >= params.betree_params_min_flush_size + then + do + let (st1, content1) ← + betree_internal_flush_fwd (mkbetree_internal_t i i0 n n0) params + node_id_cnt content0 st0 + let (node0, _) ← + betree_internal_flush_back (mkbetree_internal_t i i0 n n0) params + node_id_cnt content0 st0 + let (mkbetree_internal_t i1 _ _ _) := node0 + let (st2, _) ← betree_store_internal_node_fwd i1 content1 st1 + Result.ret (st2, ()) + else + do + let (st1, _) ← betree_store_internal_node_fwd i content0 st0 + Result.ret (st1, ()) + | betree_node_t.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 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 + let (st2, _) ← + betree_store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil + st1 + Result.ret (st2, ()) + else + do + let (st1, _) ← + betree_store_leaf_node_fwd node.betree_leaf_id content0 st0 + Result.ret (st1, ()) + +/- [betree_main::betree::Node::{5}::apply_messages] -/ +divergent def betree_node_apply_messages_back + (self : betree_node_t) (params : betree_params_t) + (node_id_cnt : betree_node_id_counter_t) + (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : + Result (betree_node_t × betree_node_id_counter_t) + := + match h: self with + | betree_node_t.Internal node => + do + let (mkbetree_internal_t 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_t) content0 + if num_msgs >= params.betree_params_min_flush_size + then + do + let (st1, content1) ← + betree_internal_flush_fwd (mkbetree_internal_t i i0 n n0) params + node_id_cnt content0 st0 + let (node0, node_id_cnt0) ← + betree_internal_flush_back (mkbetree_internal_t i i0 n n0) params + node_id_cnt content0 st0 + let (mkbetree_internal_t i1 i2 n1 n2) := node0 + let _ ← betree_store_internal_node_fwd i1 content1 st1 + Result.ret (betree_node_t.Internal (mkbetree_internal_t i1 i2 n1 n2), + node_id_cnt0) + else + do + let _ ← betree_store_internal_node_fwd i content0 st0 + Result.ret (betree_node_t.Internal (mkbetree_internal_t i i0 n n0), + node_id_cnt) + | betree_node_t.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 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 + let _ ← + betree_store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil + st1 + let node_id_cnt0 ← + betree_leaf_split_back node content0 params node_id_cnt st0 + Result.ret (betree_node_t.Internal new_node, node_id_cnt0) + else + do + let _ ← betree_store_leaf_node_fwd node.betree_leaf_id content0 st0 + Result.ret (betree_node_t.Leaf { node with betree_leaf_size := len }, + node_id_cnt) + +/- [betree_main::betree::Internal::{4}::flush] -/ +divergent def betree_internal_flush_fwd + (self : betree_internal_t) (params : betree_params_t) + (node_id_cnt : betree_node_id_counter_t) + (content : betree_list_t (U64 × betree_message_t)) (st : State) : + Result (State × (betree_list_t (U64 × betree_message_t))) + := + do + let (mkbetree_internal_t _ i n n0) := self + let p ← betree_list_partition_at_pivot_fwd betree_message_t content i + let (msgs_left, msgs_right) := p + let len_left ← betree_list_len_fwd (U64 × betree_message_t) 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 + 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_t) 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 + let _ ← + betree_node_apply_messages_back n0 params node_id_cnt0 msgs_right + st0 + Result.ret (st1, betree_list_t.Nil) + else Result.ret (st0, msgs_right) + else + do + let (st0, _) ← + betree_node_apply_messages_fwd 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] -/ +divergent def betree_internal_flush_back + (self : betree_internal_t) (params : betree_params_t) + (node_id_cnt : betree_node_id_counter_t) + (content : betree_list_t (U64 × betree_message_t)) (st : State) : + Result (betree_internal_t × betree_node_id_counter_t) + := + do + let (mkbetree_internal_t i i0 n n0) := self + let p ← betree_list_partition_at_pivot_fwd betree_message_t content i0 + let (msgs_left, msgs_right) := p + let len_left ← betree_list_len_fwd (U64 × betree_message_t) 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 + 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_t) msgs_right + if len_right >= params.betree_params_min_flush_size + then + do + let (n2, node_id_cnt1) ← + betree_node_apply_messages_back n0 params node_id_cnt0 msgs_right + st0 + Result.ret (mkbetree_internal_t i i0 n1 n2, node_id_cnt1) + else Result.ret (mkbetree_internal_t i i0 n1 n0, node_id_cnt0) + else + do + let (n1, node_id_cnt0) ← + betree_node_apply_messages_back n0 params node_id_cnt msgs_right st + Result.ret (mkbetree_internal_t i i0 n n1, node_id_cnt0) + +end + +/- [betree_main::betree::Node::{5}::apply] -/ +def betree_node_apply_fwd + (self : betree_node_t) (params : betree_params_t) + (node_id_cnt : betree_node_id_counter_t) (key : U64) + (new_msg : betree_message_t) (st : State) : + Result (State × Unit) + := + do + let l := betree_list_t.Nil + let (st0, _) ← + betree_node_apply_messages_fwd self params node_id_cnt + (betree_list_t.Cons (key, new_msg) l) st + let _ ← + betree_node_apply_messages_back self params node_id_cnt + (betree_list_t.Cons (key, new_msg) l) st + Result.ret (st0, ()) + +/- [betree_main::betree::Node::{5}::apply] -/ +def betree_node_apply_back + (self : betree_node_t) (params : betree_params_t) + (node_id_cnt : betree_node_id_counter_t) (key : U64) + (new_msg : betree_message_t) (st : State) : + Result (betree_node_t × betree_node_id_counter_t) + := + let l := betree_list_t.Nil + betree_node_apply_messages_back self params node_id_cnt (betree_list_t.Cons + (key, new_msg) l) st + +/- [betree_main::betree::BeTree::{6}::new] -/ +def betree_be_tree_new_fwd + (min_flush_size : U64) (split_size : U64) (st : State) : + Result (State × betree_be_tree_t) + := + do + let node_id_cnt ← betree_node_id_counter_new_fwd + let id ← betree_node_id_counter_fresh_id_fwd node_id_cnt + let (st0, _) ← betree_store_leaf_node_fwd id betree_list_t.Nil st + let node_id_cnt0 ← betree_node_id_counter_fresh_id_back node_id_cnt + Result.ret (st0, + { + betree_be_tree_params := + { + betree_params_min_flush_size := min_flush_size, + betree_params_split_size := split_size + }, + betree_be_tree_node_id_cnt := node_id_cnt0, + betree_be_tree_root := + (betree_node_t.Leaf + { + betree_leaf_id := id, + betree_leaf_size := (U64.ofInt 0 (by intlit)) + }) + }) + +/- [betree_main::betree::BeTree::{6}::apply] -/ +def betree_be_tree_apply_fwd + (self : betree_be_tree_t) (key : U64) (msg : betree_message_t) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + betree_node_apply_fwd 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] -/ +def betree_be_tree_apply_back + (self : betree_be_tree_t) (key : U64) (msg : betree_message_t) (st : State) : + Result betree_be_tree_t + := + do + let (n, nic) ← + 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 + { self with betree_be_tree_node_id_cnt := nic, betree_be_tree_root := n } + +/- [betree_main::betree::BeTree::{6}::insert] -/ +def betree_be_tree_insert_fwd + (self : betree_be_tree_t) (key : U64) (value : U64) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + betree_be_tree_apply_fwd self key (betree_message_t.Insert value) st + let _ ← + betree_be_tree_apply_back self key (betree_message_t.Insert value) st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::insert] -/ +def betree_be_tree_insert_back + (self : betree_be_tree_t) (key : U64) (value : U64) (st : State) : + Result betree_be_tree_t + := + betree_be_tree_apply_back self key (betree_message_t.Insert value) st + +/- [betree_main::betree::BeTree::{6}::delete] -/ +def betree_be_tree_delete_fwd + (self : betree_be_tree_t) (key : U64) (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + betree_be_tree_apply_fwd self key betree_message_t.Delete st + let _ ← betree_be_tree_apply_back self key betree_message_t.Delete st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::delete] -/ +def betree_be_tree_delete_back + (self : betree_be_tree_t) (key : U64) (st : State) : + Result betree_be_tree_t + := + betree_be_tree_apply_back self key betree_message_t.Delete st + +/- [betree_main::betree::BeTree::{6}::upsert] -/ +def betree_be_tree_upsert_fwd + (self : betree_be_tree_t) (key : U64) (upd : betree_upsert_fun_state_t) + (st : State) : + Result (State × Unit) + := + do + let (st0, _) ← + betree_be_tree_apply_fwd self key (betree_message_t.Upsert upd) st + let _ ← + betree_be_tree_apply_back self key (betree_message_t.Upsert upd) st + Result.ret (st0, ()) + +/- [betree_main::betree::BeTree::{6}::upsert] -/ +def betree_be_tree_upsert_back + (self : betree_be_tree_t) (key : U64) (upd : betree_upsert_fun_state_t) + (st : State) : + Result betree_be_tree_t + := + betree_be_tree_apply_back self key (betree_message_t.Upsert upd) st + +/- [betree_main::betree::BeTree::{6}::lookup] -/ +def betree_be_tree_lookup_fwd + (self : betree_be_tree_t) (key : U64) (st : State) : + Result (State × (Option U64)) + := + betree_node_lookup_fwd self.betree_be_tree_root key st + +/- [betree_main::betree::BeTree::{6}::lookup] -/ +def betree_be_tree_lookup_back + (self : betree_be_tree_t) (key : U64) (st : State) : + Result betree_be_tree_t + := + 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 := + Result.ret () + +/- Unit test for [betree_main::main] -/ +#assert (main_fwd == .ret ()) + diff --git a/tests/lean/BetreeMain/Opaque.lean b/tests/lean/BetreeMain/Opaque.lean new file mode 100644 index 00000000..c8226d4e --- /dev/null +++ b/tests/lean/BetreeMain/Opaque.lean @@ -0,0 +1,31 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: opaque function definitions +import Base +import BetreeMain.Types +open Primitives + +structure OpaqueDefs where + + /- [betree_main::betree_utils::load_internal_node] -/ + betree_utils_load_internal_node_fwd + : + U64 -> State -> Result (State × (betree_list_t (U64 × betree_message_t))) + + /- [betree_main::betree_utils::store_internal_node] -/ + betree_utils_store_internal_node_fwd + : + U64 -> betree_list_t (U64 × betree_message_t) -> State -> Result (State × + Unit) + + /- [betree_main::betree_utils::load_leaf_node] -/ + betree_utils_load_leaf_node_fwd + : U64 -> State -> Result (State × (betree_list_t (U64 × U64))) + + /- [betree_main::betree_utils::store_leaf_node] -/ + betree_utils_store_leaf_node_fwd + : U64 -> betree_list_t (U64 × U64) -> State -> Result (State × Unit) + + /- [core::option::Option::{0}::unwrap] -/ + core_option_option_unwrap_fwd + (T : Type) : Option T -> State -> Result (State × T) + diff --git a/tests/lean/BetreeMain/Types.lean b/tests/lean/BetreeMain/Types.lean new file mode 100644 index 00000000..4875a8ba --- /dev/null +++ b/tests/lean/BetreeMain/Types.lean @@ -0,0 +1,62 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: type definitions +import Base +open Primitives + +/- [betree_main::betree::List] -/ +inductive betree_list_t (T : Type) := +| Cons : T -> betree_list_t T -> betree_list_t T +| Nil : betree_list_t T + +/- [betree_main::betree::UpsertFunState] -/ +inductive betree_upsert_fun_state_t := +| Add : U64 -> betree_upsert_fun_state_t +| Sub : U64 -> betree_upsert_fun_state_t + +/- [betree_main::betree::Message] -/ +inductive betree_message_t := +| Insert : U64 -> betree_message_t +| Delete : betree_message_t +| Upsert : betree_upsert_fun_state_t -> betree_message_t + +/- [betree_main::betree::Leaf] -/ +structure betree_leaf_t where + betree_leaf_id : U64 + betree_leaf_size : U64 + +mutual + +/- [betree_main::betree::Node] -/ +inductive betree_node_t := +| Internal : betree_internal_t -> betree_node_t +| Leaf : betree_leaf_t -> betree_node_t + +/- [betree_main::betree::Internal] -/ +inductive betree_internal_t := +| mkbetree_internal_t : + U64 -> + U64 -> + betree_node_t -> + betree_node_t -> + betree_internal_t + +end + +/- [betree_main::betree::Params] -/ +structure betree_params_t where + betree_params_min_flush_size : U64 + betree_params_split_size : U64 + +/- [betree_main::betree::NodeIdCounter] -/ +structure betree_node_id_counter_t where + betree_node_id_counter_next_node_id : U64 + +/- [betree_main::betree::BeTree] -/ +structure betree_be_tree_t where + betree_be_tree_params : betree_params_t + betree_be_tree_node_id_cnt : betree_node_id_counter_t + betree_be_tree_root : betree_node_t + +/- The state type used in the state-error monad -/ +axiom State : Type + -- cgit v1.2.3 From b643bd00747e75d69b6066c55a1798b61277c4b6 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 4 Jul 2023 18:09:36 +0200 Subject: Regenerate the Lean test files --- tests/lean/BetreeMain/ExternalFuns.lean | 9 ++ tests/lean/BetreeMain/Funs.lean | 147 ++++++++++++++++---------------- tests/lean/BetreeMain/Opaque.lean | 16 ++-- tests/lean/BetreeMain/Types.lean | 24 +++--- 4 files changed, 105 insertions(+), 91 deletions(-) create mode 100644 tests/lean/BetreeMain/ExternalFuns.lean (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/ExternalFuns.lean b/tests/lean/BetreeMain/ExternalFuns.lean new file mode 100644 index 00000000..59beb514 --- /dev/null +++ b/tests/lean/BetreeMain/ExternalFuns.lean @@ -0,0 +1,9 @@ +import Base +import BetreeMain.Types +import BetreeMain.Opaque + +namespace BetreeMain + +def opaque_defs : OpaqueDefs := by sorry + +end BetreeMain diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index fb48b3a6..2eb7fa1f 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -5,6 +5,8 @@ import BetreeMain.Types import BetreeMain.ExternalFuns open Primitives +namespace BetreeMain + /- [betree_main::betree::load_internal_node] -/ def betree_load_internal_node_fwd (id : U64) (st : State) : @@ -75,13 +77,13 @@ 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 (prev : Option U64) (st : betree_upsert_fun_state_t) : Result U64 := - match h: prev with + match prev with | Option.none => - match h: st with + match st with | betree_upsert_fun_state_t.Add v => Result.ret v | betree_upsert_fun_state_t.Sub i => Result.ret (U64.ofInt 0 (by intlit)) | Option.some prev0 => - match h: st with + match st with | betree_upsert_fun_state_t.Add v => do let margin ← core_num_u64_max_c - prev0 @@ -96,7 +98,7 @@ def betree_upsert_update_fwd /- [betree_main::betree::List::{1}::len] -/ divergent def betree_list_len_fwd (T : Type) (self : betree_list_t T) : Result U64 := - match h: self with + match self with | betree_list_t.Cons t tl => do let i ← betree_list_len_fwd T tl @@ -111,7 +113,7 @@ divergent def betree_list_split_at_fwd if n = (U64.ofInt 0 (by intlit)) then Result.ret (betree_list_t.Nil, self) else - match h: self with + match self with | betree_list_t.Cons hd tl => do let i ← n - (U64.ofInt 1 (by intlit)) @@ -131,7 +133,7 @@ def betree_list_push_front_fwd_back /- [betree_main::betree::List::{1}::pop_front] -/ def betree_list_pop_front_fwd (T : Type) (self : betree_list_t T) : Result T := let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil - match h: ls with + match ls with | betree_list_t.Cons x tl => Result.ret x | betree_list_t.Nil => Result.fail Error.panic @@ -139,20 +141,20 @@ def betree_list_pop_front_fwd (T : Type) (self : betree_list_t T) : Result T := def betree_list_pop_front_back (T : Type) (self : betree_list_t T) : Result (betree_list_t T) := let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil - match h: ls with + match ls with | betree_list_t.Cons x tl => Result.ret tl | betree_list_t.Nil => Result.fail Error.panic /- [betree_main::betree::List::{1}::hd] -/ def betree_list_hd_fwd (T : Type) (self : betree_list_t T) : Result T := - match h: self with + match self with | betree_list_t.Cons hd l => Result.ret hd | betree_list_t.Nil => Result.fail Error.panic /- [betree_main::betree::List::{2}::head_has_key] -/ def betree_list_head_has_key_fwd (T : Type) (self : betree_list_t (U64 × T)) (key : U64) : Result Bool := - match h: self with + match self with | betree_list_t.Cons hd l => let (i, _) := hd Result.ret (i = key) | betree_list_t.Nil => Result.ret false @@ -162,7 +164,7 @@ divergent def betree_list_partition_at_pivot_fwd (T : Type) (self : betree_list_t (U64 × T)) (pivot : U64) : Result ((betree_list_t (U64 × T)) × (betree_list_t (U64 × T))) := - match h: self with + match self with | betree_list_t.Cons hd tl => let (i, t) := hd if i >= pivot @@ -204,7 +206,7 @@ def betree_leaf_split_fwd betree_leaf_id := id1, betree_leaf_size := params.betree_params_split_size } - Result.ret (st1, mkbetree_internal_t self.betree_leaf_id pivot n n0) + Result.ret (st1, betree_internal_t.mk self.betree_leaf_id pivot n n0) /- [betree_main::betree::Leaf::{3}::split] -/ def betree_leaf_split_back @@ -229,7 +231,7 @@ def betree_leaf_split_back /- [betree_main::betree::Node::{5}::lookup_in_bindings] -/ divergent def betree_node_lookup_in_bindings_fwd (key : U64) (bindings : betree_list_t (U64 × U64)) : Result (Option U64) := - match h: bindings with + match bindings with | betree_list_t.Cons hd tl => let (i, i0) := hd if i = key @@ -245,7 +247,7 @@ divergent def betree_node_lookup_first_message_for_key_fwd (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := - match h: msgs with + match msgs with | betree_list_t.Cons x next_msgs => let (i, m) := x if i >= key @@ -259,7 +261,7 @@ divergent def betree_node_lookup_first_message_for_key_back (ret0 : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := - match h: msgs with + match msgs with | betree_list_t.Cons x next_msgs => let (i, m) := x if i >= key @@ -284,7 +286,7 @@ divergent def betree_node_apply_upserts_fwd do let msg ← betree_list_pop_front_fwd (U64 × betree_message_t) msgs let (_, m) := msg - match h: m with + match m with | betree_message_t.Insert i => Result.fail Error.panic | betree_message_t.Delete => Result.fail Error.panic | betree_message_t.Upsert s => @@ -314,7 +316,7 @@ divergent def betree_node_apply_upserts_back do let msg ← betree_list_pop_front_fwd (U64 × betree_message_t) msgs let (_, m) := msg - match h: m with + match m with | betree_message_t.Insert i => Result.fail Error.panic | betree_message_t.Delete => Result.fail Error.panic | betree_message_t.Upsert s => @@ -334,27 +336,27 @@ mutual divergent def betree_node_lookup_fwd (self : betree_node_t) (key : U64) (st : State) : Result (State × (Option U64)) := - match h: self with + match self with | betree_node_t.Internal node => do - let (mkbetree_internal_t i i0 n n0) := node + 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 - match h: pending with + match pending with | betree_list_t.Cons p l => let (k, msg) := p if k != key then do let (st1, opt) ← - betree_internal_lookup_in_children_fwd (mkbetree_internal_t i i0 + betree_internal_lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let _ ← betree_node_lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, msg) l) Result.ret (st1, opt) else - match h: msg with + match msg with | betree_message_t.Insert v => do let _ ← @@ -370,15 +372,15 @@ mutual divergent def betree_node_lookup_fwd | betree_message_t.Upsert ufs => do let (st1, v) ← - betree_internal_lookup_in_children_fwd (mkbetree_internal_t i + betree_internal_lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let (st2, v0) ← betree_node_apply_upserts_fwd (betree_list_t.Cons (k, betree_message_t.Upsert ufs) l) v key st1 let node0 ← - betree_internal_lookup_in_children_back (mkbetree_internal_t i + betree_internal_lookup_in_children_back (betree_internal_t.mk i i0 n n0) key st0 - let (mkbetree_internal_t i1 _ _ _) := node0 + let ⟨ i1, _, _, _ ⟩ := node0 let pending0 ← betree_node_apply_upserts_back (betree_list_t.Cons (k, betree_message_t.Upsert ufs) l) v key st1 @@ -389,7 +391,7 @@ mutual divergent def betree_node_lookup_fwd | betree_list_t.Nil => do let (st1, opt) ← - betree_internal_lookup_in_children_fwd (mkbetree_internal_t i i0 n + betree_internal_lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let _ ← betree_node_lookup_first_message_for_key_back key msgs @@ -404,13 +406,13 @@ mutual divergent def betree_node_lookup_fwd /- [betree_main::betree::Node::{5}::lookup] -/ divergent def betree_node_lookup_back (self : betree_node_t) (key : U64) (st : State) : Result betree_node_t := - match h: self with + match self with | betree_node_t.Internal node => do - let (mkbetree_internal_t i i0 n n0) := node + 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 - match h: pending with + match pending with | betree_list_t.Cons p l => let (k, msg) := p if k != key @@ -420,44 +422,44 @@ divergent def betree_node_lookup_back betree_node_lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, msg) l) let node0 ← - betree_internal_lookup_in_children_back (mkbetree_internal_t i i0 - n n0) key st0 + betree_internal_lookup_in_children_back (betree_internal_t.mk i + i0 n n0) key st0 Result.ret (betree_node_t.Internal node0) else - match h: msg with + match msg with | betree_message_t.Insert v => do let _ ← betree_node_lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, betree_message_t.Insert v) l) - Result.ret (betree_node_t.Internal (mkbetree_internal_t i i0 n + Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0)) | betree_message_t.Delete => do let _ ← betree_node_lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, betree_message_t.Delete) l) - Result.ret (betree_node_t.Internal (mkbetree_internal_t i i0 n + Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0)) | betree_message_t.Upsert ufs => do let (st1, v) ← - betree_internal_lookup_in_children_fwd (mkbetree_internal_t i + betree_internal_lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let (st2, _) ← betree_node_apply_upserts_fwd (betree_list_t.Cons (k, betree_message_t.Upsert ufs) l) v key st1 let node0 ← - betree_internal_lookup_in_children_back (mkbetree_internal_t i + betree_internal_lookup_in_children_back (betree_internal_t.mk i i0 n n0) key st0 - let (mkbetree_internal_t i1 i2 n1 n2) := node0 + let ⟨ i1, i2, n1, n2 ⟩ := node0 let pending0 ← betree_node_apply_upserts_back (betree_list_t.Cons (k, betree_message_t.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 - Result.ret (betree_node_t.Internal (mkbetree_internal_t i1 i2 n1 + Result.ret (betree_node_t.Internal (betree_internal_t.mk i1 i2 n1 n2)) | betree_list_t.Nil => do @@ -465,8 +467,8 @@ divergent def betree_node_lookup_back betree_node_lookup_first_message_for_key_back key msgs betree_list_t.Nil let node0 ← - betree_internal_lookup_in_children_back (mkbetree_internal_t i i0 n - n0) key st0 + betree_internal_lookup_in_children_back (betree_internal_t.mk i i0 + n n0) key st0 Result.ret (betree_node_t.Internal node0) | betree_node_t.Leaf node => do @@ -479,7 +481,7 @@ divergent def betree_internal_lookup_in_children_fwd (self : betree_internal_t) (key : U64) (st : State) : Result (State × (Option U64)) := - let (mkbetree_internal_t _ i n n0) := self + let ⟨ _, i, n, n0 ⟩ := self if key < i then betree_node_lookup_fwd n key st else betree_node_lookup_fwd n0 key st @@ -489,16 +491,16 @@ divergent def betree_internal_lookup_in_children_back (self : betree_internal_t) (key : U64) (st : State) : Result betree_internal_t := - let (mkbetree_internal_t i i0 n n0) := self + let ⟨ i, i0, n, n0 ⟩ := self if key < i0 then do let n1 ← betree_node_lookup_back n key st - Result.ret (mkbetree_internal_t i i0 n1 n0) + Result.ret (betree_internal_t.mk i i0 n1 n0) else do let n1 ← betree_node_lookup_back n0 key st - Result.ret (mkbetree_internal_t i i0 n n1) + Result.ret (betree_internal_t.mk i i0 n n1) end @@ -507,7 +509,7 @@ divergent def betree_node_lookup_mut_in_bindings_fwd (key : U64) (bindings : betree_list_t (U64 × U64)) : Result (betree_list_t (U64 × U64)) := - match h: bindings with + match bindings with | betree_list_t.Cons hd tl => let (i, i0) := hd if i >= key @@ -521,7 +523,7 @@ divergent def betree_node_lookup_mut_in_bindings_back (ret0 : betree_list_t (U64 × U64)) : Result (betree_list_t (U64 × U64)) := - match h: bindings with + match bindings with | betree_list_t.Cons hd tl => let (i, i0) := hd if i >= key @@ -545,7 +547,7 @@ def betree_node_apply_to_leaf_fwd_back then do let hd ← betree_list_pop_front_fwd (U64 × U64) bindings0 - match h: new_msg with + match new_msg with | betree_message_t.Insert v => do let bindings1 ← betree_list_pop_front_back (U64 × U64) bindings0 @@ -565,7 +567,7 @@ def betree_node_apply_to_leaf_fwd_back betree_list_push_front_fwd_back (U64 × U64) bindings1 (key, v) betree_node_lookup_mut_in_bindings_back key bindings bindings2 else - match h: new_msg with + match new_msg with | betree_message_t.Insert v => do let bindings1 ← @@ -586,7 +588,7 @@ divergent def betree_node_apply_messages_to_leaf_fwd_back (new_msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × U64)) := - match h: new_msgs with + match new_msgs with | betree_list_t.Cons new_msg new_msgs_tl => do let (i, m) := new_msg @@ -599,7 +601,7 @@ divergent def betree_node_filter_messages_for_key_fwd_back (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := - match h: msgs with + match msgs with | betree_list_t.Cons p l => let (k, m) := p if k = key @@ -617,7 +619,7 @@ divergent def betree_node_lookup_first_message_after_key_fwd (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := - match h: msgs with + match msgs with | betree_list_t.Cons p next_msgs => let (k, m) := p if k = key @@ -631,7 +633,7 @@ divergent def betree_node_lookup_first_message_after_key_back (ret0 : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := - match h: msgs with + match msgs with | betree_list_t.Cons p next_msgs => let (k, m) := p if k = key @@ -654,7 +656,7 @@ def betree_node_apply_to_internal_fwd_back let b ← betree_list_head_has_key_fwd betree_message_t msgs0 key if b then - match h: new_msg with + match new_msg with | betree_message_t.Insert i => do let msgs1 ← betree_node_filter_messages_for_key_fwd_back key msgs0 @@ -673,7 +675,7 @@ def betree_node_apply_to_internal_fwd_back do let p ← betree_list_hd_fwd (U64 × betree_message_t) msgs0 let (_, m) := p - match h: m with + match m with | betree_message_t.Insert prev => do let v ← betree_upsert_update_fwd (Option.some prev) s @@ -715,7 +717,7 @@ divergent def betree_node_apply_messages_to_internal_fwd_back (new_msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := - match h: new_msgs with + match new_msgs with | betree_list_t.Cons new_msg new_msgs_tl => do let (i, m) := new_msg @@ -730,10 +732,10 @@ mutual divergent def betree_node_apply_messages_fwd (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : Result (State × Unit) := - match h: self with + match self with | betree_node_t.Internal node => do - let (mkbetree_internal_t i i0 n n0) := node + 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 @@ -742,12 +744,12 @@ mutual divergent def betree_node_apply_messages_fwd then do let (st1, content1) ← - betree_internal_flush_fwd (mkbetree_internal_t i i0 n n0) params + betree_internal_flush_fwd (betree_internal_t.mk i i0 n n0) params node_id_cnt content0 st0 let (node0, _) ← - betree_internal_flush_back (mkbetree_internal_t i i0 n n0) params + betree_internal_flush_back (betree_internal_t.mk i i0 n n0) params node_id_cnt content0 st0 - let (mkbetree_internal_t i1 _ _ _) := node0 + let ⟨ i1, _, _, _ ⟩ := node0 let (st2, _) ← betree_store_internal_node_fwd i1 content1 st1 Result.ret (st2, ()) else @@ -782,10 +784,10 @@ divergent def betree_node_apply_messages_back (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : Result (betree_node_t × betree_node_id_counter_t) := - match h: self with + match self with | betree_node_t.Internal node => do - let (mkbetree_internal_t i i0 n n0) := node + 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 @@ -794,19 +796,19 @@ divergent def betree_node_apply_messages_back then do let (st1, content1) ← - betree_internal_flush_fwd (mkbetree_internal_t i i0 n n0) params + betree_internal_flush_fwd (betree_internal_t.mk i i0 n n0) params node_id_cnt content0 st0 let (node0, node_id_cnt0) ← - betree_internal_flush_back (mkbetree_internal_t i i0 n n0) params + betree_internal_flush_back (betree_internal_t.mk i i0 n n0) params node_id_cnt content0 st0 - let (mkbetree_internal_t i1 i2 n1 n2) := node0 + let ⟨ i1, i2, n1, n2 ⟩ := node0 let _ ← betree_store_internal_node_fwd i1 content1 st1 - Result.ret (betree_node_t.Internal (mkbetree_internal_t i1 i2 n1 n2), - node_id_cnt0) + Result.ret (betree_node_t.Internal (betree_internal_t.mk i1 i2 n1 + n2), node_id_cnt0) else do let _ ← betree_store_internal_node_fwd i content0 st0 - Result.ret (betree_node_t.Internal (mkbetree_internal_t i i0 n n0), + Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0), node_id_cnt) | betree_node_t.Leaf node => do @@ -839,7 +841,7 @@ divergent def betree_internal_flush_fwd Result (State × (betree_list_t (U64 × betree_message_t))) := do - let (mkbetree_internal_t _ i n n0) := self + let ⟨ _, i, n, n0 ⟩ := self let p ← betree_list_partition_at_pivot_fwd betree_message_t content i let (msgs_left, msgs_right) := p let len_left ← betree_list_len_fwd (U64 × betree_message_t) msgs_left @@ -879,7 +881,7 @@ divergent def betree_internal_flush_back Result (betree_internal_t × betree_node_id_counter_t) := do - let (mkbetree_internal_t i i0 n n0) := self + let ⟨ i, i0, n, n0 ⟩ := self let p ← betree_list_partition_at_pivot_fwd betree_message_t content i0 let (msgs_left, msgs_right) := p let len_left ← betree_list_len_fwd (U64 × betree_message_t) msgs_left @@ -898,13 +900,13 @@ divergent def betree_internal_flush_back let (n2, node_id_cnt1) ← betree_node_apply_messages_back n0 params node_id_cnt0 msgs_right st0 - Result.ret (mkbetree_internal_t i i0 n1 n2, node_id_cnt1) - else Result.ret (mkbetree_internal_t i i0 n1 n0, node_id_cnt0) + Result.ret (betree_internal_t.mk i i0 n1 n2, node_id_cnt1) + else Result.ret (betree_internal_t.mk i i0 n1 n0, node_id_cnt0) else do let (n1, node_id_cnt0) ← betree_node_apply_messages_back n0 params node_id_cnt msgs_right st - Result.ret (mkbetree_internal_t i i0 n n1, node_id_cnt0) + Result.ret (betree_internal_t.mk i i0 n n1, node_id_cnt0) end @@ -1069,3 +1071,4 @@ def main_fwd : Result Unit := /- Unit test for [betree_main::main] -/ #assert (main_fwd == .ret ()) +end BetreeMain diff --git a/tests/lean/BetreeMain/Opaque.lean b/tests/lean/BetreeMain/Opaque.lean index c8226d4e..d043186b 100644 --- a/tests/lean/BetreeMain/Opaque.lean +++ b/tests/lean/BetreeMain/Opaque.lean @@ -4,28 +4,32 @@ import Base import BetreeMain.Types open Primitives +namespace BetreeMain + structure OpaqueDefs where /- [betree_main::betree_utils::load_internal_node] -/ betree_utils_load_internal_node_fwd : - U64 -> State -> Result (State × (betree_list_t (U64 × betree_message_t))) + U64 → State → Result (State × (betree_list_t (U64 × + betree_message_t))) /- [betree_main::betree_utils::store_internal_node] -/ betree_utils_store_internal_node_fwd : - U64 -> betree_list_t (U64 × betree_message_t) -> State -> Result (State × - Unit) + U64 → betree_list_t (U64 × betree_message_t) → State → Result (State + × Unit) /- [betree_main::betree_utils::load_leaf_node] -/ betree_utils_load_leaf_node_fwd - : U64 -> State -> Result (State × (betree_list_t (U64 × U64))) + : U64 → State → Result (State × (betree_list_t (U64 × U64))) /- [betree_main::betree_utils::store_leaf_node] -/ betree_utils_store_leaf_node_fwd - : U64 -> betree_list_t (U64 × U64) -> State -> Result (State × Unit) + : U64 → betree_list_t (U64 × U64) → State → Result (State × Unit) /- [core::option::Option::{0}::unwrap] -/ core_option_option_unwrap_fwd - (T : Type) : Option T -> State -> Result (State × T) + (T : Type) : Option T → State → Result (State × T) +end BetreeMain diff --git a/tests/lean/BetreeMain/Types.lean b/tests/lean/BetreeMain/Types.lean index 4875a8ba..cfed6a28 100644 --- a/tests/lean/BetreeMain/Types.lean +++ b/tests/lean/BetreeMain/Types.lean @@ -3,21 +3,23 @@ import Base open Primitives +namespace BetreeMain + /- [betree_main::betree::List] -/ inductive betree_list_t (T : Type) := -| Cons : T -> betree_list_t T -> betree_list_t T +| Cons : T → betree_list_t T → betree_list_t T | Nil : betree_list_t T /- [betree_main::betree::UpsertFunState] -/ inductive betree_upsert_fun_state_t := -| Add : U64 -> betree_upsert_fun_state_t -| Sub : U64 -> betree_upsert_fun_state_t +| Add : U64 → betree_upsert_fun_state_t +| Sub : U64 → betree_upsert_fun_state_t /- [betree_main::betree::Message] -/ inductive betree_message_t := -| Insert : U64 -> betree_message_t +| Insert : U64 → betree_message_t | Delete : betree_message_t -| Upsert : betree_upsert_fun_state_t -> betree_message_t +| Upsert : betree_upsert_fun_state_t → betree_message_t /- [betree_main::betree::Leaf] -/ structure betree_leaf_t where @@ -28,17 +30,12 @@ mutual /- [betree_main::betree::Node] -/ inductive betree_node_t := -| Internal : betree_internal_t -> betree_node_t -| Leaf : betree_leaf_t -> betree_node_t +| Internal : betree_internal_t → betree_node_t +| Leaf : betree_leaf_t → betree_node_t /- [betree_main::betree::Internal] -/ inductive betree_internal_t := -| mkbetree_internal_t : - U64 -> - U64 -> - betree_node_t -> - betree_node_t -> - betree_internal_t +| mk : U64 → U64 → betree_node_t → betree_node_t → betree_internal_t end @@ -60,3 +57,4 @@ structure betree_be_tree_t where /- The state type used in the state-error monad -/ axiom State : Type +end BetreeMain -- cgit v1.2.3 From 0a0445c72e005c328b4764f5fb0f8f38e7a55d60 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 5 Jul 2023 14:52:23 +0200 Subject: Start using namespaces in the Lean backend --- tests/lean/BetreeMain/ExternalFuns.lean | 9 - tests/lean/BetreeMain/Funs.lean | 498 +++++++++++------------ tests/lean/BetreeMain/FunsExternal.lean | 35 ++ tests/lean/BetreeMain/FunsExternal_Template.lean | 31 ++ tests/lean/BetreeMain/Opaque.lean | 35 -- tests/lean/BetreeMain/Types.lean | 5 +- 6 files changed, 316 insertions(+), 297 deletions(-) delete mode 100644 tests/lean/BetreeMain/ExternalFuns.lean create mode 100644 tests/lean/BetreeMain/FunsExternal.lean create mode 100644 tests/lean/BetreeMain/FunsExternal_Template.lean delete mode 100644 tests/lean/BetreeMain/Opaque.lean (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/ExternalFuns.lean b/tests/lean/BetreeMain/ExternalFuns.lean deleted file mode 100644 index 59beb514..00000000 --- a/tests/lean/BetreeMain/ExternalFuns.lean +++ /dev/null @@ -1,9 +0,0 @@ -import Base -import BetreeMain.Types -import BetreeMain.Opaque - -namespace BetreeMain - -def opaque_defs : OpaqueDefs := by sorry - -end BetreeMain diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index 2eb7fa1f..78e14146 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -2,59 +2,57 @@ -- [betree_main]: function definitions import Base import BetreeMain.Types -import BetreeMain.ExternalFuns +import BetreeMain.FunsExternal open Primitives - -namespace BetreeMain +namespace betree_main /- [betree_main::betree::load_internal_node] -/ -def betree_load_internal_node_fwd +def betree.load_internal_node_fwd (id : U64) (st : State) : Result (State × (betree_list_t (U64 × betree_message_t))) := - opaque_defs.betree_utils_load_internal_node_fwd id st + betree_utils.load_internal_node_fwd id st /- [betree_main::betree::store_internal_node] -/ -def betree_store_internal_node_fwd +def betree.store_internal_node_fwd (id : U64) (content : betree_list_t (U64 × betree_message_t)) (st : State) : Result (State × Unit) := do - let (st0, _) ← - opaque_defs.betree_utils_store_internal_node_fwd id content st + let (st0, _) ← betree_utils.store_internal_node_fwd id content st Result.ret (st0, ()) /- [betree_main::betree::load_leaf_node] -/ -def betree_load_leaf_node_fwd +def betree.load_leaf_node_fwd (id : U64) (st : State) : Result (State × (betree_list_t (U64 × U64))) := - opaque_defs.betree_utils_load_leaf_node_fwd id st + betree_utils.load_leaf_node_fwd id st /- [betree_main::betree::store_leaf_node] -/ -def betree_store_leaf_node_fwd +def betree.store_leaf_node_fwd (id : U64) (content : betree_list_t (U64 × U64)) (st : State) : Result (State × Unit) := do - let (st0, _) ← opaque_defs.betree_utils_store_leaf_node_fwd id content st + let (st0, _) ← betree_utils.store_leaf_node_fwd id content st Result.ret (st0, ()) /- [betree_main::betree::fresh_node_id] -/ -def betree_fresh_node_id_fwd (counter : U64) : Result U64 := +def betree.fresh_node_id_fwd (counter : U64) : Result U64 := do let _ ← counter + (U64.ofInt 1 (by intlit)) Result.ret counter /- [betree_main::betree::fresh_node_id] -/ -def betree_fresh_node_id_back (counter : U64) : Result U64 := +def betree.fresh_node_id_back (counter : U64) : Result U64 := counter + (U64.ofInt 1 (by intlit)) /- [betree_main::betree::NodeIdCounter::{0}::new] -/ -def betree_node_id_counter_new_fwd : Result betree_node_id_counter_t := +def betree.NodeIdCounter.new_fwd : Result betree_node_id_counter_t := Result.ret { betree_node_id_counter_next_node_id := (U64.ofInt 0 (by intlit)) } /- [betree_main::betree::NodeIdCounter::{0}::fresh_id] -/ -def betree_node_id_counter_fresh_id_fwd +def betree.NodeIdCounter.fresh_id_fwd (self : betree_node_id_counter_t) : Result U64 := do let _ ← self.betree_node_id_counter_next_node_id + @@ -62,7 +60,7 @@ def betree_node_id_counter_fresh_id_fwd Result.ret self.betree_node_id_counter_next_node_id /- [betree_main::betree::NodeIdCounter::{0}::fresh_id] -/ -def betree_node_id_counter_fresh_id_back +def betree.NodeIdCounter.fresh_id_back (self : betree_node_id_counter_t) : Result betree_node_id_counter_t := do let i ← self.betree_node_id_counter_next_node_id + @@ -75,7 +73,7 @@ def core_num_u64_max_body : Result U64 := 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 +def betree.upsert_update_fwd (prev : Option U64) (st : betree_upsert_fun_state_t) : Result U64 := match prev with | Option.none => @@ -96,17 +94,17 @@ def betree_upsert_update_fwd else Result.ret (U64.ofInt 0 (by intlit)) /- [betree_main::betree::List::{1}::len] -/ -divergent def betree_list_len_fwd +divergent def betree.List.len_fwd (T : Type) (self : betree_list_t T) : Result U64 := match self with | betree_list_t.Cons t tl => do - let i ← betree_list_len_fwd T tl + let i ← betree.List.len_fwd T tl (U64.ofInt 1 (by intlit)) + i | betree_list_t.Nil => Result.ret (U64.ofInt 0 (by intlit)) /- [betree_main::betree::List::{1}::split_at] -/ -divergent def betree_list_split_at_fwd +divergent def betree.List.split_at_fwd (T : Type) (self : betree_list_t T) (n : U64) : Result ((betree_list_t T) × (betree_list_t T)) := @@ -117,28 +115,28 @@ divergent def betree_list_split_at_fwd | betree_list_t.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_fwd T tl i let (ls0, ls1) := p let l := ls0 Result.ret (betree_list_t.Cons hd l, ls1) | betree_list_t.Nil => Result.fail Error.panic /- [betree_main::betree::List::{1}::push_front] -/ -def betree_list_push_front_fwd_back +def betree.List.push_front_fwd_back (T : Type) (self : betree_list_t T) (x : T) : Result (betree_list_t T) := let tl := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil let l := tl Result.ret (betree_list_t.Cons x l) /- [betree_main::betree::List::{1}::pop_front] -/ -def betree_list_pop_front_fwd (T : Type) (self : betree_list_t T) : Result T := +def betree.List.pop_front_fwd (T : Type) (self : betree_list_t T) : Result T := let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil match ls with | betree_list_t.Cons x tl => Result.ret x | betree_list_t.Nil => Result.fail Error.panic /- [betree_main::betree::List::{1}::pop_front] -/ -def betree_list_pop_front_back +def betree.List.pop_front_back (T : Type) (self : betree_list_t T) : Result (betree_list_t T) := let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil match ls with @@ -146,13 +144,13 @@ def betree_list_pop_front_back | betree_list_t.Nil => Result.fail Error.panic /- [betree_main::betree::List::{1}::hd] -/ -def betree_list_hd_fwd (T : Type) (self : betree_list_t T) : Result T := +def betree.List.hd_fwd (T : Type) (self : betree_list_t T) : Result T := match self with | betree_list_t.Cons hd l => Result.ret hd | betree_list_t.Nil => Result.fail Error.panic /- [betree_main::betree::List::{2}::head_has_key] -/ -def betree_list_head_has_key_fwd +def betree.List.head_has_key_fwd (T : Type) (self : betree_list_t (U64 × T)) (key : U64) : Result Bool := match self with | betree_list_t.Cons hd l => let (i, _) := hd @@ -160,7 +158,7 @@ def betree_list_head_has_key_fwd | betree_list_t.Nil => Result.ret false /- [betree_main::betree::List::{2}::partition_at_pivot] -/ -divergent def betree_list_partition_at_pivot_fwd +divergent def betree.List.partition_at_pivot_fwd (T : Type) (self : betree_list_t (U64 × T)) (pivot : U64) : Result ((betree_list_t (U64 × T)) × (betree_list_t (U64 × T))) := @@ -171,14 +169,14 @@ divergent def betree_list_partition_at_pivot_fwd then Result.ret (betree_list_t.Nil, betree_list_t.Cons (i, t) tl) else do - let p ← betree_list_partition_at_pivot_fwd T tl pivot + let p ← betree.List.partition_at_pivot_fwd T tl pivot let (ls0, ls1) := p let l := ls0 Result.ret (betree_list_t.Cons (i, t) l, ls1) | betree_list_t.Nil => Result.ret (betree_list_t.Nil, betree_list_t.Nil) /- [betree_main::betree::Leaf::{3}::split] -/ -def betree_leaf_split_fwd +def betree.Leaf.split_fwd (self : betree_leaf_t) (content : betree_list_t (U64 × U64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (st : State) : @@ -186,16 +184,16 @@ def betree_leaf_split_fwd := do let p ← - betree_list_split_at_fwd (U64 × U64) content + betree.List.split_at_fwd (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_fwd (U64 × U64) content1 let (pivot, _) := p0 - let id0 ← betree_node_id_counter_fresh_id_fwd node_id_cnt - let node_id_cnt0 ← betree_node_id_counter_fresh_id_back node_id_cnt - let id1 ← betree_node_id_counter_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 id0 ← betree.NodeIdCounter.fresh_id_fwd 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 n := betree_node_t.Leaf { betree_leaf_id := id0, @@ -209,7 +207,7 @@ def betree_leaf_split_fwd Result.ret (st1, betree_internal_t.mk self.betree_leaf_id pivot n n0) /- [betree_main::betree::Leaf::{3}::split] -/ -def betree_leaf_split_back +def betree.Leaf.split_back (self : betree_leaf_t) (content : betree_list_t (U64 × U64)) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (st : State) : @@ -217,19 +215,19 @@ def betree_leaf_split_back := do let p ← - betree_list_split_at_fwd (U64 × U64) content + betree.List.split_at_fwd (U64 × U64) content params.betree_params_split_size let (content0, content1) := p - let _ ← betree_list_hd_fwd (U64 × U64) content1 - let id0 ← betree_node_id_counter_fresh_id_fwd node_id_cnt - let node_id_cnt0 ← betree_node_id_counter_fresh_id_back node_id_cnt - let id1 ← betree_node_id_counter_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 - betree_node_id_counter_fresh_id_back node_id_cnt0 + let _ ← betree.List.hd_fwd (U64 × U64) content1 + let id0 ← betree.NodeIdCounter.fresh_id_fwd 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 + betree.NodeIdCounter.fresh_id_back node_id_cnt0 /- [betree_main::betree::Node::{5}::lookup_in_bindings] -/ -divergent def betree_node_lookup_in_bindings_fwd +divergent def betree.Node.lookup_in_bindings_fwd (key : U64) (bindings : betree_list_t (U64 × U64)) : Result (Option U64) := match bindings with | betree_list_t.Cons hd tl => @@ -239,11 +237,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_fwd key tl | betree_list_t.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 +divergent def betree.Node.lookup_first_message_for_key_fwd (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := @@ -252,11 +250,11 @@ divergent def betree_node_lookup_first_message_for_key_fwd let (i, m) := x if i >= key then Result.ret (betree_list_t.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_fwd key next_msgs | betree_list_t.Nil => Result.ret betree_list_t.Nil /- [betree_main::betree::Node::{5}::lookup_first_message_for_key] -/ -divergent def betree_node_lookup_first_message_for_key_back +divergent def betree.Node.lookup_first_message_for_key_back (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) (ret0 : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) @@ -269,70 +267,70 @@ divergent def betree_node_lookup_first_message_for_key_back else do let next_msgs0 ← - betree_node_lookup_first_message_for_key_back key next_msgs ret0 + betree.Node.lookup_first_message_for_key_back key next_msgs ret0 Result.ret (betree_list_t.Cons (i, m) next_msgs0) | betree_list_t.Nil => Result.ret ret0 /- [betree_main::betree::Node::{5}::apply_upserts] -/ -divergent def betree_node_apply_upserts_fwd +divergent def betree.Node.apply_upserts_fwd (msgs : betree_list_t (U64 × betree_message_t)) (prev : Option U64) (key : U64) (st : State) : Result (State × U64) := do - let b ← betree_list_head_has_key_fwd betree_message_t msgs key + let b ← betree.List.head_has_key_fwd betree_message_t msgs key if b then do - let msg ← betree_list_pop_front_fwd (U64 × betree_message_t) msgs + let msg ← betree.List.pop_front_fwd (U64 × betree_message_t) msgs let (_, m) := msg match m with | betree_message_t.Insert i => Result.fail Error.panic | betree_message_t.Delete => Result.fail Error.panic | betree_message_t.Upsert s => do - let v ← betree_upsert_update_fwd prev s + let v ← betree.upsert_update_fwd prev s let msgs0 ← - betree_list_pop_front_back (U64 × betree_message_t) msgs - betree_node_apply_upserts_fwd msgs0 (Option.some v) key st + betree.List.pop_front_back (U64 × betree_message_t) msgs + betree.Node.apply_upserts_fwd msgs0 (Option.some v) key st else do - let (st0, v) ← opaque_defs.core_option_option_unwrap_fwd U64 prev st + let (st0, v) ← core.option.Option.unwrap_fwd U64 prev st let _ ← - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs (key, + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs (key, betree_message_t.Insert v) Result.ret (st0, v) /- [betree_main::betree::Node::{5}::apply_upserts] -/ -divergent def betree_node_apply_upserts_back +divergent def betree.Node.apply_upserts_back (msgs : betree_list_t (U64 × betree_message_t)) (prev : Option U64) (key : U64) (st : State) : Result (betree_list_t (U64 × betree_message_t)) := do - let b ← betree_list_head_has_key_fwd betree_message_t msgs key + let b ← betree.List.head_has_key_fwd betree_message_t msgs key if b then do - let msg ← betree_list_pop_front_fwd (U64 × betree_message_t) msgs + let msg ← betree.List.pop_front_fwd (U64 × betree_message_t) msgs let (_, m) := msg match m with | betree_message_t.Insert i => Result.fail Error.panic | betree_message_t.Delete => Result.fail Error.panic | betree_message_t.Upsert s => do - let v ← betree_upsert_update_fwd prev s + let v ← betree.upsert_update_fwd prev s let msgs0 ← - betree_list_pop_front_back (U64 × betree_message_t) msgs - betree_node_apply_upserts_back msgs0 (Option.some v) key st + betree.List.pop_front_back (U64 × betree_message_t) msgs + betree.Node.apply_upserts_back msgs0 (Option.some v) key st else do - let (_, v) ← opaque_defs.core_option_option_unwrap_fwd U64 prev st - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs (key, + let (_, v) ← core.option.Option.unwrap_fwd U64 prev st + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs (key, betree_message_t.Insert v) /- [betree_main::betree::Node::{5}::lookup] -/ -mutual divergent def betree_node_lookup_fwd +mutual divergent def betree.Node.lookup_fwd (self : betree_node_t) (key : U64) (st : State) : Result (State × (Option U64)) := @@ -340,8 +338,8 @@ mutual divergent def betree_node_lookup_fwd | betree_node_t.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_fwd i st + let pending ← betree.Node.lookup_first_message_for_key_fwd key msgs match pending with | betree_list_t.Cons p l => let (k, msg) := p @@ -349,10 +347,10 @@ mutual divergent def betree_node_lookup_fwd then do let (st1, opt) ← - betree_internal_lookup_in_children_fwd (betree_internal_t.mk i i0 + betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, msg) l) Result.ret (st1, opt) else @@ -360,58 +358,58 @@ mutual divergent def betree_node_lookup_fwd | betree_message_t.Insert v => do let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, betree_message_t.Insert v) l) Result.ret (st0, Option.some v) | betree_message_t.Delete => do let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, betree_message_t.Delete) l) Result.ret (st0, Option.none) | betree_message_t.Upsert ufs => do let (st1, v) ← - betree_internal_lookup_in_children_fwd (betree_internal_t.mk i + betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let (st2, v0) ← - betree_node_apply_upserts_fwd (betree_list_t.Cons (k, + betree.Node.apply_upserts_fwd (betree_list_t.Cons (k, betree_message_t.Upsert ufs) l) v key st1 let node0 ← - betree_internal_lookup_in_children_back (betree_internal_t.mk i + betree.Internal.lookup_in_children_back (betree_internal_t.mk i i0 n n0) key st0 let ⟨ i1, _, _, _ ⟩ := node0 let pending0 ← - betree_node_apply_upserts_back (betree_list_t.Cons (k, + betree.Node.apply_upserts_back (betree_list_t.Cons (k, betree_message_t.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 + betree.Node.lookup_first_message_for_key_back key msgs pending0 + let (st3, _) ← betree.store_internal_node_fwd i1 msgs0 st2 Result.ret (st3, Option.some v0) | betree_list_t.Nil => do let (st1, opt) ← - betree_internal_lookup_in_children_fwd (betree_internal_t.mk i i0 n + betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs betree_list_t.Nil Result.ret (st1, opt) | betree_node_t.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_fwd node.betree_leaf_id st + let opt ← betree.Node.lookup_in_bindings_fwd key bindings Result.ret (st0, opt) /- [betree_main::betree::Node::{5}::lookup] -/ -divergent def betree_node_lookup_back +divergent def betree.Node.lookup_back (self : betree_node_t) (key : U64) (st : State) : Result betree_node_t := match self with | betree_node_t.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_fwd i st + let pending ← betree.Node.lookup_first_message_for_key_fwd key msgs match pending with | betree_list_t.Cons p l => let (k, msg) := p @@ -419,10 +417,10 @@ divergent def betree_node_lookup_back then do let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, msg) l) let node0 ← - betree_internal_lookup_in_children_back (betree_internal_t.mk i + betree.Internal.lookup_in_children_back (betree_internal_t.mk i i0 n n0) key st0 Result.ret (betree_node_t.Internal node0) else @@ -430,64 +428,64 @@ divergent def betree_node_lookup_back | betree_message_t.Insert v => do let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, betree_message_t.Insert v) l) Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0)) | betree_message_t.Delete => do let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs (betree_list_t.Cons (k, betree_message_t.Delete) l) Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0)) | betree_message_t.Upsert ufs => do let (st1, v) ← - betree_internal_lookup_in_children_fwd (betree_internal_t.mk i + betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i i0 n n0) key st0 let (st2, _) ← - betree_node_apply_upserts_fwd (betree_list_t.Cons (k, + betree.Node.apply_upserts_fwd (betree_list_t.Cons (k, betree_message_t.Upsert ufs) l) v key st1 let node0 ← - betree_internal_lookup_in_children_back (betree_internal_t.mk i + betree.Internal.lookup_in_children_back (betree_internal_t.mk i i0 n n0) key st0 let ⟨ i1, i2, n1, n2 ⟩ := node0 let pending0 ← - betree_node_apply_upserts_back (betree_list_t.Cons (k, + betree.Node.apply_upserts_back (betree_list_t.Cons (k, betree_message_t.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 + betree.Node.lookup_first_message_for_key_back key msgs pending0 + let _ ← betree.store_internal_node_fwd i1 msgs0 st2 Result.ret (betree_node_t.Internal (betree_internal_t.mk i1 i2 n1 n2)) | betree_list_t.Nil => do let _ ← - betree_node_lookup_first_message_for_key_back key msgs + betree.Node.lookup_first_message_for_key_back key msgs betree_list_t.Nil let node0 ← - betree_internal_lookup_in_children_back (betree_internal_t.mk i i0 + betree.Internal.lookup_in_children_back (betree_internal_t.mk i i0 n n0) key st0 Result.ret (betree_node_t.Internal node0) | betree_node_t.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_fwd node.betree_leaf_id st + let _ ← betree.Node.lookup_in_bindings_fwd key bindings Result.ret (betree_node_t.Leaf node) /- [betree_main::betree::Internal::{4}::lookup_in_children] -/ -divergent def betree_internal_lookup_in_children_fwd +divergent def betree.Internal.lookup_in_children_fwd (self : betree_internal_t) (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_fwd n key st + else betree.Node.lookup_fwd n0 key st /- [betree_main::betree::Internal::{4}::lookup_in_children] -/ -divergent def betree_internal_lookup_in_children_back +divergent def betree.Internal.lookup_in_children_back (self : betree_internal_t) (key : U64) (st : State) : Result betree_internal_t := @@ -495,17 +493,17 @@ divergent def betree_internal_lookup_in_children_back if key < i0 then do - let n1 ← betree_node_lookup_back n key st + let n1 ← betree.Node.lookup_back n key st Result.ret (betree_internal_t.mk i i0 n1 n0) else do - let n1 ← betree_node_lookup_back n0 key st + let n1 ← betree.Node.lookup_back n0 key st Result.ret (betree_internal_t.mk i i0 n n1) end /- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ -divergent def betree_node_lookup_mut_in_bindings_fwd +divergent def betree.Node.lookup_mut_in_bindings_fwd (key : U64) (bindings : betree_list_t (U64 × U64)) : Result (betree_list_t (U64 × U64)) := @@ -514,11 +512,11 @@ divergent def betree_node_lookup_mut_in_bindings_fwd let (i, i0) := hd if i >= key then Result.ret (betree_list_t.Cons (i, i0) tl) - else betree_node_lookup_mut_in_bindings_fwd key tl + else betree.Node.lookup_mut_in_bindings_fwd key tl | betree_list_t.Nil => Result.ret betree_list_t.Nil /- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ -divergent def betree_node_lookup_mut_in_bindings_back +divergent def betree.Node.lookup_mut_in_bindings_back (key : U64) (bindings : betree_list_t (U64 × U64)) (ret0 : betree_list_t (U64 × U64)) : Result (betree_list_t (U64 × U64)) @@ -530,60 +528,60 @@ divergent def betree_node_lookup_mut_in_bindings_back then Result.ret ret0 else do - let tl0 ← betree_node_lookup_mut_in_bindings_back key tl ret0 + let tl0 ← betree.Node.lookup_mut_in_bindings_back key tl ret0 Result.ret (betree_list_t.Cons (i, i0) tl0) | betree_list_t.Nil => Result.ret ret0 /- [betree_main::betree::Node::{5}::apply_to_leaf] -/ -def betree_node_apply_to_leaf_fwd_back +def betree.Node.apply_to_leaf_fwd_back (bindings : betree_list_t (U64 × U64)) (key : U64) (new_msg : betree_message_t) : Result (betree_list_t (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_fwd key bindings + let b ← betree.List.head_has_key_fwd U64 bindings0 key if b then do - let hd ← betree_list_pop_front_fwd (U64 × U64) bindings0 + let hd ← betree.List.pop_front_fwd (U64 × U64) bindings0 match new_msg with | betree_message_t.Insert v => do - let bindings1 ← betree_list_pop_front_back (U64 × U64) bindings0 + let bindings1 ← betree.List.pop_front_back (U64 × U64) bindings0 let bindings2 ← - betree_list_push_front_fwd_back (U64 × U64) bindings1 (key, v) - betree_node_lookup_mut_in_bindings_back key bindings bindings2 + betree.List.push_front_fwd_back (U64 × U64) bindings1 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings2 | betree_message_t.Delete => do - let bindings1 ← betree_list_pop_front_back (U64 × U64) bindings0 - betree_node_lookup_mut_in_bindings_back key bindings bindings1 + let bindings1 ← betree.List.pop_front_back (U64 × U64) bindings0 + betree.Node.lookup_mut_in_bindings_back key bindings bindings1 | betree_message_t.Upsert s => do let (_, i) := hd - let v ← betree_upsert_update_fwd (Option.some i) s - let bindings1 ← betree_list_pop_front_back (U64 × U64) bindings0 + let v ← betree.upsert_update_fwd (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_node_lookup_mut_in_bindings_back key bindings bindings2 + betree.List.push_front_fwd_back (U64 × U64) bindings1 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings2 else match new_msg with | betree_message_t.Insert v => do let bindings1 ← - betree_list_push_front_fwd_back (U64 × U64) bindings0 (key, v) - betree_node_lookup_mut_in_bindings_back key bindings bindings1 + betree.List.push_front_fwd_back (U64 × U64) bindings0 (key, v) + betree.Node.lookup_mut_in_bindings_back key bindings bindings1 | betree_message_t.Delete => - betree_node_lookup_mut_in_bindings_back key bindings bindings0 + betree.Node.lookup_mut_in_bindings_back key bindings bindings0 | betree_message_t.Upsert s => do - let v ← betree_upsert_update_fwd Option.none s + let v ← betree.upsert_update_fwd Option.none s let bindings1 ← - betree_list_push_front_fwd_back (U64 × U64) bindings0 (key, v) - betree_node_lookup_mut_in_bindings_back key bindings bindings1 + betree.List.push_front_fwd_back (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 +divergent def betree.Node.apply_messages_to_leaf_fwd_back (bindings : betree_list_t (U64 × U64)) (new_msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × U64)) @@ -592,12 +590,12 @@ divergent def betree_node_apply_messages_to_leaf_fwd_back | betree_list_t.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_fwd_back bindings i m + betree.Node.apply_messages_to_leaf_fwd_back bindings0 new_msgs_tl | betree_list_t.Nil => Result.ret bindings /- [betree_main::betree::Node::{5}::filter_messages_for_key] -/ -divergent def betree_node_filter_messages_for_key_fwd_back +divergent def betree.Node.filter_messages_for_key_fwd_back (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := @@ -608,14 +606,14 @@ divergent def betree_node_filter_messages_for_key_fwd_back then do let msgs0 ← - betree_list_pop_front_back (U64 × betree_message_t) + betree.List.pop_front_back (U64 × betree_message_t) (betree_list_t.Cons (k, m) l) - betree_node_filter_messages_for_key_fwd_back key msgs0 + betree.Node.filter_messages_for_key_fwd_back key msgs0 else Result.ret (betree_list_t.Cons (k, m) l) | betree_list_t.Nil => Result.ret betree_list_t.Nil /- [betree_main::betree::Node::{5}::lookup_first_message_after_key] -/ -divergent def betree_node_lookup_first_message_after_key_fwd +divergent def betree.Node.lookup_first_message_after_key_fwd (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) := @@ -623,12 +621,12 @@ divergent def betree_node_lookup_first_message_after_key_fwd | betree_list_t.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_fwd key next_msgs else Result.ret (betree_list_t.Cons (k, m) next_msgs) | betree_list_t.Nil => Result.ret betree_list_t.Nil /- [betree_main::betree::Node::{5}::lookup_first_message_after_key] -/ -divergent def betree_node_lookup_first_message_after_key_back +divergent def betree.Node.lookup_first_message_after_key_back (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) (ret0 : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) @@ -640,79 +638,79 @@ divergent def betree_node_lookup_first_message_after_key_back then do let next_msgs0 ← - betree_node_lookup_first_message_after_key_back key next_msgs ret0 + betree.Node.lookup_first_message_after_key_back key next_msgs ret0 Result.ret (betree_list_t.Cons (k, m) next_msgs0) else Result.ret ret0 | betree_list_t.Nil => Result.ret ret0 /- [betree_main::betree::Node::{5}::apply_to_internal] -/ -def betree_node_apply_to_internal_fwd_back +def betree.Node.apply_to_internal_fwd_back (msgs : betree_list_t (U64 × betree_message_t)) (key : U64) (new_msg : betree_message_t) : Result (betree_list_t (U64 × betree_message_t)) := do - let msgs0 ← betree_node_lookup_first_message_for_key_fwd key msgs - let b ← betree_list_head_has_key_fwd betree_message_t msgs0 key + let msgs0 ← betree.Node.lookup_first_message_for_key_fwd key msgs + let b ← betree.List.head_has_key_fwd betree_message_t msgs0 key if b then match new_msg with | betree_message_t.Insert i => do - let msgs1 ← betree_node_filter_messages_for_key_fwd_back key msgs0 + let msgs1 ← betree.Node.filter_messages_for_key_fwd_back key msgs0 let msgs2 ← - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 (key, betree_message_t.Insert i) - betree_node_lookup_first_message_for_key_back key msgs msgs2 + betree.Node.lookup_first_message_for_key_back key msgs msgs2 | betree_message_t.Delete => do - let msgs1 ← betree_node_filter_messages_for_key_fwd_back key msgs0 + let msgs1 ← betree.Node.filter_messages_for_key_fwd_back key msgs0 let msgs2 ← - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 (key, betree_message_t.Delete) - betree_node_lookup_first_message_for_key_back key msgs msgs2 + betree.Node.lookup_first_message_for_key_back key msgs msgs2 | betree_message_t.Upsert s => do - let p ← betree_list_hd_fwd (U64 × betree_message_t) msgs0 + let p ← betree.List.hd_fwd (U64 × betree_message_t) msgs0 let (_, m) := p match m with | betree_message_t.Insert prev => do - let v ← betree_upsert_update_fwd (Option.some prev) s + let v ← betree.upsert_update_fwd (Option.some prev) s let msgs1 ← - betree_list_pop_front_back (U64 × betree_message_t) msgs0 + betree.List.pop_front_back (U64 × betree_message_t) msgs0 let msgs2 ← - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 (key, betree_message_t.Insert v) - betree_node_lookup_first_message_for_key_back key msgs msgs2 + betree.Node.lookup_first_message_for_key_back key msgs msgs2 | betree_message_t.Delete => do - let v ← betree_upsert_update_fwd Option.none s + let v ← betree.upsert_update_fwd Option.none s let msgs1 ← - betree_list_pop_front_back (U64 × betree_message_t) msgs0 + betree.List.pop_front_back (U64 × betree_message_t) msgs0 let msgs2 ← - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 (key, betree_message_t.Insert v) - betree_node_lookup_first_message_for_key_back key msgs msgs2 + betree.Node.lookup_first_message_for_key_back key msgs msgs2 | betree_message_t.Upsert ufs => do let msgs1 ← - betree_node_lookup_first_message_after_key_fwd key msgs0 + betree.Node.lookup_first_message_after_key_fwd key msgs0 let msgs2 ← - betree_list_push_front_fwd_back (U64 × betree_message_t) msgs1 + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 (key, betree_message_t.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 + 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_t) msgs0 (key, + betree.List.push_front_fwd_back (U64 × betree_message_t) msgs0 (key, new_msg) - betree_node_lookup_first_message_for_key_back key msgs msgs1 + 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 +divergent def betree.Node.apply_messages_to_internal_fwd_back (msgs : betree_list_t (U64 × betree_message_t)) (new_msgs : betree_list_t (U64 × betree_message_t)) : Result (betree_list_t (U64 × betree_message_t)) @@ -721,12 +719,12 @@ divergent def betree_node_apply_messages_to_internal_fwd_back | betree_list_t.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_fwd_back msgs i m + betree.Node.apply_messages_to_internal_fwd_back msgs0 new_msgs_tl | betree_list_t.Nil => Result.ret msgs /- [betree_main::betree::Node::{5}::apply_messages] -/ -mutual divergent def betree_node_apply_messages_fwd +mutual divergent def betree.Node.apply_messages_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : @@ -736,49 +734,49 @@ mutual divergent def betree_node_apply_messages_fwd | betree_node_t.Internal node => do let ⟨ i, i0, n, n0 ⟩ := node - let (st0, content) ← betree_load_internal_node_fwd i st + 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_t) content0 + betree.Node.apply_messages_to_internal_fwd_back content msgs + let num_msgs ← betree.List.len_fwd (U64 × betree_message_t) content0 if num_msgs >= params.betree_params_min_flush_size then do let (st1, content1) ← - betree_internal_flush_fwd (betree_internal_t.mk i i0 n n0) params + betree.Internal.flush_fwd (betree_internal_t.mk i i0 n n0) params node_id_cnt content0 st0 let (node0, _) ← - betree_internal_flush_back (betree_internal_t.mk i i0 n n0) params + betree.Internal.flush_back (betree_internal_t.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_fwd i1 content1 st1 Result.ret (st2, ()) else do - let (st1, _) ← betree_store_internal_node_fwd i content0 st0 + let (st1, _) ← betree.store_internal_node_fwd i content0 st0 Result.ret (st1, ()) | betree_node_t.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_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 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_fwd node content0 params node_id_cnt st0 let (st2, _) ← - betree_store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil + betree.store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil st1 Result.ret (st2, ()) else do let (st1, _) ← - betree_store_leaf_node_fwd node.betree_leaf_id content0 st0 + betree.store_leaf_node_fwd node.betree_leaf_id content0 st0 Result.ret (st1, ()) /- [betree_main::betree::Node::{5}::apply_messages] -/ -divergent def betree_node_apply_messages_back +divergent def betree.Node.apply_messages_back (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : @@ -788,53 +786,53 @@ divergent def betree_node_apply_messages_back | betree_node_t.Internal node => do let ⟨ i, i0, n, n0 ⟩ := node - let (st0, content) ← betree_load_internal_node_fwd i st + 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_t) content0 + betree.Node.apply_messages_to_internal_fwd_back content msgs + let num_msgs ← betree.List.len_fwd (U64 × betree_message_t) content0 if num_msgs >= params.betree_params_min_flush_size then do let (st1, content1) ← - betree_internal_flush_fwd (betree_internal_t.mk i i0 n n0) params + betree.Internal.flush_fwd (betree_internal_t.mk i i0 n n0) params node_id_cnt content0 st0 let (node0, node_id_cnt0) ← - betree_internal_flush_back (betree_internal_t.mk i i0 n n0) params + betree.Internal.flush_back (betree_internal_t.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_fwd i1 content1 st1 Result.ret (betree_node_t.Internal (betree_internal_t.mk i1 i2 n1 n2), node_id_cnt0) else do - let _ ← betree_store_internal_node_fwd i content0 st0 + let _ ← betree.store_internal_node_fwd i content0 st0 Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0), node_id_cnt) | betree_node_t.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_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 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_fwd node content0 params node_id_cnt st0 let _ ← - betree_store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil + betree.store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil st1 let node_id_cnt0 ← - betree_leaf_split_back node content0 params node_id_cnt st0 + betree.Leaf.split_back node content0 params node_id_cnt st0 Result.ret (betree_node_t.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_fwd node.betree_leaf_id content0 st0 Result.ret (betree_node_t.Leaf { node with betree_leaf_size := len }, node_id_cnt) /- [betree_main::betree::Internal::{4}::flush] -/ -divergent def betree_internal_flush_fwd +divergent def betree.Internal.flush_fwd (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (content : betree_list_t (U64 × betree_message_t)) (st : State) : @@ -842,39 +840,39 @@ divergent def betree_internal_flush_fwd := do let ⟨ _, i, n, n0 ⟩ := self - let p ← betree_list_partition_at_pivot_fwd betree_message_t content i + let p ← betree.List.partition_at_pivot_fwd betree_message_t content i let (msgs_left, msgs_right) := p - let len_left ← betree_list_len_fwd (U64 × betree_message_t) msgs_left + let len_left ← betree.List.len_fwd (U64 × betree_message_t) 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_fwd 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 + betree.Node.apply_messages_back n params node_id_cnt msgs_left st let len_right ← - betree_list_len_fwd (U64 × betree_message_t) msgs_right + betree.List.len_fwd (U64 × betree_message_t) 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 + betree.Node.apply_messages_fwd n0 params node_id_cnt0 msgs_right st0 let _ ← - betree_node_apply_messages_back n0 params node_id_cnt0 msgs_right + betree.Node.apply_messages_back n0 params node_id_cnt0 msgs_right st0 Result.ret (st1, betree_list_t.Nil) else Result.ret (st0, msgs_right) else do let (st0, _) ← - betree_node_apply_messages_fwd n0 params node_id_cnt msgs_right st + betree.Node.apply_messages_fwd n0 params node_id_cnt msgs_right st let _ ← - betree_node_apply_messages_back n0 params node_id_cnt msgs_right st + betree.Node.apply_messages_back n0 params node_id_cnt msgs_right st Result.ret (st0, msgs_left) /- [betree_main::betree::Internal::{4}::flush] -/ -divergent def betree_internal_flush_back +divergent def betree.Internal.flush_back (self : betree_internal_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (content : betree_list_t (U64 × betree_message_t)) (st : State) : @@ -882,36 +880,36 @@ divergent def betree_internal_flush_back := do let ⟨ i, i0, n, n0 ⟩ := self - let p ← betree_list_partition_at_pivot_fwd betree_message_t content i0 + let p ← betree.List.partition_at_pivot_fwd betree_message_t content i0 let (msgs_left, msgs_right) := p - let len_left ← betree_list_len_fwd (U64 × betree_message_t) msgs_left + let len_left ← betree.List.len_fwd (U64 × betree_message_t) 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_fwd 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 + betree.Node.apply_messages_back n params node_id_cnt msgs_left st let len_right ← - betree_list_len_fwd (U64 × betree_message_t) msgs_right + betree.List.len_fwd (U64 × betree_message_t) msgs_right if len_right >= params.betree_params_min_flush_size then do let (n2, node_id_cnt1) ← - betree_node_apply_messages_back n0 params node_id_cnt0 msgs_right + betree.Node.apply_messages_back n0 params node_id_cnt0 msgs_right st0 Result.ret (betree_internal_t.mk i i0 n1 n2, node_id_cnt1) else Result.ret (betree_internal_t.mk i i0 n1 n0, node_id_cnt0) else do let (n1, node_id_cnt0) ← - betree_node_apply_messages_back n0 params node_id_cnt msgs_right st + betree.Node.apply_messages_back n0 params node_id_cnt msgs_right st Result.ret (betree_internal_t.mk i i0 n n1, node_id_cnt0) end /- [betree_main::betree::Node::{5}::apply] -/ -def betree_node_apply_fwd +def betree.Node.apply_fwd (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : U64) (new_msg : betree_message_t) (st : State) : @@ -920,34 +918,34 @@ def betree_node_apply_fwd do let l := betree_list_t.Nil let (st0, _) ← - betree_node_apply_messages_fwd self params node_id_cnt + betree.Node.apply_messages_fwd self params node_id_cnt (betree_list_t.Cons (key, new_msg) l) st let _ ← - betree_node_apply_messages_back self params node_id_cnt + betree.Node.apply_messages_back self params node_id_cnt (betree_list_t.Cons (key, new_msg) l) st Result.ret (st0, ()) /- [betree_main::betree::Node::{5}::apply] -/ -def betree_node_apply_back +def betree.Node.apply_back (self : betree_node_t) (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) (key : U64) (new_msg : betree_message_t) (st : State) : Result (betree_node_t × betree_node_id_counter_t) := let l := betree_list_t.Nil - betree_node_apply_messages_back self params node_id_cnt (betree_list_t.Cons + betree.Node.apply_messages_back self params node_id_cnt (betree_list_t.Cons (key, new_msg) l) st /- [betree_main::betree::BeTree::{6}::new] -/ -def betree_be_tree_new_fwd +def betree.BeTree.new_fwd (min_flush_size : U64) (split_size : U64) (st : State) : Result (State × betree_be_tree_t) := do - let node_id_cnt ← betree_node_id_counter_new_fwd - let id ← betree_node_id_counter_fresh_id_fwd node_id_cnt - let (st0, _) ← betree_store_leaf_node_fwd id betree_list_t.Nil st - let node_id_cnt0 ← betree_node_id_counter_fresh_id_back node_id_cnt + 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_t.Nil st + let node_id_cnt0 ← betree.NodeIdCounter.fresh_id_back node_id_cnt Result.ret (st0, { betree_be_tree_params := @@ -965,103 +963,103 @@ def betree_be_tree_new_fwd }) /- [betree_main::betree::BeTree::{6}::apply] -/ -def betree_be_tree_apply_fwd +def betree.BeTree.apply_fwd (self : betree_be_tree_t) (key : U64) (msg : betree_message_t) (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_fwd 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 + 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] -/ -def betree_be_tree_apply_back +def betree.BeTree.apply_back (self : betree_be_tree_t) (key : U64) (msg : betree_message_t) (st : State) : Result betree_be_tree_t := do let (n, nic) ← - betree_node_apply_back self.betree_be_tree_root + 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 { self with betree_be_tree_node_id_cnt := nic, betree_be_tree_root := n } /- [betree_main::betree::BeTree::{6}::insert] -/ -def betree_be_tree_insert_fwd +def betree.BeTree.insert_fwd (self : betree_be_tree_t) (key : U64) (value : U64) (st : State) : Result (State × Unit) := do let (st0, _) ← - betree_be_tree_apply_fwd self key (betree_message_t.Insert value) st + betree.BeTree.apply_fwd self key (betree_message_t.Insert value) st let _ ← - betree_be_tree_apply_back self key (betree_message_t.Insert value) st + betree.BeTree.apply_back self key (betree_message_t.Insert value) st Result.ret (st0, ()) /- [betree_main::betree::BeTree::{6}::insert] -/ -def betree_be_tree_insert_back +def betree.BeTree.insert_back (self : betree_be_tree_t) (key : U64) (value : U64) (st : State) : Result betree_be_tree_t := - betree_be_tree_apply_back self key (betree_message_t.Insert value) st + betree.BeTree.apply_back self key (betree_message_t.Insert value) st /- [betree_main::betree::BeTree::{6}::delete] -/ -def betree_be_tree_delete_fwd +def betree.BeTree.delete_fwd (self : betree_be_tree_t) (key : U64) (st : State) : Result (State × Unit) := do let (st0, _) ← - betree_be_tree_apply_fwd self key betree_message_t.Delete st - let _ ← betree_be_tree_apply_back self key betree_message_t.Delete st + betree.BeTree.apply_fwd self key betree_message_t.Delete st + let _ ← betree.BeTree.apply_back self key betree_message_t.Delete st Result.ret (st0, ()) /- [betree_main::betree::BeTree::{6}::delete] -/ -def betree_be_tree_delete_back +def betree.BeTree.delete_back (self : betree_be_tree_t) (key : U64) (st : State) : Result betree_be_tree_t := - betree_be_tree_apply_back self key betree_message_t.Delete st + betree.BeTree.apply_back self key betree_message_t.Delete st /- [betree_main::betree::BeTree::{6}::upsert] -/ -def betree_be_tree_upsert_fwd +def betree.BeTree.upsert_fwd (self : betree_be_tree_t) (key : U64) (upd : betree_upsert_fun_state_t) (st : State) : Result (State × Unit) := do let (st0, _) ← - betree_be_tree_apply_fwd self key (betree_message_t.Upsert upd) st + betree.BeTree.apply_fwd self key (betree_message_t.Upsert upd) st let _ ← - betree_be_tree_apply_back self key (betree_message_t.Upsert upd) st + betree.BeTree.apply_back self key (betree_message_t.Upsert upd) st Result.ret (st0, ()) /- [betree_main::betree::BeTree::{6}::upsert] -/ -def betree_be_tree_upsert_back +def betree.BeTree.upsert_back (self : betree_be_tree_t) (key : U64) (upd : betree_upsert_fun_state_t) (st : State) : Result betree_be_tree_t := - betree_be_tree_apply_back self key (betree_message_t.Upsert upd) st + betree.BeTree.apply_back self key (betree_message_t.Upsert upd) st /- [betree_main::betree::BeTree::{6}::lookup] -/ -def betree_be_tree_lookup_fwd +def betree.BeTree.lookup_fwd (self : betree_be_tree_t) (key : U64) (st : State) : Result (State × (Option U64)) := - betree_node_lookup_fwd self.betree_be_tree_root key st + betree.Node.lookup_fwd self.betree_be_tree_root key st /- [betree_main::betree::BeTree::{6}::lookup] -/ -def betree_be_tree_lookup_back +def betree.BeTree.lookup_back (self : betree_be_tree_t) (key : U64) (st : State) : Result betree_be_tree_t := do - let n ← betree_node_lookup_back self.betree_be_tree_root key st + 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] -/ @@ -1071,4 +1069,4 @@ def main_fwd : Result Unit := /- Unit test for [betree_main::main] -/ #assert (main_fwd == .ret ()) -end BetreeMain +end betree_main diff --git a/tests/lean/BetreeMain/FunsExternal.lean b/tests/lean/BetreeMain/FunsExternal.lean new file mode 100644 index 00000000..0c715ef9 --- /dev/null +++ b/tests/lean/BetreeMain/FunsExternal.lean @@ -0,0 +1,35 @@ +-- [betree_main]: external functions. +import Base +import BetreeMain.Types +open Primitives +open betree_main + +-- TODO: fill those bodies + +/- [betree_main::betree_utils::load_internal_node] -/ +def betree_utils.load_internal_node_fwd + : + U64 → State → Result (State × (betree_list_t (U64 × betree_message_t))) := + fun _ _ => .fail .panic + +/- [betree_main::betree_utils::store_internal_node] -/ +def betree_utils.store_internal_node_fwd + : + U64 → betree_list_t (U64 × betree_message_t) → State → Result (State + × Unit) := + fun _ _ _ => .fail .panic + +/- [betree_main::betree_utils::load_leaf_node] -/ +def betree_utils.load_leaf_node_fwd + : U64 → State → Result (State × (betree_list_t (U64 × U64))) := + fun _ _ => .fail .panic + +/- [betree_main::betree_utils::store_leaf_node] -/ +def betree_utils.store_leaf_node_fwd + : U64 → betree_list_t (U64 × U64) → State → Result (State × Unit) := + fun _ _ _ => .fail .panic + +/- [core::option::Option::{0}::unwrap] -/ +def core.option.Option.unwrap_fwd + (T : Type) : Option T → State → Result (State × T) := + fun _ _ => .fail .panic diff --git a/tests/lean/BetreeMain/FunsExternal_Template.lean b/tests/lean/BetreeMain/FunsExternal_Template.lean new file mode 100644 index 00000000..9b5a54e5 --- /dev/null +++ b/tests/lean/BetreeMain/FunsExternal_Template.lean @@ -0,0 +1,31 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [betree_main]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import BetreeMain.Types +open Primitives +open betree_main + +/- [betree_main::betree_utils::load_internal_node] -/ +axiom betree_utils.load_internal_node_fwd + : + U64 → State → Result (State × (betree_list_t (U64 × betree_message_t))) + +/- [betree_main::betree_utils::store_internal_node] -/ +axiom betree_utils.store_internal_node_fwd + : + U64 → betree_list_t (U64 × betree_message_t) → State → Result (State + × Unit) + +/- [betree_main::betree_utils::load_leaf_node] -/ +axiom betree_utils.load_leaf_node_fwd + : U64 → State → Result (State × (betree_list_t (U64 × U64))) + +/- [betree_main::betree_utils::store_leaf_node] -/ +axiom betree_utils.store_leaf_node_fwd + : U64 → betree_list_t (U64 × U64) → State → Result (State × Unit) + +/- [core::option::Option::{0}::unwrap] -/ +axiom core.option.Option.unwrap_fwd + (T : Type) : Option T → State → Result (State × T) + diff --git a/tests/lean/BetreeMain/Opaque.lean b/tests/lean/BetreeMain/Opaque.lean deleted file mode 100644 index d043186b..00000000 --- a/tests/lean/BetreeMain/Opaque.lean +++ /dev/null @@ -1,35 +0,0 @@ --- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS --- [betree_main]: opaque function definitions -import Base -import BetreeMain.Types -open Primitives - -namespace BetreeMain - -structure OpaqueDefs where - - /- [betree_main::betree_utils::load_internal_node] -/ - betree_utils_load_internal_node_fwd - : - U64 → State → Result (State × (betree_list_t (U64 × - betree_message_t))) - - /- [betree_main::betree_utils::store_internal_node] -/ - betree_utils_store_internal_node_fwd - : - U64 → betree_list_t (U64 × betree_message_t) → State → Result (State - × Unit) - - /- [betree_main::betree_utils::load_leaf_node] -/ - betree_utils_load_leaf_node_fwd - : U64 → State → Result (State × (betree_list_t (U64 × U64))) - - /- [betree_main::betree_utils::store_leaf_node] -/ - betree_utils_store_leaf_node_fwd - : U64 → betree_list_t (U64 × U64) → State → Result (State × Unit) - - /- [core::option::Option::{0}::unwrap] -/ - core_option_option_unwrap_fwd - (T : Type) : Option T → State → Result (State × T) - -end BetreeMain diff --git a/tests/lean/BetreeMain/Types.lean b/tests/lean/BetreeMain/Types.lean index cfed6a28..3ecbd668 100644 --- a/tests/lean/BetreeMain/Types.lean +++ b/tests/lean/BetreeMain/Types.lean @@ -2,8 +2,7 @@ -- [betree_main]: type definitions import Base open Primitives - -namespace BetreeMain +namespace betree_main /- [betree_main::betree::List] -/ inductive betree_list_t (T : Type) := @@ -57,4 +56,4 @@ structure betree_be_tree_t where /- The state type used in the state-error monad -/ axiom State : Type -end BetreeMain +end betree_main -- cgit v1.2.3 From c07721dedb2cfe4c726c42606e623395cdfe5b80 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 5 Jul 2023 15:09:07 +0200 Subject: Simplify the generated names for the types in Lean --- tests/lean/BetreeMain/Funs.lean | 614 +++++++++++------------ tests/lean/BetreeMain/FunsExternal.lean | 8 +- tests/lean/BetreeMain/FunsExternal_Template.lean | 11 +- tests/lean/BetreeMain/Types.lean | 44 +- 4 files changed, 330 insertions(+), 347 deletions(-) (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index 78e14146..3a678c71 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -9,13 +9,13 @@ namespace betree_main /- [betree_main::betree::load_internal_node] -/ def betree.load_internal_node_fwd (id : U64) (st : State) : - Result (State × (betree_list_t (U64 × betree_message_t))) + Result (State × (betree.List (U64 × betree.Message))) := betree_utils.load_internal_node_fwd id st /- [betree_main::betree::store_internal_node] -/ def betree.store_internal_node_fwd - (id : U64) (content : betree_list_t (U64 × betree_message_t)) (st : State) : + (id : U64) (content : betree.List (U64 × betree.Message)) (st : State) : Result (State × Unit) := do @@ -24,12 +24,12 @@ def betree.store_internal_node_fwd /- [betree_main::betree::load_leaf_node] -/ def betree.load_leaf_node_fwd - (id : U64) (st : State) : Result (State × (betree_list_t (U64 × U64))) := + (id : U64) (st : State) : Result (State × (betree.List (U64 × U64))) := betree_utils.load_leaf_node_fwd id st /- [betree_main::betree::store_leaf_node] -/ def betree.store_leaf_node_fwd - (id : U64) (content : betree_list_t (U64 × U64)) (st : State) : + (id : U64) (content : betree.List (U64 × U64)) (st : State) : Result (State × Unit) := do @@ -47,13 +47,13 @@ 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_node_id_counter_t := +def betree.NodeIdCounter.new_fwd : 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_node_id_counter_t) : Result U64 := + (self : betree.NodeIdCounter) : Result U64 := do let _ ← self.betree_node_id_counter_next_node_id + (U64.ofInt 1 (by intlit)) @@ -61,7 +61,7 @@ def betree.NodeIdCounter.fresh_id_fwd /- [betree_main::betree::NodeIdCounter::{0}::fresh_id] -/ def betree.NodeIdCounter.fresh_id_back - (self : betree_node_id_counter_t) : Result betree_node_id_counter_t := + (self : betree.NodeIdCounter) : Result betree.NodeIdCounter := do let i ← self.betree_node_id_counter_next_node_id + (U64.ofInt 1 (by intlit)) @@ -74,113 +74,112 @@ 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 - (prev : Option U64) (st : betree_upsert_fun_state_t) : Result U64 := + (prev : Option U64) (st : betree.UpsertFunState) : Result U64 := match prev with | Option.none => match st with - | betree_upsert_fun_state_t.Add v => Result.ret v - | betree_upsert_fun_state_t.Sub i => Result.ret (U64.ofInt 0 (by intlit)) + | betree.UpsertFunState.Add v => Result.ret v + | betree.UpsertFunState.Sub i => Result.ret (U64.ofInt 0 (by intlit)) | Option.some prev0 => match st with - | betree_upsert_fun_state_t.Add v => + | betree.UpsertFunState.Add v => do let margin ← core_num_u64_max_c - prev0 if margin >= v then prev0 + v else Result.ret core_num_u64_max_c - | betree_upsert_fun_state_t.Sub v => + | betree.UpsertFunState.Sub v => if prev0 >= v 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 T) : Result U64 := + (T : Type) (self : betree.List T) : Result U64 := match self with - | betree_list_t.Cons t tl => + | betree.List.Cons t tl => do let i ← betree.List.len_fwd T tl (U64.ofInt 1 (by intlit)) + i - | betree_list_t.Nil => Result.ret (U64.ofInt 0 (by intlit)) + | betree.List.Nil => Result.ret (U64.ofInt 0 (by intlit)) /- [betree_main::betree::List::{1}::split_at] -/ divergent def betree.List.split_at_fwd - (T : Type) (self : betree_list_t T) (n : U64) : - Result ((betree_list_t T) × (betree_list_t T)) + (T : Type) (self : betree.List T) (n : U64) : + Result ((betree.List T) × (betree.List T)) := if n = (U64.ofInt 0 (by intlit)) - then Result.ret (betree_list_t.Nil, self) + then Result.ret (betree.List.Nil, self) else match self with - | betree_list_t.Cons hd tl => + | 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 (ls0, ls1) := p let l := ls0 - Result.ret (betree_list_t.Cons hd l, ls1) - | betree_list_t.Nil => Result.fail Error.panic + 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 - (T : Type) (self : betree_list_t T) (x : T) : Result (betree_list_t T) := - let tl := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil + (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 l := tl - Result.ret (betree_list_t.Cons x l) + 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 T) : Result T := - let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil +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 match ls with - | betree_list_t.Cons x tl => Result.ret x - | betree_list_t.Nil => Result.fail Error.panic + | betree.List.Cons x tl => Result.ret x + | betree.List.Nil => Result.fail Error.panic /- [betree_main::betree::List::{1}::pop_front] -/ def betree.List.pop_front_back - (T : Type) (self : betree_list_t T) : Result (betree_list_t T) := - let ls := mem_replace_fwd (betree_list_t T) self betree_list_t.Nil + (T : Type) (self : betree.List T) : Result (betree.List T) := + let ls := mem_replace_fwd (betree.List T) self betree.List.Nil match ls with - | betree_list_t.Cons x tl => Result.ret tl - | betree_list_t.Nil => Result.fail Error.panic + | 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 T) : Result T := +def betree.List.hd_fwd (T : Type) (self : betree.List T) : Result T := match self with - | betree_list_t.Cons hd l => Result.ret hd - | betree_list_t.Nil => Result.fail Error.panic + | 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 - (T : Type) (self : betree_list_t (U64 × T)) (key : U64) : Result Bool := + (T : Type) (self : betree.List (U64 × T)) (key : U64) : Result Bool := match self with - | betree_list_t.Cons hd l => let (i, _) := hd - Result.ret (i = key) - | betree_list_t.Nil => Result.ret false + | 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 - (T : Type) (self : betree_list_t (U64 × T)) (pivot : U64) : - Result ((betree_list_t (U64 × T)) × (betree_list_t (U64 × T))) + (T : Type) (self : betree.List (U64 × T)) (pivot : U64) : + Result ((betree.List (U64 × T)) × (betree.List (U64 × T))) := match self with - | betree_list_t.Cons hd tl => + | betree.List.Cons hd tl => let (i, t) := hd if i >= pivot - then Result.ret (betree_list_t.Nil, betree_list_t.Cons (i, t) tl) + 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 (ls0, ls1) := p let l := ls0 - Result.ret (betree_list_t.Cons (i, t) l, ls1) - | betree_list_t.Nil => Result.ret (betree_list_t.Nil, betree_list_t.Nil) + 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 - (self : betree_leaf_t) (content : betree_list_t (U64 × U64)) - (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) - (st : State) : - Result (State × betree_internal_t) + (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 ← @@ -194,24 +193,23 @@ def betree.Leaf.split_fwd 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 n := betree_node_t.Leaf + let n := betree.Node.Leaf { betree_leaf_id := id0, betree_leaf_size := params.betree_params_split_size } - let n0 := betree_node_t.Leaf + let n0 := betree.Node.Leaf { betree_leaf_id := id1, betree_leaf_size := params.betree_params_split_size } - Result.ret (st1, betree_internal_t.mk self.betree_leaf_id pivot n n0) + Result.ret (st1, betree.Internal.mk self.betree_leaf_id pivot n n0) /- [betree_main::betree::Leaf::{3}::split] -/ def betree.Leaf.split_back - (self : betree_leaf_t) (content : betree_list_t (U64 × U64)) - (params : betree_params_t) (node_id_cnt : betree_node_id_counter_t) - (st : State) : - Result betree_node_id_counter_t + (self : betree.Leaf) (content : betree.List (U64 × U64)) + (params : betree.Params) (node_id_cnt : betree.NodeIdCounter) (st : State) : + Result betree.NodeIdCounter := do let p ← @@ -228,9 +226,9 @@ def betree.Leaf.split_back /- [betree_main::betree::Node::{5}::lookup_in_bindings] -/ divergent def betree.Node.lookup_in_bindings_fwd - (key : U64) (bindings : betree_list_t (U64 × U64)) : Result (Option U64) := + (key : U64) (bindings : betree.List (U64 × U64)) : Result (Option U64) := match bindings with - | betree_list_t.Cons hd tl => + | betree.List.Cons hd tl => let (i, i0) := hd if i = key then Result.ret (Option.some i0) @@ -238,29 +236,29 @@ divergent def betree.Node.lookup_in_bindings_fwd if i > key then Result.ret Option.none else betree.Node.lookup_in_bindings_fwd key tl - | betree_list_t.Nil => Result.ret Option.none + | 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 - (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × betree_message_t)) + (key : U64) (msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) := match msgs with - | betree_list_t.Cons x next_msgs => + | betree.List.Cons x next_msgs => let (i, m) := x if i >= key - then Result.ret (betree_list_t.Cons (i, m) next_msgs) + then Result.ret (betree.List.Cons (i, m) next_msgs) else betree.Node.lookup_first_message_for_key_fwd key next_msgs - | betree_list_t.Nil => Result.ret betree_list_t.Nil + | betree.List.Nil => Result.ret betree.List.Nil /- [betree_main::betree::Node::{5}::lookup_first_message_for_key] -/ divergent def betree.Node.lookup_first_message_for_key_back - (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) - (ret0 : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × betree_message_t)) + (key : U64) (msgs : betree.List (U64 × betree.Message)) + (ret0 : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) := match msgs with - | betree_list_t.Cons x next_msgs => + | betree.List.Cons x next_msgs => let (i, m) := x if i >= key then Result.ret ret0 @@ -268,134 +266,134 @@ divergent def betree.Node.lookup_first_message_for_key_back do let next_msgs0 ← betree.Node.lookup_first_message_for_key_back key next_msgs ret0 - Result.ret (betree_list_t.Cons (i, m) next_msgs0) - | betree_list_t.Nil => Result.ret ret0 + 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 - (msgs : betree_list_t (U64 × betree_message_t)) (prev : Option U64) - (key : U64) (st : State) : + (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_t msgs key + let b ← betree.List.head_has_key_fwd betree.Message msgs key if b then do - let msg ← betree.List.pop_front_fwd (U64 × betree_message_t) msgs + let msg ← betree.List.pop_front_fwd (U64 × betree.Message) msgs let (_, m) := msg match m with - | betree_message_t.Insert i => Result.fail Error.panic - | betree_message_t.Delete => Result.fail Error.panic - | betree_message_t.Upsert s => + | 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 msgs0 ← - betree.List.pop_front_back (U64 × betree_message_t) msgs + betree.List.pop_front_back (U64 × betree.Message) msgs betree.Node.apply_upserts_fwd msgs0 (Option.some v) key st else do let (st0, v) ← core.option.Option.unwrap_fwd U64 prev st let _ ← - betree.List.push_front_fwd_back (U64 × betree_message_t) msgs (key, - betree_message_t.Insert v) + betree.List.push_front_fwd_back (U64 × betree.Message) msgs (key, + betree.Message.Insert v) Result.ret (st0, v) /- [betree_main::betree::Node::{5}::apply_upserts] -/ divergent def betree.Node.apply_upserts_back - (msgs : betree_list_t (U64 × betree_message_t)) (prev : Option U64) - (key : U64) (st : State) : - Result (betree_list_t (U64 × betree_message_t)) + (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_t msgs key + let b ← betree.List.head_has_key_fwd betree.Message msgs key if b then do - let msg ← betree.List.pop_front_fwd (U64 × betree_message_t) msgs + let msg ← betree.List.pop_front_fwd (U64 × betree.Message) msgs let (_, m) := msg match m with - | betree_message_t.Insert i => Result.fail Error.panic - | betree_message_t.Delete => Result.fail Error.panic - | betree_message_t.Upsert s => + | 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 msgs0 ← - betree.List.pop_front_back (U64 × betree_message_t) msgs + 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_t) msgs (key, - betree_message_t.Insert v) + betree.List.push_front_fwd_back (U64 × betree.Message) msgs (key, + betree.Message.Insert v) /- [betree_main::betree::Node::{5}::lookup] -/ mutual divergent def betree.Node.lookup_fwd - (self : betree_node_t) (key : U64) (st : State) : + (self : betree.Node) (key : U64) (st : State) : Result (State × (Option U64)) := match self with - | betree_node_t.Internal node => + | 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 match pending with - | betree_list_t.Cons p l => + | betree.List.Cons p l => let (k, msg) := p if k != key then do let (st1, opt) ← - betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i i0 - n n0) key st0 + betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 n + n0) key st0 let _ ← betree.Node.lookup_first_message_for_key_back key msgs - (betree_list_t.Cons (k, msg) l) + (betree.List.Cons (k, msg) l) Result.ret (st1, opt) else match msg with - | betree_message_t.Insert v => + | betree.Message.Insert v => do let _ ← betree.Node.lookup_first_message_for_key_back key msgs - (betree_list_t.Cons (k, betree_message_t.Insert v) l) + (betree.List.Cons (k, betree.Message.Insert v) l) Result.ret (st0, Option.some v) - | betree_message_t.Delete => + | betree.Message.Delete => do let _ ← betree.Node.lookup_first_message_for_key_back key msgs - (betree_list_t.Cons (k, betree_message_t.Delete) l) + (betree.List.Cons (k, betree.Message.Delete) l) Result.ret (st0, Option.none) - | betree_message_t.Upsert ufs => + | betree.Message.Upsert ufs => do let (st1, v) ← - betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i - i0 n n0) key st0 + betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 + n n0) key st0 let (st2, v0) ← - betree.Node.apply_upserts_fwd (betree_list_t.Cons (k, - betree_message_t.Upsert ufs) l) v key st1 + betree.Node.apply_upserts_fwd (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 let node0 ← - betree.Internal.lookup_in_children_back (betree_internal_t.mk i + betree.Internal.lookup_in_children_back (betree.Internal.mk i i0 n n0) key st0 let ⟨ i1, _, _, _ ⟩ := node0 let pending0 ← - betree.Node.apply_upserts_back (betree_list_t.Cons (k, - betree_message_t.Upsert ufs) l) v key st1 + betree.Node.apply_upserts_back (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 let msgs0 ← betree.Node.lookup_first_message_for_key_back key msgs pending0 let (st3, _) ← betree.store_internal_node_fwd i1 msgs0 st2 Result.ret (st3, Option.some v0) - | betree_list_t.Nil => + | betree.List.Nil => do let (st1, opt) ← - betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i i0 n + betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 n n0) key st0 let _ ← betree.Node.lookup_first_message_for_key_back key msgs - betree_list_t.Nil + betree.List.Nil Result.ret (st1, opt) - | betree_node_t.Leaf node => + | 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 @@ -403,80 +401,78 @@ mutual divergent def betree.Node.lookup_fwd /- [betree_main::betree::Node::{5}::lookup] -/ divergent def betree.Node.lookup_back - (self : betree_node_t) (key : U64) (st : State) : Result betree_node_t := + (self : betree.Node) (key : U64) (st : State) : Result betree.Node := match self with - | betree_node_t.Internal node => + | 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 match pending with - | betree_list_t.Cons p l => + | betree.List.Cons p l => let (k, msg) := p if k != key then do let _ ← betree.Node.lookup_first_message_for_key_back key msgs - (betree_list_t.Cons (k, msg) l) + (betree.List.Cons (k, msg) l) let node0 ← - betree.Internal.lookup_in_children_back (betree_internal_t.mk i - i0 n n0) key st0 - Result.ret (betree_node_t.Internal node0) + betree.Internal.lookup_in_children_back (betree.Internal.mk i i0 + n n0) key st0 + Result.ret (betree.Node.Internal node0) else match msg with - | betree_message_t.Insert v => + | betree.Message.Insert v => do let _ ← betree.Node.lookup_first_message_for_key_back key msgs - (betree_list_t.Cons (k, betree_message_t.Insert v) l) - Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n - n0)) - | betree_message_t.Delete => + (betree.List.Cons (k, betree.Message.Insert v) l) + Result.ret (betree.Node.Internal (betree.Internal.mk i i0 n n0)) + | betree.Message.Delete => do let _ ← betree.Node.lookup_first_message_for_key_back key msgs - (betree_list_t.Cons (k, betree_message_t.Delete) l) - Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n - n0)) - | betree_message_t.Upsert ufs => + (betree.List.Cons (k, betree.Message.Delete) l) + Result.ret (betree.Node.Internal (betree.Internal.mk i i0 n n0)) + | betree.Message.Upsert ufs => do let (st1, v) ← - betree.Internal.lookup_in_children_fwd (betree_internal_t.mk i - i0 n n0) key st0 + betree.Internal.lookup_in_children_fwd (betree.Internal.mk i i0 + n n0) key st0 let (st2, _) ← - betree.Node.apply_upserts_fwd (betree_list_t.Cons (k, - betree_message_t.Upsert ufs) l) v key st1 + betree.Node.apply_upserts_fwd (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 let node0 ← - betree.Internal.lookup_in_children_back (betree_internal_t.mk i + betree.Internal.lookup_in_children_back (betree.Internal.mk i i0 n n0) key st0 let ⟨ i1, i2, n1, n2 ⟩ := node0 let pending0 ← - betree.Node.apply_upserts_back (betree_list_t.Cons (k, - betree_message_t.Upsert ufs) l) v key st1 + betree.Node.apply_upserts_back (betree.List.Cons (k, + betree.Message.Upsert ufs) l) v key st1 let msgs0 ← betree.Node.lookup_first_message_for_key_back key msgs pending0 let _ ← betree.store_internal_node_fwd i1 msgs0 st2 - Result.ret (betree_node_t.Internal (betree_internal_t.mk i1 i2 n1 + Result.ret (betree.Node.Internal (betree.Internal.mk i1 i2 n1 n2)) - | betree_list_t.Nil => + | betree.List.Nil => do let _ ← betree.Node.lookup_first_message_for_key_back key msgs - betree_list_t.Nil + betree.List.Nil let node0 ← - betree.Internal.lookup_in_children_back (betree_internal_t.mk i i0 - n n0) key st0 - Result.ret (betree_node_t.Internal node0) - | betree_node_t.Leaf node => + betree.Internal.lookup_in_children_back (betree.Internal.mk i i0 n + n0) key st0 + Result.ret (betree.Node.Internal node0) + | betree.Node.Leaf node => do let (_, bindings) ← betree.load_leaf_node_fwd node.betree_leaf_id st let _ ← betree.Node.lookup_in_bindings_fwd key bindings - Result.ret (betree_node_t.Leaf node) + Result.ret (betree.Node.Leaf node) /- [betree_main::betree::Internal::{4}::lookup_in_children] -/ divergent def betree.Internal.lookup_in_children_fwd - (self : betree_internal_t) (key : U64) (st : State) : + (self : betree.Internal) (key : U64) (st : State) : Result (State × (Option U64)) := let ⟨ _, i, n, n0 ⟩ := self @@ -486,57 +482,55 @@ divergent def betree.Internal.lookup_in_children_fwd /- [betree_main::betree::Internal::{4}::lookup_in_children] -/ divergent def betree.Internal.lookup_in_children_back - (self : betree_internal_t) (key : U64) (st : State) : - Result betree_internal_t - := + (self : betree.Internal) (key : U64) (st : State) : Result betree.Internal := let ⟨ i, i0, n, n0 ⟩ := self if key < i0 then do let n1 ← betree.Node.lookup_back n key st - Result.ret (betree_internal_t.mk i i0 n1 n0) + Result.ret (betree.Internal.mk i i0 n1 n0) else do let n1 ← betree.Node.lookup_back n0 key st - Result.ret (betree_internal_t.mk i i0 n n1) + Result.ret (betree.Internal.mk i i0 n n1) end /- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ divergent def betree.Node.lookup_mut_in_bindings_fwd - (key : U64) (bindings : betree_list_t (U64 × U64)) : - Result (betree_list_t (U64 × U64)) + (key : U64) (bindings : betree.List (U64 × U64)) : + Result (betree.List (U64 × U64)) := match bindings with - | betree_list_t.Cons hd tl => + | betree.List.Cons hd tl => let (i, i0) := hd if i >= key - then Result.ret (betree_list_t.Cons (i, i0) tl) + then Result.ret (betree.List.Cons (i, i0) tl) else betree.Node.lookup_mut_in_bindings_fwd key tl - | betree_list_t.Nil => Result.ret betree_list_t.Nil + | betree.List.Nil => Result.ret betree.List.Nil /- [betree_main::betree::Node::{5}::lookup_mut_in_bindings] -/ divergent def betree.Node.lookup_mut_in_bindings_back - (key : U64) (bindings : betree_list_t (U64 × U64)) - (ret0 : betree_list_t (U64 × U64)) : - Result (betree_list_t (U64 × U64)) + (key : U64) (bindings : betree.List (U64 × U64)) + (ret0 : betree.List (U64 × U64)) : + Result (betree.List (U64 × U64)) := match bindings with - | betree_list_t.Cons hd tl => + | betree.List.Cons hd tl => let (i, i0) := hd if i >= key then Result.ret ret0 else do let tl0 ← betree.Node.lookup_mut_in_bindings_back key tl ret0 - Result.ret (betree_list_t.Cons (i, i0) tl0) - | betree_list_t.Nil => Result.ret ret0 + 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 - (bindings : betree_list_t (U64 × U64)) (key : U64) - (new_msg : betree_message_t) : - Result (betree_list_t (U64 × U64)) + (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 @@ -546,17 +540,17 @@ def betree.Node.apply_to_leaf_fwd_back do let hd ← betree.List.pop_front_fwd (U64 × U64) bindings0 match new_msg with - | betree_message_t.Insert v => + | 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.Node.lookup_mut_in_bindings_back key bindings bindings2 - | betree_message_t.Delete => + | betree.Message.Delete => do let bindings1 ← betree.List.pop_front_back (U64 × U64) bindings0 betree.Node.lookup_mut_in_bindings_back key bindings bindings1 - | betree_message_t.Upsert s => + | betree.Message.Upsert s => do let (_, i) := hd let v ← betree.upsert_update_fwd (Option.some i) s @@ -566,14 +560,14 @@ def betree.Node.apply_to_leaf_fwd_back betree.Node.lookup_mut_in_bindings_back key bindings bindings2 else match new_msg with - | betree_message_t.Insert v => + | betree.Message.Insert v => do let bindings1 ← betree.List.push_front_fwd_back (U64 × U64) bindings0 (key, v) betree.Node.lookup_mut_in_bindings_back key bindings bindings1 - | betree_message_t.Delete => + | betree.Message.Delete => betree.Node.lookup_mut_in_bindings_back key bindings bindings0 - | betree_message_t.Upsert s => + | betree.Message.Upsert s => do let v ← betree.upsert_update_fwd Option.none s let bindings1 ← @@ -582,170 +576,170 @@ def betree.Node.apply_to_leaf_fwd_back /- [betree_main::betree::Node::{5}::apply_messages_to_leaf] -/ divergent def betree.Node.apply_messages_to_leaf_fwd_back - (bindings : betree_list_t (U64 × U64)) - (new_msgs : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × U64)) + (bindings : betree.List (U64 × U64)) + (new_msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × U64)) := match new_msgs with - | betree_list_t.Cons new_msg new_msgs_tl => + | 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 - | betree_list_t.Nil => Result.ret bindings + | 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 - (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × betree_message_t)) + (key : U64) (msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) := match msgs with - | betree_list_t.Cons p l => + | betree.List.Cons p l => let (k, m) := p if k = key then do let msgs0 ← - betree.List.pop_front_back (U64 × betree_message_t) - (betree_list_t.Cons (k, m) l) + betree.List.pop_front_back (U64 × betree.Message) (betree.List.Cons + (k, m) l) betree.Node.filter_messages_for_key_fwd_back key msgs0 - else Result.ret (betree_list_t.Cons (k, m) l) - | betree_list_t.Nil => Result.ret betree_list_t.Nil + 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 - (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × betree_message_t)) + (key : U64) (msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) := match msgs with - | betree_list_t.Cons p next_msgs => + | 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 - else Result.ret (betree_list_t.Cons (k, m) next_msgs) - | betree_list_t.Nil => Result.ret betree_list_t.Nil + 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] -/ divergent def betree.Node.lookup_first_message_after_key_back - (key : U64) (msgs : betree_list_t (U64 × betree_message_t)) - (ret0 : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × betree_message_t)) + (key : U64) (msgs : betree.List (U64 × betree.Message)) + (ret0 : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) := match msgs with - | betree_list_t.Cons p next_msgs => + | betree.List.Cons p next_msgs => let (k, m) := p if k = key then do let next_msgs0 ← betree.Node.lookup_first_message_after_key_back key next_msgs ret0 - Result.ret (betree_list_t.Cons (k, m) next_msgs0) + Result.ret (betree.List.Cons (k, m) next_msgs0) else Result.ret ret0 - | betree_list_t.Nil => 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 - (msgs : betree_list_t (U64 × betree_message_t)) (key : U64) - (new_msg : betree_message_t) : - Result (betree_list_t (U64 × betree_message_t)) + (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_t msgs0 key + let b ← betree.List.head_has_key_fwd betree.Message msgs0 key if b then match new_msg with - | betree_message_t.Insert i => + | betree.Message.Insert i => do let msgs1 ← betree.Node.filter_messages_for_key_fwd_back key msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 - (key, betree_message_t.Insert i) + betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 (key, + betree.Message.Insert i) betree.Node.lookup_first_message_for_key_back key msgs msgs2 - | betree_message_t.Delete => + | betree.Message.Delete => do let msgs1 ← betree.Node.filter_messages_for_key_fwd_back key msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 - (key, betree_message_t.Delete) + betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 (key, + betree.Message.Delete) betree.Node.lookup_first_message_for_key_back key msgs msgs2 - | betree_message_t.Upsert s => + | betree.Message.Upsert s => do - let p ← betree.List.hd_fwd (U64 × betree_message_t) msgs0 + let p ← betree.List.hd_fwd (U64 × betree.Message) msgs0 let (_, m) := p match m with - | betree_message_t.Insert prev => + | betree.Message.Insert prev => do let v ← betree.upsert_update_fwd (Option.some prev) s let msgs1 ← - betree.List.pop_front_back (U64 × betree_message_t) msgs0 + betree.List.pop_front_back (U64 × betree.Message) msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 - (key, betree_message_t.Insert v) + betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 + (key, betree.Message.Insert v) betree.Node.lookup_first_message_for_key_back key msgs msgs2 - | betree_message_t.Delete => + | betree.Message.Delete => do let v ← betree.upsert_update_fwd Option.none s let msgs1 ← - betree.List.pop_front_back (U64 × betree_message_t) msgs0 + betree.List.pop_front_back (U64 × betree.Message) msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 - (key, betree_message_t.Insert v) + betree.List.push_front_fwd_back (U64 × betree.Message) msgs1 + (key, betree.Message.Insert v) betree.Node.lookup_first_message_for_key_back key msgs msgs2 - | betree_message_t.Upsert ufs => + | betree.Message.Upsert ufs => do let msgs1 ← betree.Node.lookup_first_message_after_key_fwd key msgs0 let msgs2 ← - betree.List.push_front_fwd_back (U64 × betree_message_t) msgs1 - (key, betree_message_t.Upsert s) + betree.List.push_front_fwd_back (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_t) msgs0 (key, + betree.List.push_front_fwd_back (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 - (msgs : betree_list_t (U64 × betree_message_t)) - (new_msgs : betree_list_t (U64 × betree_message_t)) : - Result (betree_list_t (U64 × betree_message_t)) + (msgs : betree.List (U64 × betree.Message)) + (new_msgs : betree.List (U64 × betree.Message)) : + Result (betree.List (U64 × betree.Message)) := match new_msgs with - | betree_list_t.Cons new_msg new_msgs_tl => + | 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 - | betree_list_t.Nil => Result.ret msgs + | betree.List.Nil => Result.ret msgs /- [betree_main::betree::Node::{5}::apply_messages] -/ mutual divergent def betree.Node.apply_messages_fwd - (self : betree_node_t) (params : betree_params_t) - (node_id_cnt : betree_node_id_counter_t) - (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (msgs : betree.List (U64 × betree.Message)) (st : State) : Result (State × Unit) := match self with - | betree_node_t.Internal node => + | 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_t) content0 + let num_msgs ← betree.List.len_fwd (U64 × betree.Message) content0 if num_msgs >= params.betree_params_min_flush_size then do let (st1, content1) ← - betree.Internal.flush_fwd (betree_internal_t.mk i i0 n n0) params + betree.Internal.flush_fwd (betree.Internal.mk i i0 n n0) params node_id_cnt content0 st0 let (node0, _) ← - betree.Internal.flush_back (betree_internal_t.mk i i0 n n0) params + 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 @@ -754,7 +748,7 @@ mutual divergent def betree.Node.apply_messages_fwd do let (st1, _) ← betree.store_internal_node_fwd i content0 st0 Result.ret (st1, ()) - | betree_node_t.Leaf node => + | 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 @@ -766,8 +760,7 @@ mutual divergent def betree.Node.apply_messages_fwd let (st1, _) ← betree.Leaf.split_fwd node content0 params node_id_cnt st0 let (st2, _) ← - betree.store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil - st1 + betree.store_leaf_node_fwd node.betree_leaf_id betree.List.Nil st1 Result.ret (st2, ()) else do @@ -777,38 +770,38 @@ mutual divergent def betree.Node.apply_messages_fwd /- [betree_main::betree::Node::{5}::apply_messages] -/ divergent def betree.Node.apply_messages_back - (self : betree_node_t) (params : betree_params_t) - (node_id_cnt : betree_node_id_counter_t) - (msgs : betree_list_t (U64 × betree_message_t)) (st : State) : - Result (betree_node_t × betree_node_id_counter_t) + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (msgs : betree.List (U64 × betree.Message)) (st : State) : + Result (betree.Node × betree.NodeIdCounter) := match self with - | betree_node_t.Internal node => + | 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_t) content0 + let num_msgs ← betree.List.len_fwd (U64 × betree.Message) content0 if num_msgs >= params.betree_params_min_flush_size then do let (st1, content1) ← - betree.Internal.flush_fwd (betree_internal_t.mk i i0 n n0) params + betree.Internal.flush_fwd (betree.Internal.mk i i0 n n0) params node_id_cnt content0 st0 let (node0, node_id_cnt0) ← - betree.Internal.flush_back (betree_internal_t.mk i i0 n n0) params + 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 - Result.ret (betree_node_t.Internal (betree_internal_t.mk i1 i2 n1 - n2), node_id_cnt0) + 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 - Result.ret (betree_node_t.Internal (betree_internal_t.mk i i0 n n0), + Result.ret (betree.Node.Internal (betree.Internal.mk i i0 n n0), node_id_cnt) - | betree_node_t.Leaf node => + | 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 @@ -820,29 +813,28 @@ divergent def betree.Node.apply_messages_back let (st1, new_node) ← betree.Leaf.split_fwd node content0 params node_id_cnt st0 let _ ← - betree.store_leaf_node_fwd node.betree_leaf_id betree_list_t.Nil - st1 + betree.store_leaf_node_fwd 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_t.Internal new_node, node_id_cnt0) + Result.ret (betree.Node.Internal new_node, node_id_cnt0) else do let _ ← betree.store_leaf_node_fwd node.betree_leaf_id content0 st0 - Result.ret (betree_node_t.Leaf { node with betree_leaf_size := len }, + 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 - (self : betree_internal_t) (params : betree_params_t) - (node_id_cnt : betree_node_id_counter_t) - (content : betree_list_t (U64 × betree_message_t)) (st : State) : - Result (State × (betree_list_t (U64 × betree_message_t))) + (self : betree.Internal) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (content : betree.List (U64 × betree.Message)) (st : State) : + Result (State × (betree.List (U64 × betree.Message))) := do let ⟨ _, i, n, n0 ⟩ := self - let p ← betree.List.partition_at_pivot_fwd betree_message_t content i + let p ← betree.List.partition_at_pivot_fwd betree.Message content i let (msgs_left, msgs_right) := p - let len_left ← betree.List.len_fwd (U64 × betree_message_t) msgs_left + let len_left ← betree.List.len_fwd (U64 × betree.Message) msgs_left if len_left >= params.betree_params_min_flush_size then do @@ -851,7 +843,7 @@ divergent def betree.Internal.flush_fwd 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_t) msgs_right + betree.List.len_fwd (U64 × betree.Message) msgs_right if len_right >= params.betree_params_min_flush_size then do @@ -861,7 +853,7 @@ divergent def betree.Internal.flush_fwd let _ ← betree.Node.apply_messages_back n0 params node_id_cnt0 msgs_right st0 - Result.ret (st1, betree_list_t.Nil) + Result.ret (st1, betree.List.Nil) else Result.ret (st0, msgs_right) else do @@ -873,16 +865,16 @@ divergent def betree.Internal.flush_fwd /- [betree_main::betree::Internal::{4}::flush] -/ divergent def betree.Internal.flush_back - (self : betree_internal_t) (params : betree_params_t) - (node_id_cnt : betree_node_id_counter_t) - (content : betree_list_t (U64 × betree_message_t)) (st : State) : - Result (betree_internal_t × betree_node_id_counter_t) + (self : betree.Internal) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) + (content : betree.List (U64 × betree.Message)) (st : State) : + Result (betree.Internal × betree.NodeIdCounter) := do let ⟨ i, i0, n, n0 ⟩ := self - let p ← betree.List.partition_at_pivot_fwd betree_message_t content i0 + let p ← betree.List.partition_at_pivot_fwd betree.Message content i0 let (msgs_left, msgs_right) := p - let len_left ← betree.List.len_fwd (U64 × betree_message_t) msgs_left + let len_left ← betree.List.len_fwd (U64 × betree.Message) msgs_left if len_left >= params.betree_params_min_flush_size then do @@ -891,60 +883,60 @@ divergent def betree.Internal.flush_back 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_t) msgs_right + betree.List.len_fwd (U64 × betree.Message) msgs_right if len_right >= params.betree_params_min_flush_size then do let (n2, node_id_cnt1) ← betree.Node.apply_messages_back n0 params node_id_cnt0 msgs_right st0 - Result.ret (betree_internal_t.mk i i0 n1 n2, node_id_cnt1) - else Result.ret (betree_internal_t.mk i i0 n1 n0, node_id_cnt0) + Result.ret (betree.Internal.mk i i0 n1 n2, node_id_cnt1) + else Result.ret (betree.Internal.mk i i0 n1 n0, node_id_cnt0) else do let (n1, node_id_cnt0) ← betree.Node.apply_messages_back n0 params node_id_cnt msgs_right st - Result.ret (betree_internal_t.mk i i0 n n1, node_id_cnt0) + Result.ret (betree.Internal.mk i i0 n n1, node_id_cnt0) end /- [betree_main::betree::Node::{5}::apply] -/ def betree.Node.apply_fwd - (self : betree_node_t) (params : betree_params_t) - (node_id_cnt : betree_node_id_counter_t) (key : U64) - (new_msg : betree_message_t) (st : State) : + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) (key : U64) (new_msg : betree.Message) + (st : State) : Result (State × Unit) := do - let l := betree_list_t.Nil + let l := betree.List.Nil let (st0, _) ← - betree.Node.apply_messages_fwd self params node_id_cnt - (betree_list_t.Cons (key, new_msg) l) st + betree.Node.apply_messages_fwd 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_t.Cons (key, new_msg) l) st + 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] -/ def betree.Node.apply_back - (self : betree_node_t) (params : betree_params_t) - (node_id_cnt : betree_node_id_counter_t) (key : U64) - (new_msg : betree_message_t) (st : State) : - Result (betree_node_t × betree_node_id_counter_t) + (self : betree.Node) (params : betree.Params) + (node_id_cnt : betree.NodeIdCounter) (key : U64) (new_msg : betree.Message) + (st : State) : + Result (betree.Node × betree.NodeIdCounter) := - let l := betree_list_t.Nil - betree.Node.apply_messages_back self params node_id_cnt (betree_list_t.Cons + let l := betree.List.Nil + betree.Node.apply_messages_back self params node_id_cnt (betree.List.Cons (key, new_msg) l) st /- [betree_main::betree::BeTree::{6}::new] -/ def betree.BeTree.new_fwd (min_flush_size : U64) (split_size : U64) (st : State) : - Result (State × betree_be_tree_t) + 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_t.Nil st + let (st0, _) ← betree.store_leaf_node_fwd id betree.List.Nil st let node_id_cnt0 ← betree.NodeIdCounter.fresh_id_back node_id_cnt Result.ret (st0, { @@ -955,7 +947,7 @@ def betree.BeTree.new_fwd }, betree_be_tree_node_id_cnt := node_id_cnt0, betree_be_tree_root := - (betree_node_t.Leaf + (betree.Node.Leaf { betree_leaf_id := id, betree_leaf_size := (U64.ofInt 0 (by intlit)) @@ -964,7 +956,7 @@ def betree.BeTree.new_fwd /- [betree_main::betree::BeTree::{6}::apply] -/ def betree.BeTree.apply_fwd - (self : betree_be_tree_t) (key : U64) (msg : betree_message_t) (st : State) : + (self : betree.BeTree) (key : U64) (msg : betree.Message) (st : State) : Result (State × Unit) := do @@ -978,8 +970,8 @@ def betree.BeTree.apply_fwd /- [betree_main::betree::BeTree::{6}::apply] -/ def betree.BeTree.apply_back - (self : betree_be_tree_t) (key : U64) (msg : betree_message_t) (st : State) : - Result betree_be_tree_t + (self : betree.BeTree) (key : U64) (msg : betree.Message) (st : State) : + Result betree.BeTree := do let (n, nic) ← @@ -990,74 +982,66 @@ def betree.BeTree.apply_back /- [betree_main::betree::BeTree::{6}::insert] -/ def betree.BeTree.insert_fwd - (self : betree_be_tree_t) (key : U64) (value : U64) (st : State) : + (self : betree.BeTree) (key : U64) (value : U64) (st : State) : Result (State × Unit) := do let (st0, _) ← - betree.BeTree.apply_fwd self key (betree_message_t.Insert value) st + betree.BeTree.apply_fwd self key (betree.Message.Insert value) st let _ ← - betree.BeTree.apply_back self key (betree_message_t.Insert value) st + betree.BeTree.apply_back self key (betree.Message.Insert value) st Result.ret (st0, ()) /- [betree_main::betree::BeTree::{6}::insert] -/ def betree.BeTree.insert_back - (self : betree_be_tree_t) (key : U64) (value : U64) (st : State) : - Result betree_be_tree_t + (self : betree.BeTree) (key : U64) (value : U64) (st : State) : + Result betree.BeTree := - betree.BeTree.apply_back self key (betree_message_t.Insert value) st + betree.BeTree.apply_back self key (betree.Message.Insert value) st /- [betree_main::betree::BeTree::{6}::delete] -/ def betree.BeTree.delete_fwd - (self : betree_be_tree_t) (key : U64) (st : State) : - Result (State × Unit) - := + (self : betree.BeTree) (key : U64) (st : State) : Result (State × Unit) := do - let (st0, _) ← - betree.BeTree.apply_fwd self key betree_message_t.Delete st - let _ ← betree.BeTree.apply_back self key betree_message_t.Delete st + let (st0, _) ← betree.BeTree.apply_fwd 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] -/ def betree.BeTree.delete_back - (self : betree_be_tree_t) (key : U64) (st : State) : - Result betree_be_tree_t - := - betree.BeTree.apply_back self key betree_message_t.Delete st + (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 - (self : betree_be_tree_t) (key : U64) (upd : betree_upsert_fun_state_t) - (st : State) : + (self : betree.BeTree) (key : U64) (upd : betree.UpsertFunState) (st : State) + : Result (State × Unit) := do let (st0, _) ← - betree.BeTree.apply_fwd self key (betree_message_t.Upsert upd) st - let _ ← - betree.BeTree.apply_back self key (betree_message_t.Upsert upd) st + betree.BeTree.apply_fwd 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] -/ def betree.BeTree.upsert_back - (self : betree_be_tree_t) (key : U64) (upd : betree_upsert_fun_state_t) - (st : State) : - Result betree_be_tree_t + (self : betree.BeTree) (key : U64) (upd : betree.UpsertFunState) (st : State) + : + Result betree.BeTree := - betree.BeTree.apply_back self key (betree_message_t.Upsert upd) st + betree.BeTree.apply_back self key (betree.Message.Upsert upd) st /- [betree_main::betree::BeTree::{6}::lookup] -/ def betree.BeTree.lookup_fwd - (self : betree_be_tree_t) (key : U64) (st : State) : + (self : betree.BeTree) (key : U64) (st : State) : Result (State × (Option U64)) := betree.Node.lookup_fwd self.betree_be_tree_root key st /- [betree_main::betree::BeTree::{6}::lookup] -/ def betree.BeTree.lookup_back - (self : betree_be_tree_t) (key : U64) (st : State) : - Result betree_be_tree_t - := + (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 } diff --git a/tests/lean/BetreeMain/FunsExternal.lean b/tests/lean/BetreeMain/FunsExternal.lean index 0c715ef9..7bcba380 100644 --- a/tests/lean/BetreeMain/FunsExternal.lean +++ b/tests/lean/BetreeMain/FunsExternal.lean @@ -9,24 +9,24 @@ open betree_main /- [betree_main::betree_utils::load_internal_node] -/ def betree_utils.load_internal_node_fwd : - U64 → State → Result (State × (betree_list_t (U64 × betree_message_t))) := + 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 : - U64 → betree_list_t (U64 × betree_message_t) → State → Result (State + 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 - : U64 → State → Result (State × (betree_list_t (U64 × U64))) := + : 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 - : U64 → betree_list_t (U64 × U64) → State → Result (State × Unit) := + : U64 → betree.List (U64 × U64) → State → Result (State × Unit) := fun _ _ _ => .fail .panic /- [core::option::Option::{0}::unwrap] -/ diff --git a/tests/lean/BetreeMain/FunsExternal_Template.lean b/tests/lean/BetreeMain/FunsExternal_Template.lean index 9b5a54e5..d768bb20 100644 --- a/tests/lean/BetreeMain/FunsExternal_Template.lean +++ b/tests/lean/BetreeMain/FunsExternal_Template.lean @@ -8,22 +8,21 @@ open betree_main /- [betree_main::betree_utils::load_internal_node] -/ axiom betree_utils.load_internal_node_fwd - : - U64 → State → Result (State × (betree_list_t (U64 × betree_message_t))) + : U64 → State → Result (State × (betree.List (U64 × betree.Message))) /- [betree_main::betree_utils::store_internal_node] -/ axiom betree_utils.store_internal_node_fwd : - U64 → betree_list_t (U64 × betree_message_t) → State → Result (State - × Unit) + U64 → betree.List (U64 × betree.Message) → State → Result (State × + Unit) /- [betree_main::betree_utils::load_leaf_node] -/ axiom betree_utils.load_leaf_node_fwd - : U64 → State → Result (State × (betree_list_t (U64 × U64))) + : U64 → State → Result (State × (betree.List (U64 × U64))) /- [betree_main::betree_utils::store_leaf_node] -/ axiom betree_utils.store_leaf_node_fwd - : U64 → betree_list_t (U64 × U64) → State → Result (State × Unit) + : U64 → betree.List (U64 × U64) → State → Result (State × Unit) /- [core::option::Option::{0}::unwrap] -/ axiom core.option.Option.unwrap_fwd diff --git a/tests/lean/BetreeMain/Types.lean b/tests/lean/BetreeMain/Types.lean index 3ecbd668..afbdac9a 100644 --- a/tests/lean/BetreeMain/Types.lean +++ b/tests/lean/BetreeMain/Types.lean @@ -5,53 +5,53 @@ open Primitives namespace betree_main /- [betree_main::betree::List] -/ -inductive betree_list_t (T : Type) := -| Cons : T → betree_list_t T → betree_list_t T -| Nil : betree_list_t T +inductive betree.List (T : Type) := +| Cons : T → betree.List T → betree.List T +| Nil : betree.List T /- [betree_main::betree::UpsertFunState] -/ -inductive betree_upsert_fun_state_t := -| Add : U64 → betree_upsert_fun_state_t -| Sub : U64 → betree_upsert_fun_state_t +inductive betree.UpsertFunState := +| Add : U64 → betree.UpsertFunState +| Sub : U64 → betree.UpsertFunState /- [betree_main::betree::Message] -/ -inductive betree_message_t := -| Insert : U64 → betree_message_t -| Delete : betree_message_t -| Upsert : betree_upsert_fun_state_t → betree_message_t +inductive betree.Message := +| Insert : U64 → betree.Message +| Delete : betree.Message +| Upsert : betree.UpsertFunState → betree.Message /- [betree_main::betree::Leaf] -/ -structure betree_leaf_t where +structure betree.Leaf where betree_leaf_id : U64 betree_leaf_size : U64 mutual /- [betree_main::betree::Node] -/ -inductive betree_node_t := -| Internal : betree_internal_t → betree_node_t -| Leaf : betree_leaf_t → betree_node_t +inductive betree.Node := +| Internal : betree.Internal → betree.Node +| Leaf : betree.Leaf → betree.Node /- [betree_main::betree::Internal] -/ -inductive betree_internal_t := -| mk : U64 → U64 → betree_node_t → betree_node_t → betree_internal_t +inductive betree.Internal := +| mk : U64 → U64 → betree.Node → betree.Node → betree.Internal end /- [betree_main::betree::Params] -/ -structure betree_params_t where +structure betree.Params where betree_params_min_flush_size : U64 betree_params_split_size : U64 /- [betree_main::betree::NodeIdCounter] -/ -structure betree_node_id_counter_t where +structure betree.NodeIdCounter where betree_node_id_counter_next_node_id : U64 /- [betree_main::betree::BeTree] -/ -structure betree_be_tree_t where - betree_be_tree_params : betree_params_t - betree_be_tree_node_id_cnt : betree_node_id_counter_t - betree_be_tree_root : betree_node_t +structure betree.BeTree where + betree_be_tree_params : betree.Params + betree_be_tree_node_id_cnt : betree.NodeIdCounter + betree_be_tree_root : betree.Node /- The state type used in the state-error monad -/ axiom State : Type -- cgit v1.2.3 From 5ca36bfc50083a01af2b7ae5f75993a520757ef5 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 5 Jul 2023 15:17:58 +0200 Subject: Simplify the names used in Primitives.lean --- tests/lean/BetreeMain/Funs.lean | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index 3a678c71..074fff5e 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -124,13 +124,13 @@ divergent def betree.List.split_at_fwd /- [betree_main::betree::List::{1}::push_front] -/ def betree.List.push_front_fwd_back (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_fwd (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 + let ls := mem.replace_fwd (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 @@ -138,7 +138,7 @@ def betree.List.pop_front_fwd (T : Type) (self : betree.List T) : Result T := /- [betree_main::betree::List::{1}::pop_front] -/ 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_fwd (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 -- cgit v1.2.3 From 7c95800cefc87fad894f8bf855cfc047e713b3a7 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 6 Jul 2023 12:20:28 +0200 Subject: Improve the generated comments --- tests/lean/BetreeMain/Funs.lean | 472 +++++++++++------------ tests/lean/BetreeMain/FunsExternal.lean | 10 +- tests/lean/BetreeMain/FunsExternal_Template.lean | 20 +- 3 files changed, 249 insertions(+), 253 deletions(-) (limited to 'tests/lean/BetreeMain') 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) -- cgit v1.2.3 From 36c3348bacf7127d3736f9aac16a430a30424020 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 6 Jul 2023 13:46:26 +0200 Subject: Use short names for the structure fields in Lean --- tests/lean/BetreeMain/Funs.lean | 106 ++++++++++++++------------------------- tests/lean/BetreeMain/Types.lean | 16 +++--- 2 files changed, 47 insertions(+), 75 deletions(-) (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index 41e4349e..b0939155 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -48,23 +48,20 @@ def betree.fresh_node_id_back (counter : U64) : Result U64 := /- [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)) } + Result.ret { next_node_id := (U64.ofInt 0 (by intlit)) } /- [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 + let _ ← self.next_node_id + (U64.ofInt 1 (by intlit)) + Result.ret self.next_node_id /- [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 -/ def betree.NodeIdCounter.fresh_id_back (self : betree.NodeIdCounter) : Result betree.NodeIdCounter := do - let i ← self.betree_node_id_counter_next_node_id + - (U64.ofInt 1 (by intlit)) - Result.ret { betree_node_id_counter_next_node_id := i } + let i ← self.next_node_id + (U64.ofInt 1 (by intlit)) + Result.ret { next_node_id := i } /- [core::num::u64::{10}::MAX] -/ def core_num_u64_max_body : Result U64 := @@ -181,8 +178,7 @@ def betree.Leaf.split Result (State × betree.Internal) := do - let p ← - betree.List.split_at (U64 × U64) content params.betree_params_split_size + let p ← betree.List.split_at (U64 × U64) content params.split_size let (content0, content1) := p let p0 ← betree.List.hd (U64 × U64) content1 let (pivot, _) := p0 @@ -191,17 +187,9 @@ def betree.Leaf.split 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, - betree_leaf_size := params.betree_params_split_size - } - let n0 := betree.Node.Leaf - { - betree_leaf_id := id1, - betree_leaf_size := params.betree_params_split_size - } - Result.ret (st1, betree.Internal.mk self.betree_leaf_id pivot n n0) + let n := betree.Node.Leaf { id := id0, size := params.split_size } + let n0 := betree.Node.Leaf { id := id1, size := params.split_size } + Result.ret (st1, betree.Internal.mk self.id pivot n n0) /- [betree_main::betree::Leaf::{3}::split]: backward function 2 -/ def betree.Leaf.split_back @@ -210,8 +198,7 @@ def betree.Leaf.split_back Result betree.NodeIdCounter := do - let p ← - betree.List.split_at (U64 × U64) content params.betree_params_split_size + let p ← betree.List.split_at (U64 × U64) content params.split_size let (content0, content1) := p let _ ← betree.List.hd (U64 × U64) content1 let id0 ← betree.NodeIdCounter.fresh_id node_id_cnt @@ -392,7 +379,7 @@ mutual divergent def betree.Node.lookup Result.ret (st1, opt) | betree.Node.Leaf node => do - let (st0, bindings) ← betree.load_leaf_node node.betree_leaf_id st + let (st0, bindings) ← betree.load_leaf_node node.id st let opt ← betree.Node.lookup_in_bindings key bindings Result.ret (st0, opt) @@ -463,7 +450,7 @@ divergent def betree.Node.lookup_back Result.ret (betree.Node.Internal node0) | betree.Node.Leaf node => do - let (_, bindings) ← betree.load_leaf_node node.betree_leaf_id st + let (_, bindings) ← betree.load_leaf_node node.id st let _ ← betree.Node.lookup_in_bindings key bindings Result.ret (betree.Node.Leaf node) @@ -732,7 +719,7 @@ mutual divergent def betree.Node.apply_messages 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 + if num_msgs >= params.min_flush_size then do let (st1, content1) ← @@ -750,22 +737,20 @@ mutual divergent def betree.Node.apply_messages Result.ret (st1, ()) | betree.Node.Leaf node => do - let (st0, content) ← betree.load_leaf_node node.betree_leaf_id st + let (st0, content) ← betree.load_leaf_node node.id st let content0 ← betree.Node.apply_messages_to_leaf content msgs let len ← betree.List.len (U64 × U64) content0 - let i ← (U64.ofInt 2 (by intlit)) * params.betree_params_split_size + let i ← (U64.ofInt 2 (by intlit)) * params.split_size if len >= i then do let (st1, _) ← betree.Leaf.split node content0 params node_id_cnt st0 - let (st2, _) ← - betree.store_leaf_node node.betree_leaf_id betree.List.Nil st1 + let (st2, _) ← betree.store_leaf_node node.id betree.List.Nil st1 Result.ret (st2, ()) else do - let (st1, _) ← - betree.store_leaf_node node.betree_leaf_id content0 st0 + let (st1, _) ← betree.store_leaf_node node.id content0 st0 Result.ret (st1, ()) /- [betree_main::betree::Node::{5}::apply_messages]: backward function 0 -/ @@ -782,7 +767,7 @@ divergent def betree.Node.apply_messages_back 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 + if num_msgs >= params.min_flush_size then do let (st1, content1) ← @@ -802,25 +787,23 @@ divergent def betree.Node.apply_messages_back node_id_cnt) | betree.Node.Leaf node => do - let (st0, content) ← betree.load_leaf_node node.betree_leaf_id st + let (st0, content) ← betree.load_leaf_node node.id st let content0 ← betree.Node.apply_messages_to_leaf content msgs let len ← betree.List.len (U64 × U64) content0 - let i ← (U64.ofInt 2 (by intlit)) * params.betree_params_split_size + let i ← (U64.ofInt 2 (by intlit)) * params.split_size if len >= i then do let (st1, new_node) ← betree.Leaf.split node content0 params node_id_cnt st0 - let _ ← - betree.store_leaf_node node.betree_leaf_id betree.List.Nil st1 + let _ ← betree.store_leaf_node node.id betree.List.Nil st1 let node_id_cnt0 ← betree.Leaf.split_back node content0 params node_id_cnt st0 Result.ret (betree.Node.Internal new_node, node_id_cnt0) else do - let _ ← betree.store_leaf_node node.betree_leaf_id content0 st0 - Result.ret (betree.Node.Leaf { node with betree_leaf_size := len }, - node_id_cnt) + let _ ← betree.store_leaf_node node.id content0 st0 + Result.ret (betree.Node.Leaf { node with size := len }, node_id_cnt) /- [betree_main::betree::Internal::{4}::flush]: forward function -/ divergent def betree.Internal.flush @@ -834,7 +817,7 @@ divergent def betree.Internal.flush let p ← betree.List.partition_at_pivot betree.Message content i let (msgs_left, msgs_right) := p let len_left ← betree.List.len (U64 × betree.Message) msgs_left - if len_left >= params.betree_params_min_flush_size + if len_left >= params.min_flush_size then do let (st0, _) ← @@ -842,7 +825,7 @@ divergent def betree.Internal.flush let (_, node_id_cnt0) ← betree.Node.apply_messages_back n params node_id_cnt msgs_left st let len_right ← betree.List.len (U64 × betree.Message) msgs_right - if len_right >= params.betree_params_min_flush_size + if len_right >= params.min_flush_size then do let (st1, _) ← @@ -872,7 +855,7 @@ divergent def betree.Internal.flush_back let p ← betree.List.partition_at_pivot betree.Message content i0 let (msgs_left, msgs_right) := p let len_left ← betree.List.len (U64 × betree.Message) msgs_left - if len_left >= params.betree_params_min_flush_size + if len_left >= params.min_flush_size then do let (st0, _) ← @@ -880,7 +863,7 @@ divergent def betree.Internal.flush_back let (n1, node_id_cnt0) ← betree.Node.apply_messages_back n params node_id_cnt msgs_left st let len_right ← betree.List.len (U64 × betree.Message) msgs_right - if len_right >= params.betree_params_min_flush_size + if len_right >= params.min_flush_size then do let (n2, node_id_cnt1) ← @@ -936,18 +919,11 @@ def betree.BeTree.new let node_id_cnt0 ← betree.NodeIdCounter.fresh_id_back node_id_cnt Result.ret (st0, { - betree_be_tree_params := - { - betree_params_min_flush_size := min_flush_size, - betree_params_split_size := split_size - }, - betree_be_tree_node_id_cnt := node_id_cnt0, - betree_be_tree_root := - (betree.Node.Leaf - { - betree_leaf_id := id, - betree_leaf_size := (U64.ofInt 0 (by intlit)) - }) + params := + { min_flush_size := min_flush_size, split_size := split_size }, + node_id_cnt := node_id_cnt0, + root := + (betree.Node.Leaf { id := id, size := (U64.ofInt 0 (by intlit)) }) }) /- [betree_main::betree::BeTree::{6}::apply]: forward function -/ @@ -957,11 +933,9 @@ def betree.BeTree.apply := do let (st0, _) ← - betree.Node.apply self.betree_be_tree_root self.betree_be_tree_params - self.betree_be_tree_node_id_cnt key msg st + betree.Node.apply self.root self.params self.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 + betree.Node.apply_back self.root self.params self.node_id_cnt key msg st Result.ret (st0, ()) /- [betree_main::betree::BeTree::{6}::apply]: backward function 0 -/ @@ -971,10 +945,8 @@ def betree.BeTree.apply_back := do let (n, nic) ← - 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 - { self with betree_be_tree_node_id_cnt := nic, betree_be_tree_root := n } + betree.Node.apply_back self.root self.params self.node_id_cnt key msg st + Result.ret { self with node_id_cnt := nic, root := n } /- [betree_main::betree::BeTree::{6}::insert]: forward function -/ def betree.BeTree.insert @@ -1033,14 +1005,14 @@ def betree.BeTree.lookup (self : betree.BeTree) (key : U64) (st : State) : Result (State × (Option U64)) := - betree.Node.lookup self.betree_be_tree_root key st + betree.Node.lookup self.root key st /- [betree_main::betree::BeTree::{6}::lookup]: backward function 0 -/ def betree.BeTree.lookup_back (self : betree.BeTree) (key : U64) (st : State) : Result betree.BeTree := do - let n ← betree.Node.lookup_back self.betree_be_tree_root key st - Result.ret { self with betree_be_tree_root := n } + let n ← betree.Node.lookup_back self.root key st + Result.ret { self with root := n } /- [betree_main::main]: forward function -/ def main : Result Unit := diff --git a/tests/lean/BetreeMain/Types.lean b/tests/lean/BetreeMain/Types.lean index afbdac9a..783ade64 100644 --- a/tests/lean/BetreeMain/Types.lean +++ b/tests/lean/BetreeMain/Types.lean @@ -22,8 +22,8 @@ inductive betree.Message := /- [betree_main::betree::Leaf] -/ structure betree.Leaf where - betree_leaf_id : U64 - betree_leaf_size : U64 + id : U64 + size : U64 mutual @@ -40,18 +40,18 @@ end /- [betree_main::betree::Params] -/ structure betree.Params where - betree_params_min_flush_size : U64 - betree_params_split_size : U64 + min_flush_size : U64 + split_size : U64 /- [betree_main::betree::NodeIdCounter] -/ structure betree.NodeIdCounter where - betree_node_id_counter_next_node_id : U64 + next_node_id : U64 /- [betree_main::betree::BeTree] -/ structure betree.BeTree where - betree_be_tree_params : betree.Params - betree_be_tree_node_id_cnt : betree.NodeIdCounter - betree_be_tree_root : betree.Node + params : betree.Params + node_id_cnt : betree.NodeIdCounter + root : betree.Node /- The state type used in the state-error monad -/ axiom State : Type -- cgit v1.2.3 From e010c10fb9a1e2d88b52a4f6b4a0865448276013 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 12 Jul 2023 15:58:38 +0200 Subject: Make the `by inlit` implicit --- tests/lean/BetreeMain/Funs.lean | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'tests/lean/BetreeMain') diff --git a/tests/lean/BetreeMain/Funs.lean b/tests/lean/BetreeMain/Funs.lean index b0939155..142adf08 100644 --- a/tests/lean/BetreeMain/Funs.lean +++ b/tests/lean/BetreeMain/Funs.lean @@ -39,33 +39,33 @@ def betree.store_leaf_node /- [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)) + let _ ← counter + (U64.ofInt 1) Result.ret counter /- [betree_main::betree::fresh_node_id]: backward function 0 -/ def betree.fresh_node_id_back (counter : U64) : Result U64 := - counter + (U64.ofInt 1 (by intlit)) + counter + (U64.ofInt 1) /- [betree_main::betree::NodeIdCounter::{0}::new]: forward function -/ def betree.NodeIdCounter.new : Result betree.NodeIdCounter := - Result.ret { next_node_id := (U64.ofInt 0 (by intlit)) } + Result.ret { next_node_id := (U64.ofInt 0) } /- [betree_main::betree::NodeIdCounter::{0}::fresh_id]: forward function -/ def betree.NodeIdCounter.fresh_id (self : betree.NodeIdCounter) : Result U64 := do - let _ ← self.next_node_id + (U64.ofInt 1 (by intlit)) + let _ ← self.next_node_id + (U64.ofInt 1) Result.ret self.next_node_id /- [betree_main::betree::NodeIdCounter::{0}::fresh_id]: backward function 0 -/ def betree.NodeIdCounter.fresh_id_back (self : betree.NodeIdCounter) : Result betree.NodeIdCounter := do - let i ← self.next_node_id + (U64.ofInt 1 (by intlit)) + let i ← self.next_node_id + (U64.ofInt 1) Result.ret { next_node_id := i } /- [core::num::u64::{10}::MAX] -/ def core_num_u64_max_body : Result U64 := - Result.ret (U64.ofInt 18446744073709551615 (by intlit)) + Result.ret (U64.ofInt 18446744073709551615) def core_num_u64_max_c : U64 := eval_global core_num_u64_max_body (by simp) /- [betree_main::betree::upsert_update]: forward function -/ @@ -75,7 +75,7 @@ def betree.upsert_update | Option.none => match st with | betree.UpsertFunState.Add v => Result.ret v - | betree.UpsertFunState.Sub i => Result.ret (U64.ofInt 0 (by intlit)) + | betree.UpsertFunState.Sub i => Result.ret (U64.ofInt 0) | Option.some prev0 => match st with | betree.UpsertFunState.Add v => @@ -87,7 +87,7 @@ def betree.upsert_update | betree.UpsertFunState.Sub v => if prev0 >= v then prev0 - v - else Result.ret (U64.ofInt 0 (by intlit)) + else Result.ret (U64.ofInt 0) /- [betree_main::betree::List::{1}::len]: forward function -/ divergent def betree.List.len (T : Type) (self : betree.List T) : Result U64 := @@ -95,21 +95,21 @@ divergent def betree.List.len (T : Type) (self : betree.List T) : Result U64 := | betree.List.Cons t tl => do let i ← betree.List.len T tl - (U64.ofInt 1 (by intlit)) + i - | betree.List.Nil => Result.ret (U64.ofInt 0 (by intlit)) + (U64.ofInt 1) + i + | betree.List.Nil => Result.ret (U64.ofInt 0) /- [betree_main::betree::List::{1}::split_at]: forward function -/ divergent def betree.List.split_at (T : Type) (self : betree.List T) (n : U64) : Result ((betree.List T) × (betree.List T)) := - if n = (U64.ofInt 0 (by intlit)) + if n = (U64.ofInt 0) then Result.ret (betree.List.Nil, self) else match self with | betree.List.Cons hd tl => do - let i ← n - (U64.ofInt 1 (by intlit)) + let i ← n - (U64.ofInt 1) let p ← betree.List.split_at T tl i let (ls0, ls1) := p let l := ls0 @@ -740,7 +740,7 @@ mutual divergent def betree.Node.apply_messages let (st0, content) ← betree.load_leaf_node node.id st let content0 ← betree.Node.apply_messages_to_leaf content msgs let len ← betree.List.len (U64 × U64) content0 - let i ← (U64.ofInt 2 (by intlit)) * params.split_size + let i ← (U64.ofInt 2) * params.split_size if len >= i then do @@ -790,7 +790,7 @@ divergent def betree.Node.apply_messages_back let (st0, content) ← betree.load_leaf_node node.id st let content0 ← betree.Node.apply_messages_to_leaf content msgs let len ← betree.List.len (U64 × U64) content0 - let i ← (U64.ofInt 2 (by intlit)) * params.split_size + let i ← (U64.ofInt 2) * params.split_size if len >= i then do @@ -922,8 +922,7 @@ def betree.BeTree.new params := { min_flush_size := min_flush_size, split_size := split_size }, node_id_cnt := node_id_cnt0, - root := - (betree.Node.Leaf { id := id, size := (U64.ofInt 0 (by intlit)) }) + root := (betree.Node.Leaf { id := id, size := (U64.ofInt 0) }) }) /- [betree_main::betree::BeTree::{6}::apply]: forward function -/ -- cgit v1.2.3