From 497be3902e91f11ad6f8ed77b285717ea125ceb1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Wed, 4 Mar 2026 15:33:07 -0800 Subject: [PATCH] Rename our OOM-handling `HashSet` to `TryHashSet` --- crates/environ/src/collections.rs | 2 +- crates/environ/src/collections/hash_set.rs | 18 +++++++++--------- crates/environ/src/prelude.rs | 4 ++-- crates/fuzzing/tests/oom.rs | 12 ++++++------ crates/wasmtime/src/runtime/type_registry.rs | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/environ/src/collections.rs b/crates/environ/src/collections.rs index 699da59f80d9..543ef582c522 100644 --- a/crates/environ/src/collections.rs +++ b/crates/environ/src/collections.rs @@ -11,7 +11,7 @@ mod secondary_map; pub use btree_map::BTreeMap; pub use entity_set::TryEntitySet; pub use hash_map::TryHashMap; -pub use hash_set::HashSet; +pub use hash_set::TryHashSet; pub use index_map::IndexMap; pub use primary_map::PrimaryMap; pub use secondary_map::SecondaryMap; diff --git a/crates/environ/src/collections/hash_set.rs b/crates/environ/src/collections/hash_set.rs index 9dc28065352b..4593ffecff5d 100644 --- a/crates/environ/src/collections/hash_set.rs +++ b/crates/environ/src/collections/hash_set.rs @@ -13,11 +13,11 @@ use hashbrown::{DefaultHashBuilder, hash_set as inner}; /// A wrapper type around [`hashbrown::hash_set::HashSet`] that only exposes /// fallible allocation. -pub struct HashSet { +pub struct TryHashSet { inner: inner::HashSet, } -impl Default for HashSet +impl Default for TryHashSet where S: Default, { @@ -28,7 +28,7 @@ where } } -impl PartialEq for HashSet +impl PartialEq for TryHashSet where T: Eq + Hash, S: BuildHasher, @@ -38,14 +38,14 @@ where } } -impl Eq for HashSet +impl Eq for TryHashSet where T: Eq + Hash, S: BuildHasher, { } -impl fmt::Debug for HashSet +impl fmt::Debug for TryHashSet where T: fmt::Debug, { @@ -54,7 +54,7 @@ where } } -impl HashSet { +impl TryHashSet { /// Same as [`hashbrown::hash_set::HashSet::new`]. pub fn new() -> Self { Self { @@ -63,7 +63,7 @@ impl HashSet { } } -impl HashSet +impl TryHashSet where T: Eq + Hash, { @@ -76,7 +76,7 @@ where } } -impl HashSet { +impl TryHashSet { /// Same as [`hashbrown::hash_set::HashSet::with_hasher`]. pub const fn with_hasher(hasher: S) -> Self { Self { @@ -131,7 +131,7 @@ impl HashSet { } } -impl HashSet +impl TryHashSet where T: Eq + Hash, S: BuildHasher, diff --git a/crates/environ/src/prelude.rs b/crates/environ/src/prelude.rs index 6712bffaae00..23e7228dbebd 100644 --- a/crates/environ/src/prelude.rs +++ b/crates/environ/src/prelude.rs @@ -20,8 +20,8 @@ //! and then `use crate::*` works as usual. pub use crate::collections::{ - TryClone, TryCollect, TryEntitySet, TryExtend, TryFromIterator, TryHashMap, TryNew, TryString, - TryToOwned, TryVec, try_new, try_vec, + TryClone, TryCollect, TryEntitySet, TryExtend, TryFromIterator, TryHashMap, TryHashSet, TryNew, + TryString, TryToOwned, TryVec, try_new, try_vec, }; pub use crate::error::{Context, Error, Result, bail, ensure, format_err}; pub use alloc::borrow::ToOwned; diff --git a/crates/fuzzing/tests/oom.rs b/crates/fuzzing/tests/oom.rs index 59dd10278a36..300788690747 100644 --- a/crates/fuzzing/tests/oom.rs +++ b/crates/fuzzing/tests/oom.rs @@ -213,26 +213,26 @@ fn try_entity_set_insert() -> Result<()> { } #[test] -fn hash_set_with_capacity() -> Result<()> { +fn try_hash_set_with_capacity() -> Result<()> { OomTest::new().test(|| { - let _s = HashSet::::with_capacity(100)?; + let _s = TryHashSet::::with_capacity(100)?; Ok(()) }) } #[test] -fn hash_set_reserve() -> Result<()> { +fn try_hash_set_reserve() -> Result<()> { OomTest::new().test(|| { - let mut set = HashSet::::new(); + let mut set = TryHashSet::::new(); set.reserve(100)?; Ok(()) }) } #[test] -fn hash_set_insert() -> Result<()> { +fn try_hash_set_insert() -> Result<()> { OomTest::new().test(|| { - let mut set = HashSet::::new(); + let mut set = TryHashSet::::new(); for i in 0..1024 { set.insert(i)?; } diff --git a/crates/wasmtime/src/runtime/type_registry.rs b/crates/wasmtime/src/runtime/type_registry.rs index 23d0de644eb7..50773fe86a3e 100644 --- a/crates/wasmtime/src/runtime/type_registry.rs +++ b/crates/wasmtime/src/runtime/type_registry.rs @@ -25,7 +25,7 @@ use wasmtime_core::slab::{Id as SlabId, Slab}; use wasmtime_environ::{ EngineOrModuleTypeIndex, EntityRef, GcLayout, ModuleInternedTypeIndex, ModuleTypes, TypeTrace, Undo, VMSharedTypeIndex, WasmRecGroup, WasmSubType, - collections::{HashSet, PrimaryMap, SecondaryMap, TryCow}, + collections::{PrimaryMap, SecondaryMap, TryCow}, iter_entity_range, packed_option::{PackedOption, ReservedValue}, }; @@ -592,7 +592,7 @@ struct TypeRegistryInner { // registered. Before registering new rec groups, we first check this map to // see if we've already registered an identical rec group that we should // reuse instead. - hash_consing_map: HashSet, + hash_consing_map: TryHashSet, // A map from `VMSharedTypeIndex::bits()` to the type index's associated // Wasm type.