04 Codegen: Parameter Plumbing
This section wires the LLVM codegen to pass elem_inc_fn and elem_dec_fn to the updated runtime functions. The infrastructure already exists — get_or_generate_elem_inc_fn() and get_or_generate_elem_dec_fn() in element_fn_gen.rs are used by collect and collect_set. This section extends their use to ALL consumer and adapter calls.
04.1 Runtime Function Declarations
File: compiler/ori_llvm/src/codegen/runtime_decl/runtime_functions.rs
Every C-ABI runtime function is declared in this file. Update signatures to match the new parameters.
-
Update
ori_iter_from_listdeclaration: addelem_inc_fn: ptrparameter -
Update
ori_iter_filterdeclaration: addelem_dec_fn: ptrparameter -
Update
ori_iter_skipdeclaration: addelem_dec_fn: ptrparameter -
Update all 11 consumer declarations: add
elem_dec_fn: ptrparameter (count, any, all, find, for_each, fold, last, rfind, rfold, join). Removeelem_inc_fnfrom collect. For collect_set: removeelem_inc_fn, addelem_dec_fn. -
Verify parameter counts match between declaration and call site (mismatch = LLVM verification error)
-
Subsection close-out (04.1) — MANDATORY before starting 04.2:
- All tasks above are
[x]and behavior verified - Update this subsection’s
statusin section frontmatter tocomplete - Run
/improve-toolingretrospectively on THIS subsection - Run
/sync-claudeon THIS subsection — check whether code changes invalidated any CLAUDE.md,.claude/rules/*.md, orcanon.mdclaims. If no API/command/phase changes, document briefly. Fix any drift NOW. - Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
- All tasks above are
04.2 Source Emission: emit_iter_from_list
File: compiler/ori_llvm/src/codegen/arc_emitter/builtins/iterator.rs
-
In
emit_iter_from_list: generateelem_inc_fnviaget_or_generate_elem_inc_fn(elem_ty)and pass as additional argument toori_iter_from_list -
For map/option source emitters: pass
elem_inc_fnif their signatures were extended in Section 01.4 -
Verify range emitter unchanged (int elements, no inc needed)
-
Subsection close-out (04.2) — MANDATORY before starting 04.3:
- All tasks above are
[x]and behavior verified - Update this subsection’s
statusin section frontmatter tocomplete - Run
/improve-toolingretrospectively on THIS subsection - Run
/sync-claudeon THIS subsection — check whether code changes invalidated any CLAUDE.md,.claude/rules/*.md, orcanon.mdclaims. If no API/command/phase changes, document briefly. Fix any drift NOW. - Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
- All tasks above are
04.3 Adapter Emission: filter, skip
File: compiler/ori_llvm/src/codegen/arc_emitter/builtins/iterator.rs
-
In
emit_iter_filter: generateelem_dec_fnviaget_or_generate_elem_dec_fn(elem_ty)and pass as additional argument toori_iter_filter -
In
emit_iter_skip: same — passelem_dec_fn -
For cycle: if
elem_inc_fnwas added to its constructor (Section 02.3), pass it here -
Verify other adapter emitters (take, chain, enumerate, zip, flatten, flat_map) don’t need changes — their constructors didn’t gain new parameters
-
Subsection close-out (04.3) — MANDATORY before starting 04.4:
- All tasks above are
[x]and behavior verified - Update this subsection’s
statusin section frontmatter tocomplete - Run
/improve-toolingretrospectively on THIS subsection - Run
/sync-claudeon THIS subsection — check whether code changes invalidated any CLAUDE.md,.claude/rules/*.md, orcanon.mdclaims. If no API/command/phase changes, document briefly. Fix any drift NOW. - Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
- All tasks above are
04.4 Consumer Emission: All 11 Functions
File: compiler/ori_llvm/src/codegen/arc_emitter/builtins/iterator_consumers.rs
For each consumer emission function, generate elem_dec_fn and add it to the call.
-
emit_iter_collect: Removeelem_inc_fnfrom the call. Elements are already owned. Keep the post-callelem_dec_fnstorage in the buffer header (unchanged). -
emit_iter_collect_set: Removeelem_inc_fn. Addelem_dec_fnto the call (for duplicate cleanup). -
emit_iter_count: Addelem_dec_fnto call -
emit_iter_any: Addelem_dec_fnto call -
emit_iter_all: Addelem_dec_fnto call -
emit_iter_find: Addelem_dec_fnto call -
emit_iter_for_each: Addelem_dec_fnto call -
emit_iter_fold: Addelem_dec_fnto call -
emit_iter_last: Addelem_dec_fnto call -
emit_iter_rfind: Addelem_dec_fnto call -
emit_iter_rfold: Addelem_dec_fnto call -
emit_iter_join: Addelem_dec_fnto call -
TDD: Compile and run existing AOT iterator tests — all should pass with zero leaks
-
Verify LLVM IR verification passes on all emitted consumer calls (
fn_val.verify(true)) -
Subsection close-out (04.4) — MANDATORY before starting Section 05:
- All tasks above are
[x]and behavior verified - Update this subsection’s
statusin section frontmatter tocomplete - Run
/improve-toolingretrospectively on THIS subsection - Run
/sync-claudeon THIS subsection — check whether code changes invalidated any CLAUDE.md,.claude/rules/*.md, orcanon.mdclaims. If no API/command/phase changes, document briefly. Fix any drift NOW. - Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
- All tasks above are
04.R Third Party Review Findings
- None.
04.N Completion Checklist
- All runtime function declarations match updated C signatures
- All source/adapter/consumer emitters pass correct elem_inc/dec_fn
- LLVM IR verification passes on all emitted functions
-
timeout 150 ./test-all.shgreen -
timeout 150 ./clippy-all.shgreen -
/commit-push -
/tpr-reviewpassed -
/impl-hygiene-reviewpassed -
/improve-toolingsection-close sweep