Skip to content

Commit d42d0b6

Browse files
authored
Use our OOM-handling PrimaryMap in the wasmtime_environ::module_artifacts module (bytecodealliance#12623)
1 parent 8a8a923 commit d42d0b6

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

crates/environ/src/module_artifacts.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
//! with `bincode` as part of a module's compilation process.
33
44
use crate::prelude::*;
5-
use crate::{FilePos, FuncIndex, FuncKey, FuncKeyIndex, FuncKeyKind, FuncKeyNamespace, Module};
5+
use crate::{
6+
EntityRef, FilePos, FuncIndex, FuncKey, FuncKeyIndex, FuncKeyKind, FuncKeyNamespace, Module,
7+
PanicOnOom as _, collections::PrimaryMap,
8+
};
69
use core::ops::Range;
710
use core::{fmt, u32};
811
use core::{iter, str};
9-
use cranelift_entity::{EntityRef, PrimaryMap};
1012
use serde_derive::{Deserialize, Serialize};
1113
#[cfg(feature = "rr")]
1214
use sha2::{Digest, Sha256};
@@ -158,16 +160,18 @@ impl CompiledFunctionsTableBuilder {
158160
})
159161
.unwrap_or_else(|| {
160162
let start = self.inner.func_locs.next_key();
161-
let ns_idx = self.inner.namespaces.push(key_ns);
162-
let ns_idx2 = self.inner.func_loc_starts.push(start);
163+
let ns_idx = self.inner.namespaces.push(key_ns).panic_on_oom();
164+
let ns_idx2 = self.inner.func_loc_starts.push(start).panic_on_oom();
163165
let ns_idx3 = self
164166
.inner
165167
.sparse_starts
166-
.push(self.inner.sparse_indices.next_key());
168+
.push(self.inner.sparse_indices.next_key())
169+
.panic_on_oom();
167170
let ns_idx4 = self
168171
.inner
169172
.src_loc_starts
170-
.push(self.inner.src_locs.next_key());
173+
.push(self.inner.src_locs.next_key())
174+
.panic_on_oom();
171175
debug_assert_eq!(ns_idx, ns_idx2);
172176
debug_assert_eq!(ns_idx, ns_idx3);
173177
debug_assert_eq!(ns_idx, ns_idx4);
@@ -197,26 +201,28 @@ impl CompiledFunctionsTableBuilder {
197201
let gap = index.index() - self.inner.func_locs.len();
198202
self.inner
199203
.func_locs
200-
.extend(iter::repeat(null_func_loc).take(gap));
204+
.try_extend(iter::repeat(null_func_loc).take(gap))
205+
.panic_on_oom();
201206
debug_assert_eq!(index, self.inner.func_locs.next_key());
202207

203208
if CompiledFunctionsTable::has_src_locs(key_ns.kind()) {
204209
self.inner
205210
.src_locs
206-
.extend(iter::repeat(FilePos::none()).take(gap));
211+
.try_extend(iter::repeat(FilePos::none()).take(gap))
212+
.panic_on_oom();
207213
}
208214
} else {
209215
debug_assert!(
210216
src_loc.is_none(),
211217
"sparse keys do not have source locations"
212218
);
213-
self.inner.sparse_indices.push(key_index);
219+
self.inner.sparse_indices.push(key_index).panic_on_oom();
214220
}
215221

216222
// And finally, we push this entry.
217-
self.inner.func_locs.push(func_loc);
223+
self.inner.func_locs.push(func_loc).panic_on_oom();
218224
if CompiledFunctionsTable::has_src_locs(key_ns.kind()) {
219-
self.inner.src_locs.push(src_loc);
225+
self.inner.src_locs.push(src_loc).panic_on_oom();
220226
} else {
221227
debug_assert!(src_loc.is_none());
222228
}

0 commit comments

Comments
 (0)