Skip to main content

vstd/std_specs/
hash.rs

1//! This code adds specifications for the standard-library types
2//! `std::collections::HashMap` and `std::collections::HashSet`.
3//!
4//! Most of the specification only applies if you use `HashMap<Key,
5//! Value>` or `HashSet<Key>`. If you use some custom build hasher,
6//! e.g., with`HashMap<Key, Value, CustomBuildHasher>`, the
7//! specification won't specify much unless you assume
8//! [`builds_valid_hashers<CustomBuildHasher>()`].
9//!
10//! Likewise, the specification is only meaningful when `eq_spec`
11//! faithfully models executable equality; executable equality is
12//! reflexive, symmetric, and transitive; hashing is
13//! deterministic; executable-equal keys hash identically; and
14//! cloning, when supported, preserves structural identity and
15//! executable equality. We have an axiom that all primitive types and
16//! `Box`es thereof obey this model. But if you want to use some other
17//! key type `MyKey`, you need to explicitly state your assumption
18//! that it does so with
19//! `assume(vstd::std_specs::hash::obeys_key_model::<MyKey>());`. In
20//! the future, we plan to devise a way for you to prove that it does
21//! so, so that you don't have to make such an assumption.
22//!
23//! The assumed specs don't assume that executable equality matches
24//! structural equality, or that executable equality matches deep_view
25//! equality. But we provide broadcast lemmas that derive stronger
26//! properties for when either of those do match.
27//!
28//! Borrowed-key lookups also require
29//! `borrowed_key_hashing_matches::<Key, Q>()` and use the model in
30//! `BorrowSpec`. Their postconditions additionally require `Q` to obey
31//! the hashing and equality models. Compatibility is supplied for identity,
32//! reference, `Box`, and `String` borrowing.
33//!
34//! By default, the Verus standard library brings useful axioms
35//! about the behavior of `HashMap` and `HashSet` into the ambient
36//! reasoning context by broadcasting the group
37//! `vstd::std_specs::hash::group_hash_axioms`.
38use super::super::laws_eq::{obeys_concrete_eq, obeys_deep_eq};
39use super::super::map::{assert_maps_equal, assert_maps_equal_internal};
40use super::super::pervasive::obeys_clone_eq;
41use super::super::prelude::*;
42use super::borrow::BorrowSpec;
43use super::cmp::PartialEqSpec;
44use super::iter::IteratorSpec;
45
46use core::alloc::Allocator;
47use core::borrow::Borrow;
48use core::hash::{BuildHasher, Hash, Hasher};
49use core::marker::PhantomData;
50use core::option::Option;
51use core::option::Option::None;
52use std::collections::hash_map;
53use std::collections::hash_map::{
54    DefaultHasher, Entry, Keys, OccupiedEntry, RandomState, VacantEntry, Values,
55};
56use std::collections::hash_set;
57use std::collections::{HashMap, HashSet};
58
59verus! {
60
61/// Specifications for the behavior of
62/// [`std::collections::hash_map::DefaultHasher`](https://doc.rust-lang.org/std/collections/hash_map/struct.DefaultHasher.html).
63///
64/// We model a `DefaultHasher` as having a view (i.e., an abstract
65/// state) of type `Seq<Seq<u8>>`. This reflects the sequence of write
66/// operations performed so far, where each write is modeled as having
67/// written a sequence of bytes. There's also a specification for
68/// how a view will be transformed by `finish` into a `u64`.
69#[verifier::external_type_specification]
70#[verifier::external_body]
71pub struct ExDefaultHasher(DefaultHasher);
72
73impl View for DefaultHasher {
74    type V = Seq<Seq<u8>>;
75
76    #[verifier::external_body]
77    uninterp spec fn view(&self) -> Seq<Seq<u8>>;
78}
79
80pub trait DefaultHasherAdditionalSpecFns {
81    spec fn spec_finish(s: Seq<Seq<u8>>) -> u64;
82}
83
84impl DefaultHasherAdditionalSpecFns for DefaultHasher {
85    #[verifier::external_body]
86    uninterp spec fn spec_finish(s: Seq<Seq<u8>>) -> u64;
87}
88
89// This is the specification of behavior for `DefaultHasher::new()`.
90pub assume_specification[ DefaultHasher::new ]() -> (result: DefaultHasher)
91    ensures
92        result@ == Seq::<Seq<u8>>::empty(),
93;
94
95// This is the specification of behavior for `DefaultHasher::write(&[u8])`.
96pub assume_specification[ DefaultHasher::write ](state: &mut DefaultHasher, bytes: &[u8])
97    ensures
98        final(state)@ == old(state)@.push(bytes@),
99;
100
101// This is the specification of behavior for `DefaultHasher::finish()`.
102pub assume_specification[ DefaultHasher::finish ](state: &DefaultHasher) -> (result: u64)
103    ensures
104        result == DefaultHasher::spec_finish(state@),
105;
106
107/// Specifies whether a type `Key` conforms to our requirements to be
108/// a key in our hash table (and hash set) model.
109///
110/// These requirements are that (1)
111/// `<Key as PartialEqSpec>::obeys_eq_spec()` is true and executable
112/// equality is reflexive, symmetric, and transitive; (2) the hash
113/// function is deterministic; (3) executable-equal keys have equal
114/// hashes; and (4) if `Key` implements `Clone`, cloning produces a
115/// result structurally identical and executable-equal to its input.
116/// `Key` need not implement `Clone`. Requirement (2) isn't satisfied
117/// by having `Key` implement `Hash`, since this trait doesn't mandate
118/// determinism.
119///
120/// The standard library has axioms that all primitive types, `String`, `str`,
121/// and `Box`es of primitive types obey this model. If you want to use some other key
122/// type `MyKey`, you need to explicitly state your assumption that it
123/// does so with
124/// `assume(vstd::std_specs::hash::obeys_key_model::<MyKey>())`.
125/// In the future, we plan to devise a way for you to prove that it
126/// does so, so that you don't have to make such an assumption.
127#[verifier::external_body]
128pub uninterp spec fn obeys_key_model<Key: ?Sized>() -> bool;
129
130/// The key model supplies faithful equality and equivalence laws, including for unsized keys.
131pub broadcast axiom fn axiom_key_model_implies_obeys_eq<Key: Hash + Eq + ?Sized>()
132    requires
133        #[trigger] obeys_key_model::<Key>(),
134    ensures
135        <Key as PartialEqSpec>::obeys_eq_spec(),
136        forall|a: &Key| #[trigger] a.eq_spec(a),
137        forall|a: &Key, b: &Key| #[trigger] a.eq_spec(b) <==> b.eq_spec(a),
138        forall|a: &Key, b: &Key, c: &Key|
139            a.eq_spec(b) && #[trigger] b.eq_spec(c) ==> #[trigger] a.eq_spec(c),
140;
141
142pub broadcast proof fn lemma_key_model_implies_obeys_eq<Key: Hash + Eq>()
143    requires
144        #[trigger] obeys_key_model::<Key>(),
145    ensures
146        crate::laws_eq::obeys_eq::<Key>(),
147{
148    broadcast use axiom_key_model_implies_obeys_eq;
149
150    reveal(crate::laws_eq::obeys_eq_spec_properties);
151}
152
153/// Whether borrowing a key preserves its `Hash` and `Eq` behavior.
154///
155/// Owned keys and their borrowed forms must hash identically for any
156/// hasher and compare equal in the same circumstances. This predicate
157/// is opaque because `Hash` does not yet have a specification model.
158pub uninterp spec fn borrowed_key_hashing_matches<
159    Key: Borrow<Q> + Hash + Eq + ?Sized,
160    Q: Hash + Eq + ?Sized,
161>() -> bool;
162
163pub broadcast axiom fn axiom_borrowed_key_hashing_matches_self<Q: Hash + Eq + ?Sized>()
164    ensures
165        #[trigger] borrowed_key_hashing_matches::<Q, Q>(),
166;
167
168pub broadcast axiom fn axiom_borrowed_key_hashing_matches_ref<Q: Hash + Eq + ?Sized>()
169    ensures
170        #[trigger] borrowed_key_hashing_matches::<&Q, Q>(),
171;
172
173pub broadcast axiom fn axiom_borrowed_key_hashing_matches_box<Q: Hash + Eq + ?Sized, A: Allocator>()
174    ensures
175        #[trigger] borrowed_key_hashing_matches::<Box<Q, A>, Q>(),
176;
177
178pub broadcast axiom fn axiom_borrowed_key_hashing_matches_string()
179    ensures
180        #[trigger] borrowed_key_hashing_matches::<String, str>(),
181;
182
183pub broadcast axiom fn axiom_string_obeys_hash_table_key_model()
184    ensures
185        #[trigger] obeys_key_model::<String>(),
186;
187
188pub broadcast axiom fn axiom_str_obeys_hash_table_key_model()
189    ensures
190        #[trigger] obeys_key_model::<str>(),
191;
192
193// These axioms state that any primitive type, or `Box` thereof,
194// obeys the requirements to be a key in a hash table that
195// conforms to our hash-table model.
196// (Declare each separately to enable pruning of unused primitive types.)
197pub broadcast proof fn axiom_bool_obeys_hash_table_key_model()
198    ensures
199        #[trigger] obeys_key_model::<bool>(),
200{
201    admit();
202}
203
204pub broadcast proof fn axiom_u8_obeys_hash_table_key_model()
205    ensures
206        #[trigger] obeys_key_model::<u8>(),
207{
208    admit();
209}
210
211pub broadcast proof fn axiom_u16_obeys_hash_table_key_model()
212    ensures
213        #[trigger] obeys_key_model::<u16>(),
214{
215    admit();
216}
217
218pub broadcast proof fn axiom_u32_obeys_hash_table_key_model()
219    ensures
220        #[trigger] obeys_key_model::<u32>(),
221{
222    admit();
223}
224
225pub broadcast proof fn axiom_u64_obeys_hash_table_key_model()
226    ensures
227        #[trigger] obeys_key_model::<u64>(),
228{
229    admit();
230}
231
232pub broadcast proof fn axiom_u128_obeys_hash_table_key_model()
233    ensures
234        #[trigger] obeys_key_model::<u128>(),
235{
236    admit();
237}
238
239pub broadcast proof fn axiom_usize_obeys_hash_table_key_model()
240    ensures
241        #[trigger] obeys_key_model::<usize>(),
242{
243    admit();
244}
245
246pub broadcast proof fn axiom_i8_obeys_hash_table_key_model()
247    ensures
248        #[trigger] obeys_key_model::<i8>(),
249{
250    admit();
251}
252
253pub broadcast proof fn axiom_i16_obeys_hash_table_key_model()
254    ensures
255        #[trigger] obeys_key_model::<i16>(),
256{
257    admit();
258}
259
260pub broadcast proof fn axiom_i32_obeys_hash_table_key_model()
261    ensures
262        #[trigger] obeys_key_model::<i32>(),
263{
264    admit();
265}
266
267pub broadcast proof fn axiom_i64_obeys_hash_table_key_model()
268    ensures
269        #[trigger] obeys_key_model::<i64>(),
270{
271    admit();
272}
273
274pub broadcast proof fn axiom_i128_obeys_hash_table_key_model()
275    ensures
276        #[trigger] obeys_key_model::<i128>(),
277{
278    admit();
279}
280
281pub broadcast proof fn axiom_isize_obeys_hash_table_key_model()
282    ensures
283        #[trigger] obeys_key_model::<isize>(),
284{
285    admit();
286}
287
288pub broadcast proof fn axiom_box_bool_obeys_hash_table_key_model()
289    ensures
290        #[trigger] obeys_key_model::<Box<bool>>(),
291{
292    admit();
293}
294
295pub broadcast proof fn axiom_box_integer_type_obeys_hash_table_key_model<Key: Integer + ?Sized>()
296    requires
297        obeys_key_model::<Key>(),
298    ensures
299        #[trigger] obeys_key_model::<Box<Key>>(),
300{
301    admit();
302}
303
304// Our model for the external trait `BuildHasher` is that for any two
305// `Hasher`s it builds, if they're both given the same write sequence
306// then their states will match and they'll produce the same digest
307// when invoked with `finish()`.
308//
309// We don't expect that all types implementing the `BuildHasher` trait
310// will conform to our model, just the types T for which
311// `builds_valid_hashers::<T>()` holds.
312#[verifier::external_trait_specification]
313pub trait ExBuildHasher {
314    type ExternalTraitSpecificationFor: BuildHasher;
315
316    type Hasher: Hasher;
317}
318
319/// Specifies whether a type conforms to our requirements to be a hash builder
320/// in our hash table (and hash set) model.
321///
322/// Our model requires that for any two `Hasher`s that the `BuildHasher` builds,
323/// if they're both given the same write sequence
324/// then their states will match and they'll produce the same digest
325/// when invoked with `finish()`.
326///
327/// The standard library has an axiom that `RandomState`, the default `BuildHasher`
328/// used by `HashMap` and `HashSet`, implements this model.
329/// If you want to use some other hash builder type `MyHashBuilder`,
330/// you need to explicitly state your assumption that it does so with
331/// `assume(vstd::std_specs::hash::builds_valid_hashers::<MyHashBuilder>())`.
332#[verifier::external_body]
333pub uninterp spec fn builds_valid_hashers<T: ?Sized>() -> bool;
334
335/// Specifications for the behavior of
336/// [`std::hash::RandomState`](https://doc.rust-lang.org/std/hash/struct.RandomState.html).
337///
338/// `RandomState` is the default `BuildHasher` used by Rust's `HashMap` and `HashSet` implementations.
339/// We have an axiom that `RandomState` satisfies [`builds_valid_hashers()`](https://verus-lang.github.io/verus/verusdoc/vstd/std_specs/hash/fn.builds_valid_hashers.html)
340/// and thereby conforms to our model of how `BuildHasher` behaves.
341#[verifier::external_type_specification]
342#[verifier::external_body]
343pub struct ExRandomState(RandomState);
344
345pub broadcast proof fn axiom_random_state_builds_valid_hashers()
346    ensures
347        #[trigger] builds_valid_hashers::<RandomState>(),
348{
349    admit();
350}
351
352/// Specifications for the behavior of
353/// [`std::collections::hash_map::Keys`](https://doc.rust-lang.org/std/collections/hash_map/struct.Keys.html).
354#[verifier::external_type_specification]
355#[verifier::external_body]
356#[verifier::accept_recursive_types(Key)]
357#[verifier::accept_recursive_types(Value)]
358pub struct ExKeys<'a, Key: 'a, Value: 'a>(Keys<'a, Key, Value>);
359
360// To allow reasoning about the "contents" of the Keys iterator, without using
361// a prophecy, we need a function that gives us the underlying sequence of the original keys.
362pub uninterp spec fn into_iter_keys<'a, Key, Value>(i: Keys<'a, Key, Value>) -> Seq<Key>;
363
364impl<'a, K, V> super::iter::IteratorSpecImpl for Keys<'a, K, V> {
365    open spec fn obeys_prophetic_iter_laws(&self) -> bool {
366        true
367    }
368
369    uninterp spec fn remaining(&self) -> Seq<Self::Item>;
370
371    #[verifier::prophetic]
372    open spec fn produces(&self) -> Seq<bool> {
373        Seq::new(IteratorSpec::remaining(self).len(), |i: int| true)
374    }
375
376    uninterp spec fn decrease(&self) -> Option<nat>;
377
378    open spec fn peek(&self, index: int) -> Option<Self::Item> {
379        if 0 <= index < into_iter_keys(*self).len() {
380            Some(&into_iter_keys(*self)[index])
381        } else {
382            None
383        }
384    }
385}
386
387/// Specifications for the behavior of
388/// [`std::collections::hash_map::Values`](https://doc.rust-lang.org/std/collections/hash_map/struct.Values.html).
389#[verifier::external_type_specification]
390#[verifier::external_body]
391#[verifier::accept_recursive_types(Key)]
392#[verifier::accept_recursive_types(Value)]
393pub struct ExValues<'a, Key: 'a, Value: 'a>(Values<'a, Key, Value>);
394
395// To allow reasoning about the "contents" of the Values iterator, without using
396// a prophecy, we need a function that gives us the underlying sequence of the original values.
397pub uninterp spec fn into_iter_values<'a, Key, Value>(i: Values<'a, Key, Value>) -> Seq<Value>;
398
399impl<'a, K, V> super::iter::IteratorSpecImpl for Values<'a, K, V> {
400    open spec fn obeys_prophetic_iter_laws(&self) -> bool {
401        true
402    }
403
404    uninterp spec fn remaining(&self) -> Seq<Self::Item>;
405
406    #[verifier::prophetic]
407    open spec fn produces(&self) -> Seq<bool> {
408        Seq::new(IteratorSpec::remaining(self).len(), |i: int| true)
409    }
410
411    uninterp spec fn decrease(&self) -> Option<nat>;
412
413    open spec fn peek(&self, index: int) -> Option<Self::Item> {
414        if 0 <= index < into_iter_values(*self).len() {
415            Some(&into_iter_values(*self)[index])
416        } else {
417            None
418        }
419    }
420}
421
422// The `iter` method of a `HashMap` returns an iterator of type `hash_map::Iter`,
423// so we specify that type here.
424#[verifier::external_type_specification]
425#[verifier::external_body]
426#[verifier::accept_recursive_types(Key)]
427#[verifier::accept_recursive_types(Value)]
428pub struct ExMapIter<'a, Key: 'a, Value: 'a>(hash_map::Iter<'a, Key, Value>);
429
430// To allow reasoning about the "contents" of the Iter iterator, without using
431// a prophecy, we need a function that gives us the underlying sequence of the original map.
432pub uninterp spec fn into_iter<'a, Key, Value>(i: hash_map::Iter<'a, Key, Value>) -> Seq<
433    (Key, Value),
434>;
435
436impl<'a, K, V> super::iter::IteratorSpecImpl for hash_map::Iter<'a, K, V> {
437    open spec fn obeys_prophetic_iter_laws(&self) -> bool {
438        true
439    }
440
441    uninterp spec fn remaining(&self) -> Seq<Self::Item>;
442
443    #[verifier::prophetic]
444    open spec fn produces(&self) -> Seq<bool> {
445        Seq::new(IteratorSpec::remaining(self).len(), |i: int| true)
446    }
447
448    uninterp spec fn decrease(&self) -> Option<nat>;
449
450    open spec fn peek(&self, index: int) -> Option<Self::Item> {
451        if 0 <= index < into_iter(*self).len() {
452            let (k, v) = into_iter(*self)[index];
453            Some((&k, &v))
454        } else {
455            None
456        }
457    }
458}
459
460pub assume_specification<'a, Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::iter ](
461    m: &'a HashMap<Key, Value, S, A>,
462) -> (iter: hash_map::Iter<'a, Key, Value>)
463    ensures
464        obeys_key_model::<Key>() && builds_valid_hashers::<S>() && hash_map_wf(m) ==> {
465            // `m.len()` is mentioned so callers learn that the length fits in a `usize`
466            // (needed, e.g., by `enumerate` and `position`)
467            &&& IteratorSpec::remaining(&iter).len() == m@.dom().len()
468            &&& IteratorSpec::remaining(&iter).len() == m.len()
469            &&& forall|i: int|
470                #![trigger m@.contains_key(*IteratorSpec::remaining(&iter)[i].0)]
471                #![trigger m@[*IteratorSpec::remaining(&iter)[i].0]]
472                0 <= i < IteratorSpec::remaining(&iter).len() ==> m@.contains_key(
473                    *IteratorSpec::remaining(&iter)[i].0,
474                ) && m@[*IteratorSpec::remaining(&iter)[i].0] == *IteratorSpec::remaining(
475                    &iter,
476                )[i].1
477            &&& forall|k: Key| #[trigger]
478                m@.contains_key(k) ==> IteratorSpec::remaining(&iter).contains((&k, &m@[k]))
479            &&& IteratorSpec::remaining(&iter).unref().to_set() == m@.kv_pairs()
480            &&& iter.remaining().no_duplicates()
481            &&& into_iter(iter) == IteratorSpec::remaining(&iter).unref()
482            &&& IteratorSpec::decrease(&iter) is Some
483        },
484;
485
486#[verifier::external_type_specification]
487#[verifier::external_body]
488#[verifier::accept_recursive_types(Key)]
489#[verifier::accept_recursive_types(Value)]
490#[verifier::reject_recursive_types(A)]
491pub struct ExMapIntoIter<Key, Value, A: Allocator>(hash_map::IntoIter<Key, Value, A>);
492
493pub uninterp spec fn into_iter_entries<Key, Value, A: Allocator>(
494    iter: hash_map::IntoIter<Key, Value, A>,
495) -> Seq<(Key, Value)>;
496
497impl<K, V, A: Allocator> super::iter::IteratorSpecImpl for hash_map::IntoIter<K, V, A> {
498    open spec fn obeys_prophetic_iter_laws(&self) -> bool {
499        true
500    }
501
502    uninterp spec fn remaining(&self) -> Seq<Self::Item>;
503
504    #[verifier::prophetic]
505    open spec fn produces(&self) -> Seq<bool> {
506        Seq::new(IteratorSpec::remaining(self).len(), |i: int| true)
507    }
508
509    uninterp spec fn decrease(&self) -> Option<nat>;
510
511    open spec fn peek(&self, index: int) -> Option<Self::Item> {
512        if 0 <= index < into_iter_entries(*self).len() {
513            Some(into_iter_entries(*self)[index])
514        } else {
515            None
516        }
517    }
518}
519
520pub assume_specification<Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::into_iter ](
521    m: HashMap<Key, Value, S, A>,
522) -> (iter: hash_map::IntoIter<Key, Value, A>)
523    ensures
524        obeys_key_model::<Key>() && builds_valid_hashers::<S>() && hash_map_wf(&m) ==> {
525            &&& IteratorSpec::remaining(&iter).to_set() == m@.kv_pairs()
526            &&& iter.remaining().no_duplicates()
527        },
528        into_iter_entries(iter) == IteratorSpec::remaining(&iter),
529        IteratorSpec::decrease(&iter) is Some,
530;
531
532/// Specifications for the behavior of [`std::collections::HashMap`](https://doc.rust-lang.org/std/collections/struct.HashMap.html).
533///
534/// We model a `HashMap` as having a view of type `Map<Key, Value>`, which reflects the current state of the map.
535///
536/// These specifications are only meaningful if `obeys_key_model::<Key>()` and `builds_valid_hashers::<S>()` hold.
537/// See [`obeys_key_model()`](https://verus-lang.github.io/verus/verusdoc/vstd/std_specs/hash/fn.obeys_key_model.html)
538/// for information on use with primitive types and other types,
539/// and see [`builds_valid_hashers()`](https://verus-lang.github.io/verus/verusdoc/vstd/std_specs/hash/fn.builds_valid_hashers.html)
540/// for information on use with Rust's default implementation and custom implementations.
541///
542/// Axioms about the behavior of HashMap are present in the broadcast group `vstd::std_specs::hash::group_hash_axioms`.
543#[verifier::external_type_specification]
544#[verifier::external_body]
545#[verifier::accept_recursive_types(Key)]
546#[verifier::accept_recursive_types(Value)]
547#[verifier::reject_recursive_types(S)]
548#[verifier::reject_recursive_types(A)]
549pub struct ExHashMap<Key, Value, S, A: Allocator>(HashMap<Key, Value, S, A>);
550
551pub trait HashMapAdditionalSpecFns<Key, Value>: View<V = Map<Key, Value>> {
552    spec fn spec_index(&self, k: Key) -> Value
553        recommends
554            self@.contains_key(k),
555    ;
556}
557
558impl<Key, Value, S, A: Allocator> HashMapAdditionalSpecFns<Key, Value> for HashMap<
559    Key,
560    Value,
561    S,
562    A,
563> {
564    #[verifier::inline]
565    open spec fn spec_index(&self, k: Key) -> Value {
566        self@.index(k)
567    }
568}
569
570/// The actual definition of `HashMap::deep_view`.
571///
572/// This is a separate function since it introduces a lot of quantifiers and revealing an opaque trait
573/// method is not supported. In most cases, it's easier to use one of the lemmas below instead
574/// of revealing this function directly.
575#[verifier::opaque]
576pub open spec fn hash_map_deep_view_impl<
577    Key: DeepView,
578    Value: DeepView,
579    S,
580    A: core::alloc::Allocator,
581>(m: HashMap<Key, Value, S, A>) -> Map<Key::V, Value::V> {
582    Map::new(
583        m@.dom().map(|k: Key| k.deep_view()),
584        |dk: Key::V|
585            {
586                let k = choose|k: Key| m@.contains_key(k) && #[trigger] k.deep_view() == dk;
587                m@[k].deep_view()
588            },
589    )
590}
591
592pub broadcast proof fn lemma_hashmap_deepview_dom<K: DeepView, V: DeepView>(m: HashMap<K, V>)
593    ensures
594        #[trigger] m.deep_view().dom() == m@.dom().map(|k: K| k.deep_view()),
595{
596    reveal(hash_map_deep_view_impl);
597    broadcast use group_hash_axioms;
598    broadcast use crate::vstd::group_vstd_default;
599
600    assert(m.deep_view().dom() =~= m@.dom().map(|k: K| k.deep_view()));
601}
602
603pub broadcast proof fn lemma_hashmap_deepview_properties<K: DeepView, V: DeepView>(m: HashMap<K, V>)
604    requires
605        crate::relations::injective(|k: K| k.deep_view()),
606    ensures
607        #![trigger m.deep_view()]
608        // all elements in m.view() are present in m.deep_view()
609        forall|k: K| #[trigger]
610            m@.contains_key(k) ==> m.deep_view().contains_key(k.deep_view())
611                && m.deep_view()[k.deep_view()] == m@[k].deep_view(),
612        // all elements in m.deep_view() are present in m.view()
613        forall|dk: <K as DeepView>::V| #[trigger]
614            m.deep_view().contains_key(dk) ==> exists|k: K|
615                k.deep_view() == dk && #[trigger] m@.contains_key(k),
616{
617    reveal(hash_map_deep_view_impl);
618    broadcast use group_hash_axioms;
619    broadcast use crate::vstd::group_vstd_default;
620
621    lemma_hashmap_deepview_dom(m);
622    assert(m.deep_view().dom() == m@.dom().map(|k: K| k.deep_view()));
623    assert forall|k: K| #[trigger] m@.contains_key(k) implies m.deep_view().contains_key(
624        k.deep_view(),
625    ) && m.deep_view()[k.deep_view()] == m@[k].deep_view() by {
626        assert(m@.dom().contains(k));
627        assert(m@.dom().map(|k: K| k.deep_view()).contains(k.deep_view()));
628        assert(m.deep_view().dom().contains(k.deep_view()));
629        let k2 = choose|k2: K| m@.contains_key(k2) && #[trigger] k2.deep_view() == k.deep_view();
630        assert forall|k1: K, k2: K| #[trigger]
631            k1.deep_view() == #[trigger] k2.deep_view() implies k1 == k2 by {
632            let ghost k_deepview = |k: K| k.deep_view();
633            assert(crate::relations::injective(k_deepview));
634            assert(k_deepview(k1) == k_deepview(k2));
635        }
636        assert(k2 == k);
637    }
638    assert forall|dk: K::V| #[trigger] m.deep_view().contains_key(dk) implies exists|k: K|
639        k.deep_view() == dk && #[trigger] m@.contains_key(k) by {
640        assert(m.deep_view().dom().contains(dk));
641        assert(m@.dom().map(|k: K| k.deep_view()).contains(dk));
642        let k = choose|k: K| #[trigger] m@.dom().contains(k) && k.deep_view() == dk;
643        assert(m@.contains_key(k));
644    }
645}
646
647pub broadcast proof fn lemma_hashmap_deepview_values<K: DeepView, V: DeepView>(m: HashMap<K, V>)
648    requires
649        crate::relations::injective(|k: K| k.deep_view()),
650    ensures
651        #[trigger] m.deep_view().values() =~= m@.values().map(|v: V| v.deep_view()),
652{
653    reveal(hash_map_deep_view_impl);
654    broadcast use group_hash_axioms;
655    broadcast use lemma_hashmap_deepview_properties;
656    broadcast use crate::vstd::group_vstd_default;
657
658    let lhs = m.deep_view().values();
659    let rhs = m@.values().map(|v: V| v.deep_view());
660    assert forall|v: V::V| #[trigger] lhs.contains(v) implies rhs.contains(v) by {
661        let dk = choose|dk: K::V| #[trigger]
662            m.deep_view().contains_key(dk) && m.deep_view()[dk] == v;
663        let k = choose|k: K| #[trigger] m@.contains_key(k) && k.deep_view() == dk;
664        let ov = choose|ov: V| #[trigger] m@.contains_key(k) && m@[k] == ov && ov.deep_view() == v;
665        assert(v == ov.deep_view());
666        assert(m@.values().contains(ov));
667    }
668}
669
670pub uninterp spec fn spec_hash_map_len<Key, Value, S, A: Allocator>(
671    m: &HashMap<Key, Value, S, A>,
672) -> usize;
673
674pub broadcast proof fn axiom_spec_hash_map_len<Key, Value, S, A: Allocator>(
675    m: &HashMap<Key, Value, S, A>,
676)
677    ensures
678        obeys_key_model::<Key>() && builds_valid_hashers::<S>() ==> #[trigger] spec_hash_map_len(m)
679            == m@.len(),
680{
681    admit();
682}
683
684#[verifier::when_used_as_spec(spec_hash_map_len)]
685pub assume_specification<Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::len ](
686    m: &HashMap<Key, Value, S, A>,
687) -> (len: usize)
688    ensures
689        len == spec_hash_map_len(m),
690;
691
692pub assume_specification<Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::capacity ](
693    m: &HashMap<Key, Value, S, A>,
694) -> (cap: usize)
695    ensures
696        cap >= spec_hash_map_len(m),
697;
698
699pub assume_specification<Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::is_empty ](
700    m: &HashMap<Key, Value, S, A>,
701) -> (res: bool)
702    ensures
703        res == m@.is_empty(),
704;
705
706pub assume_specification<K: Clone, V: Clone, S: Clone, A: Allocator + Clone>[ <HashMap::<
707    K,
708    V,
709    S,
710    A,
711> as Clone>::clone ](this: &HashMap<K, V, S, A>) -> (other: HashMap<K, V, S, A>)
712    ensures
713// The keys are cloned too, and stay in the buckets of the originals; only keys that
714// clone to equal values leave them unchanged (and the copy well formed).
715
716        obeys_clone_eq::<K>() ==> {
717            &&& other@.dom() == this@.dom()
718            &&& forall|key|
719                #![trigger other@.dom().contains(key)]
720                other@.dom().contains(key) ==> cloned(this@[key], #[trigger] other@[key])
721        },
722        obeys_clone_eq::<K>() && hash_map_wf(this) ==> hash_map_wf(&other),
723;
724
725pub assume_specification<Key, Value>[ HashMap::<Key, Value>::new ]() -> (m: HashMap<
726    Key,
727    Value,
728    RandomState,
729>)
730    ensures
731        m@ == Map::<Key, Value>::empty(),
732        hash_map_wf(&m),
733;
734
735pub assume_specification<K, V, S: core::default::Default>[ <HashMap<
736    K,
737    V,
738    S,
739> as core::default::Default>::default ]() -> (m: HashMap<K, V, S>)
740    ensures
741        m@ == Map::<K, V>::empty(),
742        hash_map_wf(&m),
743;
744
745pub assume_specification<Key, Value>[ HashMap::<Key, Value>::with_capacity ](capacity: usize) -> (m:
746    HashMap<Key, Value, RandomState>)
747    ensures
748        m@ == Map::<Key, Value>::empty(),
749        hash_map_wf(&m),
750;
751
752pub assume_specification<Key, Value, S>[ HashMap::<Key, Value, S>::with_hasher ](
753    hash_builder: S,
754) -> (m: HashMap<Key, Value, S>)
755    ensures
756        m@ == Map::<Key, Value>::empty(),
757        hash_map_wf(&m),
758;
759
760pub assume_specification<Key: Eq + Hash, Value, S: BuildHasher, A: Allocator>[ HashMap::<
761    Key,
762    Value,
763    S,
764    A,
765>::reserve ](m: &mut HashMap<Key, Value, S, A>, additional: usize)
766    ensures
767        final(m)@ == old(m)@,
768        hash_map_wf(old(m)) ==> hash_map_wf(final(m)),
769;
770
771/// Whether each of the map's entries is stored where its key's hash says, so that the map's
772/// view describes what its operations do. The specified operations build well-formed maps,
773/// and keep a map well formed. Safe code can build malformed maps, though: for example by
774/// cloning a map whose key type's `Clone` changes the key (see [`obeys_clone_eq`]; the copy
775/// keeps each changed key in the original's bucket). So a map from unverified code is not
776/// known to be well formed.
777///
778/// This depends on the map value, not only its view: a malformed copy can have the same view
779/// as the well-formed original.
780pub uninterp spec fn hash_map_wf<Key, Value, S, A: Allocator>(
781    m: &HashMap<Key, Value, S, A>,
782) -> bool;
783
784pub open spec fn hash_map_inv<Key: Eq + Hash, Value, S, A: Allocator>(
785    m: &HashMap<Key, Value, S, A>,
786) -> bool {
787    &&& hash_map_wf(m)
788    &&& forall|k1: Key, k2: Key|
789        {
790            &&& #[trigger] m@.contains_key(k1)
791            &&& #[trigger] m@.contains_key(k2)
792            &&& k1 != k2
793        } ==> !k1.eq_spec(&k2)
794}
795
796pub open spec fn hash_map_insert_ensures<Key: Eq + Hash, Value, S: BuildHasher, A: Allocator>(
797    old_m: &HashMap<Key, Value, S, A>,
798    final_m: &HashMap<Key, Value, S, A>,
799    k: Key,
800    v: Value,
801    result: Option<Value>,
802) -> bool {
803    ({
804        &&& obeys_key_model::<Key>()
805        &&& builds_valid_hashers::<S>()
806        &&& hash_map_inv(old_m)
807    }) ==> {
808        &&& hash_map_inv(final_m)
809        &&& match result {
810            Some(old_value) => exists|stored_key: Key|
811                {
812                    &&& #[trigger] old_m@.contains_key(stored_key)
813                    &&& k.eq_spec(&stored_key)
814                    &&& old_value == old_m@[stored_key]
815                    &&& final_m@ == old_m@.insert(stored_key, v)
816                },
817            None => {
818                &&& forall|stored_key: Key| #[trigger]
819                    old_m@.contains_key(stored_key) ==> !k.eq_spec(&stored_key)
820                &&& final_m@ == old_m@.insert(k, v)
821            },
822        }
823    }
824}
825
826pub assume_specification<Key: Eq + Hash, Value, S: BuildHasher, A: Allocator>[ HashMap::<
827    Key,
828    Value,
829    S,
830    A,
831>::insert ](m: &mut HashMap<Key, Value, S, A>, k: Key, v: Value) -> (result: Option<Value>)
832    ensures
833        hash_map_wf(old(m)) ==> hash_map_wf(final(m)),
834        hash_map_insert_ensures(old(m), final(m), k, v, result),
835;
836
837pub broadcast proof fn lemma_hash_map_insert_ensures_if_obeys_concrete_eq<
838    Key: Eq + Hash,
839    Value,
840    S: BuildHasher,
841    A: Allocator,
842>(
843    old_m: &HashMap<Key, Value, S, A>,
844    final_m: &HashMap<Key, Value, S, A>,
845    k: Key,
846    v: Value,
847    result: Option<Value>,
848)
849    requires
850        obeys_key_model::<Key>(),
851        builds_valid_hashers::<S>(),
852        obeys_concrete_eq::<Key>(),
853        hash_map_inv(old_m),
854        #[trigger] hash_map_insert_ensures(old_m, final_m, k, v, result),
855    ensures
856        final_m@ == old_m@.insert(k, v),
857        match result {
858            Some(old_value) => old_m@.contains_key(k) && old_value == old_m@[k],
859            None => !old_m@.contains_key(k),
860        },
861{
862    reveal(obeys_concrete_eq);
863}
864
865pub broadcast proof fn lemma_hash_map_insert_ensures_if_obeys_deep_eq<
866    Key: Eq + Hash + DeepView,
867    Value: DeepView,
868    S: BuildHasher,
869    A: Allocator,
870>(
871    old_m: &HashMap<Key, Value, S, A>,
872    final_m: &HashMap<Key, Value, S, A>,
873    k: Key,
874    v: Value,
875    result: Option<Value>,
876)
877    requires
878        obeys_key_model::<Key>(),
879        builds_valid_hashers::<S>(),
880        obeys_deep_eq::<Key>(),
881        hash_map_inv(old_m),
882        #[trigger] hash_map_insert_ensures(old_m, final_m, k, v, result),
883    ensures
884        final_m.deep_view() == old_m.deep_view().insert(k.deep_view(), v.deep_view()),
885        match result {
886            Some(old_value) => {
887                &&& old_m.deep_view().contains_key(k.deep_view())
888                &&& old_value.deep_view() == old_m.deep_view()[k.deep_view()]
889            },
890            None => !old_m.deep_view().contains_key(k.deep_view()),
891        },
892{
893    reveal(obeys_deep_eq);
894    broadcast use {
895        crate::map::group_map_lemmas,
896        crate::set::group_set_lemmas,
897        Set::lemma_map_contains,
898    };
899
900    reveal(hash_map_deep_view_impl);
901
902    let stored_key = match result {
903        Some(old_value) => choose|stored_key: Key|
904            {
905                &&& #[trigger] old_m@.contains_key(stored_key)
906                &&& k.eq_spec(&stored_key)
907                &&& old_value == old_m@[stored_key]
908                &&& final_m@ == old_m@.insert(stored_key, v)
909            },
910        None => k,
911    };
912    assert(final_m@.contains_key(stored_key));
913    assert_maps_equal!(
914        final_m.deep_view(),
915        old_m.deep_view().insert(k.deep_view(), v.deep_view()),
916        kd => {
917            if final_m.deep_view().contains_key(kd) && kd != k.deep_view() {
918                let key = choose|key: Key|
919                    final_m@.contains_key(key) && #[trigger] key.deep_view() == kd;
920                assert(old_m@.contains_key(key));
921            }
922            if old_m.deep_view().contains_key(kd) {
923                let key = choose|key: Key|
924                    old_m@.contains_key(key) && #[trigger] key.deep_view() == kd;
925                assert(final_m@.contains_key(key));
926            }
927        }
928    );
929}
930
931pub open spec fn hash_map_contains_key_ensures<
932    Key: Borrow<Q> + Hash + Eq,
933    Value,
934    S: BuildHasher,
935    A: Allocator,
936    Q: Hash + Eq + ?Sized,
937>(m: &HashMap<Key, Value, S, A>, k: &Q, result: bool) -> bool {
938    ({
939        &&& obeys_key_model::<Key>()
940        &&& obeys_key_model::<Q>()
941        &&& builds_valid_hashers::<S>()
942        &&& <Key as BorrowSpec<Q>>::obeys_borrow_spec()
943        &&& hash_map_inv(m)
944    }) ==> {
945        result == exists|key: Key|
946            {
947                &&& #[trigger] m@.contains_key(key)
948                &&& k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key))
949            }
950    }
951}
952
953pub assume_specification<
954    Key: Borrow<Q> + Hash + Eq,
955    Value,
956    S: BuildHasher,
957    A: Allocator,
958    Q: Hash + Eq + ?Sized,
959>[ HashMap::<Key, Value, S, A>::contains_key::<Q> ](
960    m: &HashMap<Key, Value, S, A>,
961    k: &Q,
962) -> (result: bool)
963    requires
964        borrowed_key_hashing_matches::<Key, Q>(),
965    ensures
966        hash_map_contains_key_ensures(m, k, result),
967;
968
969pub broadcast proof fn lemma_hash_map_contains_key_ensures_if_obeys_concrete_eq<
970    Key: Eq + Hash,
971    Value,
972    S: BuildHasher,
973    A: Allocator,
974>(m: &HashMap<Key, Value, S, A>, k: &Key, result: bool)
975    requires
976        obeys_key_model::<Key>(),
977        builds_valid_hashers::<S>(),
978        obeys_concrete_eq::<Key>(),
979        hash_map_inv(m),
980        #[trigger] hash_map_contains_key_ensures(m, k, result),
981    ensures
982        result == m@.contains_key(*k),
983{
984    reveal(obeys_concrete_eq);
985}
986
987pub broadcast proof fn lemma_hash_map_contains_key_ensures_if_obeys_deep_eq<
988    Key: Eq + Hash + DeepView,
989    Value: DeepView,
990    S: BuildHasher,
991    A: Allocator,
992>(m: &HashMap<Key, Value, S, A>, k: &Key, result: bool)
993    requires
994        obeys_key_model::<Key>(),
995        builds_valid_hashers::<S>(),
996        obeys_deep_eq::<Key>(),
997        hash_map_inv(m),
998        #[trigger] hash_map_contains_key_ensures(m, k, result),
999    ensures
1000        result == m.deep_view().contains_key(k.deep_view()),
1001{
1002    reveal(obeys_deep_eq);
1003    broadcast use {
1004        crate::map::group_map_lemmas,
1005        crate::set::group_set_lemmas,
1006        Set::lemma_map_contains,
1007    };
1008
1009    reveal(hash_map_deep_view_impl);
1010
1011    if result {
1012        let key = choose|key: Key|
1013            {
1014                &&& #[trigger] m@.contains_key(key)
1015                &&& k.eq_spec(&key)
1016            };
1017        assert(m.deep_view().contains_key(key.deep_view()));
1018    }
1019    if m.deep_view().contains_key(k.deep_view()) {
1020        let key = choose|key: Key|
1021            m@.contains_key(key) && #[trigger] key.deep_view() == k.deep_view();
1022        assert(k.eq_spec(&key));
1023    }
1024}
1025
1026pub open spec fn hash_map_get_ensures<
1027    Key: Borrow<Q> + Hash + Eq,
1028    Value,
1029    S: BuildHasher,
1030    A: Allocator,
1031    Q: Hash + Eq + ?Sized,
1032>(m: &HashMap<Key, Value, S, A>, k: &Q, result: Option<&Value>) -> bool {
1033    ({
1034        &&& obeys_key_model::<Key>()
1035        &&& obeys_key_model::<Q>()
1036        &&& builds_valid_hashers::<S>()
1037        &&& <Key as BorrowSpec<Q>>::obeys_borrow_spec()
1038        &&& hash_map_inv(m)
1039    }) ==> {
1040        match result {
1041            Some(v) => exists|key: Key|
1042                {
1043                    &&& #[trigger] m@.contains_key(key)
1044                    &&& k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key))
1045                    &&& m@[key] == *v
1046                },
1047            None => forall|key: Key| #[trigger]
1048                m@.contains_key(key) ==> !k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key)),
1049        }
1050    }
1051}
1052
1053pub assume_specification<
1054    'a,
1055    Key: Borrow<Q> + Hash + Eq,
1056    Value,
1057    S: BuildHasher,
1058    A: Allocator,
1059    Q: Hash + Eq + ?Sized,
1060>[ HashMap::<Key, Value, S, A>::get::<Q> ](m: &'a HashMap<Key, Value, S, A>, k: &Q) -> (result:
1061    Option<&'a Value>)
1062    requires
1063        borrowed_key_hashing_matches::<Key, Q>(),
1064    ensures
1065        hash_map_get_ensures(m, k, result),
1066;
1067
1068pub broadcast proof fn lemma_hash_map_get_ensures_if_obeys_concrete_eq<
1069    Key: Eq + Hash,
1070    Value,
1071    S: BuildHasher,
1072    A: Allocator,
1073>(m: &HashMap<Key, Value, S, A>, k: &Key, result: Option<&Value>)
1074    requires
1075        obeys_key_model::<Key>(),
1076        builds_valid_hashers::<S>(),
1077        obeys_concrete_eq::<Key>(),
1078        hash_map_inv(m),
1079        #[trigger] hash_map_get_ensures(m, k, result),
1080    ensures
1081        match result {
1082            Some(v) => m@.contains_key(*k) && *v == m@[*k],
1083            None => !m@.contains_key(*k),
1084        },
1085{
1086    reveal(obeys_concrete_eq);
1087}
1088
1089pub broadcast proof fn lemma_hash_map_get_ensures_if_obeys_deep_eq<
1090    Key: Eq + Hash + DeepView,
1091    Value: DeepView,
1092    S: BuildHasher,
1093    A: Allocator,
1094>(m: &HashMap<Key, Value, S, A>, k: &Key, result: Option<&Value>)
1095    requires
1096        obeys_key_model::<Key>(),
1097        builds_valid_hashers::<S>(),
1098        obeys_deep_eq::<Key>(),
1099        hash_map_inv(m),
1100        #[trigger] hash_map_get_ensures(m, k, result),
1101    ensures
1102        match result {
1103            Some(v) => {
1104                &&& m.deep_view().contains_key(k.deep_view())
1105                &&& v.deep_view() == m.deep_view()[k.deep_view()]
1106            },
1107            None => !m.deep_view().contains_key(k.deep_view()),
1108        },
1109{
1110    reveal(obeys_deep_eq);
1111    broadcast use {
1112        crate::map::group_map_lemmas,
1113        crate::set::group_set_lemmas,
1114        Set::lemma_map_contains,
1115    };
1116
1117    reveal(hash_map_deep_view_impl);
1118
1119    match result {
1120        Some(v) => {
1121            let stored_key = choose|key: Key|
1122                {
1123                    &&& #[trigger] m@.contains_key(key)
1124                    &&& k.eq_spec(&key)
1125                    &&& m@[key] == *v
1126                };
1127            assert(m.deep_view().contains_key(k.deep_view()));
1128            let key = choose|key: Key|
1129                m@.contains_key(key) && #[trigger] key.deep_view() == k.deep_view();
1130            assert(key == stored_key);
1131        },
1132        None => {
1133            if m.deep_view().contains_key(k.deep_view()) {
1134                let key = choose|key: Key|
1135                    m@.contains_key(key) && #[trigger] key.deep_view() == k.deep_view();
1136                assert(k.eq_spec(&key));
1137            }
1138        },
1139    }
1140}
1141
1142pub open spec fn hash_map_remove_ensures<
1143    Key: Borrow<Q> + Hash + Eq,
1144    Value,
1145    S: BuildHasher,
1146    A: Allocator,
1147    Q: Hash + Eq + ?Sized,
1148>(
1149    old_m: &HashMap<Key, Value, S, A>,
1150    final_m: &HashMap<Key, Value, S, A>,
1151    k: &Q,
1152    result: Option<Value>,
1153) -> bool {
1154    ({
1155        &&& obeys_key_model::<Key>()
1156        &&& obeys_key_model::<Q>()
1157        &&& builds_valid_hashers::<S>()
1158        &&& <Key as BorrowSpec<Q>>::obeys_borrow_spec()
1159        &&& hash_map_inv(old_m)
1160    }) ==> {
1161        &&& hash_map_inv(final_m)
1162        &&& match result {
1163            Some(v) => exists|key: Key|
1164                {
1165                    &&& #[trigger] old_m@.contains_key(key)
1166                    &&& k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key))
1167                    &&& old_m@[key] == v
1168                    &&& final_m@ == old_m@.remove(key)
1169                },
1170            None => {
1171                &&& forall|key: Key| #[trigger]
1172                    old_m@.contains_key(key) ==> !k.eq_spec(
1173                        <Key as BorrowSpec<Q>>::borrow_spec(&key),
1174                    )
1175                &&& final_m@ == old_m@
1176            },
1177        }
1178    }
1179}
1180
1181pub assume_specification<
1182    Key: Borrow<Q> + Hash + Eq,
1183    Value,
1184    S: BuildHasher,
1185    A: Allocator,
1186    Q: Hash + Eq + ?Sized,
1187>[ HashMap::<Key, Value, S, A>::remove::<Q> ](m: &mut HashMap<Key, Value, S, A>, k: &Q) -> (result:
1188    Option<Value>)
1189    requires
1190        borrowed_key_hashing_matches::<Key, Q>(),
1191    ensures
1192        hash_map_wf(old(m)) ==> hash_map_wf(final(m)),
1193        hash_map_remove_ensures(old(m), final(m), k, result),
1194;
1195
1196pub broadcast proof fn lemma_hash_map_remove_ensures_if_obeys_concrete_eq<
1197    Key: Eq + Hash,
1198    Value,
1199    S: BuildHasher,
1200    A: Allocator,
1201>(
1202    old_m: &HashMap<Key, Value, S, A>,
1203    final_m: &HashMap<Key, Value, S, A>,
1204    k: &Key,
1205    result: Option<Value>,
1206)
1207    requires
1208        obeys_key_model::<Key>(),
1209        builds_valid_hashers::<S>(),
1210        obeys_concrete_eq::<Key>(),
1211        hash_map_inv(old_m),
1212        #[trigger] hash_map_remove_ensures(old_m, final_m, k, result),
1213    ensures
1214        final_m@ == old_m@.remove(*k),
1215        match result {
1216            Some(v) => old_m@.contains_key(*k) && v == old_m@[*k],
1217            None => !old_m@.contains_key(*k),
1218        },
1219{
1220    reveal(obeys_concrete_eq);
1221    broadcast use {crate::map::group_map_lemmas, crate::set::group_set_lemmas};
1222
1223    if result is None {
1224        assert(!old_m@.contains_key(*k));
1225        assert(old_m@.remove(*k) =~= old_m@);
1226    }
1227}
1228
1229pub broadcast proof fn lemma_hash_map_remove_ensures_if_obeys_deep_eq<
1230    Key: Eq + Hash + DeepView,
1231    Value: DeepView,
1232    S: BuildHasher,
1233    A: Allocator,
1234>(
1235    old_m: &HashMap<Key, Value, S, A>,
1236    final_m: &HashMap<Key, Value, S, A>,
1237    k: &Key,
1238    result: Option<Value>,
1239)
1240    requires
1241        obeys_key_model::<Key>(),
1242        builds_valid_hashers::<S>(),
1243        obeys_deep_eq::<Key>(),
1244        hash_map_inv(old_m),
1245        #[trigger] hash_map_remove_ensures(old_m, final_m, k, result),
1246    ensures
1247        final_m.deep_view() == old_m.deep_view().remove(k.deep_view()),
1248        match result {
1249            Some(v) => {
1250                &&& old_m.deep_view().contains_key(k.deep_view())
1251                &&& v.deep_view() == old_m.deep_view()[k.deep_view()]
1252            },
1253            None => !old_m.deep_view().contains_key(k.deep_view()),
1254        },
1255{
1256    reveal(obeys_deep_eq);
1257    broadcast use {
1258        crate::map::group_map_lemmas,
1259        crate::set::group_set_lemmas,
1260        Set::lemma_map_contains,
1261    };
1262
1263    reveal(hash_map_deep_view_impl);
1264
1265    let stored_key = match result {
1266        Some(v) => choose|key: Key|
1267            {
1268                &&& #[trigger] old_m@.contains_key(key)
1269                &&& k.eq_spec(&key)
1270                &&& old_m@[key] == v
1271                &&& final_m@ == old_m@.remove(key)
1272            },
1273        None => *k,
1274    };
1275    match result {
1276        Some(v) => {
1277            assert(old_m.deep_view().contains_key(k.deep_view()));
1278            let key = choose|key: Key|
1279                old_m@.contains_key(key) && #[trigger] key.deep_view() == k.deep_view();
1280            assert(key == stored_key);
1281        },
1282        None => {
1283            if old_m.deep_view().contains_key(k.deep_view()) {
1284                let key = choose|key: Key|
1285                    old_m@.contains_key(key) && #[trigger] key.deep_view() == k.deep_view();
1286                assert(k.eq_spec(&key));
1287            }
1288        },
1289    }
1290
1291    assert_maps_equal!(
1292        final_m.deep_view(),
1293        old_m.deep_view().remove(k.deep_view()),
1294        kd => {
1295            if final_m.deep_view().contains_key(kd) {
1296                let key = choose|key: Key|
1297                    final_m@.contains_key(key) && #[trigger] key.deep_view() == kd;
1298                assert(old_m@.contains_key(key));
1299                assert(key.deep_view() != k.deep_view());
1300            }
1301            if old_m.deep_view().contains_key(kd) && kd != k.deep_view() {
1302                let key = choose|key: Key|
1303                    old_m@.contains_key(key) && #[trigger] key.deep_view() == kd;
1304                assert(final_m@.contains_key(key));
1305            }
1306        }
1307    );
1308}
1309
1310pub assume_specification<Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::clear ](
1311    m: &mut HashMap<Key, Value, S, A>,
1312)
1313    ensures
1314        final(m)@ == Map::<Key, Value>::empty(),
1315        hash_map_wf(final(m)),
1316;
1317
1318pub assume_specification<'a, Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::keys ](
1319    m: &'a HashMap<Key, Value, S, A>,
1320) -> (keys: Keys<'a, Key, Value>)
1321    ensures
1322        obeys_key_model::<Key>() && builds_valid_hashers::<S>() && hash_map_wf(m) ==> {
1323            &&& IteratorSpec::remaining(&keys).unref().to_set() == m@.dom()
1324            &&& IteratorSpec::remaining(&keys).no_duplicates()
1325            &&& IteratorSpec::remaining(&keys).len() == m@.dom().len()
1326            &&& IteratorSpec::remaining(&keys).len() == m.len()
1327            &&& into_iter_keys(keys) == IteratorSpec::remaining(&keys).unref()
1328            &&& IteratorSpec::decrease(&keys) is Some
1329        },
1330;
1331
1332pub assume_specification<'a, Key, Value, S, A: Allocator>[ HashMap::<Key, Value, S, A>::values ](
1333    m: &'a HashMap<Key, Value, S, A>,
1334) -> (values: Values<'a, Key, Value>)
1335    ensures
1336        obeys_key_model::<Key>() && builds_valid_hashers::<S>() && hash_map_wf(m) ==> {
1337            &&& IteratorSpec::remaining(&values).unref().to_set() == m@.values()
1338            &&& IteratorSpec::remaining(&values).len() == m@.dom().len()
1339            &&& IteratorSpec::remaining(&values).len() == m.len()
1340            &&& into_iter_values(values) == IteratorSpec::remaining(&values).unref()
1341            &&& IteratorSpec::decrease(&values) is Some
1342        },
1343;
1344
1345pub broadcast proof fn axiom_hashmap_decreases<Key, Value, S>(m: HashMap<Key, Value, S>)
1346    ensures
1347        #[trigger] (decreases_to!(m => m@)),
1348{
1349    admit();
1350}
1351
1352// The `iter` method of a `HashSet` returns an iterator of type `hash_set::Iter`,
1353// so we specify that type here.
1354#[verifier::external_type_specification]
1355#[verifier::external_body]
1356#[verifier::accept_recursive_types(Key)]
1357pub struct ExSetIter<'a, Key: 'a>(hash_set::Iter<'a, Key>);
1358
1359// To allow reasoning about the "contents" of the HashSet iterator, without using
1360// a prophecy, we need a function that gives us the underlying sequence of the original keys.
1361pub uninterp spec fn into_iter_hash_keys<'a, Key>(i: hash_set::Iter::<'a, Key>) -> Seq<Key>;
1362
1363impl<'a, K> super::iter::IteratorSpecImpl for hash_set::Iter::<'a, K> {
1364    open spec fn obeys_prophetic_iter_laws(&self) -> bool {
1365        true
1366    }
1367
1368    uninterp spec fn remaining(&self) -> Seq<Self::Item>;
1369
1370    #[verifier::prophetic]
1371    open spec fn produces(&self) -> Seq<bool> {
1372        Seq::new(IteratorSpec::remaining(self).len(), |i: int| true)
1373    }
1374
1375    uninterp spec fn decrease(&self) -> Option<nat>;
1376
1377    open spec fn peek(&self, index: int) -> Option<Self::Item> {
1378        if 0 <= index < into_iter_hash_keys(*self).len() {
1379            Some(&into_iter_hash_keys(*self)[index])
1380        } else {
1381            None
1382        }
1383    }
1384}
1385
1386/// Specifications for the behavior of [`std::collections::HashSet`](https://doc.rust-lang.org/std/collections/struct.HashSet.html).
1387///
1388/// We model a `HashSet` as having a view of type `Set<Key>`, which reflects the current state of the set.
1389///
1390/// These specifications are only meaningful if `obeys_key_model::<Key>()` and `builds_valid_hashers::<S>()` hold.
1391/// See [`obeys_key_model()`](https://verus-lang.github.io/verus/verusdoc/vstd/std_specs/hash/fn.obeys_key_model.html)
1392/// for information on use with primitive types and custom types,
1393/// and see [`builds_valid_hashers()`](https://verus-lang.github.io/verus/verusdoc/vstd/std_specs/hash/fn.builds_valid_hashers.html)
1394/// for information on use with Rust's default implementation and custom implementations.
1395///
1396/// Axioms about the behavior of HashSet are present in the broadcast group `vstd::std_specs::hash::group_hash_axioms`.
1397#[verifier::external_type_specification]
1398#[verifier::external_body]
1399#[verifier::accept_recursive_types(Key)]
1400#[verifier::reject_recursive_types(S)]
1401#[verifier::reject_recursive_types(A)]
1402pub struct ExHashSet<Key, S, A: Allocator>(HashSet<Key, S, A>);
1403
1404pub uninterp spec fn spec_hash_set_len<Key, S, A: Allocator>(m: &HashSet<Key, S, A>) -> usize;
1405
1406pub broadcast proof fn axiom_spec_hash_set_len<Key, S, A: Allocator>(m: &HashSet<Key, S, A>)
1407    ensures
1408        obeys_key_model::<Key>() && builds_valid_hashers::<S>() ==> #[trigger] spec_hash_set_len(m)
1409            == m@.len(),
1410{
1411    admit();
1412}
1413
1414#[verifier::when_used_as_spec(spec_hash_set_len)]
1415pub assume_specification<Key, S, A: Allocator>[ HashSet::<Key, S, A>::len ](
1416    m: &HashSet<Key, S, A>,
1417) -> (len: usize)
1418    ensures
1419        len == spec_hash_set_len(m),
1420;
1421
1422pub assume_specification<Key, S, A: Allocator>[ HashSet::<Key, S, A>::is_empty ](
1423    m: &HashSet<Key, S, A>,
1424) -> (res: bool)
1425    ensures
1426        res == m@.is_empty(),
1427;
1428
1429pub assume_specification<Key>[ HashSet::<Key>::new ]() -> (m: HashSet<Key, RandomState>)
1430    ensures
1431        m@ == Set::<Key>::empty(),
1432        hash_set_wf(&m),
1433;
1434
1435pub assume_specification<T, S: core::default::Default>[ <HashSet<
1436    T,
1437    S,
1438> as core::default::Default>::default ]() -> (m: HashSet<T, S>)
1439    ensures
1440        m@ == Set::<T>::empty(),
1441        hash_set_wf(&m),
1442;
1443
1444pub assume_specification<Key>[ HashSet::<Key>::with_capacity ](capacity: usize) -> (m: HashSet<
1445    Key,
1446    RandomState,
1447>)
1448    ensures
1449        m@ == Set::<Key>::empty(),
1450        hash_set_wf(&m),
1451;
1452
1453pub assume_specification<Key, S>[ HashSet::<Key, S>::with_hasher ](hash_builder: S) -> (m: HashSet<
1454    Key,
1455    S,
1456>)
1457    ensures
1458        m@ == Set::<Key>::empty(),
1459        hash_set_wf(&m),
1460;
1461
1462pub assume_specification<Key, S>[ HashSet::<Key, S>::with_capacity_and_hasher ](
1463    capacity: usize,
1464    hash_builder: S,
1465) -> (m: HashSet<Key, S>)
1466    ensures
1467        m@ == Set::<Key>::empty(),
1468        hash_set_wf(&m),
1469;
1470
1471pub assume_specification<Key: Eq + Hash, S: BuildHasher, A: Allocator>[ HashSet::<
1472    Key,
1473    S,
1474    A,
1475>::reserve ](m: &mut HashSet<Key, S, A>, additional: usize)
1476    ensures
1477        final(m)@ == old(m)@,
1478        hash_set_wf(old(m)) ==> hash_set_wf(final(m)),
1479;
1480
1481/// Whether each of the set's elements is stored where its hash says; see [`hash_map_wf`].
1482/// Verified code can still get a malformed set by cloning one through a generic `T: Clone`.
1483pub uninterp spec fn hash_set_wf<Key, S, A: Allocator>(m: &HashSet<Key, S, A>) -> bool;
1484
1485pub open spec fn hash_set_inv<Key: Eq + Hash, S, A: Allocator>(m: &HashSet<Key, S, A>) -> bool {
1486    &&& hash_set_wf(m)
1487    &&& forall|k1: Key, k2: Key|
1488        {
1489            &&& #[trigger] m@.contains(k1)
1490            &&& #[trigger] m@.contains(k2)
1491            &&& k1 != k2
1492        } ==> !k1.eq_spec(&k2)
1493}
1494
1495pub open spec fn hash_set_insert_ensures<Key: Eq + Hash, S: BuildHasher, A: Allocator>(
1496    old_m: &HashSet<Key, S, A>,
1497    final_m: &HashSet<Key, S, A>,
1498    k: Key,
1499    result: bool,
1500) -> bool {
1501    ({
1502        &&& obeys_key_model::<Key>()
1503        &&& builds_valid_hashers::<S>()
1504        &&& hash_set_inv(old_m)
1505    }) ==> {
1506        &&& hash_set_inv(final_m)
1507        &&& if result {
1508            &&& forall|stored_key: Key| #[trigger]
1509                old_m@.contains(stored_key) ==> !k.eq_spec(&stored_key)
1510            &&& final_m@ == old_m@.insert(k)
1511        } else {
1512            &&& exists|stored_key: Key| #[trigger]
1513                old_m@.contains(stored_key) && k.eq_spec(&stored_key)
1514            &&& final_m@ == old_m@
1515        }
1516    }
1517}
1518
1519pub assume_specification<Key: Eq + Hash, S: BuildHasher, A: Allocator>[ HashSet::<
1520    Key,
1521    S,
1522    A,
1523>::insert ](m: &mut HashSet<Key, S, A>, k: Key) -> (result: bool)
1524    ensures
1525        hash_set_wf(old(m)) ==> hash_set_wf(final(m)),
1526        hash_set_insert_ensures(old(m), final(m), k, result),
1527;
1528
1529pub broadcast proof fn lemma_hash_set_insert_ensures_if_obeys_concrete_eq<
1530    Key: Eq + Hash,
1531    S: BuildHasher,
1532    A: Allocator,
1533>(old_m: &HashSet<Key, S, A>, final_m: &HashSet<Key, S, A>, k: Key, result: bool)
1534    requires
1535        obeys_key_model::<Key>(),
1536        builds_valid_hashers::<S>(),
1537        obeys_concrete_eq::<Key>(),
1538        hash_set_inv(old_m),
1539        #[trigger] hash_set_insert_ensures(old_m, final_m, k, result),
1540    ensures
1541        final_m@ == old_m@.insert(k),
1542        result == !old_m@.contains(k),
1543{
1544    reveal(obeys_concrete_eq);
1545    broadcast use crate::set::group_set_lemmas;
1546
1547    assert(k.eq_spec(&k));
1548    if !result {
1549        assert(old_m@.contains(k));
1550        assert(old_m@.insert(k) =~= old_m@);
1551    }
1552}
1553
1554pub broadcast proof fn lemma_hash_set_insert_ensures_if_obeys_deep_eq<
1555    Key: Eq + Hash + DeepView,
1556    S: BuildHasher,
1557    A: Allocator,
1558>(old_m: &HashSet<Key, S, A>, final_m: &HashSet<Key, S, A>, k: Key, result: bool)
1559    requires
1560        obeys_key_model::<Key>(),
1561        builds_valid_hashers::<S>(),
1562        obeys_deep_eq::<Key>(),
1563        hash_set_inv(old_m),
1564        #[trigger] hash_set_insert_ensures(old_m, final_m, k, result),
1565    ensures
1566        final_m.deep_view() == old_m.deep_view().insert(k.deep_view()),
1567        result == !old_m.deep_view().contains(k.deep_view()),
1568{
1569    reveal(obeys_deep_eq);
1570    broadcast use {
1571        crate::set::group_set_lemmas,
1572        Set::lemma_map_contains,
1573        Set::lemma_set_map_insert_commute,
1574    };
1575
1576    if result {
1577        assert(!old_m.deep_view().contains(k.deep_view())) by {
1578            if old_m.deep_view().contains(k.deep_view()) {
1579                let stored_key = choose|stored_key: Key|
1580                    old_m@.contains(stored_key) && #[trigger] stored_key.deep_view()
1581                        == k.deep_view();
1582                assert(k.eq_spec(&stored_key));
1583            }
1584        }
1585    } else {
1586        let stored_key = choose|stored_key: Key| #[trigger]
1587            old_m@.contains(stored_key) && k.eq_spec(&stored_key);
1588        assert(stored_key.deep_view() == k.deep_view());
1589        assert(old_m.deep_view().contains(k.deep_view()));
1590    }
1591    assert(final_m.deep_view() =~= old_m.deep_view().insert(k.deep_view()));
1592}
1593
1594pub open spec fn hash_set_contains_ensures<
1595    Key: Borrow<Q> + Hash + Eq,
1596    S: BuildHasher,
1597    A: Allocator,
1598    Q: Hash + Eq + ?Sized,
1599>(m: &HashSet<Key, S, A>, k: &Q, result: bool) -> bool {
1600    ({
1601        &&& obeys_key_model::<Key>()
1602        &&& obeys_key_model::<Q>()
1603        &&& builds_valid_hashers::<S>()
1604        &&& <Key as BorrowSpec<Q>>::obeys_borrow_spec()
1605        &&& hash_set_inv(m)
1606    }) ==> {
1607        result == exists|key: Key|
1608            {
1609                &&& #[trigger] m@.contains(key)
1610                &&& k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key))
1611            }
1612    }
1613}
1614
1615pub assume_specification<
1616    Key: Borrow<Q> + Hash + Eq,
1617    S: BuildHasher,
1618    A: Allocator,
1619    Q: Hash + Eq + ?Sized,
1620>[ HashSet::<Key, S, A>::contains ](m: &HashSet<Key, S, A>, k: &Q) -> (result: bool)
1621    requires
1622        borrowed_key_hashing_matches::<Key, Q>(),
1623    ensures
1624        hash_set_contains_ensures(m, k, result),
1625;
1626
1627pub broadcast proof fn lemma_hash_set_contains_ensures_if_obeys_concrete_eq<
1628    Key: Eq + Hash,
1629    S: BuildHasher,
1630    A: Allocator,
1631>(m: &HashSet<Key, S, A>, k: &Key, result: bool)
1632    requires
1633        obeys_key_model::<Key>(),
1634        builds_valid_hashers::<S>(),
1635        obeys_concrete_eq::<Key>(),
1636        hash_set_inv(m),
1637        #[trigger] hash_set_contains_ensures(m, k, result),
1638    ensures
1639        result == m@.contains(*k),
1640{
1641    reveal(obeys_concrete_eq);
1642}
1643
1644pub broadcast proof fn lemma_hash_set_contains_ensures_if_obeys_deep_eq<
1645    Key: Eq + Hash + DeepView,
1646    S: BuildHasher,
1647    A: Allocator,
1648>(m: &HashSet<Key, S, A>, k: &Key, result: bool)
1649    requires
1650        obeys_key_model::<Key>(),
1651        builds_valid_hashers::<S>(),
1652        obeys_deep_eq::<Key>(),
1653        hash_set_inv(m),
1654        #[trigger] hash_set_contains_ensures(m, k, result),
1655    ensures
1656        result == m.deep_view().contains(k.deep_view()),
1657{
1658    reveal(obeys_deep_eq);
1659    broadcast use {crate::set::group_set_lemmas, Set::lemma_map_contains};
1660
1661    if result {
1662        let key = choose|key: Key| #[trigger] m@.contains(key) && k.eq_spec(&key);
1663        assert(m.deep_view().contains(key.deep_view()));
1664    }
1665    if m.deep_view().contains(k.deep_view()) {
1666        let key = choose|key: Key| m@.contains(key) && #[trigger] key.deep_view() == k.deep_view();
1667        assert(k.eq_spec(&key));
1668    }
1669}
1670
1671pub open spec fn hash_set_get_ensures<
1672    Key: Borrow<Q> + Hash + Eq,
1673    S: BuildHasher,
1674    A: Allocator,
1675    Q: Hash + Eq + ?Sized,
1676>(m: &HashSet<Key, S, A>, k: &Q, result: Option<&Key>) -> bool {
1677    ({
1678        &&& obeys_key_model::<Key>()
1679        &&& obeys_key_model::<Q>()
1680        &&& builds_valid_hashers::<S>()
1681        &&& <Key as BorrowSpec<Q>>::obeys_borrow_spec()
1682        &&& hash_set_inv(m)
1683    }) ==> {
1684        match result {
1685            Some(key) => {
1686                &&& m@.contains(*key)
1687                &&& k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(key))
1688            },
1689            None => forall|key: Key| #[trigger]
1690                m@.contains(key) ==> !k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key)),
1691        }
1692    }
1693}
1694
1695pub assume_specification<
1696    'a,
1697    Key: Borrow<Q> + Hash + Eq,
1698    S: BuildHasher,
1699    A: Allocator,
1700    Q: Hash + Eq + ?Sized,
1701>[ HashSet::<Key, S, A>::get::<Q> ](m: &'a HashSet<Key, S, A>, k: &Q) -> (result: Option<&'a Key>)
1702    requires
1703        borrowed_key_hashing_matches::<Key, Q>(),
1704    ensures
1705        hash_set_get_ensures(m, k, result),
1706;
1707
1708pub broadcast proof fn lemma_hash_set_get_ensures_if_obeys_concrete_eq<
1709    Key: Eq + Hash,
1710    S: BuildHasher,
1711    A: Allocator,
1712>(m: &HashSet<Key, S, A>, k: &Key, result: Option<&Key>)
1713    requires
1714        obeys_key_model::<Key>(),
1715        builds_valid_hashers::<S>(),
1716        obeys_concrete_eq::<Key>(),
1717        hash_set_inv(m),
1718        #[trigger] hash_set_get_ensures(m, k, result),
1719    ensures
1720        match result {
1721            Some(key) => m@.contains(*key) && *key == *k,
1722            None => !m@.contains(*k),
1723        },
1724{
1725    reveal(obeys_concrete_eq);
1726}
1727
1728pub broadcast proof fn lemma_hash_set_get_ensures_if_obeys_deep_eq<
1729    Key: Eq + Hash + DeepView,
1730    S: BuildHasher,
1731    A: Allocator,
1732>(m: &HashSet<Key, S, A>, k: &Key, result: Option<&Key>)
1733    requires
1734        obeys_key_model::<Key>(),
1735        builds_valid_hashers::<S>(),
1736        obeys_deep_eq::<Key>(),
1737        hash_set_inv(m),
1738        #[trigger] hash_set_get_ensures(m, k, result),
1739    ensures
1740        match result {
1741            Some(key) => {
1742                &&& m@.contains(*key)
1743                &&& m.deep_view().contains(k.deep_view())
1744                &&& key.deep_view() == k.deep_view()
1745            },
1746            None => !m.deep_view().contains(k.deep_view()),
1747        },
1748{
1749    reveal(obeys_deep_eq);
1750    broadcast use {crate::set::group_set_lemmas, Set::lemma_map_contains};
1751
1752    match result {
1753        Some(key) => {
1754            assert(m.deep_view().contains(key.deep_view()));
1755        },
1756        None => {
1757            if m.deep_view().contains(k.deep_view()) {
1758                let key = choose|key: Key|
1759                    m@.contains(key) && #[trigger] key.deep_view() == k.deep_view();
1760                assert(k.eq_spec(&key));
1761            }
1762        },
1763    }
1764}
1765
1766pub open spec fn hash_set_remove_ensures<
1767    Key: Borrow<Q> + Hash + Eq,
1768    S: BuildHasher,
1769    A: Allocator,
1770    Q: Hash + Eq + ?Sized,
1771>(old_m: &HashSet<Key, S, A>, final_m: &HashSet<Key, S, A>, k: &Q, result: bool) -> bool {
1772    ({
1773        &&& obeys_key_model::<Key>()
1774        &&& obeys_key_model::<Q>()
1775        &&& builds_valid_hashers::<S>()
1776        &&& <Key as BorrowSpec<Q>>::obeys_borrow_spec()
1777        &&& hash_set_inv(old_m)
1778    }) ==> {
1779        &&& hash_set_inv(final_m)
1780        &&& if result {
1781            exists|key: Key|
1782                {
1783                    &&& #[trigger] old_m@.contains(key)
1784                    &&& k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key))
1785                    &&& final_m@ == old_m@.remove(key)
1786                }
1787        } else {
1788            &&& forall|key: Key| #[trigger]
1789                old_m@.contains(key) ==> !k.eq_spec(<Key as BorrowSpec<Q>>::borrow_spec(&key))
1790            &&& final_m@ == old_m@
1791        }
1792    }
1793}
1794
1795pub assume_specification<
1796    Key: Borrow<Q> + Hash + Eq,
1797    S: BuildHasher,
1798    A: Allocator,
1799    Q: Hash + Eq + ?Sized,
1800>[ HashSet::<Key, S, A>::remove::<Q> ](m: &mut HashSet<Key, S, A>, k: &Q) -> (result: bool)
1801    requires
1802        borrowed_key_hashing_matches::<Key, Q>(),
1803    ensures
1804        hash_set_wf(old(m)) ==> hash_set_wf(final(m)),
1805        hash_set_remove_ensures(old(m), final(m), k, result),
1806;
1807
1808pub broadcast proof fn lemma_hash_set_remove_ensures_if_obeys_concrete_eq<
1809    Key: Eq + Hash,
1810    S: BuildHasher,
1811    A: Allocator,
1812>(old_m: &HashSet<Key, S, A>, final_m: &HashSet<Key, S, A>, k: &Key, result: bool)
1813    requires
1814        obeys_key_model::<Key>(),
1815        builds_valid_hashers::<S>(),
1816        obeys_concrete_eq::<Key>(),
1817        hash_set_inv(old_m),
1818        #[trigger] hash_set_remove_ensures(old_m, final_m, k, result),
1819    ensures
1820        final_m@ == old_m@.remove(*k),
1821        result == old_m@.contains(*k),
1822{
1823    reveal(obeys_concrete_eq);
1824    broadcast use crate::set::group_set_lemmas;
1825
1826    if !result {
1827        assert(!old_m@.contains(*k));
1828        assert(old_m@.remove(*k) =~= old_m@);
1829    }
1830}
1831
1832pub broadcast proof fn lemma_hash_set_remove_ensures_if_obeys_deep_eq<
1833    Key: Eq + Hash + DeepView,
1834    S: BuildHasher,
1835    A: Allocator,
1836>(old_m: &HashSet<Key, S, A>, final_m: &HashSet<Key, S, A>, k: &Key, result: bool)
1837    requires
1838        obeys_key_model::<Key>(),
1839        builds_valid_hashers::<S>(),
1840        obeys_deep_eq::<Key>(),
1841        hash_set_inv(old_m),
1842        #[trigger] hash_set_remove_ensures(old_m, final_m, k, result),
1843    ensures
1844        final_m.deep_view() == old_m.deep_view().remove(k.deep_view()),
1845        result == old_m.deep_view().contains(k.deep_view()),
1846{
1847    reveal(obeys_deep_eq);
1848    broadcast use {crate::set::group_set_lemmas, Set::lemma_map_contains};
1849
1850    let stored_key = if result {
1851        choose|key: Key|
1852            {
1853                &&& #[trigger] old_m@.contains(key)
1854                &&& k.eq_spec(&key)
1855                &&& final_m@ == old_m@.remove(key)
1856            }
1857    } else {
1858        *k
1859    };
1860    assert(stored_key.deep_view() == k.deep_view());
1861
1862    if result {
1863        assert(old_m.deep_view().contains(k.deep_view()));
1864    } else if old_m.deep_view().contains(k.deep_view()) {
1865        let key = choose|key: Key|
1866            old_m@.contains(key) && #[trigger] key.deep_view() == k.deep_view();
1867        assert(k.eq_spec(&key));
1868    }
1869    assert forall|kd: Key::V| #[trigger]
1870        final_m.deep_view().contains(kd) <==> old_m.deep_view().remove(k.deep_view()).contains(
1871            kd,
1872        ) by {
1873        if final_m.deep_view().contains(kd) {
1874            let key = choose|key: Key| final_m@.contains(key) && #[trigger] key.deep_view() == kd;
1875            assert(old_m@.contains(key));
1876            assert(key.deep_view() != k.deep_view());
1877        }
1878        if old_m.deep_view().contains(kd) && kd != k.deep_view() {
1879            let key = choose|key: Key| old_m@.contains(key) && #[trigger] key.deep_view() == kd;
1880            assert(final_m@.contains(key));
1881        }
1882    }
1883    assert(final_m.deep_view() =~= old_m.deep_view().remove(k.deep_view()));
1884}
1885
1886pub assume_specification<Key, S, A: Allocator>[ HashSet::<Key, S, A>::clear ](
1887    m: &mut HashSet<Key, S, A>,
1888)
1889    ensures
1890        final(m)@ == Set::<Key>::empty(),
1891        hash_set_wf(final(m)),
1892;
1893
1894pub assume_specification<'a, Key, S, A: Allocator>[ HashSet::<Key, S, A>::iter ](
1895    m: &'a HashSet<Key, S, A>,
1896) -> (hash_keys: hash_set::Iter<'a, Key>)
1897    ensures
1898        obeys_key_model::<Key>() && builds_valid_hashers::<S>() && hash_set_wf(m) ==> {
1899            &&& IteratorSpec::remaining(&hash_keys).unref().to_set() == m@
1900            &&& IteratorSpec::remaining(&hash_keys).no_duplicates()
1901            &&& IteratorSpec::remaining(&hash_keys).len() == m@.len()
1902            &&& IteratorSpec::remaining(&hash_keys).len() == m.len()
1903            &&& into_iter_hash_keys(hash_keys) == IteratorSpec::remaining(&hash_keys).unref()
1904            &&& IteratorSpec::decrease(&hash_keys) is Some
1905        },
1906;
1907
1908pub broadcast proof fn axiom_hashset_decreases<Key, S, A: Allocator>(m: HashSet<Key, S, A>)
1909    ensures
1910        #[trigger] (decreases_to!(m => m@)),
1911{
1912    admit();
1913}
1914
1915//////// Entry API
1916// Specs for OccupiedEntry, VacantEntry, and the Entry enum
1917// OccupiedEntry and VacantEntry are both opaque;
1918// Entry is just an enum wrapper around the other 2, so we leave it transparent.
1919#[verifier::reject_recursive_types_in_ground_variants(K)]
1920#[verifier::reject_recursive_types_in_ground_variants(V)]
1921#[verifier::reject_recursive_types(A)]
1922#[verifier::external_body]
1923#[verifier::external_type_specification]
1924pub struct ExOccupiedEntry<'a, K: 'a, V: 'a, A: Allocator>(OccupiedEntry<'a, K, V, A>);
1925
1926#[verifier::reject_recursive_types_in_ground_variants(K)]
1927#[verifier::accept_recursive_types(V)]
1928#[verifier::reject_recursive_types(A)]
1929#[verifier::external_body]
1930#[verifier::external_type_specification]
1931pub struct ExVacantEntry<'a, K: 'a, V: 'a, A: Allocator>(VacantEntry<'a, K, V, A>);
1932
1933#[verifier::external_type_specification]
1934#[verifier::reject_recursive_types(A)]
1935pub struct ExEntry<'a, K: 'a, V: 'a, A: Allocator>(Entry<'a, K, V, A>);
1936
1937/// Specification for an [`OccupiedEntry`].
1938/// Contains the current key and value in the entry,
1939/// and prophesies the final value after this instantiation of the entry API is complete.
1940/// The final value is optional, since the user might choose to remove the entry.
1941pub trait OccupiedEntrySpecFns<K, V, A>: Sized {
1942    spec fn spec_key(self) -> K;
1943
1944    spec fn value(self) -> V;
1945
1946    #[verifier::prophetic]
1947    spec fn final_value(self) -> Option<V>;
1948}
1949
1950impl<'a, K, V, A: Allocator> OccupiedEntrySpecFns<K, V, A> for OccupiedEntry<'a, K, V, A> {
1951    uninterp spec fn spec_key(self) -> K;
1952
1953    uninterp spec fn value(self) -> V;
1954
1955    #[verifier::prophetic]
1956    uninterp spec fn final_value(self) -> Option<V>;
1957}
1958
1959/// Specification for a [`VacantEntry`].
1960/// Contains the current key for the entry,
1961/// and prophesies the final value after this instantiation of the entry API is complete.
1962/// The final value is optional, since the user may or may not choose to insert a value.
1963pub trait VacantEntrySpecFns<K, V, A>: Sized {
1964    spec fn spec_key(self) -> K;
1965
1966    #[verifier::prophetic]
1967    spec fn final_value(self) -> Option<V>;
1968}
1969
1970impl<'a, K, V, A: Allocator> VacantEntrySpecFns<K, V, A> for VacantEntry<'a, K, V, A> {
1971    uninterp spec fn spec_key(self) -> K;
1972
1973    #[verifier::prophetic]
1974    uninterp spec fn final_value(self) -> Option<V>;
1975}
1976
1977/// Specification for an [`Entry`].
1978/// Contains the current key for the entry,
1979/// and prophesies the final value after this instantiation of the entry API is complete.
1980pub trait EntrySpecFns<K, V, A>: Sized {
1981    spec fn spec_key(self) -> K;
1982
1983    spec fn value(self) -> Option<V>;
1984
1985    #[verifier::prophetic]
1986    spec fn final_value(self) -> Option<V>;
1987}
1988
1989impl<'a, K, V, A: Allocator> EntrySpecFns<K, V, A> for Entry<'a, K, V, A> {
1990    open spec fn spec_key(self) -> K {
1991        match self {
1992            Entry::Occupied(occupied_entry) => occupied_entry.spec_key(),
1993            Entry::Vacant(vacant_entry) => vacant_entry.spec_key(),
1994        }
1995    }
1996
1997    open spec fn value(self) -> Option<V> {
1998        match self {
1999            Entry::Occupied(occupied_entry) => Some(occupied_entry.value()),
2000            Entry::Vacant(vacant_entry) => None,
2001        }
2002    }
2003
2004    #[verifier::prophetic]
2005    open spec fn final_value(self) -> Option<V> {
2006        match self {
2007            Entry::Occupied(occupied_entry) => occupied_entry.final_value(),
2008            Entry::Vacant(vacant_entry) => vacant_entry.final_value(),
2009        }
2010    }
2011}
2012
2013pub broadcast axiom fn axiom_has_resolved_occupied_entry<K, V, A: Allocator>(
2014    entry: OccupiedEntry<K, V, A>,
2015)
2016    ensures
2017        #[trigger] has_resolved(entry) ==> entry.final_value() == Some(entry.value()),
2018;
2019
2020pub broadcast axiom fn axiom_has_resolved_vacant_entry<K, V, A: Allocator>(
2021    entry: VacantEntry<K, V, A>,
2022)
2023    ensures
2024        #[trigger] has_resolved(entry) ==> entry.final_value() == None::<V>,
2025;
2026
2027pub broadcast proof fn axiom_has_resolved_entry<K, V, A: Allocator>(entry: Entry<K, V, A>)
2028    ensures
2029        #[trigger] has_resolved(entry) ==> entry.final_value() == entry.value(),
2030{
2031    broadcast use axiom_has_resolved_occupied_entry;
2032    broadcast use axiom_has_resolved_vacant_entry;
2033
2034}
2035
2036#[verifier::prophetic]
2037pub open spec fn hash_map_entry_ensures<Key: Eq + Hash, Value, S: BuildHasher, A: Allocator>(
2038    old_m: &HashMap<Key, Value, S, A>,
2039    final_m: &HashMap<Key, Value, S, A>,
2040    key: Key,
2041    entry: Entry<Key, Value, A>,
2042) -> bool {
2043    ({
2044        &&& obeys_key_model::<Key>()
2045        &&& builds_valid_hashers::<S>()
2046        &&& hash_map_inv(old_m)
2047    }) ==> {
2048        &&& hash_map_inv(final_m)
2049        &&& match entry {
2050            Entry::Occupied(occupied_entry) => {
2051                &&& old_m@.contains_key(occupied_entry.spec_key())
2052                &&& key.eq_spec(&occupied_entry.spec_key())
2053                &&& occupied_entry.value() == old_m@[occupied_entry.spec_key()]
2054            },
2055            Entry::Vacant(vacant_entry) => {
2056                &&& vacant_entry.spec_key() == key
2057                &&& forall|stored_key: Key| #[trigger]
2058                    old_m@.contains_key(stored_key) ==> !key.eq_spec(&stored_key)
2059            },
2060        }
2061        &&& final_m@ == match entry.final_value() {
2062            Some(value) => old_m@.insert(entry.spec_key(), value),
2063            None => old_m@.remove(entry.spec_key()),
2064        }
2065    }
2066}
2067
2068pub assume_specification<'a, Key: Hash + Eq, Value, S: BuildHasher, A: Allocator>[ HashMap::<
2069    Key,
2070    Value,
2071    S,
2072    A,
2073>::entry ](m: &'a mut HashMap<Key, Value, S, A>, key: Key) -> (entry: Entry<'a, Key, Value, A>)
2074    ensures
2075        hash_map_wf(old(m)) ==> hash_map_wf(final(m)),
2076        hash_map_entry_ensures(old(m), final(m), key, entry),
2077;
2078
2079pub broadcast proof fn lemma_hash_map_entry_ensures_if_obeys_concrete_eq<
2080    Key: Eq + Hash,
2081    Value,
2082    S: BuildHasher,
2083    A: Allocator,
2084>(
2085    old_m: &HashMap<Key, Value, S, A>,
2086    final_m: &HashMap<Key, Value, S, A>,
2087    key: Key,
2088    entry: Entry<Key, Value, A>,
2089)
2090    requires
2091        obeys_key_model::<Key>(),
2092        builds_valid_hashers::<S>(),
2093        obeys_concrete_eq::<Key>(),
2094        hash_map_inv(old_m),
2095        #[trigger] hash_map_entry_ensures(old_m, final_m, key, entry),
2096    ensures
2097        entry.spec_key() == key,
2098        entry.value() == old_m@.get(key),
2099        final_m@ == match entry.final_value() {
2100            Some(value) => old_m@.insert(key, value),
2101            None => old_m@.remove(key),
2102        },
2103{
2104    reveal(obeys_concrete_eq);
2105}
2106
2107pub broadcast proof fn lemma_hash_map_entry_ensures_if_obeys_deep_eq<
2108    Key: Eq + Hash + DeepView,
2109    Value: DeepView,
2110    S: BuildHasher,
2111    A: Allocator,
2112>(
2113    old_m: &HashMap<Key, Value, S, A>,
2114    final_m: &HashMap<Key, Value, S, A>,
2115    key: Key,
2116    entry: Entry<Key, Value, A>,
2117)
2118    requires
2119        obeys_key_model::<Key>(),
2120        builds_valid_hashers::<S>(),
2121        obeys_deep_eq::<Key>(),
2122        hash_map_inv(old_m),
2123        #[trigger] hash_map_entry_ensures(old_m, final_m, key, entry),
2124    ensures
2125        entry.spec_key().deep_view() == key.deep_view(),
2126        match entry.value() {
2127            Some(value) => {
2128                &&& old_m.deep_view().contains_key(key.deep_view())
2129                &&& value.deep_view() == old_m.deep_view()[key.deep_view()]
2130            },
2131            None => !old_m.deep_view().contains_key(key.deep_view()),
2132        },
2133        final_m.deep_view() == match entry.final_value() {
2134            Some(value) => old_m.deep_view().insert(key.deep_view(), value.deep_view()),
2135            None => old_m.deep_view().remove(key.deep_view()),
2136        },
2137{
2138    reveal(obeys_deep_eq);
2139    broadcast use {
2140        crate::map::group_map_lemmas,
2141        crate::set::group_set_lemmas,
2142        Set::lemma_map_contains,
2143    };
2144
2145    reveal(hash_map_deep_view_impl);
2146
2147    let stored_key = entry.spec_key();
2148    assert(stored_key.deep_view() == key.deep_view());
2149    match entry.value() {
2150        Some(value) => {
2151            assert(old_m.deep_view().contains_key(key.deep_view()));
2152            let k = choose|k: Key|
2153                old_m@.contains_key(k) && #[trigger] k.deep_view() == key.deep_view();
2154            assert(k == stored_key);
2155        },
2156        None => {
2157            if old_m.deep_view().contains_key(key.deep_view()) {
2158                let k = choose|k: Key|
2159                    old_m@.contains_key(k) && #[trigger] k.deep_view() == key.deep_view();
2160                assert(key.eq_spec(&k));
2161            }
2162        },
2163    }
2164
2165    if entry.final_value() is Some {
2166        assert(final_m@.contains_key(stored_key));
2167    }
2168    assert_maps_equal!(
2169        final_m.deep_view(),
2170        match entry.final_value() {
2171            Some(value) => old_m.deep_view().insert(key.deep_view(), value.deep_view()),
2172            None => old_m.deep_view().remove(key.deep_view()),
2173        },
2174        kd => {
2175            if final_m.deep_view().contains_key(kd) {
2176                let k = choose|k: Key|
2177                    final_m@.contains_key(k) && #[trigger] k.deep_view() == kd;
2178                if entry.final_value() is None {
2179                    assert(old_m@.contains_key(k));
2180                    assert(k.deep_view() != key.deep_view());
2181                } else if kd != key.deep_view() {
2182                    assert(old_m@.contains_key(k));
2183                }
2184            }
2185            if old_m.deep_view().contains_key(kd) && kd != key.deep_view() {
2186                let k = choose|k: Key|
2187                    old_m@.contains_key(k) && #[trigger] k.deep_view() == kd;
2188                assert(final_m@.contains_key(k));
2189            }
2190        }
2191    );
2192}
2193
2194//// Entry
2195#[verifier::allow_in_spec]
2196pub assume_specification<'a, 'b, K, V, A: Allocator>[ Entry::key ](
2197    entry: &'b Entry::<'a, K, V, A>,
2198) -> (key: &'b K)
2199    returns
2200        &entry.spec_key(),
2201;
2202
2203pub assume_specification<'a, K, V, A: Allocator>[ Entry::or_insert ](
2204    entry: Entry::<'a, K, V, A>,
2205    default: V,
2206) -> (value: &'a mut V)
2207    ensures
2208        *value == (match entry.value() {
2209            Some(v) => v,
2210            None => default,
2211        }),
2212        entry.final_value() == Some(*final(value)),
2213;
2214
2215pub assume_specification<'a, K, V, A: Allocator>[ Entry::insert_entry ](
2216    entry: Entry::<'a, K, V, A>,
2217    value: V,
2218) -> (occ_entry: OccupiedEntry<'a, K, V, A>)
2219    ensures
2220        occ_entry.key() == entry.key(),
2221        occ_entry.value() == value,
2222        entry.final_value() == occ_entry.final_value(),
2223;
2224
2225//// OccupiedEntry
2226// This module works around a bug with `allow_in_spec` that creates duplicate spec fn names
2227mod m_occ {
2228    use super::*;
2229
2230    #[verifier::allow_in_spec]
2231    pub assume_specification<'a, 'b, K, V, A: Allocator>[ OccupiedEntry::key ](
2232        entry: &'b OccupiedEntry::<'a, K, V, A>,
2233    ) -> (key: &'b K)
2234        returns
2235            &entry.spec_key(),
2236    ;
2237
2238}
2239
2240pub assume_specification<'a, K, V, A: Allocator>[ OccupiedEntry::remove_entry ](
2241    entry: OccupiedEntry::<'a, K, V, A>,
2242) -> (kv: (K, V))
2243    ensures
2244        entry.final_value() == None,
2245    returns
2246        (*entry.key(), entry.value()),
2247;
2248
2249pub assume_specification<'a, 'b, K, V, A: Allocator>[ OccupiedEntry::get ](
2250    entry: &'b OccupiedEntry::<'a, K, V, A>,
2251) -> (value: &'b V)
2252    ensures
2253        *value == entry.value(),
2254;
2255
2256pub assume_specification<'a, 'b, K, V, A: Allocator>[ OccupiedEntry::get_mut ](
2257    entry: &'b mut OccupiedEntry::<'a, K, V, A>,
2258) -> (value: &'b mut V)
2259    ensures
2260        *value == old(entry).value(),
2261        final(entry).key() == old(entry).key(),
2262        final(entry).value() == *final(value),
2263        final(entry).final_value() == old(entry).final_value(),
2264;
2265
2266pub assume_specification<'a, K, V, A: Allocator>[ OccupiedEntry::into_mut ](
2267    entry: OccupiedEntry::<'a, K, V, A>,
2268) -> (value: &mut V)
2269    ensures
2270        *value == entry.value(),
2271        entry.final_value() == Some(*final(value)),
2272;
2273
2274pub assume_specification<'a, K, V, A: Allocator>[ OccupiedEntry::insert ](
2275    entry: &mut OccupiedEntry::<'a, K, V, A>,
2276    value: V,
2277) -> (old_value: V)
2278    ensures
2279        old_value == old(entry).value(),
2280        final(entry).key() == old(entry).key(),
2281        final(entry).value() == value,
2282        final(entry).final_value() == old(entry).final_value(),
2283;
2284
2285pub assume_specification<'a, K, V, A: Allocator>[ OccupiedEntry::remove ](
2286    entry: OccupiedEntry::<'a, K, V, A>,
2287) -> (value: V)
2288    ensures
2289        value == entry.value(),
2290        entry.final_value() == None,
2291;
2292
2293//// VacantEntry
2294// This module works around a bug with `allow_in_spec` that creates duplicate spec fn names
2295mod m_vac {
2296    use super::*;
2297
2298    #[verifier::allow_in_spec]
2299    pub assume_specification<'a, 'b, K: 'a, V: 'a, A: Allocator>[ VacantEntry::key ](
2300        entry: &'b VacantEntry::<'a, K, V, A>,
2301    ) -> (key: &'b K)
2302        returns
2303            &entry.spec_key(),
2304    ;
2305
2306}
2307
2308pub assume_specification<'a, K: 'a, V: 'a, A: Allocator>[ VacantEntry::into_key ](
2309    entry: VacantEntry::<'a, K, V, A>,
2310) -> (key: K)
2311    ensures
2312        key == entry.key(),
2313        entry.final_value() == None,
2314;
2315
2316pub assume_specification<'a, K: 'a, V: 'a, A: Allocator>[ VacantEntry::insert ](
2317    entry: VacantEntry::<'a, K, V, A>,
2318    value: V,
2319) -> (value_ref: &mut V)
2320    ensures
2321        *value_ref == value,
2322        entry.final_value() == Some(*final(value_ref)),
2323;
2324
2325pub assume_specification<'a, K: 'a, V: 'a, A: Allocator>[ VacantEntry::insert_entry ](
2326    entry: VacantEntry::<'a, K, V, A>,
2327    value: V,
2328) -> (occ_entry: OccupiedEntry::<'a, K, V, A>)
2329    ensures
2330        occ_entry.key() == entry.key(),
2331        occ_entry.value() == value,
2332        entry.final_value() == occ_entry.final_value(),
2333;
2334
2335pub broadcast group group_hash_axioms {
2336    lemma_hash_map_insert_ensures_if_obeys_concrete_eq,
2337    lemma_hash_map_insert_ensures_if_obeys_deep_eq,
2338    lemma_hash_map_contains_key_ensures_if_obeys_concrete_eq,
2339    lemma_hash_map_contains_key_ensures_if_obeys_deep_eq,
2340    lemma_hash_map_get_ensures_if_obeys_concrete_eq,
2341    lemma_hash_map_get_ensures_if_obeys_deep_eq,
2342    lemma_hash_map_remove_ensures_if_obeys_concrete_eq,
2343    lemma_hash_map_remove_ensures_if_obeys_deep_eq,
2344    lemma_hash_map_entry_ensures_if_obeys_concrete_eq,
2345    lemma_hash_map_entry_ensures_if_obeys_deep_eq,
2346    lemma_hash_set_insert_ensures_if_obeys_concrete_eq,
2347    lemma_hash_set_insert_ensures_if_obeys_deep_eq,
2348    lemma_hash_set_contains_ensures_if_obeys_concrete_eq,
2349    lemma_hash_set_contains_ensures_if_obeys_deep_eq,
2350    lemma_hash_set_get_ensures_if_obeys_concrete_eq,
2351    lemma_hash_set_get_ensures_if_obeys_deep_eq,
2352    lemma_hash_set_remove_ensures_if_obeys_concrete_eq,
2353    lemma_hash_set_remove_ensures_if_obeys_deep_eq,
2354    axiom_borrowed_key_hashing_matches_self,
2355    axiom_borrowed_key_hashing_matches_ref,
2356    axiom_borrowed_key_hashing_matches_box,
2357    axiom_borrowed_key_hashing_matches_string,
2358    axiom_string_obeys_hash_table_key_model,
2359    axiom_str_obeys_hash_table_key_model,
2360    axiom_bool_obeys_hash_table_key_model,
2361    axiom_u8_obeys_hash_table_key_model,
2362    axiom_u16_obeys_hash_table_key_model,
2363    axiom_u32_obeys_hash_table_key_model,
2364    axiom_u64_obeys_hash_table_key_model,
2365    axiom_u128_obeys_hash_table_key_model,
2366    axiom_usize_obeys_hash_table_key_model,
2367    axiom_i8_obeys_hash_table_key_model,
2368    axiom_i16_obeys_hash_table_key_model,
2369    axiom_i32_obeys_hash_table_key_model,
2370    axiom_i64_obeys_hash_table_key_model,
2371    axiom_i128_obeys_hash_table_key_model,
2372    axiom_isize_obeys_hash_table_key_model,
2373    axiom_box_bool_obeys_hash_table_key_model,
2374    axiom_box_integer_type_obeys_hash_table_key_model,
2375    axiom_random_state_builds_valid_hashers,
2376    axiom_spec_hash_map_len,
2377    axiom_spec_hash_set_len,
2378    axiom_hashmap_decreases,
2379    axiom_hashset_decreases,
2380    axiom_has_resolved_occupied_entry,
2381    axiom_has_resolved_vacant_entry,
2382    axiom_has_resolved_entry,
2383}
2384
2385} // verus!