0%

broad-transitive-generic-body-mono-collection

Goal

Close the broad whole-corpus transitive-generic-body monomorphization gap (ROOT-B): a generic function whose body calls a trait method, a passed closure, or a generic constructor on its own rigid type param is not monomorphized per concrete instantiation when invoked from another generic body. The recorder records the OUTER generic fn’s instance but the nested calls are type-checked against rigid T and never recorded/dispatched per concrete instantiation, so the AOT mono dispatch (resolve_callee -> lookup_mono_dispatch, mono_instance_id=None fallback) starves and emits the ‘unresolved function X in apply — missing mono instance?’ diagnostic, failing LLVM codegen while the interpreter computes the value (a dual-execution parity break across the whole corpus). Deliverable: the §07 whole-corpus mission gate (s-50bfe700) reads 0 for the four monomorphization-class signatures.

Implementation Sketch

The residual at HEAD 7ac52c404 is 234 across nine generic callees (grep -F ‘missing mono instance’ compiler_repo/test-all.log | grep -oE ‘unresolved function [^]+'): assert_eq 72, transform 41, create 32, repeat 25, empty_queue 24, thread_id 16, cb 11, buffer_pop 6, repeat_value 3, plus Tag::Var-in-JIT-pre-mono 2 and UnresolvedTypeVar 4. The could not map callee var to caller scheme var` signal is 0 (§06 cleared it) and len/contains is 0 (§08/s-55bd6aa5 cleared it).

This residual was NOT cured by §05 (transitive-mono-worklist, s-cc288c2a, completed): §05 delivered ONLY the FOCUSED assert_eq nested-body case via the upstream associated-type-projection normalization fix (BUG-02-067, compiler_repo c3c084e3) and explicitly AMENDED its criterion from whole-corpus to focused spec tests, deferring the broad whole-corpus residual to §07’s gate (sc-c5309edf) + the plan-wide gate (sc-7ab4c58c). §05’s Implementation Sketch named the cure shape that was never built — the body-re-walk worklist (cf. rustc_monomorphize::collector) / per-instantiation dispatch. This section IS that owning cure.

Fix shape (the §05 sketch + the §09-proven per-instantiation approach in aot-mono-completeness s-0a67b346):

  • PREFERRED — per-instantiation dispatch: resolve nested generic/trait calls per concrete instantiation from Pool.resolutions at the AOT dispatch surface (ori_llvm/src/codegen/arc_emitter/apply.rs resolve_callee -> lookup_mono_dispatch; the apply.rs doc already names the unwired mono_instance_id=None fallback gap). This matches the §09 PROVEN per-instantiation codegen approach (derive_codegen consuming Pool.resolutions per concrete instantiation), the path that was empirically validated when the typeck-recorder-fix premise was falsified.
  • ALTERNATIVE — fixpoint body-rewalk worklist: alongside collect_mono_functions (ori_llvm/src/monomorphize/mod.rs ~:98), walk each recorded MonoFunction’s monomorphized body collecting nested MonoInstances, fed concrete substitutions via body_type_map (ori_types/src/infer/expr/calls/monomorphization.rs).

Hard constraints: do NOT touch mangle.rs / nounwind / prepare.rs — the fix changes WHETHER nested calls resolve per-instantiation, never HOW they are named (§09 mangling-contract gate). The recorder-var-mapping fix (resolve_scheme_var) was SUPERSEDED in §09 — re-attempting it is a known dead-end. TDD-first is non-negotiable: the recorder spine (maybe_record_mono_instance, the single highest-churn graph symbol) + the dispatch site (lookup_mono_dispatch) are zero-unit-tested — author failing AOT spec tests on the nine callee shapes BEFORE touching them.

Binding-constraint reconciliation (§08/s-55bd6aa5): the cure EXTENDS collect_mono_functions / the per-instantiation dispatch but MUST preserve len/contains + every prior-cleared signature at 0 (enforced by sc-b704a1 + the plan-wide whole-corpus gate + L9/L10); it does NOT touch resolve_scheme_var (the §09-superseded dead-end).

Production-path closure (the §05 FALSE-GREEN trap): the cure is done only when the WHOLE-CORPUS ./test-all.log grep reads 0 for all four signatures, not merely when focused spec tests pass. A green focused test while the whole-corpus residual persists is NOT done.

Spec References

plans/aot-mono-stdlib-completeness §05 transitive-mono-worklist (s-cc288c2a) HISTORY 2026-06-25 (the focused-vs-whole-corpus scope amendment + the deferred residual ownership); §07 whole-corpus-verification (s-50bfe700) w-bf8beb40 (the mission-probe gate this section unblocks); plans/aot-mono-completeness s-0a67b346 §09 (the proven per-instantiation codegen approach + the mangling-contract gate); ori_llvm/src/codegen/arc_emitter/apply.rs resolve_callee + lookup_mono_dispatch (the dispatch surface); ori_llvm/src/monomorphize/mod.rs collect_mono_functions (the recorder worklist); ori_types/src/infer/expr/calls/monomorphization.rs (recorder + body_type_map); .claude/rules/layer-coverage.md §1 (L1-L12 matrix); missions.md §AIMS / §ori_llvm (codegen faithfully emits per-instantiation, never re-derives). Link-back: on gate 0, this unblocks the plan-wide functional criterion sc-7ab4c58c + §07 verification + cross-plan aot-mono-completeness s-81bd0419 mission items (w-da8b78de / w-14999222 / w-b72d09ef).

Items

  • TDD-first: author failing AOT spec tests on the production path exercising the broad transitive-generic-body-mono shapes — a generic fn whose body calls a trait method / a passed closure / a generic constructor on its own rigid type param, invoked from another generic body with concrete instantiation. Cover the 9 whole-corpus callee clusters at HEAD (assert_eq, transform, create, repeat, empty_queue, thread_id, cb, buffer_pop, repeat_value); confirm each starves as ‘unresolved function X in apply — missing mono instance?’ pre-fix under ./test-all.sh. Classify the Tag::Var-in-JIT-pre-mono (2) + UnresolvedTypeVar (4) residuals against the same transitive-instantiation root or split into a sibling work_item with its own repro.
  • Implement the §01.4-selected fix shape: PREFERRED — resolve nested generic/trait calls per concrete instantiation from Pool.resolutions at the AOT dispatch surface (ori_llvm/src/codegen/arc_emitter/apply.rs resolve_callee -> lookup_mono_dispatch; wire the doc-named mono_instance_id=None fallback gap), matching the §09-proven per-instantiation codegen approach. ALTERNATIVE — a fixpoint body-rewalk worklist alongside collect_mono_functions (ori_llvm/src/monomorphize/mod.rs) walking each recorded MonoFunction’s monomorphized body to collect nested MonoInstances, fed concrete substitutions via body_type_map (ori_types/src/infer/expr/calls/monomorphization.rs). HARD CONSTRAINTS: do NOT touch mangle.rs / nounwind / prepare.rs (the fix changes WHETHER nested calls resolve per-instantiation, never HOW they are named — §09 mangling-contract gate); the recorder-var-mapping fix (resolve_scheme_var) was SUPERSEDED in §09 and is a known dead-end. Nested calls resolve per concrete instantiation; interp==LLVM parity; ORI_CHECK_LEAKS=1 zero leaks.
  • Layer-matrix closure L1-L12 per layer-coverage.md (compiler-scope: L9 dual-exec parity + L10 leak-free legs mandatory). Production-path gate: the whole-corpus ./test-all.log grep -cE ‘missing mono instance|could not map callee var to caller scheme var|Tag::Var in JIT pre-mono|UnresolvedTypeVar’ reads 0 (the §05 FALSE-GREEN trap — focused spec tests passing while the whole-corpus residual persists is NOT done); debug AND release builds; full ./test-all.sh green with no NEW suite ERR/CRASHED vs prior; /tpr-review + /impl-hygiene-review clean over the cure arc.

Fresh intel (regenerated)

{ “schema_version”: 1, “target”: { “kind”: “plan-section”, “ref”: “aot-mono-stdlib-completeness/s-a86e53ac” }, “generated_at”: “2026-06-26T08:38:31.097000+00:00”, “graph_state”: { “head_sha”: “da620829”, “last_code_import_at”: “2026-06-26T08:38:01.168Z”, “embedding_stale”: false, “insights_stale”: false, “cpg_stale”: false }, “surfaces”: {}, “summary”: “intel-package[plan-section:aot-mono-stdlib-completeness/s-a86e53ac] agent-authored dossier”, “degraded”: false, “dossier”: { “objective_symbols”: [], “tiers”: {}, “agent_authored”: true, “constrained_symbols”: [ “resolve_scheme_var”, “extract_indirect_scheme_var”, “mangle_mono_name”, “encode_type”, “encode_args_length_prefixed”, “encode_const_value”, “rewrite_apply_targets_for_monos”, “resolve_mono_target”, “pre_lower_monos_to_arc_cache”, “prepare_mono_cached”, “is_nounwind_call” ], “difficulty”: { “class”: “routine”, “research_online”: false, “research_mode”: “auto”, “signals”: [], “plan_dir”: “/home/eric/projects/ori_lang/plans/aot-mono-stdlib-completeness”

(full dossier: broad-transitive-generic-body-mono-collection—s-a86e53ac.intel.json)