Skip to content

Commit 419f0f0

Browse files
Feat: Replace silent unwrap in HeapPool get with descriptive garbage collector invariant message.
1 parent c7c8959 commit 419f0f0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

compiler/src/modules/vm/types.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,16 @@ impl HeapPool {
249249
self.usage() >= self.gc_threshold || self.alloc_count >= 1024
250250
}
251251

252-
#[inline(always)] pub fn get(&self, v: Val) -> &HeapObj { self.objects[v.as_heap() as usize].as_ref().unwrap() }
253-
#[inline(always)] pub fn get_mut(&mut self, v: Val) -> &mut HeapObj { self.objects[v.as_heap() as usize].as_mut().unwrap() }
252+
#[inline(always)] pub fn get(&self, v: Val) -> &HeapObj {
253+
self.objects[v.as_heap() as usize]
254+
.as_ref()
255+
.expect("garbage collector invariant violated: live Val references a freed heap slot")
256+
}
257+
#[inline(always)] pub fn get_mut(&mut self, v: Val) -> &mut HeapObj {
258+
self.objects[v.as_heap() as usize]
259+
.as_mut()
260+
.expect("garbage collector invariant violated: live Val references a freed heap slot (mut)")
261+
}
254262
pub fn usage(&self) -> usize { self.objects.len() - self.free_list.len() }
255263

256264
#[inline(always)]

0 commit comments

Comments
 (0)