Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Rename our OOM-handling `HashSet` to `TryHashSet` (#12724)

Nick Fitzgeraldb47252c47f66
diff --git a/crates/environ/src/collections.rs b/crates/environ/src/collections.rs
index 699da59f80..543ef582c5 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 9dc2806535..4593ffecff 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<T, S = DefaultHashBuilder> {
+pub struct TryHashSet<T, S = DefaultHashBuilder> {
inner: inner::HashSet<T, S>,
}
-impl<T, S> Default for HashSet<T, S>
+impl<T, S> Default for TryHashSet<T, S>
where
S: Default,
{
@@ -28,7 +28,7 @@ where
}
}
-impl<T, S> PartialEq for HashSet<T, S>
+impl<T, S> PartialEq for TryHashSet<T, S>
where
T: Eq + Hash,
S: BuildHasher,
@@ -38,14 +38,14 @@ where
}
}
-impl<T, S> Eq for HashSet<T, S>
+impl<T, S> Eq for TryHashSet<T, S>
where
T: Eq + Hash,
S: BuildHasher,
{
}
-impl<T, S> fmt::Debug for HashSet<T, S>
+impl<T, S> fmt::Debug for TryHashSet<T, S>
where
T: fmt::Debug,
{
@@ -54,7 +54,7 @@ where
}
}
-impl<T> HashSet<T, DefaultHashBuilder> {
+impl<T> TryHashSet<T, DefaultHashBuilder> {
/// Same as [`hashbrown::hash_set::HashSet::new`].
pub fn new() -> Self {
Self {
@@ -63,7 +63,7 @@ impl<T> HashSet<T, DefaultHashBuilder> {
}
}
-impl<T> HashSet<T, DefaultHashBuilder>
+impl<T> TryHashSet<T, DefaultHashBuilder>
where
T: Eq + Hash,
{
@@ -76,7 +76,7 @@ where
}
}
-impl<T, S> HashSet<T, S> {
+impl<T, S> TryHashSet<T, S> {
/// Same as [`hashbrown::hash_set::HashSet::with_hasher`].
pub const fn with_hasher(hasher: S) -> Self {
Self {
@@ -131,7 +131,7 @@ impl<T, S> HashSet<T, S> {
}
}
-impl<T, S> HashSet<T, S>
+impl<T, S> TryHashSet<T, S>
where
T: Eq + Hash,
S: BuildHasher,
diff --git a/crates/environ/src/prelude.rs b/crates/environ/src/prelude.rs
index 6712bffaae..23e7228dbe 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 59dd10278a..3007886907 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::<usize>::with_capacity(100)?;
+ let _s = TryHashSet::<usize>::with_capacity(100)?;
Ok(())
})
}
#[test]
-fn hash_set_reserve() -> Result<()> {
+fn try_hash_set_reserve() -> Result<()> {
OomTest::new().test(|| {
- let mut set = HashSet::<usize>::new();
+ let mut set = TryHashSet::<usize>::new();
set.reserve(100)?;
Ok(())
})
}
#[test]
-fn hash_set_insert() -> Result<()> {
+fn try_hash_set_insert() -> Result<()> {
OomTest::new().test(|| {
- let mut set = HashSet::<usize>::new();
+ let mut set = TryHashSet::<usize>::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 23d0de644e..50773fe86a 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<RecGroupEntry>,
+ hash_consing_map: TryHashSet<RecGroupEntry>,
// A map from `VMSharedTypeIndex::bits()` to the type index's associated
// Wasm type.