Intelligence Reconnaissance
Queries run 2026-04-17:
scripts/intel-query.sh --human file-symbols "ori_llvm/src/codegen/arc_emitter" --repo ori— inventoryArcIrEmittersymbols (variable-definition ordering,emitter_utils) before investigating the BUG-04-085 variable-not-yet-defined crash.scripts/intel-query.sh --human callers "compute_flags" --repo ori— blast radius ofTypeFlagscomputation (includingPROPAGATE_MASK) to trace §02.0’s effect on downstream consumers.scripts/intel-query.sh --human callers "body_type_map" --repo ori— identify all consumers ofbody_type_mapthat may have relied on pre-§02.0Tag::Scheme HAS_VAR=falseflag semantics.scripts/intel-query.sh --human similar "variable not defined arc emitter ordering" --repo swift,lean4 --limit 3— prior art for SSA variable-definition ordering bugs in ARC IR emitters.
Results summary (≤500 chars) [ori]: ArcIrEmitter lives in ori_llvm/src/codegen/arc_emitter/; emitter_utils.rs handles variable definition tracking. body_type_map consumed by prepare_mono_cached in nounwind/prepare.rs. compute_flags in ori_types/src/pool/ — PROPAGATE_MASK sets HAS_VAR on Tag::Scheme items since §02.0. [swift]: SIL variable-ordering bugs manifest as “use before definition” in ownership verification — mirrors the var=N not yet defined crash signature.
07.0 Investigate BUG-04-085 — LLVM spec runner crash (absorbed 2026-04-17)
Origin: Absorbed from bug-tracker BUG-04-085 per CLAUDE.md §Ownership & Deferral “Plan-blocker bugs belong IN the plan”. The bug was filed 2026-04-15 with explicit notes that §02.0’s Tag::Scheme PROPAGATE_MASK change may be the causal root. Because this plan introduced §02.0 and the crash may be its downstream symptom, the plan owns investigating and resolving it as part of close-out.
Failure mode (from bug entry): timeout 150 ./test-all.sh shows Ori spec (LLVM backend) CRASHED with cluster of errors on assert_eq$m$int (monomorphized assert_eq<int>):
LLVM IR verification failed after codegen (emit_prepared_functions)withCall parameter type does not match function signature!onori_rc_dec({ i64, i64, ptr }, ptr @"_ori_drop$N")- Three
ArcIrEmitter: variable not yet definederrors (var=11, var=2, var=7) — mirrors resolved BUG-04-024 signature error[E4003]: ARC internal error: index assignment reached ARC lowering before desugaring(BUG-04-070 class)thread 'ori-main' has overflowed its stack→SIGABRT- Interpreter passes all 4444 spec tests; only
--backend=llvmcrashes
Causal hypothesis: compiler/ori_types/src/pool/mod.rs:655-661 — §02.0’s Tag::Scheme PROPAGATE_MASK fix sets HAS_VAR on scheme Idx values where previously unset. If the mono pipeline’s body_type_map or ArcIrEmitter’s variable-definition ordering relied on the old flag semantics (specifically: “scheme types have !HAS_VAR so skip the substitute step”), then setting HAS_VAR correctly now surfaces as “variable not yet defined” in the downstream consumer.
- Reproduce the crash cleanly:
timeout 150 ./test-all.shon a clean post-§08 tree — confirm the specific crash line, the 3var=Nerrors, and theassert_eq$m$intfunction name. - Isolate §02.0’s causal role: revert
compiler/ori_types/src/pool/mod.rs:655-661’sTag::Schemecontribution toPROPAGATE_MASKon a scratch branch; re-runtest-all.sh. If the crash disappears, §02.0 is causal. If the crash persists, §02.0 is not causal and the root cause is elsewhere. - If §02.0 IS causal: identify the downstream consumer that depended on the old flag semantics. Candidate sites:
ArcIrEmittervariable-definition ordering (emitter_utils.rs), the mono pipeline’sbody_type_mapconstruction,prepare_mono_cached’s scheme handling. Fix the consumer to work correctly with the new (correct) flag semantics. - If §02.0 is NOT causal: file a new bug scoped to the true root cause (drop-fn pointer type mismatch? ArcIrEmitter ordering regression independent of §02.0?). That new bug is outside this plan’s scope — continue with §07.1.
- TDD: add a spec test or Rust unit test that exercises the failing path —
assert_eq<int>in a file that also uses polymorphic lambdas (overlap with §08 surface). Verify the test fails on the current code and passes after the fix. - Matrix: poly-lambda × imported generic × assert_eq type — confirm no crash for
int,str,bool,floatvariants.
Section 07: Close-out + Supersession
Status: Not Started Goal: Formally close BUG-04-074 and this plan. Verify all code changes are clean, all plan annotations are removed, and the bug-tracker is updated.
Depends on: All previous sections complete.
07.1 Final Test Verification
timeout 150 ./test-all.sh # debug build — must be green
timeout 150 cargo test --release -p ori_types # release build
timeout 150 cargo test --release -p ori_llvm # LLVM + AOT release
Also verify dual-execution parity on the Section 05 spec tests:
diagnostics/dual-exec-verify.sh tests/spec/types/collections/empty_list/empty_list_annotated_with_push.ori
diagnostics/dual-exec-verify.sh tests/spec/types/collections/empty_list/empty_list_element_struct.ori
diagnostics/dual-exec-verify.sh tests/spec/types/collections/empty_list/empty_list_with_for_yield.ori
07.2 Plan Annotation Cleanup Sweep + Post-§09.3 Helper Removal
Per CLAUDE.md §Compiler Coding Guidelines: “Plan annotations are temporary scaffolding.
They MUST be removed when the plan completes.”
07.2.a Annotation marker sweep
Run the sweep over all three trees (compiler source, spec tests, and stdlib), using
only this plan’s specific markers. The 2026-04-23 plan rename from empty-container-typeck-phase-contract to typeck-inference-completeness means BOTH pre-rename and post-rename markers must appear in the sweep regex until every annotation site has been migrated:
# Plan-specific markers in compiler source (Rust files) — must return zero hits
rg 'BUG-04-074|empty-container-typeck|typeck-inference-completeness' compiler/ --glob '*.rs'
# Plan-specific markers in AOT fixture files (Ori files in compiler tree) — must return zero hits
# These are created in §05.3 at compiler/ori_llvm/tests/aot/fixtures/empty_list/*.ori
rg 'BUG-04-074|empty-container-typeck|typeck-inference-completeness' compiler/ --glob '*.ori'
# Plan-specific markers in spec tests (regression comments added in §06.2)
rg 'BUG-04-074|empty-container-typeck|typeck-inference-completeness' tests/ --glob '*.ori'
# Plan-specific markers in stdlib (edits made in §06.3)
rg 'BUG-04-074|empty-container-typeck|typeck-inference-completeness' library/ --glob '*.ori'
Note: Generic §NN tokens (e.g. §01, §03) are intentionally excluded from the
sweep pattern because they exist in unrelated plans (e.g., compiler/ori_repr/ contains
§03 and §04 references from a different plan). Searching for bare §NN produces
false positives and sends the implementer chasing unrelated code. Use only the
plan-specific identifiers above.
Every hit must be removed or converted to a permanent spec comment
(Spec: Clause N.M format). No plan-referencing comments in shipped code.
07.2.b Post-§09.3 helper removal (traceable/ workarounds)
Scope: the @mk_ok / @mk_err helper-function workarounds applied during §06.2C remediation to tests/spec/traits/traceable/definition.ori + tests/spec/traits/traceable/result_delegation.ori. These are CLEANUP DEBT — they stay in main-branch source only until §09.3 lands. Post-§09.3, the direct-constructor form compiles clean without the helpers, and keeping them is a hygiene violation (dead-ish workarounds mascuerading as legitimate helpers).
Predecessors (MUST all be complete before this subsection starts):
-
§09.3 (Result<T, user-Error> LHS propagation) is
status: completein its frontmatter. -
§06.4.4’s “Per-file INVERTED-TDD reconciliation for 2 traceable/ helper-workaround files” step is marked
[x]and reports the scratch-revert as GREEN (proving the direct-constructor form compiles under the shipped §09.3 fix). -
Confirm §09.3 frontmatter
status: complete. -
Confirm §06.4.4’s traceable/ scratch-revert step is
[x]with GREEN result. If the scratch-revert failed, §07.2 helper removal is BLOCKED pending §09.3 completeness investigation — file a bug naming the specific residual failure. -
In main-branch source, strip the
@mk_ok/@mk_errhelper calls AND their helper definitions fromtests/spec/traits/traceable/definition.ori+tests/spec/traits/traceable/result_delegation.ori. Restore each file to the direct-constructor form (Ok(x: ...)/Err(x: ...)intry { ... }with outerlet r: Result<T, E> = ...LHS annotation — same shape as the §06.4.4 scratch-revert fixture). -
Run
timeout 150 cargo stf tests/spec/traits/traceable/— both files green. Runtimeout 150 diagnostics/dual-exec-verify.shon both files — zero parity divergences. -
Run
timeout 150 ./test-all.sh— confirm no regression outside the traceable/ directory (if a regression appears, the removal is unmasking a different compiler gap; back out and file a bug naming the new gap). -
Commit:
refactor(tests): remove @mk_ok/@mk_err helpers from traceable/ — §09.3 closes the compiler gap directly (§07.2). -
Update §06.2C table: change the Classification for the 2 traceable/ rows from
helper workaround — CLEANUP DEBTtoREMOVED (direct form, §09.3 closed gap)and the Owning column to— (resolved via §07.2). -
Update §03.N Known Failing Tests table (
section-03-bodies-pass-integration.md:~1243-1280): strike the two traceable/ rows as[REMEDIATED in §07.2 — helpers removed post-§09.3].
07.3 Final TPR + Hygiene Gate
Run this BEFORE updating any external bug trackers. All validation gates must pass before declaring BUG-04-074 resolved — marking the bug complete before gates pass leaves the tracker out of sync if a gate fails.
First, validate the entire plan directory against the plan corpus schema:
python -m scripts.plan_corpus check plans/typeck-inference-completeness/
This command must pass with zero schema errors before the plan can be marked complete.
If it fails on sections 01–04 or index.md (sections written before the plan_corpus
schema was current), update their frontmatter to satisfy the schema before proceeding.
Run final TPR over the full work arc:
/tpr-review
The scope covers the full work arc: all compiler changes in Sections 01–04, new test files from
Section 05, annotation changes from Section 06, §08 poly-lambda mono fix, all §09 body-inference
BD-2 extensions (§09.1 try-block, §09.2 def-impl Self, §09.3 Result<T,E> LHS, §09.4 lambda-param),
all §10 dispatch-on-rigid-receiver changes (§10.0 file splits, §10.1 bound-chain, §10.2 capability),
§11.1 Never-fallback predicate extension + body_inference_complete debug_assert + Some-exclusion,
§07.2 helper removal (traceable/ @mk_ok / @mk_err), and §07.5 R7-006 validator refinement. The
review must return zero actionable findings before the plan can be marked complete.
Run hygiene review:
/impl-hygiene-review
Auto-scope mode covers the full work arc. Must pass.
Run tooling improvement sweep:
/improve-tooling
Review any test harness, diagnostic script, or developer tooling gaps surfaced during
the implementation arc (Sections 01–06). Flag gaps found in dual-exec-verify.sh,
test-all.sh, or any diagnostic flag interactions.
Run CLAUDE.md sync sweep:
/sync-claude
Verify no new APIs, commands, or invocation patterns were introduced by Sections 01–06
that need documenting. If diagnostics/dual-exec-verify.sh behavior or any new
ORI_* flags were added or changed, document the exact invocation pattern in
CLAUDE.md §Commands if not already present.
07.4 Bug-Tracker Updates
Only update bug trackers AFTER 07.3 validation gates pass. This sequencing ensures the bug is not prematurely marked complete.
-
Update
bug-tracker/plans/BUG-04-074/:- Set
status: complete - Add pointer:
"Superseded by plans/typeck-inference-completeness/" - Set
resolved_in:to the commit SHA of the Section 03 landing
- Set
-
Update
plans/bug-tracker/00-overview.md:- Move BUG-04-074 from open to closed
- Decrement open bug count
-
Update
plans/bug-tracker/section-04-codegen-llvm.md(or wherever BUG-04-074 is tracked in the section-scoped trackers):- Mark as resolved
07.5 R7-006 Validator Refinement — Discriminate Lambda return-vs-param in E2005 Site Classifier
Origin. Absorbed from TPR Round 7 finding R7-006 (codex medium) per §06.R line 701 anchor. The finding cites compiler_repo/compiler/ori_types/src/check/validators/mod.rs:95-100 where site_from_expr_kind classifies every Lambda-sited Tag::Var as LambdaParam, producing the closure-parameter diagnostic wording even when the unresolved var is on the lambda’s RETURN type. The §06.1 spec bullet at :151 defines LambdaParam as specifically “ExprKind::Lambda { params, .. } where a parameter has unresolved Tag::Var” — return-type vars violate this classification.
Why post-§09/§10/§11. Running the validator refinement against a body-inference surface that still has §09 BD-2 gaps or §11.1 defaulting holes produces false diagnostic wording regressions and thrashes the test matrix. §09/§10/§11 must land FIRST so the only remaining E2005 sites are genuine residuals the validator refinement must classify correctly.
Fix shape.
- Read
compiler_repo/compiler/ori_types/src/check/validators/mod.rs:95-100+ surrounding context to understand the currentsite_from_expr_kindsignature (what does it receive? just theExprKind, or does it have access to the specific Tag::Var position that triggered the E2005?). - If the signature doesn’t currently carry position info, extend it: add a
VarPositionenum ({ LambdaParam(param_index), LambdaReturn, FunctionParam(param_index), FunctionReturn, LetBinding, MatchArm, ... }) and thread it through the validator’s Tag::Var-reporting call sites so each E2005 emission knows which slot introduced the unresolved var. - Split
LambdaParamsite class intoLambdaParam { index }+LambdaReturn— emit distinct E2005 diagnostic messages per site class (parameter wording stays verbatim per §06.1 spec; return wording is new — propose “cannot infer the return type of this lambda; add a return annotation or constrain the body expression”). - Write positive + negative test pair:
test_e2005_lambda_return_uses_return_wording(positive — synthesize an ExprKind::Lambda with unresolved return-position Tag::Var, verify the emitted E2005 message uses the return wording) +test_e2005_lambda_param_uses_param_wording_unchanged(regression — verify param-position classification still produces the pre-refinement wording). - Dual-exec parity: the validator refinement is diagnostic-only (no AST change, no canonicalization change, no codegen change) so
diagnostics/dual-exec-verify.shshould show zero parity divergences — verify explicitly. - Update §06.1’s E2005 wording success criterion at
section-06-diagnostics-audit.md:21if the return-position wording is added (currently only cites the empty-list example).
Gate. Must pass before §07.3 Final TPR + Hygiene Gate runs — §07.3 scope now includes §07.5 per the expanded scope line in §07.3 below.
Commit shape. One commit scoped to the validator refinement alone (no bundling with §07.0 BUG-04-085 investigation or §07.2 helper removal). Commit message: fix(typeck): validator E2005 site classifier discriminates Lambda return vs param (R7-006).
07.R Third Party Review Findings
Round 2 — Dual-source TPR on sections 05, 06, 07 (Codex + Gemini). Findings addressed in this revision.
[[TPR-07-001-codex]] [MEDIUM] Scope the annotation cleanup sweep to this plan’s markers and all affected trees
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:77
Reviewer: Codex | Status: Fixed
Evidence: Section 07 originally grepped compiler/ for
BUG-04-074|empty-container-typeck|§01|§02|§03|§04. That misses temporary plan comments
in spec tests (section-05-test-matrix.md instructs implementers to add Regression: BUG-04-074 comments under tests/spec/...). It also produces unrelated false-positive
hits because generic §03/§04 markers already exist in
compiler/ori_repr/src/narrowing/tests.rs:1 and compiler/ori_parse/src/dispatch.rs:134
(from a different plan).
Fix: Split the sweep into two targeted commands that use only plan-specific identifiers
(BUG-04-074|empty-container-typeck) and cover both compiler/ and tests/. Dropped
generic §NN tokens from the pattern to eliminate false positives from unrelated plans.
Updated the success_criteria in the frontmatter to match.
[[TPR-07-002-gemini]] [LOW] Expand plan annotation cleanup regex to cover all sections
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:77
Reviewer: Gemini | Status: Fixed (subsumed by TPR-07-001-codex)
Evidence: Section 07.2 used a regex that explicitly omitted §05, §06, and §07.
If developers left code annotations referencing those sections, the final cleanup sweep
would miss them.
Fix: Same as TPR-07-001-codex — the updated sweep uses plan-specific identifiers only
(BUG-04-074|empty-container-typeck) which covers all sections by design: any
annotation referencing this plan’s work will include the bug ID or plan name.
[[TPR-07-003-codex]] [MEDIUM] Add a whole-plan corpus validation gate before close-out
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:104
Reviewer: Codex | Status: Fixed
Evidence: Section 07’s final gate originally ran only /tpr-review and
/impl-hygiene-review. The command
python -m scripts.plan_corpus check plans/empty-container-typeck-phase-contract/
currently fails on index.md, section-01-value-restriction.md,
section-02-validator-module.md, and section-04-codegen-assertions.md. Without an
explicit gate, Section 07 could declare the plan complete while the owning plan directory
is still schema-invalid to the plan tooling.
Fix: Added python -m scripts.plan_corpus check plans/empty-container-typeck-phase-contract/
as the first step in 07.4. The gate must pass before TPR or hygiene review proceeds.
Also added to the 07.N checklist as an explicit - [ ] item.
Round 3 — Dual-source TPR on sections 05, 06, 07 (Codex + Gemini). Findings addressed in this revision.
[[TPR-07-004-codex]] [MEDIUM] Sweep library/ directory for plan markers during close-out
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:§07.2
Reviewer: Codex | Status: Fixed
Evidence: Section 06.3 directs implementers to annotate library/std/ code. Section 07.2
only swept compiler/ (with *.rs filter, missing .ori AOT fixtures) and tests/. The
library/ tree was entirely missing from the cleanup sweep.
Fix: Added two new sweep commands: one for compiler/ --glob '*.ori' (AOT fixtures) and
one for library/ --glob '*.ori' (stdlib). Updated success_criteria to reference all four
trees. Updated 07.N checklist to explicitly call out all four trees.
[[TPR-07-005-codex]] [MEDIUM] Add release ori_llvm test and section-04 tracker update to 07.N
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:§07.N
Reviewer: Codex | Status: Fixed
Evidence: Section 07.1 specifies cargo test --release -p ori_llvm but the 07.N checklist
item for “07.1 complete” only said “./test-all.sh green debug + release”. Section 07.3 (now
07.4) step 3 requires updating plans/bug-tracker/section-04-codegen-llvm.md but the 07.N
checklist for “07.3 complete” (now “07.4 complete”) omitted this.
Fix: Updated 07.N “07.1 complete” item to include cargo test --release -p ori_llvm. Updated
“07.4 complete” item to explicitly include plans/bug-tracker/section-04-codegen-llvm.md resolution.
[[TPR-07-006-gemini]] [HIGH] Reorder 07.3/07.4 so validation gates run before bug-tracker closure
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:§07.3/07.4
Reviewer: Gemini | Status: Fixed
Evidence: Section 07.3 was “Bug-Tracker Updates” (marks BUG-04-074 complete) and 07.4 was
“Final TPR + Hygiene Gate”. This ordering allows the bug to be declared resolved in external
trackers before the final /tpr-review and /impl-hygiene-review pass. If a gate fails after
the tracker is updated, the tracker is out of sync.
Fix: Swapped 07.3 and 07.4: 07.3 is now “Final TPR + Hygiene Gate” and 07.4 is “Bug-Tracker Updates (runs AFTER 07.3 validation passes)”. Added explicit note in 07.4 header that bug trackers must only be updated after 07.3 passes. Updated frontmatter sections list and success_criteria to reflect the new ordering.
[[TPR-07-007-gemini]] [LOW] section-04-codegen-llvm.md missing from 07.N 07.3 checklist item
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:§07.N
Reviewer: Gemini | Status: Fixed (subsumed by TPR-07-005-codex)
Evidence: The 07.N completion checklist for the bug-tracker step only listed
bug-tracker/plans/BUG-04-074/ and 00-overview.md, omitting the section-04-codegen-llvm.md update
that step 3 of the bug-tracker section explicitly requires.
Fix: Same as TPR-07-005-codex — the updated 07.N checklist for “07.4 complete” now
explicitly includes plans/bug-tracker/section-04-codegen-llvm.md entry resolved.
Round 4 — Dual-source TPR on sections 05, 06, 07 (Codex + Gemini). Findings addressed in this revision.
[[TPR-07-R4-001-codex]] [MEDIUM] /improve-tooling and /sync-claude dropped from 07.3 and 07.N
Location: plans/empty-container-typeck-phase-contract/section-07-closeout.md:§07.3
Reviewer: Codex | Status: Fixed
Evidence: 00-overview.md:165 and index.md:119 both specify Phase 6 / Section 07
close-out as /tpr-review → /impl-hygiene-review → /improve-tooling sweep → /sync-claude.
After the 07.3/07.4 reorder in Round 3, the implementation of 07.3 and the 07.N checklist
only included /tpr-review and /impl-hygiene-review. Both /improve-tooling and
/sync-claude were silently dropped, leaving the section cross-inconsistent with the
approved overview and creating two unanchored mandatory close-out tasks.
Fix: Added /improve-tooling and /sync-claude blocks to 07.3 body with instructions
for each. Updated the success_criteria to name all five gates. Updated the 07.N “07.3
complete” checklist item to explicitly list /improve-tooling and /sync-claude.
07.N Completion Checklist
- 07.1 complete —
./test-all.shgreen debug + release;cargo test --release -p ori_llvmgreen; dual-exec parity verified on ≥3 spec files - 07.2.a complete — zero
BUG-04-074|empty-container-typeck|typeck-inference-completenesshits in all four trees:compiler/*.rs,compiler/*.ori(AOT fixtures),tests/*.ori,library/*.ori - 07.2.b complete —
@mk_ok/@mk_errhelpers removed fromtests/spec/traits/traceable/definition.ori+result_delegation.ori; both files green under direct-constructor form after §09.3 shipped; §06.2C table + §03.N ledger updated to reflectREMOVED (direct form, §09.3 closed gap) - 07.3 complete —
plan_corpus check plans/typeck-inference-completeness/passes; final/tpr-reviewclean;/impl-hygiene-reviewclean;/improve-toolingsweep clean;/sync-claudesweep clean - 07.4 complete —
bug-tracker/plans/BUG-04-074/statuscompletewith pointer toplans/typeck-inference-completeness/;00-overview.mdupdated;plans/bug-tracker/section-04-codegen-llvm.mdentry resolved - This section’s own status set to
completein frontmatter -
plans/typeck-inference-completeness/plan index updated: all sections complete
Exit criteria: BUG-04-074 is formally closed. The empty-container typeck phase-contract enforcement plan is complete. The empty list ambiguity bug no longer exists in the Ori compiler.