Files
prometeu-runtime/crates/dev/prometeu-layer-tests/tests/gc_collect_unreachable.rs
T
bquarkz 3899b7f12c
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
feat(vm): add resource diagnostics and macOS stability qualification
2026-10-14 08:26:07 +01:00

26 lines
1.1 KiB
Rust

#[allow(dead_code)]
#[path = "../../../console/prometeu-vm/tests/support/callables.rs"]
mod callables;
use prometeu_bytecode::{registry::TypeId, Value};
use prometeu_vm::LogicalFrameEndingReason;
#[test]
fn gc_collects_unreachable_closures_and_retains_active_environment_through_sync() {
let body =
format!("{}FRAME_SYNC\nGET_CAPTURE 0\nRET", "MAKE_CLOSURE fn=2,type=4\nPOP\n".repeat(1030));
let mut vm = callables::vm(&[
(
"PUSH_I32 73\nMAKE_CLOSURE fn=1,type=4\nCALL_CLOSURE 4\nRET",
callables::sig(&[], &[0]),
vec![],
),
(&body, callables::sig(&[], &[0]), vec![TypeId(0)]),
("PUSH_I32 1\nRET", callables::sig(&[], &[0]), vec![]),
]);
assert_eq!(callables::run(&mut vm, 100_000).reason, LogicalFrameEndingReason::FrameSync);
assert_eq!(vm.heap().allocation_count(), 1031);
assert_eq!(vm.heap().len(), 1, "only the active closure remains reachable");
assert_eq!(callables::run(&mut vm, 100).reason, LogicalFrameEndingReason::EndOfRom);
assert_eq!(&*vm.operand_stack_top(1), &[Value::Int32(73)]);
}