pr3.8
This commit is contained in:
@@ -290,4 +290,34 @@ mod tests {
|
||||
// We can't access internal vector here, but stability is implied by handle not changing.
|
||||
assert_eq!(a.0, a.0); // placeholder sanity check
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sweep_reclaims_unrooted_cycle() {
|
||||
let mut heap = Heap::new();
|
||||
|
||||
// Build a 2-node cycle A <-> B using internal mutation (module-private access).
|
||||
let a = heap.allocate_array(vec![]);
|
||||
let b = heap.allocate_array(vec![]);
|
||||
|
||||
// Make A point to B and B point to A.
|
||||
if let Some(slot) = heap.objects.get_mut(a.0 as usize) {
|
||||
if let Some(obj) = slot.as_mut() {
|
||||
obj.array_elems = Some(vec![Value::HeapRef(b)]);
|
||||
obj.header.payload_len = 1;
|
||||
}
|
||||
}
|
||||
if let Some(slot) = heap.objects.get_mut(b.0 as usize) {
|
||||
if let Some(obj) = slot.as_mut() {
|
||||
obj.array_elems = Some(vec![Value::HeapRef(a)]);
|
||||
obj.header.payload_len = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// No roots: perform sweep directly; both should be reclaimed.
|
||||
heap.sweep();
|
||||
|
||||
assert!(!heap.is_valid(a));
|
||||
assert!(!heap.is_valid(b));
|
||||
assert_eq!(heap.len(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user