0%

05 AIMS: Logical Element Ownership Contract

This is the semantic foundation for the plan. The current pipeline treats iterator-yielded elements as borrowed from the source collection and suppresses its transitional RcDec carrier on those variables because collection teardown is assumed to own cleanup. The corrected protocol instead freezes exactly one logical owner-credit transfer from __iter_next to the consumer and exactly one downstream transfer or cleanup discharge for every control-flow path.

RcDec, walk_dec.rs, and realize are current carrier/function spellings, not the contract vocabulary. AIMS records stable owner, transfer, cleanup, and unwind identities in the shared ExecutableProgram. VmLayoutPlan and CompiledLayoutPlan(TargetSpec) then choose separate physical mechanisms that prove they satisfy those identities. No helper pointer, refcount, LLVM instruction, VM opcode, header, or ABI may feed back into this section.

WARNING: Changes to AIMS analysis interact with every physical executor. Verify the exact logical trace and AIMS lattice properties first, then require plan-satisfaction and behavioral parity from the VM and compiled sibling projections. LLVM-only success is insufficient.

05.1 Remove collect_iter_element_defs Suppression

Current transitional file: compiler/ori_arc/src/aims/emit_rc/borrowed_defs.rs (lines 123-197)

collect_iter_element_defs marks variables projected from __iter_next results as “borrowed definitions,” causing AIMS to omit their logical cleanup obligations. That semantic suppression is incorrect once the yield boundary transfers an owner credit.

  • Option A (preferred): Remove collect_iter_element_defs entirely. Standard AIMS analysis then freezes the loop variable’s logical cleanup event at its death point. The current ArcFunction may spell that event RcDec, but that is only a transitional encoding.

  • Option B (if A causes issues): Keep the function but change its semantics from “borrowed; omit cleanup” to “owned by protocol; preserve the normal logical cleanup/transfer obligation.” This is a softer carrier migration, not a second ownership path.

  • IMPORTANT: The iter_elems set (args[1] phantom type markers) must remain excluded from logical owner and cleanup events — they are zero-valued type markers, not runtime values. Every physical projection must preserve that absence independently.

  • TDD: for x in [str_list].iter() do print(x) — assert that the post-AIMS artifact contains one yield-owner event and one cleanup event for x, joined by stable identity. ORI_DUMP_AFTER_ARC=1 may additionally show the current transitional RcDec spelling, but that dump is not the semantic oracle.

  • Run AIMS property tests: timeout 150 cargo test -p ori_arc -- lattice::prop_tests — verify no regressions in lattice properties.

  • Subsection close-out (05.1) — MANDATORY before starting 05.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.

05.2 Update Transitional Release Suppression

Current transitional file: compiler/ori_arc/src/aims/realize/walk_dec.rs

Lines 140-142 in emit_last_use_decs skip the current RcDec carrier for variables in iter_element_defs; lines 94-96 in emit_defined_dead do the same. The required correction is semantic: do not suppress the logical release/cleanup event. A counter-selecting compiled plan may later lower that event to RcDec; a VM plan need not.

  • Remove or update the iter_element_defs checks in both functions

  • Ensure standard AIMS realization freezes the release/cleanup identity for iterator element variables

  • Keep the borrowed-parameter and inline-enum suppression (those are unrelated)

  • Verify exact-once placement across fallthrough, break, early return, nested loops, and unwind; no path may omit or duplicate the logical cleanup

  • TDD: Assert the post-AIMS event trace directly. Use ORI_DUMP_AFTER_ARC=1 only as an additional current-carrier check that loop variables receive the transitional release spelling.

  • Subsection close-out (05.2) — MANDATORY before starting 05.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.

05.3 Audit Compiled Forwarding Seam

File: compiler/ori_llvm/src/codegen/arc_emitter/instr_dispatch.rs (line ~48)

The current LLVM adapter registers the iterator scratch pointer for borrowed forwarding. This subsection is a seam audit: determine whether that state describes only scratch-buffer representation or incorrectly re-derives element ownership. Any physical plumbing change belongs to Section 04’s compiled projection; AIMS policy remains fixed here.

  • Read the borrowed forwarding logic and determine if it still applies

  • If the forwarding assumed borrowed elements, remove that semantic inference and bind the compiled action to the frozen owner/transfer/cleanup identity in Section 04

  • If the forwarding is about the scratch BUFFER (not the element), it may still be correct — verify

  • Assert that no LLVM type, scratch-pointer registration, helper symbol, or header state can change the logical ownership verdict

  • Current compiled projection TDD: Compile and run a for-loop with str elements; verify the compiled action trace satisfies the frozen logical events and ORI_CHECK_LEAKS=1 reports zero leaks

  • Subsection close-out (05.3) — MANDATORY before starting 05.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.

05.4 Verify AIMS Contract Consistency

  • Add a post-AIMS snapshot/oracle assertion for stable yield-owner, transfer, cleanup, and unwind event identities; this is the primary semantic pin

  • Run AIMS lattice property tests: timeout 150 cargo test -p ori_arc -- lattice::prop_tests

  • Run ORI_VERIFY_ARC=1 timeout 150 cargo test -p ori_llvm as one current compiled-projection consistency gate, not as proof that AIMS is LLVM-specific

  • Run full suite: timeout 150 ./test-all.sh

  • Verify no new VerifyError variants fire for iterator-related code

  • Require VmLayoutPlan and CompiledLayoutPlan(TargetSpec) plan-satisfaction checks to map every frozen event exactly once without re-analysis

  • Compare evaluator-oracle behavior with VM and compiled behavior over the full combined iterator matrix, including nested adapters and early exits

  • Spot-check ORI_DUMP_AFTER_ARC=1 only to confirm the current carrier maps cleanup events to the expected transitional release spelling

  • Subsection close-out (05.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.

05.R Third Party Review Findings

  • None.

05.N Completion Checklist

  • AIMS freezes one stable logical owner-credit transfer for every iterator yield
  • Every yielded owner credit has exactly one downstream transfer or cleanup discharge across all control-flow paths
  • Iterator element suppression is removed/reworked; phantom markers remain event-free
  • AIMS property tests all pass
  • ARC verification (ORI_VERIFY_ARC=1) passes
  • VM and compiled plan-satisfaction checks preserve the same frozen identities without backend-local ownership analysis
  • Current compiled RcDec placement and leak checks pass as projection evidence, not as the AIMS definition
  • 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