This commit is contained in:
2026-03-24 13:40:42 +00:00
parent bd507aeaa5
commit 8d1e0a57d6
11 changed files with 232 additions and 73 deletions
@@ -0,0 +1,21 @@
use prometeu_bytecode::Value;
use prometeu_vm::Heap;
#[test]
fn gc_collects_unreachable_closure_but_keeps_marked() {
let mut heap = Heap::new();
// Allocate two closures with small environments
let rooted = heap.alloc_closure(1, &[Value::Int32(10)]);
let unreachable = heap.alloc_closure(2, &[Value::Int32(20)]);
// Mark only the rooted one, then sweep.
heap.mark_from_roots([rooted]);
heap.sweep();
assert!(heap.is_valid(rooted), "rooted object must remain alive after sweep");
assert!(
!heap.is_valid(unreachable),
"unreachable object must be reclaimed by GC"
);
}