Skip to content

Commit e8a25f5

Browse files
authored
Use OOM-handling {Primary,Secondary}Map in wasmtime_environ::ModuleTypes (bytecodealliance#12622)
1 parent ccfd33b commit e8a25f5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

crates/environ/src/module_types.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::{
2-
ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, PrimaryMap, TypeTrace, WasmSubType,
2+
ModuleInternedRecGroupIndex, ModuleInternedTypeIndex, PanicOnOom as _, TypeTrace, WasmSubType,
3+
collections::{PrimaryMap, SecondaryMap},
4+
packed_option::PackedOption,
35
};
46
use core::ops::{Index, Range};
5-
use cranelift_entity::{SecondaryMap, packed_option::PackedOption};
67
use serde_derive::{Deserialize, Serialize};
78

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

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

8384
/// Iterate over the trampoline function types that this module requires.
@@ -131,20 +132,22 @@ impl ModuleTypes {
131132
.is_trampoline_type()
132133
);
133134

134-
self.trampoline_types[for_ty] = Some(trampoline_ty).into();
135+
self.trampoline_types
136+
.insert(for_ty, Some(trampoline_ty).into())
137+
.panic_on_oom();
135138
}
136139

137140
/// Adds a new rec group to this interned list of types.
138141
pub fn push_rec_group(
139142
&mut self,
140143
range: Range<ModuleInternedTypeIndex>,
141144
) -> ModuleInternedRecGroupIndex {
142-
self.rec_groups.push(range)
145+
self.rec_groups.push(range).panic_on_oom()
143146
}
144147

145148
/// Reserves space for `amt` more types.
146149
pub fn reserve(&mut self, amt: usize) {
147-
self.wasm_types.reserve(amt)
150+
self.wasm_types.reserve(amt).panic_on_oom()
148151
}
149152

150153
/// Returns the next return value of `push_rec_group`.

0 commit comments

Comments
 (0)