diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hashmap/Hashmap.Funs.fst | 140 | ||||
-rw-r--r-- | tests/misc/NoNestedBorrows.fst | 42 | ||||
-rw-r--r-- | tests/misc/Paper.fst | 17 |
3 files changed, 92 insertions, 107 deletions
diff --git a/tests/hashmap/Hashmap.Funs.fst b/tests/hashmap/Hashmap.Funs.fst index 4aa6f02c..318b0cf4 100644 --- a/tests/hashmap/Hashmap.Funs.fst +++ b/tests/hashmap/Hashmap.Funs.fst @@ -8,7 +8,7 @@ include Hashmap.Clauses #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" (** [hashmap::hash_key] *) -let hash_key_fwd (k : usize) : result usize = let i = k in Return i +let hash_key_fwd (k : usize) : result usize = Return k (** [hashmap::HashMap::allocate_slots] *) let rec hash_map_allocate_slots_fwd @@ -78,25 +78,25 @@ let rec hash_map_clear_slots_fwd_back | Return i1 -> begin match hash_map_clear_slots_fwd_back t v i1 with | Fail -> Fail - | Return v0 -> let slots0 = v0 in Return slots0 + | Return v0 -> Return v0 end end end - else let slots0 = slots in Return slots0 + else Return slots (** [hashmap::HashMap::clear] *) let hash_map_clear_fwd_back (t : Type0) (self : hash_map_t t) : result (hash_map_t t) = - let p = self.hash_map_max_load_factor in - let i = self.hash_map_max_load in begin match hash_map_clear_slots_fwd_back t self.hash_map_slots 0 with | Fail -> Fail - | Return v -> let self0 = Mkhash_map_t 0 p i v in Return self0 + | Return v -> + Return (Mkhash_map_t 0 self.hash_map_max_load_factor self.hash_map_max_load + v) end (** [hashmap::HashMap::len] *) let hash_map_len_fwd (t : Type0) (self : hash_map_t t) : result usize = - let i = self.hash_map_num_entries in Return i + Return self.hash_map_num_entries (** [hashmap::HashMap::insert_in_list] *) let rec hash_map_insert_in_list_fwd @@ -125,13 +125,13 @@ let rec hash_map_insert_in_list_back begin match ls with | ListCons ckey cvalue ls0 -> if ckey = key - then let ls1 = ListCons ckey value ls0 in Return ls1 + then Return (ListCons ckey value ls0) else begin match hash_map_insert_in_list_back t key value ls0 with | Fail -> Fail - | Return l -> let ls1 = ListCons ckey cvalue l in Return ls1 + | Return l -> Return (ListCons ckey cvalue l) end - | ListNil -> let l = ListNil in let ls0 = ListCons key value l in Return ls0 + | ListNil -> let l = ListNil in Return (ListCons key value l) end (** [hashmap::HashMap::insert_no_resize] *) @@ -142,11 +142,8 @@ let hash_map_insert_no_resize_fwd_back begin match hash_key_fwd key with | Fail -> Fail | Return i -> - let i0 = self.hash_map_num_entries in - let p = self.hash_map_max_load_factor in - let i1 = self.hash_map_max_load in - let i2 = vec_len (list_t t) self.hash_map_slots in - begin match usize_rem i i2 with + let i0 = vec_len (list_t t) self.hash_map_slots in + begin match usize_rem i i0 with | Fail -> Fail | Return hash_mod -> begin match vec_index_mut_fwd (list_t t) self.hash_map_slots hash_mod @@ -160,7 +157,7 @@ let hash_map_insert_no_resize_fwd_back then begin match usize_add self.hash_map_num_entries 1 with | Fail -> Fail - | Return i3 -> + | Return i1 -> begin match hash_map_insert_in_list_back t key value l with | Fail -> Fail | Return l0 -> @@ -169,7 +166,8 @@ let hash_map_insert_no_resize_fwd_back with | Fail -> Fail | Return v -> - let self0 = Mkhash_map_t i3 p i1 v in Return self0 + Return (Mkhash_map_t i1 self.hash_map_max_load_factor + self.hash_map_max_load v) end end end @@ -181,7 +179,10 @@ let hash_map_insert_no_resize_fwd_back vec_index_mut_back (list_t t) self.hash_map_slots hash_mod l0 with | Fail -> Fail - | Return v -> let self0 = Mkhash_map_t i0 p i1 v in Return self0 + | Return v -> + Return (Mkhash_map_t self.hash_map_num_entries + self.hash_map_max_load_factor self.hash_map_max_load + v) end end end @@ -202,10 +203,10 @@ let rec hash_map_move_elements_from_list_fwd_back | Return h -> begin match hash_map_move_elements_from_list_fwd_back t h tl with | Fail -> Fail - | Return h0 -> let ntable0 = h0 in Return ntable0 + | Return h0 -> Return h0 end end - | ListNil -> let ntable0 = ntable in Return ntable0 + | ListNil -> Return ntable end (** [hashmap::HashMap::move_elements] *) @@ -233,51 +234,46 @@ let rec hash_map_move_elements_fwd_back | Return i1 -> begin match hash_map_move_elements_fwd_back t h v i1 with | Fail -> Fail - | Return (h0, v0) -> - let ntable0 = h0 in let slots0 = v0 in Return (ntable0, slots0) + | Return (h0, v0) -> Return (h0, v0) end end end end end - else let ntable0 = ntable in let slots0 = slots in Return (ntable0, slots0) + else Return (ntable, slots) (** [hashmap::HashMap::try_resize] *) let hash_map_try_resize_fwd_back (t : Type0) (self : hash_map_t t) : result (hash_map_t t) = - let i = self.hash_map_num_entries in - let i0 = self.hash_map_max_load in - let v = self.hash_map_slots in - let i1 = vec_len (list_t t) self.hash_map_slots in + let i = vec_len (list_t t) self.hash_map_slots in begin match usize_div 4294967295 2 with | Fail -> Fail | Return n1 -> - let (i2, i3) = self.hash_map_max_load_factor in - begin match usize_div n1 i2 with + let (i0, i1) = self.hash_map_max_load_factor in + begin match usize_div n1 i0 with | Fail -> Fail - | Return i4 -> - if i1 <= i4 + | Return i2 -> + if i <= i2 then - begin match usize_mul i1 2 with + begin match usize_mul i 2 with | Fail -> Fail - | Return i5 -> - begin match hash_map_new_with_capacity_fwd t i5 i2 i3 with + | Return i3 -> + begin match hash_map_new_with_capacity_fwd t i3 i0 i1 with | Fail -> Fail | Return h -> begin match hash_map_move_elements_fwd_back t h self.hash_map_slots 0 with | Fail -> Fail - | Return (h0, v0) -> - let i6 = h0.hash_map_max_load in - let v1 = mem_replace_back (vec (list_t t)) v0 h0.hash_map_slots - in - let self0 = Mkhash_map_t i (i2, i3) i6 v1 in - Return - self0 + | Return (h0, v) -> + let v0 = mem_replace_back (vec (list_t t)) v h0.hash_map_slots in + Return (Mkhash_map_t self.hash_map_num_entries (i0, i1) + h0.hash_map_max_load v0) end end end - else let self0 = Mkhash_map_t i (i2, i3) i0 v in Return self0 + else + Return (Mkhash_map_t self.hash_map_num_entries (i0, i1) + self.hash_map_max_load self.hash_map_slots) end end @@ -292,18 +288,18 @@ let hash_map_insert_fwd_back begin match hash_map_len_fwd t h with | Fail -> Fail | Return i -> - let i0 = h.hash_map_num_entries in - let p = h.hash_map_max_load_factor in - let i1 = h.hash_map_max_load in - let v = h.hash_map_slots in if i > h.hash_map_max_load then - begin match hash_map_try_resize_fwd_back t (Mkhash_map_t i0 p i1 v) + begin match + hash_map_try_resize_fwd_back t (Mkhash_map_t h.hash_map_num_entries + h.hash_map_max_load_factor h.hash_map_max_load h.hash_map_slots) with | Fail -> Fail - | Return h0 -> let self0 = h0 in Return self0 + | Return h0 -> Return h0 end - else let self0 = Mkhash_map_t i0 p i1 v in Return self0 + else + Return (Mkhash_map_t h.hash_map_num_entries h.hash_map_max_load_factor + h.hash_map_max_load h.hash_map_slots) end end @@ -358,7 +354,7 @@ let rec hash_map_get_in_list_fwd else begin match hash_map_get_in_list_fwd t key ls0 with | Fail -> Fail - | Return x -> let x0 = x in Return x0 + | Return x -> Return x end | ListNil -> Fail end @@ -378,7 +374,7 @@ let hash_map_get_fwd | Return l -> begin match hash_map_get_in_list_fwd t key l with | Fail -> Fail - | Return x -> let x0 = x in Return x0 + | Return x -> Return x end end end @@ -396,7 +392,7 @@ let rec hash_map_get_mut_in_list_fwd else begin match hash_map_get_mut_in_list_fwd t key ls0 with | Fail -> Fail - | Return x -> let x0 = x in Return x0 + | Return x -> Return x end | ListNil -> Fail end @@ -410,11 +406,11 @@ let rec hash_map_get_mut_in_list_back begin match ls with | ListCons ckey cvalue ls0 -> if ckey = key - then let x = ret in let ls1 = ListCons ckey x ls0 in Return ls1 + then Return (ListCons ckey ret ls0) else begin match hash_map_get_mut_in_list_back t key ls0 ret with | Fail -> Fail - | Return l -> let ls1 = ListCons ckey cvalue l in Return ls1 + | Return l -> Return (ListCons ckey cvalue l) end | ListNil -> Fail end @@ -435,7 +431,7 @@ let hash_map_get_mut_fwd | Return l -> begin match hash_map_get_mut_in_list_fwd t key l with | Fail -> Fail - | Return x -> let x0 = x in Return x0 + | Return x -> Return x end end end @@ -449,11 +445,8 @@ let hash_map_get_mut_back begin match hash_key_fwd key with | Fail -> Fail | Return i -> - let i0 = self.hash_map_num_entries in - let p = self.hash_map_max_load_factor in - let i1 = self.hash_map_max_load in - let i2 = vec_len (list_t t) self.hash_map_slots in - begin match usize_rem i i2 with + let i0 = vec_len (list_t t) self.hash_map_slots in + begin match usize_rem i i0 with | Fail -> Fail | Return hash_mod -> begin match vec_index_mut_fwd (list_t t) self.hash_map_slots hash_mod @@ -466,7 +459,9 @@ let hash_map_get_mut_back begin match vec_index_mut_back (list_t t) self.hash_map_slots hash_mod l0 with | Fail -> Fail - | Return v -> let self0 = Mkhash_map_t i0 p i1 v in Return self0 + | Return v -> + Return (Mkhash_map_t self.hash_map_num_entries + self.hash_map_max_load_factor self.hash_map_max_load v) end end end @@ -508,15 +503,15 @@ let rec hash_map_remove_from_list_back then let mv_ls = mem_replace_fwd (list_t t) (ListCons ckey x tl) ListNil in begin match mv_ls with - | ListCons i cvalue tl0 -> let ls0 = tl0 in Return ls0 + | ListCons i cvalue tl0 -> Return tl0 | ListNil -> Fail end else begin match hash_map_remove_from_list_back t key tl with | Fail -> Fail - | Return l -> let ls0 = ListCons ckey x l in Return ls0 + | Return l -> Return (ListCons ckey x l) end - | ListNil -> let ls0 = ListNil in Return ls0 + | ListNil -> Return ListNil end (** [hashmap::HashMap::remove] *) @@ -555,11 +550,8 @@ let hash_map_remove_back begin match hash_key_fwd key with | Fail -> Fail | Return i -> - let i0 = self.hash_map_num_entries in - let p = self.hash_map_max_load_factor in - let i1 = self.hash_map_max_load in - let i2 = vec_len (list_t t) self.hash_map_slots in - begin match usize_rem i i2 with + let i0 = vec_len (list_t t) self.hash_map_slots in + begin match usize_rem i i0 with | Fail -> Fail | Return hash_mod -> begin match vec_index_mut_fwd (list_t t) self.hash_map_slots hash_mod @@ -578,13 +570,16 @@ let hash_map_remove_back vec_index_mut_back (list_t t) self.hash_map_slots hash_mod l0 with | Fail -> Fail - | Return v -> let self0 = Mkhash_map_t i0 p i1 v in Return self0 + | Return v -> + Return (Mkhash_map_t self.hash_map_num_entries + self.hash_map_max_load_factor self.hash_map_max_load + v) end end | Some x0 -> begin match usize_sub self.hash_map_num_entries 1 with | Fail -> Fail - | Return i3 -> + | Return i1 -> begin match hash_map_remove_from_list_back t key l with | Fail -> Fail | Return l0 -> @@ -593,7 +588,8 @@ let hash_map_remove_back with | Fail -> Fail | Return v -> - let self0 = Mkhash_map_t i3 p i1 v in Return self0 + Return (Mkhash_map_t i1 self.hash_map_max_load_factor + self.hash_map_max_load v) end end end diff --git a/tests/misc/NoNestedBorrows.fst b/tests/misc/NoNestedBorrows.fst index 505dfc73..9bcbaec5 100644 --- a/tests/misc/NoNestedBorrows.fst +++ b/tests/misc/NoNestedBorrows.fst @@ -157,10 +157,7 @@ let _ = assert_norm (test_is_cons_fwd = Return ()) (** [no_nested_borrows::split_list] *) let split_list_fwd (t : Type0) (l : list_t t) : result (t & (list_t t)) = - begin match l with - | ListCons hd tl -> let l0 = tl in Return (hd, l0) - | ListNil -> Fail - end + begin match l with | ListCons hd tl -> Return (hd, tl) | ListNil -> Fail end (** [no_nested_borrows::test_split_list] *) let test_split_list_fwd : result unit = @@ -175,14 +172,12 @@ let _ = assert_norm (test_split_list_fwd = Return ()) (** [no_nested_borrows::get_elem] *) let get_elem_fwd (t : Type0) (b : bool) (x : t) (y : t) : result t = - let x0 = y in let x1 = x in if b then Return x1 else Return x0 + if b then Return x else Return y (** [no_nested_borrows::get_elem] *) let get_elem_back (t : Type0) (b : bool) (x : t) (y : t) (ret : t) : result (t & t) = - if b - then let x0 = ret in let y0 = y in Return (x0, y0) - else let x0 = x in let y0 = ret in Return (x0, y0) + if b then Return (ret, y) else Return (x, ret) (** [no_nested_borrows::get_elem_test] *) let get_elem_test_fwd : result unit = @@ -300,7 +295,7 @@ let rec list_nth_shared_fwd (t : Type0) (l : list_t t) (i : u32) : result t = | Return i0 -> begin match list_nth_shared_fwd t tl i0 with | Fail -> Fail - | Return x0 -> let x1 = x0 in Return x1 + | Return x0 -> Return x0 end end end @@ -319,7 +314,7 @@ let rec list_nth_mut_fwd (t : Type0) (l : list_t t) (i : u32) : result t = | Return i0 -> begin match list_nth_mut_fwd t tl i0 with | Fail -> Fail - | Return x0 -> let x1 = x0 in Return x1 + | Return x0 -> Return x0 end end end @@ -332,14 +327,14 @@ let rec list_nth_mut_back begin match l with | ListCons x tl -> begin match i with - | 0 -> let x0 = ret in let l0 = ListCons x0 tl in Return l0 + | 0 -> Return (ListCons ret tl) | _ -> begin match u32_sub i 1 with | Fail -> Fail | Return i0 -> begin match list_nth_mut_back t tl i0 ret with | Fail -> Fail - | Return l0 -> let l1 = ListCons x l0 in Return l1 + | Return l0 -> Return (ListCons x l0) end end end @@ -408,49 +403,49 @@ let _ = assert_norm (test_list_functions_fwd = Return ()) (** [no_nested_borrows::id_mut_pair1] *) let id_mut_pair1_fwd (t1 t2 : Type0) (x : t1) (y : t2) : result (t1 & t2) = - let x0 = y in let x1 = x in Return (x1, x0) + Return (x, y) (** [no_nested_borrows::id_mut_pair1] *) let id_mut_pair1_back (t1 t2 : Type0) (x : t1) (y : t2) (ret : (t1 & t2)) : result (t1 & t2) = - let (x0, x1) = ret in let x2 = x0 in let y0 = x1 in Return (x2, y0) + let (x0, x1) = ret in Return (x0, x1) (** [no_nested_borrows::id_mut_pair2] *) let id_mut_pair2_fwd (t1 t2 : Type0) (p : (t1 & t2)) : result (t1 & t2) = - let (x, x0) = p in let x1 = x in let x2 = x0 in Return (x1, x2) + let (x, x0) = p in Return (x, x0) (** [no_nested_borrows::id_mut_pair2] *) let id_mut_pair2_back (t1 t2 : Type0) (p : (t1 & t2)) (ret : (t1 & t2)) : result (t1 & t2) = - let (x, x0) = ret in let p0 = (x, x0) in Return p0 + let (x, x0) = ret in Return (x, x0) (** [no_nested_borrows::id_mut_pair3] *) let id_mut_pair3_fwd (t1 t2 : Type0) (x : t1) (y : t2) : result (t1 & t2) = - let x0 = y in let x1 = x in Return (x1, x0) + Return (x, y) (** [no_nested_borrows::id_mut_pair3] *) let id_mut_pair3_back'a (t1 t2 : Type0) (x : t1) (y : t2) (ret : t1) : result t1 = - let x0 = ret in Return x0 + Return ret (** [no_nested_borrows::id_mut_pair3] *) let id_mut_pair3_back'b (t1 t2 : Type0) (x : t1) (y : t2) (ret : t2) : result t2 = - let y0 = ret in Return y0 + Return ret (** [no_nested_borrows::id_mut_pair4] *) let id_mut_pair4_fwd (t1 t2 : Type0) (p : (t1 & t2)) : result (t1 & t2) = - let (x, x0) = p in let x1 = x in let x2 = x0 in Return (x1, x2) + let (x, x0) = p in Return (x, x0) (** [no_nested_borrows::id_mut_pair4] *) let id_mut_pair4_back'a (t1 t2 : Type0) (p : (t1 & t2)) (ret : t1) : result t1 = - let p0 = ret in Return p0 + Return ret (** [no_nested_borrows::id_mut_pair4] *) let id_mut_pair4_back'b (t1 t2 : Type0) (p : (t1 & t2)) (ret : t2) : result t2 = - let p0 = ret in Return p0 + Return ret (** [no_nested_borrows::StructWithTuple] *) type struct_with_tuple_t (t1 t2 : Type0) = { struct_with_tuple_p : (t1 & t2); } @@ -521,6 +516,5 @@ let _ = assert_norm (test_weird_borrows1_fwd = Return ()) (** [no_nested_borrows::test_mem_replace] *) let test_mem_replace_fwd_back (px : u32) : result u32 = - let i = mem_replace_fwd u32 px 1 in - if not (i = 0) then Fail else let px0 = 2 in Return px0 + let i = mem_replace_fwd u32 px 1 in if not (i = 0) then Fail else Return 2 diff --git a/tests/misc/Paper.fst b/tests/misc/Paper.fst index 1ab42726..be4326d7 100644 --- a/tests/misc/Paper.fst +++ b/tests/misc/Paper.fst @@ -7,10 +7,7 @@ open Primitives (** [paper::ref_incr] *) let ref_incr_fwd_back (x : i32) : result i32 = - begin match i32_add x 1 with - | Fail -> Fail - | Return x0 -> let x1 = x0 in Return x1 - end + begin match i32_add x 1 with | Fail -> Fail | Return x0 -> Return x0 end (** [paper::test_incr] *) let test_incr_fwd : result unit = @@ -24,14 +21,12 @@ let _ = assert_norm (test_incr_fwd = Return ()) (** [paper::choose] *) let choose_fwd (t : Type0) (b : bool) (x : t) (y : t) : result t = - let x0 = y in let x1 = x in if b then Return x1 else Return x0 + if b then Return x else Return y (** [paper::choose] *) let choose_back (t : Type0) (b : bool) (x : t) (y : t) (ret : t) : result (t & t) = - if b - then let x0 = ret in let y0 = y in Return (x0, y0) - else let x0 = x in let y0 = ret in Return (x0, y0) + if b then Return (ret, y) else Return (x, ret) (** [paper::test_choose] *) let test_choose_fwd : result unit = @@ -74,7 +69,7 @@ let rec list_nth_mut_fwd (t : Type0) (l : list_t t) (i : u32) : result t = | Return i0 -> begin match list_nth_mut_fwd t tl i0 with | Fail -> Fail - | Return x0 -> let x1 = x0 in Return x1 + | Return x0 -> Return x0 end end end @@ -87,14 +82,14 @@ let rec list_nth_mut_back begin match l with | ListCons x tl -> begin match i with - | 0 -> let x0 = ret in let l0 = ListCons x0 tl in Return l0 + | 0 -> Return (ListCons ret tl) | _ -> begin match u32_sub i 1 with | Fail -> Fail | Return i0 -> begin match list_nth_mut_back t tl i0 ret with | Fail -> Fail - | Return l0 -> let l1 = ListCons x l0 in Return l1 + | Return l0 -> Return (ListCons x l0) end end end |