Skip to content

Commit 40215f2

Browse files
authored
Adjust Wasmtime's prelude/hash collections (#12509)
This commit updates Wasmtime's internal usage of hash maps and hash sets to use the standard library when the `std` feature is enabled, as opposed to using `hashbrown`. When `std` is disabled `hashbrown` is still used, however. Additionally the prelude of `wasmtime` is now a simple reexport of `wasmtime_environ`.
1 parent c13148b commit 40215f2

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/environ/src/collections.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@ pub use hash_set::HashSet;
1010
pub use primary_map::PrimaryMap;
1111
pub use secondary_map::SecondaryMap;
1212
pub use wasmtime_core::alloc::{TryNew, Vec, try_new};
13+
14+
/// Collections which abort on OOM.
15+
//
16+
// FIXME(#12069) this is just here for Wasmtime at this time. Ideally
17+
// collections would only be fallible in this module and would handle OOM. We're
18+
// in a bit of a transition period though.
19+
pub mod oom_abort {
20+
#[cfg(not(feature = "std"))]
21+
pub use hashbrown::{hash_map, hash_set};
22+
#[cfg(feature = "std")]
23+
pub use std::collections::{hash_map, hash_set};
24+
25+
pub use self::hash_map::HashMap;
26+
pub use self::hash_set::HashSet;
27+
}

crates/wasmtime/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ serde = { workspace = true }
4545
serde_derive = { workspace = true }
4646
serde_json = { workspace = true, optional = true }
4747
postcard = { workspace = true }
48-
indexmap = { workspace = true }
4948
once_cell = { version = "1.12.0", optional = true }
5049
rayon = { workspace = true, optional = true }
5150
object = { workspace = true, features = ['unaligned'] }
@@ -57,7 +56,6 @@ gimli = { workspace = true, optional = true }
5756
addr2line = { workspace = true, optional = true }
5857
semver = { workspace = true, optional = true }
5958
smallvec = { workspace = true, optional = true }
60-
hashbrown = { workspace = true, features = ["default-hasher"] }
6159
bitflags = { workspace = true }
6260
futures = { workspace = true, features = ["alloc"], optional = true }
6361
bytes = { workspace = true, optional = true }

crates/wasmtime/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,15 @@
409409
extern crate std;
410410
extern crate alloc;
411411

412-
pub(crate) mod prelude {
413-
pub use crate::error::{Context, Error, Result, bail, ensure, format_err};
414-
pub use wasmtime_environ::prelude::*;
415-
}
412+
// Internal `use` statement which isn't used in this module but enable
413+
// `use crate::prelude::*;` everywhere else within this crate, for example.
414+
use wasmtime_environ::prelude;
416415

417-
pub(crate) use hashbrown::{hash_map, hash_set};
416+
// FIXME(#12069) should transition to OOM-handling versions of these collections
417+
// for all internal usage instead of using abort-on-OOM versions. Once that's
418+
// done this can be removed and the collections should be directly imported from
419+
// `wasmtime_environ::collections::*`.
420+
use wasmtime_environ::collections::oom_abort::{hash_map, hash_set};
418421

419422
/// A helper macro to safely map `MaybeUninit<T>` to `MaybeUninit<U>` where `U`
420423
/// is a field projection within `T`.

0 commit comments

Comments
 (0)