2.8 KiB
PR-6.4 — GC Traversal for Closures (Model B)
Briefing
Closures introduce heap-to-heap references through their captured environments.
Under Model B, the closure object itself is passed at call time, but its environment remains stored in heap.
GC must traverse:
closure -> env -> inner HeapRefs
Target
Extend GC mark phase to handle ObjectKind::Closure:
When marking a closure:
- Iterate over env values.
- If a value contains HeapRef → mark referenced object.
No compaction. No relocation.
Work Items
- Extend mark traversal switch.
- Ensure safe iteration over env payload.
- Add regression tests.
Acceptance Checklist
- Closure env scanned.
- Nested closures retained.
- No regression in existing GC tests.
Tests
- Closure capturing another closure.
- Closure capturing heap object.
- Unreferenced closure collected.
Junie Instructions
You MAY:
- Modify mark traversal.
- Add tests.
You MUST NOT:
- Modify sweep policy.
- Introduce compaction.
If unsure whether Value variants can embed HeapRef, STOP and ask.
Definition of Done
GC correctly traverses closure environments under Model B semantics.
PR-6.5 — Verifier Support for Closures (Model B)
Briefing
The verifier must understand closure values and enforce safe invocation rules.
Under Model B:
CALL_CLOSUREinjects hiddenarg0.- User-visible arg_count excludes hidden arg.
- Captures are accessed via explicit instructions (future PR).
Target
Extend verifier to:
- Introduce stack type:
ClosureValue. - Validate MAKE_CLOSURE effects.
- Validate CALL_CLOSURE semantics:
- Ensure top of stack is ClosureValue.
- Ensure sufficient args present.
- Validate
arg_countmatches function signature expectations. - Account for hidden arg0 when checking callee arg arity.
- Validate ret_slots against function metadata.
Work Items
- Extend type lattice with ClosureValue.
- Define stack transitions for MAKE_CLOSURE.
- Define stack transitions for CALL_CLOSURE.
- Enforce strict failure on mismatch.
Acceptance Checklist
- ClosureValue type exists.
- Invalid CALL_CLOSURE rejected.
- Hidden arg0 accounted for.
- ret_slots validated.
- All verifier tests pass.
Tests
- Valid closure call passes verification.
- CALL_CLOSURE with wrong arg_count fails.
- CALL_CLOSURE on non-closure fails verification.
- Nested closure calls verify correctly.
Junie Instructions
You MAY:
- Extend verifier model.
- Add tests.
You MUST NOT:
- Weaken verification rules.
- Replace verifier checks with runtime-only traps.
If function metadata (arg_slots/ret_slots) is insufficient, STOP and request clarification.
Definition of Done
Verifier fully supports closure creation and invocation under Model B semantics.