§08 Derived Default + Prelude min/max Builtin Mono Crash
§08.0 Discovered Work Context
| Field | Value |
|---|
| Discovery date | 2026-05-16 (via ./test-all.sh baseline run; spec-LLVM suite CRASHED) |
Routing case (per routing.md §3) | (b) Independently-workable in plan’s bounded context |
| Insertion ordering | inserts_before: 07 — lands before close-out; sibling to §02/§03/§04/§05 (all collect_mono_functions cure-surface siblings) |
| Failures absorbed | Unknown count (spec-LLVM suite ABORTED before reporting full results); minimum 4× (_ori_expr_default + _ori_complex_default + min warnings × 2 + max warnings × 2) + cascading double-free + all subsequent spec-LLVM tests that would have run after the abort point |
Crash surface evidence (from compiler_repo/test-all.log) | Incorrect number of arguments passed to called function: %call = call fastcc i64 @_ori_expr_default() (LLVM verifier rejection); ORI_AUDIT_STRICT would have surfaced earlier per compiler.md §Tracing |
| LLVM verifier failure sites | compiler/ori_llvm/src/codegen/function_compiler/define_phase.rs name="test_expr_default_used" + name="test_complex_default" (verbatim from log: ArcIrEmitter: variable not yet defined var=2, var=3) |
insert_value malformed-aggregate site | compiler/ori_llvm/src/codegen/ir_builder/aggregates.rs — insert_value on non-struct value (index 0); raw_agg i8 0 produced upstream of insert_value, type resolution wrong layout |
§08.1 Mission
Three coordinated cures, each on the shared collect_mono_functions / builtin-sig surface:
| Cure | Subsystem | Surface |
|---|
Default derive method monomorphization | derived-method emission + collect_mono_functions MonoInstance registration | compiler/ori_arc/src/lower/derives/ or compiler/ori_llvm/src/codegen/derive_codegen.rs (path confirmed during §08.3.0); MonoInstance emission for Default::default(self) -> Self instances |
Default::default aggregate-build layout | LLVM IR builder for derived-method body emission | compiler/ori_llvm/src/codegen/ir_builder/aggregates.rs insert_value path; ensure raw_agg is StructValue, not IntValue { llvm_value: "i8 0" } |
min + max prelude builtin Apply mono registration | sibling-shape to §05’s __cast cure; extend builtin_sigs | compiler/ori_ir/src/builtin_constants/protocol/mod.rs canonical builtin-sig list extended with min, max; collect_mono_functions::builtin_sigs parameter consumed in BOTH JIT (evaluator/compile.rs:230) AND AOT (codegen_pipeline/mod.rs:138) call sites per §05’s pattern |
§08.2 Why These Three Crashes Share a Section
| Coupling | Argument |
|---|
| Shared cure surface | All three resolve at collect_mono_functions / builtin-sig extension — same architectural seam §02/§03/§04/§05 already extend |
| Shared crash chain | RC double-free at the end of the crash log is DOWNSTREAM of items (1)-(3); RC realization runs on malformed IR from the missing-mono + wrong-aggregate paths. Fix the IR; the double-free disappears (or is exposed as a residual to be filed separately). |
| Shared test trigger | Spec-LLVM suite exercises monomorphization paths the existing AOT integration tests don’t hit (specifically: Default derive monomorphization + prelude min/max in generic bodies). Per CLAUDE.md §Tests That Expose Bugs = Bugs Found, the spec-LLVM crash IS the discovery; the cure encompasses everything between symptom and root cause. |
Per routing.md §4 independence test | This work could promote to a sibling plan IF it didn’t share cure surface with §02-§05. Since it does, absorption is correct per routing.md §3 case (b). |
§08.3 Implementation Sketch
| Phase | Description | Files touched |
|---|
| §08.3.0 Discovery | Read compiler_repo/test-all.log LLVM-spec section verbatim; map the crash chain _ori_expr_default arg mismatch → insert_value on non-struct → min/max missing-mono → ori_rc_dec double-free. Inventory compiler/ori_arc/src/lower/derives/ + compiler/ori_llvm/src/codegen/derive_codegen.rs for the Default::default emission site. Confirm which file owns the MonoInstance emission for derived Default. | All paths above (Read only) |
| §08.3.1 TDD matrix author | Author failing tests in compiler/ori_llvm/tests/aot/derives.rs (or sibling) covering Default derive arg-count matrix + nested-struct aggregates + generic-T: Default. Author failing tests in compiler/ori_llvm/tests/aot/builtin_mono.rs (or sibling) covering min/max in generic bodies. RED state before §08.3.2/§08.3.3/§08.3.4 land. | compiler/ori_llvm/tests/aot/derives.rs, compiler/ori_llvm/tests/aot/builtin_mono.rs (new file or extension) |
| §08.3.2 Default mono cure | Extend collect_mono_functions (or the derived-method MonoInstance emission path) to register Default::default instances. Ensure the monomorphized call site’s LLVM signature matches the emitted function’s signature. | compiler/ori_arc/src/lower/derives/ (or compiler/ori_llvm/src/codegen/derive_codegen.rs); compiler/ori_llvm/src/monomorphize/mod.rs |
| §08.3.3 Aggregate-layout cure | Fix the insert_value raw_agg type resolution so monomorphized Default::default produces a StructValue aggregate before field insertions, NOT IntValue { llvm_value: "i8 0" }. Likely an ori_repr::ReprPlan consultation missing or wrong at the derived-method synth site. | compiler/ori_llvm/src/codegen/ir_builder/aggregates.rs; compiler/ori_llvm/src/codegen/derive_codegen.rs |
| §08.3.4 Min/Max builtin-sig cure | Add min + max to canonical builtin-sig list (compiler/ori_ir/src/builtin_constants/protocol/mod.rs); extend collect_mono_functions::builtin_sigs consumption to pick them up; mirror §05’s __cast wiring at both JIT + AOT call sites. | compiler/ori_ir/src/builtin_constants/protocol/mod.rs; compiler/ori_llvm/src/monomorphize/mod.rs; compiler/ori_llvm/src/evaluator/compile.rs:230 (JIT); compiler/oric/src/commands/codegen_pipeline/mod.rs (AOT) |
| §08.3.5 RC double-free verification | Re-run ORI_CHECK_LEAKS=1 cargo st post-fixes; confirm double-free disappears (downstream cure) OR file /add-bug for residual. | None (verification only) |
| §08.3.6 Verification | timeout 150 ./test-all.sh clean in debug + release; dual-exec parity clean; /tpr-review + /impl-hygiene-review clean. | — |
08.4 Implementation Items
- §08.3.0 Discovery: read
compiler_repo/test-all.log LLVM-spec section verbatim; map the crash chain end-to-end; inventory the derive_codegen + builtin_constants/protocol surfaces.
- §08.3.1.a TDD matrix author (Default derive positive pins): write failing AOT tests covering struct/nested/generic
Default derive instances. RED state before §08.3.2 lands.
- §08.3.1.b TDD matrix author (Default derive negative pins): write tests asserting
#[derive(Default)] on a struct with a non-Default field is rejected at typeck-time per E2029 family (regression guard that the cure does not weaken derive validation).
- §08.3.1.c TDD matrix author (min/max in generic bodies): write failing AOT tests covering
@f<T: Comparable>(a: T, b: T) -> T = min(a, b) + max variants on int/float/str. RED state before §08.3.4 lands.
- §08.3.2 Default mono cure: extend MonoInstance emission for
Default::default; arg-count matches between emitted fn signature and call sites. §08.3.1.a tests flip RED → GREEN.
- §08.3.3 Aggregate-layout cure: fix
insert_value raw_agg path so derived Default::default produces correct StructValue. LLVM verifier accepts the emitted IR.
- §08.3.4 Min/Max builtin-sig cure: extend canonical builtin-sig list + JIT + AOT consumption per §05’s
__cast pattern. §08.3.1.c tests flip RED → GREEN.
- §08.3.5 RC double-free verification:
ORI_CHECK_LEAKS=1 cargo st clean; if residual double-free, /add-bug (separate tracker entry since no longer downstream).
- §08.3.6 Spec sweep:
timeout 150 cargo st produces actual count totals (no longer CRASHED).
- §08.3.7 Dual-execution parity:
timeout 150 diagnostics/dual-exec-verify.sh --json | jq '.per_test[] | select(.parity_status != "match")' empty.
- §08.3.8 Cross-coverage with sibling sections:
cargo test --release -p ori_llvm --test aot poly_lambda_mono (§02) + generics::test_generic_method_on_generic_type (§03) + test_option_complex_arg_unwrap (§04) + generics::test_borrow_list_int_* (§05) all remain green (regression guard that §08 cure doesn’t perturb sibling mono surfaces).
- §08.3.R
/tpr-review on §08 diff returns clean across codex + gemini + opencode.
- §08.3.N
/impl-hygiene-review on §08 diff returns clean after TPR.
- §08.3.Close flip
status: → complete via the atomic-flip API per state-discipline.md §4.
§08.5 Banned Approaches
- Reverting
e186e2754 or any post-2026-05-14 commit to “make the spec-LLVM suite stop crashing” — banned. Each post-2026-05-14 commit landed substantive work (burden-dec variant-walk, LLVM drop_enum dispatch, etc.); the crash is a NEW monomorphization gap exposed by the spec-LLVM test corpus, not a regression of those commits.
- Adding
#[ignore] markers to the crashing spec-LLVM tests — banned per routing.md §2 + test-disposition.md. The crash IS the discovery; the cure is the deliverable.
- Filing
min/max mono as separate BUG-XX-NNN entries instead of absorbing here — banned per routing.md §3 case (b); shared cure surface with §05 (__cast already absorbed into aot-mono-completeness umbrella) means absorption is correct.
- “It’s just a verifier warning, let it through” — banned per CLAUDE.md §The One Rule. LLVM verifier rejection is a correctness signal, not noise.
- “The double-free is a separate AIMS bug” — banned at §08 close-out. Verify item §08.3.5 first; only file separate if confirmed residual.
§08.6 References
compiler_repo/test-all.log — 2026-05-16 baseline; LLVM-spec section carries the crash chain verbatim
compiler/ori_llvm/src/codegen/function_compiler/define_phase.rs — site of name="test_expr_default_used" + name="test_complex_default" verifier rejections
compiler/ori_llvm/src/codegen/ir_builder/aggregates.rs — insert_value on non-struct value site
compiler/ori_llvm/src/codegen/arc_emitter/apply.rs — unresolved function 'min'/'max' in apply — missing mono instance? warning site
compiler/ori_llvm/src/codegen/arc_emitter/terminators.rs — sibling unresolved function in invoke warning site (same root cause)
compiler/ori_arc/src/lower/derives/ + compiler/ori_llvm/src/codegen/derive_codegen.rs — Default::default emission (path to be confirmed during §08.3.0)
compiler/ori_ir/src/builtin_constants/protocol/mod.rs — canonical builtin-sig list (extension target for min + max)
compiler/ori_llvm/src/monomorphize/mod.rs:71 — collect_mono_functions (cure surface shared with §02/§03/§04/§05)
compiler/ori_llvm/src/evaluator/compile.rs:230 — JIT call site (mirror cure consumer per §05’s pattern)
compiler/oric/src/commands/codegen_pipeline/mod.rs:138 — AOT call site (mirror cure consumer per §05’s pattern)
section-05-builtin-apply-mono.md — sibling section (BUG-04-114 __cast cure; §08 extends pattern to min + max)
- CLAUDE.md §Adding a Derived Trait (8-point sync checklist for derived trait work; cross-check §08.3.2 + §08.3.3 against the checklist)
- CLAUDE.md §Derived Trait Sync — DO NOT (banned shapes for derived-trait modifications)
Intelligence Reconnaissance
Date: 2026-05-16. Graph: HEAD be3a7ba.
- [ori:compiler/ori_llvm/src/codegen/derive_codegen.rs]
scripts/intel-query.sh file-symbols compiler/ori_llvm/src/codegen/derive_codegen.rs --repo ori — discovery surface for Default::default emission (run during §08.3.0).
- [ori:compiler/ori_llvm/src/codegen/ir_builder/aggregates.rs]
scripts/intel-query.sh file-symbols compiler/ori_llvm/src/codegen/ir_builder/aggregates.rs --repo ori — discovery surface for insert_value raw_agg path.
- [ori:compiler/ori_ir/src/builtin_constants/protocol/]
scripts/intel-query.sh file-symbols compiler/ori_ir/src/builtin_constants/protocol/ --repo ori — discovery surface for canonical builtin-sig list (extension target for min + max).
- [ori]
scripts/intel-query.sh callers collect_mono_functions --repo ori — sibling-section consumers (§02/§03/§04/§05 cure surfaces; §08 mirrors their wiring).
- CPG queries on the post-
e186e2754 partial_move + post-burden_dec emission surfaces return empty until intel-query.sh refresh --code runs against current HEAD; §08 production work consumes graph state via direct Read at execution-time per plan-read-discipline.md §3.1.
HISTORY
- 2026-05-16 — Section created via
/create-plan --inline inline-insertion: LLVM-spec backend test suite CRASHED during 2026-05-16 baseline ./test-all.sh run. Crash chain (verbatim from test-all.log): (1) LLVM verifier rejected _ori_expr_default + _ori_complex_default for arg-count mismatch; (2) insert_value on non-struct value on monomorphized defaults (raw_agg i8 0 where struct expected); (3) min/max apply targets logged “missing mono instance?” warnings (4 occurrences); (4) downstream ori_rc_dec double-free aborted the suite. All three crashes share collect_mono_functions / builtin-sig cure surface with §02/§03/§04/§05; routed via /create-plan --inline aot-mono-completeness per routing.md §3 case (b). Section absorbs the crash cluster as a sibling work-section before §07 close-out.