|
2 | 2 | //! with `bincode` as part of a module's compilation process. |
3 | 3 |
|
4 | 4 | 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 | +}; |
6 | 9 | use core::ops::Range; |
7 | 10 | use core::{fmt, u32}; |
8 | 11 | use core::{iter, str}; |
9 | | -use cranelift_entity::{EntityRef, PrimaryMap}; |
10 | 12 | use serde_derive::{Deserialize, Serialize}; |
11 | 13 | #[cfg(feature = "rr")] |
12 | 14 | use sha2::{Digest, Sha256}; |
@@ -158,16 +160,18 @@ impl CompiledFunctionsTableBuilder { |
158 | 160 | }) |
159 | 161 | .unwrap_or_else(|| { |
160 | 162 | 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(); |
163 | 165 | let ns_idx3 = self |
164 | 166 | .inner |
165 | 167 | .sparse_starts |
166 | | - .push(self.inner.sparse_indices.next_key()); |
| 168 | + .push(self.inner.sparse_indices.next_key()) |
| 169 | + .panic_on_oom(); |
167 | 170 | let ns_idx4 = self |
168 | 171 | .inner |
169 | 172 | .src_loc_starts |
170 | | - .push(self.inner.src_locs.next_key()); |
| 173 | + .push(self.inner.src_locs.next_key()) |
| 174 | + .panic_on_oom(); |
171 | 175 | debug_assert_eq!(ns_idx, ns_idx2); |
172 | 176 | debug_assert_eq!(ns_idx, ns_idx3); |
173 | 177 | debug_assert_eq!(ns_idx, ns_idx4); |
@@ -197,26 +201,28 @@ impl CompiledFunctionsTableBuilder { |
197 | 201 | let gap = index.index() - self.inner.func_locs.len(); |
198 | 202 | self.inner |
199 | 203 | .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(); |
201 | 206 | debug_assert_eq!(index, self.inner.func_locs.next_key()); |
202 | 207 |
|
203 | 208 | if CompiledFunctionsTable::has_src_locs(key_ns.kind()) { |
204 | 209 | self.inner |
205 | 210 | .src_locs |
206 | | - .extend(iter::repeat(FilePos::none()).take(gap)); |
| 211 | + .try_extend(iter::repeat(FilePos::none()).take(gap)) |
| 212 | + .panic_on_oom(); |
207 | 213 | } |
208 | 214 | } else { |
209 | 215 | debug_assert!( |
210 | 216 | src_loc.is_none(), |
211 | 217 | "sparse keys do not have source locations" |
212 | 218 | ); |
213 | | - self.inner.sparse_indices.push(key_index); |
| 219 | + self.inner.sparse_indices.push(key_index).panic_on_oom(); |
214 | 220 | } |
215 | 221 |
|
216 | 222 | // 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(); |
218 | 224 | 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(); |
220 | 226 | } else { |
221 | 227 | debug_assert!(src_loc.is_none()); |
222 | 228 | } |
|
0 commit comments