Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/environ/src/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use entity_set::TryEntitySet;
pub use hash_map::TryHashMap;
pub use hash_set::TryHashSet;
pub use index_map::TryIndexMap;
pub use primary_map::PrimaryMap;
pub use primary_map::TryPrimaryMap;
pub use secondary_map::SecondaryMap;
pub use wasmtime_core::{
alloc::{
Expand Down
26 changes: 13 additions & 13 deletions crates/environ/src/collections/primary_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use serde::{Serialize, ser::SerializeSeq};
/// Like [`cranelift_entity::PrimaryMap`] but enforces fallible allocation for
/// all methods that allocate.
#[derive(Hash, PartialEq, Eq)]
pub struct PrimaryMap<K, V>
pub struct TryPrimaryMap<K, V>
where
K: EntityRef,
{
inner: cranelift_entity::PrimaryMap<K, V>,
}

impl<K, V> Default for PrimaryMap<K, V>
impl<K, V> Default for TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -28,7 +28,7 @@ where
}
}

impl<K, V> fmt::Debug for PrimaryMap<K, V>
impl<K, V> fmt::Debug for TryPrimaryMap<K, V>
where
K: EntityRef + fmt::Debug,
V: fmt::Debug,
Expand All @@ -38,7 +38,7 @@ where
}
}

impl<K, V> From<TryVec<V>> for PrimaryMap<K, V>
impl<K, V> From<TryVec<V>> for TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -49,7 +49,7 @@ where
}
}

impl<K, V> serde::ser::Serialize for PrimaryMap<K, V>
impl<K, V> serde::ser::Serialize for TryPrimaryMap<K, V>
where
K: EntityRef,
V: Serialize,
Expand All @@ -66,7 +66,7 @@ where
}
}

impl<'de, K, V> serde::de::Deserialize<'de> for PrimaryMap<K, V>
impl<'de, K, V> serde::de::Deserialize<'de> for TryPrimaryMap<K, V>
where
K: EntityRef,
V: serde::de::Deserialize<'de>,
Expand All @@ -80,7 +80,7 @@ where
}
}

impl<K, V> PrimaryMap<K, V>
impl<K, V> TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand Down Expand Up @@ -218,7 +218,7 @@ where
}
}

impl<K, V> TryExtend<V> for PrimaryMap<K, V>
impl<K, V> TryExtend<V> for TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -237,7 +237,7 @@ where
}
}

impl<K, V> Index<K> for PrimaryMap<K, V>
impl<K, V> Index<K> for TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -248,7 +248,7 @@ where
}
}

impl<K, V> IndexMut<K> for PrimaryMap<K, V>
impl<K, V> IndexMut<K> for TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -257,7 +257,7 @@ where
}
}

impl<K, V> IntoIterator for PrimaryMap<K, V>
impl<K, V> IntoIterator for TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -268,7 +268,7 @@ where
}
}

impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>
impl<'a, K, V> IntoIterator for &'a TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand All @@ -279,7 +279,7 @@ where
}
}

impl<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut TryPrimaryMap<K, V>
where
K: EntityRef,
{
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/src/compile/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
ModuleInternedTypeIndex, ModuleTypesBuilder, PanicOnOom as _, PrimaryMap, SizeOverflow,
StaticMemoryInitializer, StaticModuleIndex, TableIndex, TableInitialValue, Tag, TagIndex,
Tunables, TypeConvert, TypeIndex, WasmError, WasmHeapTopType, WasmHeapType, WasmResult,
WasmValType, WasmparserTypeConverter, collections,
WasmValType, WasmparserTypeConverter,
};
use cranelift_entity::SecondaryMap;
use cranelift_entity::packed_option::ReservedValue;
Expand Down Expand Up @@ -1107,7 +1107,7 @@ impl ModuleTranslation<'_> {
// memory initialization image is built here from the page data and then
// it's converted to a single initializer.
let data = mem::replace(&mut self.data, Vec::new());
let mut map = collections::PrimaryMap::with_capacity(info.len()).panic_on_oom();
let mut map = TryPrimaryMap::with_capacity(info.len()).panic_on_oom();
let mut module_data_size = 0u32;
for (memory, info) in info.iter() {
// Create the in-memory `image` which is the initialized contents of
Expand Down
18 changes: 9 additions & 9 deletions crates/environ/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum MemoryInitialization {
///
/// The offset, range base, and range end are all guaranteed to be page
/// aligned to the page size passed in to `try_static_init`.
map: collections::PrimaryMap<MemoryIndex, Option<StaticMemoryInitializer>>,
map: TryPrimaryMap<MemoryIndex, Option<StaticMemoryInitializer>>,
},
}

Expand Down Expand Up @@ -226,7 +226,7 @@ pub struct TableInitialization {
/// initialization. For example table initializers to a table that are all
/// in-bounds will get removed from `segment` and moved into
/// `initial_values` here.
pub initial_values: collections::PrimaryMap<DefinedTableIndex, TableInitialValue>,
pub initial_values: TryPrimaryMap<DefinedTableIndex, TableInitialValue>,

/// Element segments present in the initial wasm module which are executed
/// at instantiation time.
Expand Down Expand Up @@ -325,7 +325,7 @@ pub struct Module {
pub passive_data_map: BTreeMap<DataIndex, Range<u32>>,

/// Types declared in the wasm module.
pub types: collections::PrimaryMap<TypeIndex, EngineOrModuleTypeIndex>,
pub types: TryPrimaryMap<TypeIndex, EngineOrModuleTypeIndex>,

/// Number of imported or aliased functions in the module.
pub num_imported_funcs: usize,
Expand Down Expand Up @@ -353,22 +353,22 @@ pub struct Module {
pub num_escaped_funcs: usize,

/// Types of functions, imported and local.
pub functions: collections::PrimaryMap<FuncIndex, FunctionType>,
pub functions: TryPrimaryMap<FuncIndex, FunctionType>,

/// WebAssembly tables.
pub tables: collections::PrimaryMap<TableIndex, Table>,
pub tables: TryPrimaryMap<TableIndex, Table>,

/// WebAssembly linear memory plans.
pub memories: collections::PrimaryMap<MemoryIndex, Memory>,
pub memories: TryPrimaryMap<MemoryIndex, Memory>,

/// WebAssembly global variables.
pub globals: collections::PrimaryMap<GlobalIndex, Global>,
pub globals: TryPrimaryMap<GlobalIndex, Global>,

/// WebAssembly global initializers for locally-defined globals.
pub global_initializers: collections::PrimaryMap<DefinedGlobalIndex, ConstExpr>,
pub global_initializers: TryPrimaryMap<DefinedGlobalIndex, ConstExpr>,

/// WebAssembly exception and control tags.
pub tags: collections::PrimaryMap<TagIndex, Tag>,
pub tags: TryPrimaryMap<TagIndex, Tag>,
}

/// Initialization routines for creating an instance, encompassing imports,
Expand Down
30 changes: 15 additions & 15 deletions crates/environ/src/module_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::prelude::*;
use crate::{
EntityRef, FilePos, FuncIndex, FuncKey, FuncKeyIndex, FuncKeyKind, FuncKeyNamespace, Module,
PanicOnOom as _, collections::PrimaryMap,
PanicOnOom as _,
};
use core::ops::Range;
use core::{fmt, u32};
Expand Down Expand Up @@ -78,13 +78,13 @@ impl CompiledFunctionsTableBuilder {
pub fn new() -> Self {
Self {
inner: CompiledFunctionsTable {
namespaces: PrimaryMap::new(),
func_loc_starts: PrimaryMap::new(),
sparse_starts: PrimaryMap::new(),
src_loc_starts: PrimaryMap::new(),
sparse_indices: PrimaryMap::new(),
func_locs: PrimaryMap::new(),
src_locs: PrimaryMap::new(),
namespaces: TryPrimaryMap::new(),
func_loc_starts: TryPrimaryMap::new(),
sparse_starts: TryPrimaryMap::new(),
src_loc_starts: TryPrimaryMap::new(),
sparse_indices: TryPrimaryMap::new(),
func_locs: TryPrimaryMap::new(),
src_locs: TryPrimaryMap::new(),
},
}
}
Expand Down Expand Up @@ -289,15 +289,15 @@ pub struct CompiledFunctionsTable {
/// their associated `NamespaceIndex`. That `NamespaceIndex` can then be
/// used to find the range of other entity indices that are specific to that
/// namespace.
namespaces: PrimaryMap<NamespaceIndex, FuncKeyNamespace>,
namespaces: TryPrimaryMap<NamespaceIndex, FuncKeyNamespace>,

/// `self.func_loc_starts[i]..self.func_loc_starts[i+1]` describes the range
/// within `self.func_locs` whose entries are associated with the namespace
/// `self.index[i]`.
///
/// When `self.func_loc_starts[i+1]` is out of bounds, then the range is to
/// the end of `self.func_locs`.
func_loc_starts: PrimaryMap<NamespaceIndex, FuncLocIndex>,
func_loc_starts: TryPrimaryMap<NamespaceIndex, FuncLocIndex>,

/// `self.sparse_starts[i]..self.sparse_starts[i+1]` describes the range
/// within `self.sparse_indices` whose entries are associated with the
Expand All @@ -307,7 +307,7 @@ pub struct CompiledFunctionsTable {
/// the end of `self.sparse_indices`.
///
/// Entries are only valid for sparse, non-dense namespaces.
sparse_starts: PrimaryMap<NamespaceIndex, SparseIndex>,
sparse_starts: TryPrimaryMap<NamespaceIndex, SparseIndex>,

/// `self.src_loc_starts[i]..self.src_loc_starts[i+1]` describes the range
/// within `self.src_loc_indices` whose entries are associated with the
Expand All @@ -318,7 +318,7 @@ pub struct CompiledFunctionsTable {
///
/// Entries are only valid for namespaces whose functions have source
/// locations.
src_loc_starts: PrimaryMap<NamespaceIndex, SrcLocIndex>,
src_loc_starts: TryPrimaryMap<NamespaceIndex, SrcLocIndex>,

/// `self.sparse_indices[i]` contains the index part of
/// `FuncKey::from_parts(ns, index)` where `ns` is determined by
Expand All @@ -327,7 +327,7 @@ pub struct CompiledFunctionsTable {
/// the namespace's start index.)
///
/// This is sorted to allow for binary searches.
sparse_indices: PrimaryMap<SparseIndex, FuncKeyIndex>,
sparse_indices: TryPrimaryMap<SparseIndex, FuncKeyIndex>,

/// `self.func_locs[i]` contains the location within the text section of
/// `FuncKey::from_parts(self.namespaces[ns], i - start)`'s function, where
Expand All @@ -338,14 +338,14 @@ pub struct CompiledFunctionsTable {
///
/// The absence of a function location (for gaps in dense namespaces) is
/// represented with `FunctionLoc::none()`.
func_locs: PrimaryMap<FuncLocIndex, FunctionLoc>,
func_locs: TryPrimaryMap<FuncLocIndex, FunctionLoc>,

/// `self.src_locs[i]` contains the initial source location of
/// `FuncKey::from_parts(self.namespaces[ns], i - start)`'s function, where
/// `ns` and `start` are determined by `self.src_loc_starts`.
///
/// The absence of a source location is represented by `FilePos::none()`.
src_locs: PrimaryMap<SrcLocIndex, FilePos>,
src_locs: TryPrimaryMap<SrcLocIndex, FilePos>,
}

impl CompiledFunctionsTable {
Expand Down
7 changes: 3 additions & 4 deletions crates/environ/src/module_types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, PanicOnOom as _, TypeTrace, WasmSubType,
collections::{PrimaryMap, SecondaryMap},
packed_option::PackedOption,
collections::SecondaryMap, packed_option::PackedOption, prelude::*,
};
use core::ops::{Index, Range};
use serde_derive::{Deserialize, Serialize};
Expand All @@ -12,8 +11,8 @@ use serde_derive::{Deserialize, Serialize};
/// implementations for this type.
#[derive(Default, Serialize, Deserialize)]
pub struct ModuleTypes {
rec_groups: PrimaryMap<ModuleInternedRecGroupIndex, Range<ModuleInternedTypeIndex>>,
wasm_types: PrimaryMap<ModuleInternedTypeIndex, WasmSubType>,
rec_groups: TryPrimaryMap<ModuleInternedRecGroupIndex, Range<ModuleInternedTypeIndex>>,
wasm_types: TryPrimaryMap<ModuleInternedTypeIndex, WasmSubType>,
trampoline_types: SecondaryMap<ModuleInternedTypeIndex, PackedOption<ModuleInternedTypeIndex>>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

pub use crate::collections::{
TryClone, TryCollect, TryEntitySet, TryExtend, TryFromIterator, TryHashMap, TryHashSet,
TryIndexMap, TryNew, TryString, TryToOwned, TryVec, try_new, try_vec,
TryIndexMap, TryNew, TryPrimaryMap, TryString, TryToOwned, TryVec, try_new, try_vec,
};
pub use crate::error::{Context, Error, Result, bail, ensure, format_err};
pub use alloc::borrow::ToOwned;
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ pub struct StoreOpaque {
#[cfg(feature = "stack-switching")]
continuations: Vec<Box<VMContRef>>,

instances: wasmtime_environ::collections::PrimaryMap<InstanceId, StoreInstance>,
instances: TryPrimaryMap<InstanceId, StoreInstance>,

signal_handler: Option<SignalHandler>,
modules: ModuleRegistry,
Expand Down Expand Up @@ -744,7 +744,7 @@ impl<T> Store<T> {
vm_store_context: Default::default(),
#[cfg(feature = "stack-switching")]
continuations: Vec::new(),
instances: wasmtime_environ::collections::PrimaryMap::new(),
instances: TryPrimaryMap::new(),
signal_handler: None,
gc_store: None,
gc_roots: RootSet::default(),
Expand Down
Loading