0%

04 Current Compiled Projection: Parameter Plumbing

This section is the current compiled counter projection of Section 05’s frozen logical iterator contract. It wires the LLVM adapter to pass the elem_inc_fn and elem_dec_fn actions selected by the compiled physical plan to the updated C runtime functions. The existing get_or_generate_elem_inc_fn() and get_or_generate_elem_dec_fn() infrastructure in element_fn_gen.rs is historical implementation evidence for this projection only.

Seam invariant: this section may bind stable logical event identities to compiled helper actions, but it may not infer ownership from LLVM types, helper presence, runtime headers, or iterator representation. elem_inc_fn / elem_dec_fn are not AIMS vocabulary and do not prescribe VM opcodes or storage. The VM consumes the same post-AIMS artifact through VmLayoutPlan; LLVM, native, compiled-WebAssembly, and JIT consume the validated compiled plan.

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.

These signatures are a current compiled ABI, not the shared iterator ownership protocol.

  • Update ori_iter_from_list declaration: add elem_inc_fn: ptr parameter

  • Update ori_iter_filter declaration: add elem_dec_fn: ptr parameter

  • Update ori_iter_skip declaration: add elem_dec_fn: ptr parameter

  • Update all 11 consumer declarations: add elem_dec_fn: ptr parameter (count, any, all, find, for_each, fold, last, rfind, rfold, join). Remove elem_inc_fn from collect. For collect_set: remove elem_inc_fn, add elem_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 status in section frontmatter to complete
    • Run /improve-tooling retrospectively on THIS subsection
    • Run /sync-claude on THIS subsection — check whether code changes invalidated any CLAUDE.md, .claude/rules/*.md, or canon.md claims. If no API/command/phase changes, document briefly. Fix any drift NOW.
    • Repo hygiene check — run diagnostics/repo-hygiene.sh --check and clean any detected temp files.

04.2 Source Emission: emit_iter_from_list

File: compiler/ori_llvm/src/codegen/arc_emitter/builtins/iterator.rs

  • In emit_iter_from_list: generate elem_inc_fn via get_or_generate_elem_inc_fn(elem_ty) and pass as additional argument to ori_iter_from_list

  • For map/option source emitters: pass elem_inc_fn if their signatures were extended in Section 01.4

  • Verify range emitter unchanged (int elements, no inc needed)

  • Preserve the stable logical yield event identity while binding its current compiled retain action; do not create a second ownership classification in the emitter

  • Subsection close-out (04.2) — MANDATORY before starting 04.3:

    • All tasks above are [x] and behavior verified
    • Update this subsection’s status in section frontmatter to complete
    • Run /improve-tooling retrospectively on THIS subsection
    • Run /sync-claude on THIS subsection — check whether code changes invalidated any CLAUDE.md, .claude/rules/*.md, or canon.md claims. If no API/command/phase changes, document briefly. Fix any drift NOW.
    • Repo hygiene check — run diagnostics/repo-hygiene.sh --check and clean any detected temp files.

04.3 Adapter Emission: filter, skip

File: compiler/ori_llvm/src/codegen/arc_emitter/builtins/iterator.rs

  • In emit_iter_filter: generate elem_dec_fn via get_or_generate_elem_dec_fn(elem_ty) and pass as additional argument to ori_iter_filter

  • In emit_iter_skip: same — pass elem_dec_fn

  • For cycle: if elem_inc_fn was 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

  • Prove discarded and forwarded elements map to the cleanup or transfer event already frozen by AIMS; helper plumbing must not create or suppress a logical event

  • Subsection close-out (04.3) — MANDATORY before starting 04.4:

    • All tasks above are [x] and behavior verified
    • Update this subsection’s status in section frontmatter to complete
    • Run /improve-tooling retrospectively on THIS subsection
    • Run /sync-claude on THIS subsection — check whether code changes invalidated any CLAUDE.md, .claude/rules/*.md, or canon.md claims. If no API/command/phase changes, document briefly. Fix any drift NOW.
    • Repo hygiene check — run diagnostics/repo-hygiene.sh --check and clean any detected temp files.

04.4 Consumer Emission: All 11 Functions

File: compiler/ori_llvm/src/codegen/arc_emitter/builtins/iterator_consumers.rs

For each consumer emission function, bind the compiled plan’s selected cleanup action by generating elem_dec_fn and adding it to the call. The action discharges an existing logical cleanup identity; it does not define that obligation.

  • emit_iter_collect: Remove elem_inc_fn from the call. Elements are already owned. Keep the post-call elem_dec_fn storage in the buffer header (unchanged).

  • emit_iter_collect_set: Remove elem_inc_fn. Add elem_dec_fn to the call (for duplicate cleanup).

  • emit_iter_count: Add elem_dec_fn to call

  • emit_iter_any: Add elem_dec_fn to call

  • emit_iter_all: Add elem_dec_fn to call

  • emit_iter_find: Add elem_dec_fn to call

  • emit_iter_for_each: Add elem_dec_fn to call

  • emit_iter_fold: Add elem_dec_fn to call

  • emit_iter_last: Add elem_dec_fn to call

  • emit_iter_rfind: Add elem_dec_fn to call

  • emit_iter_rfold: Add elem_dec_fn to call

  • emit_iter_join: Add elem_dec_fn to 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))

  • Cross-check the compiled action trace against the frozen owner/transfer/cleanup identities; LLVM IR shape alone is not proof of AIMS correctness

  • Subsection close-out (04.4) — MANDATORY before starting Section 06:

    • All tasks above are [x] and behavior verified
    • Update this subsection’s status in section frontmatter to complete
    • Run /improve-tooling retrospectively on THIS subsection
    • Run /sync-claude on THIS subsection — check whether code changes invalidated any CLAUDE.md, .claude/rules/*.md, or canon.md claims. If no API/command/phase changes, document briefly. Fix any drift NOW.
    • Repo hygiene check — run diagnostics/repo-hygiene.sh --check and clean any detected temp files.

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
  • Compiled helper actions satisfy the frozen logical event trace without re-analysis
  • No compiled helper, counter, header, ABI, or LLVM instruction becomes an AIMS fact or a VM requirement
  • timeout 150 ./test-all.sh green
  • timeout 150 ./clippy-all.sh green
  • /commit-push
  • /tpr-review passed
  • /impl-hygiene-review passed
  • /improve-tooling section-close sweep