Skip to content
Open
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
28 changes: 17 additions & 11 deletions crates/environ/src/module_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
//! with `bincode` as part of a module's compilation process.

use crate::prelude::*;
use crate::{FilePos, FuncIndex, FuncKey, FuncKeyIndex, FuncKeyKind, FuncKeyNamespace, Module};
use crate::{
EntityRef, FilePos, FuncIndex, FuncKey, FuncKeyIndex, FuncKeyKind, FuncKeyNamespace, Module,
PanicOnOom as _, collections::PrimaryMap,
};
use core::ops::Range;
use core::{fmt, u32};
use core::{iter, str};
use cranelift_entity::{EntityRef, PrimaryMap};
use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "rr")]
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -158,16 +160,18 @@ impl CompiledFunctionsTableBuilder {
})
.unwrap_or_else(|| {
let start = self.inner.func_locs.next_key();
let ns_idx = self.inner.namespaces.push(key_ns);
let ns_idx2 = self.inner.func_loc_starts.push(start);
let ns_idx = self.inner.namespaces.push(key_ns).panic_on_oom();
let ns_idx2 = self.inner.func_loc_starts.push(start).panic_on_oom();
let ns_idx3 = self
.inner
.sparse_starts
.push(self.inner.sparse_indices.next_key());
.push(self.inner.sparse_indices.next_key())
.panic_on_oom();
let ns_idx4 = self
.inner
.src_loc_starts
.push(self.inner.src_locs.next_key());
.push(self.inner.src_locs.next_key())
.panic_on_oom();
debug_assert_eq!(ns_idx, ns_idx2);
debug_assert_eq!(ns_idx, ns_idx3);
debug_assert_eq!(ns_idx, ns_idx4);
Expand Down Expand Up @@ -197,26 +201,28 @@ impl CompiledFunctionsTableBuilder {
let gap = index.index() - self.inner.func_locs.len();
self.inner
.func_locs
.extend(iter::repeat(null_func_loc).take(gap));
.try_extend(iter::repeat(null_func_loc).take(gap))
.panic_on_oom();
debug_assert_eq!(index, self.inner.func_locs.next_key());

if CompiledFunctionsTable::has_src_locs(key_ns.kind()) {
self.inner
.src_locs
.extend(iter::repeat(FilePos::none()).take(gap));
.try_extend(iter::repeat(FilePos::none()).take(gap))
.panic_on_oom();
}
} else {
debug_assert!(
src_loc.is_none(),
"sparse keys do not have source locations"
);
self.inner.sparse_indices.push(key_index);
self.inner.sparse_indices.push(key_index).panic_on_oom();
}

// And finally, we push this entry.
self.inner.func_locs.push(func_loc);
self.inner.func_locs.push(func_loc).panic_on_oom();
if CompiledFunctionsTable::has_src_locs(key_ns.kind()) {
self.inner.src_locs.push(src_loc);
self.inner.src_locs.push(src_loc).panic_on_oom();
} else {
debug_assert!(src_loc.is_none());
}
Expand Down
15 changes: 9 additions & 6 deletions crates/environ/src/module_types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, PrimaryMap, TypeTrace, WasmSubType,
ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, PanicOnOom as _, TypeTrace, WasmSubType,
collections::{PrimaryMap, SecondaryMap},
packed_option::PackedOption,
};
use core::ops::{Index, Range};
use cranelift_entity::{SecondaryMap, packed_option::PackedOption};
use serde_derive::{Deserialize, Serialize};

/// All types used in a core wasm module.
Expand Down Expand Up @@ -77,7 +78,7 @@ impl ModuleTypes {

/// Adds a new type to this interned list of types.
pub fn push(&mut self, ty: WasmSubType) -> ModuleInternedTypeIndex {
self.wasm_types.push(ty)
self.wasm_types.push(ty).panic_on_oom()
}

/// Iterate over the trampoline function types that this module requires.
Expand Down Expand Up @@ -131,20 +132,22 @@ impl ModuleTypes {
.is_trampoline_type()
);

self.trampoline_types[for_ty] = Some(trampoline_ty).into();
self.trampoline_types
.insert(for_ty, Some(trampoline_ty).into())
.panic_on_oom();
}

/// Adds a new rec group to this interned list of types.
pub fn push_rec_group(
&mut self,
range: Range<ModuleInternedTypeIndex>,
) -> ModuleInternedRecGroupIndex {
self.rec_groups.push(range)
self.rec_groups.push(range).panic_on_oom()
}

/// Reserves space for `amt` more types.
pub fn reserve(&mut self, amt: usize) {
self.wasm_types.reserve(amt)
self.wasm_types.reserve(amt).panic_on_oom()
}

/// Returns the next return value of `push_rec_group`.
Expand Down