RC Header elem_dec_fn — Proper Element Cleanup for Fat Pointer Collections
5 sections
Overview
Eliminate all element-level memory leaks and double-frees when iterating over collections whose elements require Drop semantics ([str], [[T]], [{name: str}], closures, etc.) by storing the elem_dec_fn pointer in the RC allocation header.
Completed
5 sections
RC Header Extension
Extend RC allocation header to 32 bytes (V5), adding elem_dec_fn and elem_count slots for reliable element cleanup
Codegen & Runtime Integration
Wire up LLVM codegen and runtime so elem_dec_fn and elem_count are stored in the RC header at collection construction time, and all buffer-freeing paths read from the header
Remove Workarounds & Simplify
Remove the phantom __for_coll_N binding, exit-block dummy references, and for-yield coll_param threading, simplifying the ARC lowering
Combinatorial Test Matrix
Write comprehensive cross-product tests: 9 type categories (T1-T9) x 14 language features (F1-F14) x 4 execution modes (M1-M4)
Verification & Cleanup
Full verification pass, confirm test stability, re-run code journeys, update documentation, ensure zero regressions