diff --git a/docs/evaluation/results/2026-10-06-p5-0.md b/docs/evaluation/results/2026-10-06-p5-0.md new file mode 100644 index 0000000..8cec7f7 --- /dev/null +++ b/docs/evaluation/results/2026-10-06-p5-0.md @@ -0,0 +1,90 @@ +# 2026-10-06 — P5-0: M/C regression on the frozen Phase 4 (Aji/source) + +Non-normative. This is a regression gate, not evidence for any hypothesis (protocol §39a). M and C are a regression corpus. They decide no semantic question, and the language is not tuned to them. Negative findings are kept (protocol §37). + +The private side was run by a clean-context operator. This repository received only: + +- numbers; +- diagnostic codes and their structured type fields; +- gate names; +- hashes; +- a synthetic reproducer the operator wrote itself. + +## Setup + +- **Matrix:** M, C × Aji/source × 3 native agents, 6 cells. One run per cell, sequential, fresh workspace and HOME. The order was frozen before the first run (order seed 3776241291). +- **Toolchain:** tag `p4-frozen` (`702d69b`). + - AIR bundle sha256 `fa621787…4c88`; + - Source Reference Bundle sha256 `94cfa6a3…424b`; + - the worktree was clean before and after the matrix. +- **Same as P6A-9:** + - task versions (2) and task hashes; + - the evaluator hash; + - agent fingerprints (CLI version, CLI hash, configuration hash); + - limits. + + The plan differs from P6A-9 only in `languages: ["aji_source"]` and the output directory. +- **No journal entries.** No HTTP 429, no re-run, no infrastructure failure. + +## Result + +| Cell (frozen order) | Result | P6A-9 source | +|---|---|---| +| M · N3 | PASS | PASS | +| M · N1 | PASS | PASS | +| M · N2 | PASS | PASS | +| C · N3 | PASS | FAIL (no program; output length limit) | +| C · N2 | PASS | PASS | +| C · N1 | PASS | PASS | + +Total: **6/6**, against 5/6 in P6A-9. + +## Against the gate fixed before the runs (plan, P5-0) + +| Criterion | Result | +|---|---| +| R1: the four Aji references pass on `p4-frozen` | **met**: M and C × AIR and source, each accepted with 8/8 gates | +| R2: no FAIL with a toolchain or evaluator cause | **met**: no FAIL | +| R3: no IR-form code, `E7900` or `E1001` in source cells | **not met, then fixed**: IR-form 0 and `E7900` 0, but `E1001` ×4 in M · N1 (frontend defect A below) | +| R4: codes not seen in P6A-9 source cells | `E2101` ×2 in C · N1: correct verifier feedback on a genuine program error (model), repaired in one cycle. `E1001`: see R3 | +| R5: a P6A-9 PASS now fails | none | +| R6: source/AIR ratio (`mechanical_air_eliminated_raw`) | 0.73–0.85, against 0.77–0.86 for the P6A-9 programs lowered by the same frontend. The spread follows the programs, not the toolchain | + +**Defect A (frontend, `toolchain_bug = yes`).** + +- The bug: a `ref` of an array field reached through a `mut` borrow was lowered as `borrow.field` on the `mut`, then `slice.make`. That gives `slice_mut` where the source said `ref`, and the verifier rejected the `call` with `E1001` (expected `slice`, found `slice_mut`). +- The same `ref` of a scalar field through `mut` was rejected by the frontend with `E7005`, although it is a valid program. +- The agent worked around it by changing the parameter to `slice_mut`. +- Synthetic reproducer (the operator's, unrelated to the tasks): `fn g(s: mut) -> usize { return f(ref s.buf); }` with `f(x: slice)`. +- **Fix:** a `ref` borrow of a place reached through `mut` is now a shared reborrow (`borrow.ref`, spec 07a). Both cases are accepted. +- **Regression test:** `tests/conformance/source/typecheck/ref_through_mut.aji`. It is rejected on `p4-frozen` and runs on the fix. +- This is the same symptom as checkpoint 2 (N1, `E1001` ×4), which led to P6A-12. P6A-12 closed the cast, `slice.copy` and owner cases, not this one. + +## Paired cells (P6A-9 → P5-0, source) + +| Task · agent | output tokens | uncached input | tool calls | repair cycles | seconds | codes in P5-0 | +|---|---|---|---|---|---|---| +| M · N1 | 15.7k → 9.5k | 52.1k → 52.3k | 36 → 23 | 5 → 6 | 703 → 313 | `E1001` ×4, `E7007` ×3, `E7005` ×1 | +| M · N2 | 20.2k → 32.8k | 56.3k → 83.1k | 27 → 44 | 5 → 2 | 375 → 776 | `E7005` ×2 | +| M · N3 | 53.8k → 91.5k | 221.8k → 146.8k | 39 → 88 | 2 → 1 | 2 078 → 2 520 | `E7001` ×1 | +| C · N1 | 11.6k → 14.2k | 52.5k → 46.8k | 27 → 28 | 4 → 5 | 475 → 429 | `E2101` ×2, `E7005` ×1 | +| C · N2 | 18.2k → 20.7k | 53.3k → 57.4k | 20 → 22 | 1 → 1 | 269 → 387 | `E7007` ×1 | +| C · N3 | 41.0k (no program) → 56.3k | — → 171.6k | 15 → 39 | — → 0 | 1 086 → 1 369 | none | + +These columns are reported only. With one run per cell they are noise. + +The Quick Reference grew by about 550 tokens with §7 Graphs (`quick_reference_unique` 3 568 → 4 123), so the documentation columns are not comparable one to one. + +## Harness notes + +- `ajieval checkpoint` lowers both sides with the current toolchain. The P6A-9 programs were re-lowered here with `p4-frozen`, so their ratios differ from the values recorded in the P6A-9 results. +- The operator's first report named the two private task ids. The names were not copied anywhere in this repository. + +## Verdict + +To be decided by the owner. On the facts: + +- R1, R2 and R5 are met. +- R3 found one frontend regression class, now fixed with a regression test. +- R4 is a model error. +- R6 shows no toolchain growth. diff --git a/docs/plan/phase-5-atomics-and-memory-model.md b/docs/plan/phase-5-atomics-and-memory-model.md index 53c1aa6..6038435 100644 --- a/docs/plan/phase-5-atomics-and-memory-model.md +++ b/docs/plan/phase-5-atomics-and-memory-model.md @@ -53,7 +53,7 @@ Phase 4 commit frozen (tag p4-frozen) | ID | Status | Task | Depends | Output | Done when | |---|---|---|---|---|---| -| P5-0 | todo | M/C regression on the frozen Phase 4 commit (tag `p4-frozen`): M, C × Aji/source × N1–N3, 6 cells, same agents, tasks, evaluators and procedure as P6A-9 | — | `docs/evaluation/results/` | see "Regression gate" below | +| P5-0 | done (gate: owner verdict pending) | M/C regression on the frozen Phase 4 commit (tag `p4-frozen`): M, C × Aji/source × N1–N3, 6 cells, same agents, tasks, evaluators and procedure as P6A-9 | — | [`docs/evaluation/results/2026-10-06-p5-0.md`](../evaluation/results/2026-10-06-p5-0.md) | see "Regression gate" below; 6/6 PASS; R3 found frontend defect A (`ref` through `mut`), fixed with a regression test | | P5-1 | done | RFC 0015: scalar atomics and the Aji memory model (supersedes RFC 0003); closes the owner's question list; resolves Q-015; scope of Q-017 | — | `docs/rfcs/0015-…` | Accepted by the owner and integrated into spec 04, 05, 07a, 11, 15 | | P5-1a | todo | Litmus enumerator `tools/litmus` (an executable oracle derived from spec 04 §20, not the definition) and the normative corpus: the classes MP, SB, LB, release/acquire publication, `seq_cst` ordering (IRIW, SB with `seq_cst`), relaxed counter, CAS success/failure, fence publication, forbidden non-atomic race, atomic/non-atomic mixing, plus the handoffs (mutex, channel, spawn/join). Each test has allowed and forbidden outcome sets | P5-1 | `tools/litmus/`, `reference/concurrency-litmus.md`, `tests/litmus/` | the enumerator's allowed set equals every stated set, disagreements diagnosed (spec 04 §20.5); owner review | | P5-2 | done | Contract tables: `atomic.new`, `atomic.take`, `atomic.load`, `atomic.store`, RMW, `atomic.cmpxchg`, `atomic.fence` | P5-1 | spec 04 §42, spec 07a | all spec 07 §4 fields present, with the ordering tables of spec 04 §24 (integrated with RFC 0015) | diff --git a/src/frontend/lower.zig b/src/frontend/lower.zig index e651cd0..c598a7a 100644 --- a/src/frontend/lower.zig +++ b/src/frontend/lower.zig @@ -1863,6 +1863,13 @@ const Lowerer = struct { /// returned as is (`ends` empty). fn placeBorrow(l: *Lowerer, place: ast.Expr, mutable: bool, want_slice: bool, span: Span) Error!Placed { var p = try l.placeRaw(place, mutable, span); + // `ref place` reached through a `mut` borrow (`ref s.buf` with + // `s: mut`) is a shared reborrow of it (spec 07a `borrow.ref`). + if (want_slice and !mutable and (p.v.ty == .mut or p.v.ty == .slice_mut)) { + const t = if (p.v.ty == .mut) try l.wrap(.ref, p.v.ty.inner().?) else try l.wrap(.slice, p.v.ty.inner().?); + const r = try l.def("r", t, try l.fmt("borrow.ref %{s}", .{p.v.name}), span); + p = .{ .v = r, .ends = try l.concat(p.ends, r.name) }; + } if (want_slice and (p.v.ty == .ref or p.v.ty == .mut) and p.v.ty.inner().? == .array) { const elem = p.v.ty.inner().?.array.elem; const sl = try l.def("s", (if (mutable) try l.wrap(.slice_mut, elem) else try l.wrap(.slice, elem)), try l.fmt("slice.make %{s}", .{p.v.name}), span); diff --git a/tests/conformance/source/typecheck/ref_through_mut.aji b/tests/conformance/source/typecheck/ref_through_mut.aji new file mode 100644 index 0000000..b5c0869 --- /dev/null +++ b/tests/conformance/source/typecheck/ref_through_mut.aji @@ -0,0 +1,49 @@ +// `ref` of a field reached through a `mut` borrow is a shared reborrow: a scalar +// field gives ref, an array field a slice (P5-0 regression: it was lowered +// as slice_mut and reached the verifier as E1001). +// expect: run +// result: 13 +// phase: 6 +// spec: docs/spec/15-source-language.md +module demo.ref_through_mut + +struct S { + n: usize, + buf: [u8; 4], +} + +fn total(x: slice) -> usize +effects [] +{ + var sum: usize = 0; + var i: usize = 0; + while i < x.len { + sum = sum + (x[i] as! usize); + i = i + 1; + } + sum +} + +fn read(x: ref) -> usize +effects [] +{ + *x +} + +fn both(s: mut) -> usize +effects [] +{ + s.buf[1] = 7u8; + let a = read(ref s.n); + let b = total(ref s.buf); + let c = total(ref s.buf[1..3]); + a + b + c - 7 +} + +fn main() -> usize +effects [] +{ + var s: S = zero; + s.n = 6; + both(mut s) +}