From cd754eabe3af025ca3465c5fc6d8cb48da66a1ae Mon Sep 17 00:00:00 2001 From: Sidney Congard Date: Wed, 10 Aug 2022 18:56:25 +0200 Subject: Corrected translation without using functions, remaining bug in hashmap translation --- tests/hashmap/Hashmap.Clauses.Template.fst | 4 ++++ tests/hashmap/Hashmap.Funs.fst | 19 +++++++++---------- tests/hashmap/Hashmap.Types.fst | 4 ++++ 3 files changed, 17 insertions(+), 10 deletions(-) (limited to 'tests/hashmap') diff --git a/tests/hashmap/Hashmap.Clauses.Template.fst b/tests/hashmap/Hashmap.Clauses.Template.fst index c1549e6b..2a3d9cb9 100644 --- a/tests/hashmap/Hashmap.Clauses.Template.fst +++ b/tests/hashmap/Hashmap.Clauses.Template.fst @@ -24,6 +24,10 @@ let hash_map_insert_in_list_decreases (t : Type0) (key : usize) (value : t) (ls : list_t t) : nat = admit () +(** [core::num::u32::{8}::MAX] *) +let core_num_u32_max_body : result u32 = Return 4294967295 +let core_num_u32_max_c : u32 = eval_global core_num_u32_max_body + (** [hashmap::HashMap::{0}::move_elements_from_list]: decreases clause *) unfold let hash_map_move_elements_from_list_decreases (t : Type0) diff --git a/tests/hashmap/Hashmap.Funs.fst b/tests/hashmap/Hashmap.Funs.fst index 921ed142..397ee720 100644 --- a/tests/hashmap/Hashmap.Funs.fst +++ b/tests/hashmap/Hashmap.Funs.fst @@ -248,24 +248,23 @@ let rec hash_map_move_elements_fwd_back (** [hashmap::HashMap::{0}::try_resize] *) let hash_map_try_resize_fwd_back (t : Type0) (self : hash_map_t t) : result (hash_map_t t) = - let i = core_num_u32_max_c in - begin match scalar_cast U32 Usize i with + begin match scalar_cast U32 Usize core_num_u32_max_c with | Fail -> Fail | Return max_usize -> let capacity = vec_len (list_t t) self.hash_map_slots in begin match usize_div max_usize 2 with | Fail -> Fail | Return n1 -> - let (i0, i1) = self.hash_map_max_load_factor in - begin match usize_div n1 i0 with + let (i, i0) = self.hash_map_max_load_factor in + begin match usize_div n1 i with | Fail -> Fail - | Return i2 -> - if capacity <= i2 + | Return i1 -> + if capacity <= i1 then begin match usize_mul capacity 2 with | Fail -> Fail - | Return i3 -> - begin match hash_map_new_with_capacity_fwd t i3 i0 i1 with + | Return i2 -> + begin match hash_map_new_with_capacity_fwd t i2 i i0 with | Fail -> Fail | Return ntable -> begin match @@ -273,13 +272,13 @@ let hash_map_try_resize_fwd_back with | Fail -> Fail | Return (ntable0, _) -> - Return (Mkhash_map_t self.hash_map_num_entries (i0, i1) + Return (Mkhash_map_t self.hash_map_num_entries (i, i0) ntable0.hash_map_max_load ntable0.hash_map_slots) end end end else - Return (Mkhash_map_t self.hash_map_num_entries (i0, i1) + Return (Mkhash_map_t self.hash_map_num_entries (i, i0) self.hash_map_max_load self.hash_map_slots) end end diff --git a/tests/hashmap/Hashmap.Types.fst b/tests/hashmap/Hashmap.Types.fst index 91ee26c6..f81f4185 100644 --- a/tests/hashmap/Hashmap.Types.fst +++ b/tests/hashmap/Hashmap.Types.fst @@ -19,3 +19,7 @@ type hash_map_t (t : Type0) = hash_map_slots : vec (list_t t); } +(** [core::num::u32::{8}::MAX] *) +let core_num_u32_max_body : result u32 = Return 4294967295 +let core_num_u32_max_c : u32 = eval_global core_num_u32_max_body + -- cgit v1.2.3 From e18bf82b0931a7fd8a357a8516ef8618d77d42cf Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 22 Sep 2022 17:27:24 +0200 Subject: Regenerate the translated files --- tests/hashmap/Primitives.fst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/hashmap') diff --git a/tests/hashmap/Primitives.fst b/tests/hashmap/Primitives.fst index b3da25c2..b44fe9d1 100644 --- a/tests/hashmap/Primitives.fst +++ b/tests/hashmap/Primitives.fst @@ -34,7 +34,7 @@ let bind (#a #b : Type0) (m : result a) (f : a -> result b) : result b = // Monadic assert(...) let massert (b:bool) : result unit = if b then Return () else Fail -// Unwrap a successful result by normalisation (used for globals). +// Normalize and unwrap a successful result (used for globals). let eval_global (#a : Type0) (x : result a{Return? (normalize_term x)}) : a = Return?.v x (*** Misc *) -- cgit v1.2.3