Section 06: Verification
Status: Not Started Goal: Prove that all ARC optimizations from Sections 01-05 are correct, produce identical observable behavior to the unoptimized baseline, maintain zero leaks, and provide measurable performance improvement.
Governing verification tier — cite aims-rules.md §9 VF-7: Sections 03-05 ship aims-rules.md’s already-proven-but-target-only RL-9/RL-22-RL-26 rules (per each section’s own governing-spec note). VF-7 requires ALL THREE tiers for an active rewrite to count as sound: (a) compile-time structural verification, (b) test-time behavioral verification, (c) a documented proof sketch. This section’s 06.1-06.5 work satisfies tiers (a)+(b) (test matrix, ORI_DISABLE_ARC_OPTS A/B, code journey, leak/valgrind/codegen-audit); tier (c) is satisfied by CITING the already-compiled Lean proof for the shipped rule (compiler_repo/aims-proof/proofs/08-realization/RL-{9,22,23,24,25,26}.proof + Lean mirror in AimsProof.Realization/Coexistence) — do not re-derive a proof sketch from scratch, cite the existing one. 06.6 closes the loop with the arc.md §CP-2 four-surface sync.
Depends on: All prior sections.
06.1 Test Matrix
Build a comprehensive test matrix covering every optimization through every relevant type × pattern × CFG combination.
-
Section 01 (Statistics):
- Verify
SynergyMetricsfields are correctly populated for all test programs rc_ops_post_emission > 0for programs with heap types (str, [int], closures)rc_ops_post_emission == 0for int-only programscoalesce_reduction_percent()returns plausible values (0-100%)CoalesceStatscounts match manual IR inspection for 3+ programs- Statistics do not regress program output (pure instrumentation)
- Verify
-
Section 02 (Barriers):
- Type: str, [int], Option<str>, closures, {str: int} map, Set<str>
- Call pattern: all-borrowed, all-owned, mixed, no-contract (FFI)
- CFG: linear, loop body, conditional call
-
Section 03 (KnownSafe):
- Type: str, [int], Option<str>, closures, structs with heap fields
- Nesting: 1-deep (no elim), 2-deep (one pair), 3-deep (two pairs)
- CFG: linear, diamond (both arms increment), loop (invariant RC)
-
Section 04 (COW Contraction):
- Type: struct with mutable field, [int], {str: int}
- CowMode: StaticUnique, Dynamic, StaticShared
- Pattern: single mutation, loop mutation, conditional mutation
- Executor: evaluator oracle, VM, LLVM debug, LLVM release, AOT
- Resource: shared ownership/drop/unwind order, zero leaks, bounded error cleanup
-
Section 05 (RC Motion):
- Type: str, [int], Option<str>, closures, maps
- CFG: diamond (retain in pred, release in succs), triangle, loop, nested loop, early return
- Pattern: same-block pair, cross-block pair, loop-invariant RC
06.1.1 Discovered Gaps
| Gap | Roadmap Location | Test | Severity |
|---|---|---|---|
| (to be filled during implementation) |
-
/tpr-reviewpassed — independent review found no critical or major issues (or all findings triaged) -
/impl-hygiene-reviewpassed — hygiene review clean. MUST run AFTER/tpr-reviewis clean. - Subsection close-out (06.1) — MANDATORY before starting the next subsection. Run
/improve-toolingretrospectively on THIS subsection’s debugging journey (per.claude/skills/improve-tooling/SKILL.md“Per-Subsection Workflow”): whichdiagnostics/scripts you ran, where you addeddbg!/tracingcalls, where output was hard to interpret, where test failures gave unhelpful messages, where you ran the same command sequence repeatedly. Forward-look: what tool/log/diagnostic would shorten the next regression in this code path by 10 minutes? Implement improvements NOW (zero deferral) and commit each via SEPARATE/commit-pushusing a valid conventional-commit type (build(diagnostics): ... — surfaced by section-06.1 retrospective—build/test/chore/ci/docsare valid;tools(...)is rejected by the lefthook commit-msg hook). Mandatory even when nothing felt painful. If genuinely no gaps, document briefly: “Retrospective 06.1: no tooling gaps”. Update this subsection’sstatusin section frontmatter tocomplete. -
/sync-claudesection-close doc sync — verify Claude artifacts across all section commits. Map changed crates to rules files, check CLAUDE.md, canon.md. Fix drift NOW. - Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
06.2 Behavioral Equivalence
Verify that optimized programs produce identical output to unoptimized.
-
Implement layer-specific, centrally registered ablation inputs; do not create one
ORI_DISABLE_ARC_OPTSswitch that conflates the calculus and physical adapters:- Register via the SAME mechanism every other toggle in
arc.md §Debugginguses —debug_flags.rs’sflags!macro (perimpl-hygiene.md COVER-33/COVER-34/SPEC-71’s central-enumeration +check-debug-flags.shverification requirement), NOT a hand-rolledstd::env::var+OnceLockoutside that registry. A toggle read via a separate ad-hoc mechanism is invisible tocheck-debug-flags.shand toarc.md’s “Toggle convention” documentation sweep. - One diagnostic input may disable the Section-02 logical event-ordering refinement at closed AIMS realization; it cannot affect physical plan selection
- Separate explicit
VmPhysicalOptions/CompiledPhysicalOptionsfields disable Sections 03/04-physical/05 after layout/mechanism selection; neither entersAimsPipelineConfig - Resolve environment flags once in
oricinto those typed inputs; pure planners and AIMS receive values, never read ambient environment state - A/B results report logical-plan identity and physical-plan identity separately, preventing a physical win from masquerading as a calculus change
- Give the logical and physical ablations distinct centrally registered names and
// Env:documentation, each with a path-exercising test andarc.md/physical-plan documentation naming exactly what it bisects - Add
COVER-33-shaped negative pins proving each flag independently restores only its own prior behavior; the physical flag must leave the AIMS trace byte-identical, and the logical flag must not change target-plan selection policy
- Register via the SAME mechanism every other toggle in
-
Build comparison harness:
- Execute the evaluator oracle plus VM, LLVM debug, LLVM release, and AOT lanes
- Run every physical lane with and without new optimizations
- Compare value, typed error, stdout, stderr, exit state, panic, and timeout classification
- Compare ownership/drop/unwind event order between VM and compiled lanes
- Require zero live allocations, zero leaked resources, and bounded cleanup in every physical lane
- Report any mismatch; generic/physical agreement inside one backend is not an absolute parity result
-
Extend the canonical parity harness to execute the full spec corpus under a 2×2 matrix: logical event coalescing on/off × selected physical ownership optimization on/off, for VM, LLVM debug/release, and AOT. The evaluator remains the representation-abstract behavioral oracle. Every physical lane must match its behavior, the two physical settings must preserve the exact AIMS trace identity, and all physical lanes must satisfy the shared ownership/drop/unwind and resource gates. Do not implement this as a chat-owned shell loop or stdout-only
diff. -
Track and investigate every mismatch.
-
/tpr-reviewpassed — independent review found no critical or major issues (or all findings triaged) -
/impl-hygiene-reviewpassed — hygiene review clean. MUST run AFTER/tpr-reviewis clean. -
Subsection close-out (06.2) — MANDATORY before starting the next subsection. Run
/improve-toolingretrospectively on THIS subsection’s debugging journey (per.claude/skills/improve-tooling/SKILL.md“Per-Subsection Workflow”): whichdiagnostics/scripts you ran, where you addeddbg!/tracingcalls, where output was hard to interpret, where test failures gave unhelpful messages, where you ran the same command sequence repeatedly. Forward-look: what tool/log/diagnostic would shorten the next regression in this code path by 10 minutes? Implement improvements NOW (zero deferral) and commit each via SEPARATE/commit-pushusing a valid conventional-commit type (build(diagnostics): ... — surfaced by section-06.2 retrospective—build/test/chore/ci/docsare valid;tools(...)is rejected by the lefthook commit-msg hook). Mandatory even when nothing felt painful. If genuinely no gaps, document briefly: “Retrospective 06.2: no tooling gaps”. Update this subsection’sstatusin section frontmatter tocomplete. -
/sync-claudesection-close doc sync — verify Claude artifacts across all section commits. Map changed crates to rules files, check CLAUDE.md, canon.md. Fix drift NOW. -
Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
06.3 Code Journey
Run /code-journey to test the full pipeline end-to-end with progressively complex programs.
-
Run
/code-journey— journeys escalate until the compiler breaks down -
All CRITICAL findings from journey results triaged (fixed or tracked)
-
Evaluator, VM, LLVM debug/release, and AOT produce identical results for all passing journeys
-
VM and compiled journeys preserve shared ownership/drop/unwind events and clear resource gates
-
Journey results archived in
plans/code-journeys/ -
/tpr-reviewpassed — independent review found no critical or major issues (or all findings triaged) -
/impl-hygiene-reviewpassed — hygiene review clean. MUST run AFTER/tpr-reviewis clean. -
Subsection close-out (06.3) — MANDATORY before starting the next subsection. Run
/improve-toolingretrospectively on THIS subsection’s debugging journey (per.claude/skills/improve-tooling/SKILL.md“Per-Subsection Workflow”): whichdiagnostics/scripts you ran, where you addeddbg!/tracingcalls, where output was hard to interpret, where test failures gave unhelpful messages, where you ran the same command sequence repeatedly. Forward-look: what tool/log/diagnostic would shorten the next regression in this code path by 10 minutes? Implement improvements NOW (zero deferral) and commit each via SEPARATE/commit-pushusing a valid conventional-commit type (build(diagnostics): ... — surfaced by section-06.3 retrospective—build/test/chore/ci/docsare valid;tools(...)is rejected by the lefthook commit-msg hook). Mandatory even when nothing felt painful. If genuinely no gaps, document briefly: “Retrospective 06.3: no tooling gaps”. Update this subsection’sstatusin section frontmatter tocomplete. -
/sync-claudesection-close doc sync — verify Claude artifacts across all section commits. Map changed crates to rules files, check CLAUDE.md, canon.md. Fix drift NOW. -
Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
06.4 Safety Verification
-
RC balance:
diagnostics/rc-stats.shon all test programs → balanced -
Leak check:
ORI_CHECK_LEAKS=1on all test programs → zero leaks -
VM resource check: zero live heap/value-arena objects after success, error, panic, and quota exit
-
Event check: VM and compiled ownership/drop/unwind traces preserve the shared artifact order
-
Valgrind:
diagnostics/valgrind-aot.shon representative programs → no memory errors -
Codegen audit:
ORI_AUDIT_CODEGEN=1 ORI_AUDIT_STRICT=1on all test programs → no findings -
Stress test: 1000+ allocations, 100+ recursion depth, 1000+ list elements — all clean
-
/tpr-reviewpassed — independent review found no critical or major issues (or all findings triaged) -
/impl-hygiene-reviewpassed — hygiene review clean. MUST run AFTER/tpr-reviewis clean. -
Subsection close-out (06.4) — MANDATORY before starting the next subsection. Run
/improve-toolingretrospectively on THIS subsection’s debugging journey (per.claude/skills/improve-tooling/SKILL.md“Per-Subsection Workflow”): whichdiagnostics/scripts you ran, where you addeddbg!/tracingcalls, where output was hard to interpret, where test failures gave unhelpful messages, where you ran the same command sequence repeatedly. Forward-look: what tool/log/diagnostic would shorten the next regression in this code path by 10 minutes? Implement improvements NOW (zero deferral) and commit each via SEPARATE/commit-pushusing a valid conventional-commit type (build(diagnostics): ... — surfaced by section-06.4 retrospective—build/test/chore/ci/docsare valid;tools(...)is rejected by the lefthook commit-msg hook). Mandatory even when nothing felt painful. If genuinely no gaps, document briefly: “Retrospective 06.4: no tooling gaps”. Update this subsection’sstatusin section frontmatter tocomplete. -
/sync-claudesection-close doc sync — verify Claude artifacts across all section commits. Map changed crates to rules files, check CLAUDE.md, canon.md. Fix drift NOW. -
Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
06.5 Performance Validation
-
RC operation reduction:
- Baseline:
ORI_LOG=ori_arc=info ori build tests/spec/with Sections 02-05 disabled - Optimized: same with all sections enabled
- Target: 30%+ total RC operation reduction on typical programs
- Note:
aims-compare.shwas removed (used non-existent--features aims). RC operation measurement requires a new tool — useORI_AUDIT_CODEGEN=1+diagnostics/rc-stats.shas an interim approach for counting RC ops.
- Baseline:
-
Compile-time overhead:
- Measure compilation time with and without new passes
- Target: < 5% compile-time regression
- Run
cargo bench -p oricif parser/typeck benchmarks exist
-
Runtime performance:
- Benchmark programs in
tests/benchmarks/ - Measure execution time with and without optimizations
- Target: measurable improvement on RC-heavy programs
- Benchmark programs in
-
/tpr-reviewpassed — independent review found no critical or major issues (or all findings triaged) -
/impl-hygiene-reviewpassed — hygiene review clean. MUST run AFTER/tpr-reviewis clean. -
Subsection close-out (06.5) — MANDATORY before starting the next subsection. Run
/improve-toolingretrospectively on THIS subsection’s debugging journey (per.claude/skills/improve-tooling/SKILL.md“Per-Subsection Workflow”): whichdiagnostics/scripts you ran, where you addeddbg!/tracingcalls, where output was hard to interpret, where test failures gave unhelpful messages, where you ran the same command sequence repeatedly. Forward-look: what tool/log/diagnostic would shorten the next regression in this code path by 10 minutes? Implement improvements NOW (zero deferral) and commit each via SEPARATE/commit-pushusing a valid conventional-commit type (build(diagnostics): ... — surfaced by section-06.5 retrospective—build/test/chore/ci/docsare valid;tools(...)is rejected by the lefthook commit-msg hook). Mandatory even when nothing felt painful. If genuinely no gaps, document briefly: “Retrospective 06.5: no tooling gaps”. Update this subsection’sstatusin section frontmatter tocomplete. -
/sync-claudesection-close doc sync — verify Claude artifacts across all section commits. Map changed crates to rules files, check CLAUDE.md, canon.md. Fix drift NOW. -
Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
06.6 Documentation and Cleanup
-
Update
CLAUDE.mdwith new pipeline steps if applicable -
Update
.claude/rules/arc.mdwith new pass descriptions -
Update
compiler/ori_arc/src/aims/mod.rsmodule docs -
Add architecture notes to
compiler/ori_arc/src/aims/knownsafe/mod.rs -
Add architecture notes to
compiler/ori_arc/src/aims/rc_motion/mod.rs -
arc.md §CP-2four-surface sync (MANDATORY, not optional doc polish):RL-9/RL-22-RL-26move fromtarget-onlyto shipped in this section — the compiled Lean +.proofstay unchanged (already proven), but the other two surfaces MUST flip in the same change set:.claude/rules/aims-rules.mdtop-of-file carve-out list: remove “§8 RL-22 thru RL-26(post-pipeline): target-only” (or narrow it if a subset ships).claude/rules/arc.md“Where AIMS is HEADED” section: remove the “Clang ARC patterns (plans/clang-arc-lessons/) - KnownSafe flag, barrier analysis, RC motion, COW contraction, per-phase elimination statistics” bullet; fold the shipped capabilities into “What AIMS does TODAY (shipped, not roadmap)”- Add an
aims-rules.mdHISTORY entry recording the conformance shipping per the file’s own per-rule provenance-table convention (terminal state staysproven_sound; this is a shipped-conformance note, not a calculus change)
-
Plan annotation cleanup: strip ALL code annotations referencing this plan (
clang-arc-lessons, section numbers01-06, any plan-specific markers) from all source files. Runbash .claude/skills/impl-hygiene-review/plan-annotations.sh --plan clang-arc-lessonsand verify 0 annotations remain. Only spec references (Spec: Clause N.M) are permanent. -
/tpr-reviewpassed — independent review found no critical or major issues (or all findings triaged) -
/impl-hygiene-reviewpassed — hygiene review clean. MUST run AFTER/tpr-reviewis clean. -
Subsection close-out (06.6) — MANDATORY before starting the next subsection. Run
/improve-toolingretrospectively on THIS subsection’s debugging journey (per.claude/skills/improve-tooling/SKILL.md“Per-Subsection Workflow”): whichdiagnostics/scripts you ran, where you addeddbg!/tracingcalls, where output was hard to interpret, where test failures gave unhelpful messages, where you ran the same command sequence repeatedly. Forward-look: what tool/log/diagnostic would shorten the next regression in this code path by 10 minutes? Implement improvements NOW (zero deferral) and commit each via SEPARATE/commit-pushusing a valid conventional-commit type (build(diagnostics): ... — surfaced by section-06.6 retrospective—build/test/chore/ci/docsare valid;tools(...)is rejected by the lefthook commit-msg hook). Mandatory even when nothing felt painful. If genuinely no gaps, document briefly: “Retrospective 06.6: no tooling gaps”. Update this subsection’sstatusin section frontmatter tocomplete. -
/sync-claudesection-close doc sync — verify Claude artifacts across all section commits. Map changed crates to rules files, check CLAUDE.md, canon.md. Fix drift NOW. -
Repo hygiene check — run
diagnostics/repo-hygiene.sh --checkand clean any detected temp files.
06.7 Completion Checklist
- Test matrix covers all sections (01-05) × types × patterns × CFG combinations
-
ORI_DISABLE_ARC_OPTSflag implemented, registered indebug_flags.rs, documented inarc.md §Debugging, and functional - Behavioral equivalence verified — 0 evaluator/VM/LLVM-debug/LLVM-release/AOT mismatches
- VM and compiled ownership/drop/unwind traces match the shared artifact; every resource gate is clean
- Code journey passes — all evaluator/VM/compiled lanes match, no CRITICAL findings
- RC balance verified via
rc-stats.sh— all functions balanced -
ORI_CHECK_LEAKS=1— zero leaks on all test programs - Valgrind clean on representative programs
- Codegen audit clean (
ORI_AUDIT_STRICT=1) - Stress tests pass
- 30%+ total RC operation reduction on typical programs
- < 5% compile-time regression
- All documentation updated
- Plan annotation cleanup:
plan-annotations.shreturns 0 annotations for this plan -
./test-all.shgreen -
./clippy-all.shgreen -
/tpr-reviewpassed — independent Codex review clean -
/impl-hygiene-reviewpassed — hygiene review clean -
/improve-toolingretrospective completed — MANDATORY at section close, after both reviews are clean. Reflect on the section’s debugging journey (whichdiagnostics/scripts you ran, which command sequences you repeated, where you added ad-hocdbg!/tracingcalls, where output was hard to interpret) and identify any tool/log/diagnostic improvement that would have made this section materially easier OR that would help the next section touching this area. Implement every accepted improvement NOW (zero deferral) and commit each via SEPARATE/commit-push. The retrospective is mandatory even when nothing felt painful — that is exactly when blind spots accumulate. See.claude/skills/improve-tooling/SKILL.md“Retrospective Mode” for the full protocol.
Exit Criteria: All test programs produce identical output with and without optimizations. Zero leaks. Zero valgrind errors. Zero codegen audit findings. ./test-all.sh passes with 0 regressions across all ~N tests. RC operation reduction measured and documented. Compile-time overhead < 5%.