diag: add stable source reasons and diagnostic incidence reporting

This commit is contained in:
dev committed 2026-10-07 18:52:36 +03:00
1 parent 911982dd1c
commit dbd9763713
21 files changed
+571 -156

No files matched your search

+2
View File
@@ -144,3 +144,5 @@ RFC 0036 review fixes clarify reserved task borrow returns and known array bound
P6-8 source formatter (cl100k): Quick Reference 8,688 → 8,728 (+40), other source docs 64,214 → 64,677 (+463), full source 72,902 → 73,405 (+0.69%). language/tooling.md is 3,051 tokens. o200k groups are 8,763 / 64,876 / 73,639; Qwen2.5 8,994 / 66,259 / 75,253. AIR stays 179,282 bytes / 46,300 cl100k tokens, and library/std.md stays unchanged. One command with check/write modes reduces whitespace repair and diff noise while preserving tokens, comments and canonical AIR; it adds no language concept, feature, verifier/runtime state or diagnostic code. No empirical MCC benefit is claimed.
Q-040 block boundaries (DD-016, cl100k): Quick Reference 8,728 → 8,769 (+41), other source docs 64,677 → 65,012 (+335), full source 73,405 → 73,781 (+0.51%). o200k groups are 8,805 / 65,212 / 74,017; Qwen2.5 9,037 / 66,603 / 75,640. AIR and library/std.md are unchanged. One syntactic boundary rule and an explicit-discard guard replace an ambiguity; there is no new syntax form, diagnostic code or verifier/runtime state. No empirical MCC benefit is claimed.
DD-017 stable E7006 reasons (cl100k): Quick Reference 8,769 → 8,807 (+38), other source docs 65,012 → 65,799 (+787), full source 73,781 → 74,606 (+1.12%). o200k groups are 8,843 / 66,001 / 74,844; Qwen2.5 9,077 / 67,402 / 76,479. AIR grows 46,300 → 46,937 (+637, +1.38%), 179,282 → 182,254 bytes, because the shared diagnostic registry includes the 28 source categories. library/std.md is unchanged. One structured discriminator replaces prose classification; there is no new code, programming syntax, verifier/runtime state or repair application. Historical reasons remain unknown. No empirical MCC benefit is claimed.
+1
View File
@@ -317,6 +317,7 @@ scope s { // every task spawned in s must
| E2001, E3001, E2002 | used after move / after consume / twice | restructure so each linear value is consumed once on every path |
| E3002 | linear value leaked | consume it (close, free, take, join, send) on every path, including `return` |
| E3101 | effect not declared | copy `suggested_effects` into `effects [...]` |
| E7006 | invalid source construct | inspect stable `reason`; `move_copy` means an explicit move of a Copy value, `move_borrow` a move of a borrow |
| E3201 | wrong capability kind | pass the right `cap<K>` |
| E4001, E4002 | not Send / not Share | move owned data into tasks; share only `Share` data by `ref` |
| E4101 | data race with a task | lend disjoint parts (`split_at`, fields) or join first |
+6
View File
@@ -95,3 +95,9 @@ Spec 15 §4 and the grammar resolve Q-040 syntactically: leading bare `if`, `mat
Reason: `if true { *p = 2u64; } *p = 3u64;` must denote two statements regardless of spacing. Greedy expression parsing consumed multiplication instead. Merely splitting would silently change `{2i64} -3i64` from −1 to −3; rejecting the undiscarded value avoids that change. Neither line-sensitive syntax nor assignment lookahead is needed. This is a small grammar decision, not a new AIR facility.
Compatibility: formerly accepted bare continuations in statement/tail position require parentheses around the initial construct. Formerly accepted value-producing bare block statements require explicit `;`, including mixed branches such as `if c { return 1u64; } else { 2u64 }` before another statement. Existing tails, explicit discards and initializer/return/argument/condition/expression-arm continuations retain their meanings. Ownership, lexical borrow ends, verifier transfers and deterministic runtime rules are unchanged. A borrow bound inside a preceding block remains inaccessible afterwards (E7002); aliasing and task rules still come from the existing verifier. No new diagnostic code, source syntax form, feature or verifier/runtime state is added. One frontend statement marker enforces the value guard and gives the formatter an explicit boundary; it never changes tokens or inserts separators. No empirical Model Capability Compression benefit is claimed; source documentation growth is measured in docs/agent/README.md.
## DD-017 — Stable E7006 reasons before repair-frequency analysis
Spec 15 §10 requires a registered reason on each E7006. Frontend rejection sites select an enum category explicitly; `move_copy` excludes borrowed and non-materializable operands. ajieval groups observed codes/reasons per run and reports unknown historical reasons separately, without reading message prose. Existing code counts remain compatible; missing logs are unavailable evidence. Counts describe observed command outputs, not the true frequency of all errors.
Reason: a shared code cannot establish whether Copy moves occur often enough to justify RFC 0038. Structured categories also let an agent choose the appropriate rule without classifying prose. This small diagnostic schema extension uses a decision record and a P6-7 plan increment; no new rejection, code, source/AIR syntax, verifier/runtime state or repair application is introduced. Existing locations, payloads, interpreter records, resource/borrow invariants and frozen evaluation inputs remain intact. Enum/registry and CLI/report tests cover serialization, generic/package propagation and historical uncertainty. Bundle growth is recorded in docs/agent/README.md. RFC 0038 remains Proposed with its existing recommendation to defer pending frequency and application-usability data.
+7
View File
@@ -33,6 +33,7 @@ Status values: `open`, `resolved`.
| Q-036 | resolved | STD-6a | Dynamic initialized linear buffer storage and drain |
| Q-038 | resolved | STD-6d.2 | Pure construction of built-in errors |
| Q-039 | resolved | STD-6d | Explicit static function parameters |
| Q-041 | open | P6-2 task block forms | Source scope-handle value bindings |
## Q-001 — Text AIR grammar
@@ -297,3 +298,9 @@ General collections and algorithms need explicit typed hash/equality/order opera
P6-8 review found an existing parser ambiguity: `if true { *p = 2u64; } *p = *p + 1u64;` is consumed as an expression continued by multiplication and then rejects E7006 at the assignment. The same failure is reproduced after a standalone block or `match`; `while` dispatches separately and is not affected. Source whitespace is insignificant; spec 15 §4 and the grammar admit both block statements and expressions beginning with block/control-flow forms. The intended disambiguation must be specified before changing which previously parsed expressions are accepted. Decide how a standalone block statement ends before a dereference/other unary-leading statement while preserving block-valued expressions in explicit expression contexts. Add positive/rejected parser and lowering cases for the chosen rule. The formatter preserves the current tokens/AST and MUST NOT insert semicolons or infer the intended statement boundary. This question is separate from P6-8.
**Resolved (DD-016, spec 15 §4):** leading bare `if`, `match` and `{…}` in statement/tail position stop before outer expression operations. The next `}` selects a tail, `;` an explicit discard, otherwise a block statement must yield `void` or diverge (E7006). Parentheses permit continuation; nested expression contexts retain ordinary parsing. The value guard prevents silent reinterpretation of former expressions such as `{2i64} -3i64`. Parser, lowering, formatter and source conformance cover the boundary and compatibility rules. This resolves one P6-1/P6-2 ambiguity, not the complete grammar tasks.
## Q-041 — Source scope-handle value bindings
Independent E7006 review found that `module scope_move fn main()->u64 effects [] { scope sc { let alias = move sc; } 42u64 }` checks and returns 42 with fuel 10,000. Its AIR contains only `task.scope.begin` and `task.scope.end` on the same SSA value; the unused alias introduces no instruction. This observation alone establishes no memory/concurrency safety defect. Spec 15 §3 excludes `scope` from source type spellings, §7 ties scope completion to the block, and spec 04 §33 permits function-local scope flow while preserving linear completion. They do not explicitly say which ordinary source value-binding forms may name that internal handle or how an explicit transfer interacts with the block's retained completion obligation.
Clarify whether `let`/`move` aliases and rebinding of a scope name are permitted, how their availability relates to the originating block, and which existing diagnostic applies to rejected forms. Keep AIR scope identity, live-child/loan checks, deterministic completion and the no-escape invariant intact; add source acceptance/rejection tests for the chosen contract before changing lowering. This is separate from DD-017's reason field and RFC 0038's proposed repairs; neither adopts a new scope rule.
+3 -3
View File
@@ -182,16 +182,16 @@ Updated count after RFC review: **1 concrete RFC candidate** (C5), **1 deferred
RFC 0038 is therefore retained with a recommendation to defer work, preserving formal Proposed status. Its byte offsets and file hash identify an exact edit for a programmatic applicator, but `expected: "[]"` does not identify a unique string replacement. Context plus edit line/column, or an explicitly invoked application command, remain design alternatives rather than adopted fixes. Resume review only after aggregate eligible per-run incidence with a defined denominator, evidence of material repair cost, and validation of the actual application workflow. No arbitrary N% is set from these reports; any owner-selected threshold and minimum sample size must precede a new cohort's evaluation. M/C may only check regression and cannot select or tune the feature. Frozen evaluation inputs remain untouched.
**Independent measurement prerequisite: stable E7006 reasons.** Current frontend E7006 diagnostics do not provide a stable `reason` discriminator. The move rejection in [lower.zig](../../src/frontend/lower.zig) exposes `name`/`type`, but the same rejection site can cover Copy values and other non-linear forms, and E7006 also covers unrelated constructs across frontend stages. Parsing `message` would violate the machine-readable intent of spec 14 §3.5 and cannot supply a reliable Copy-move incidence metric.
**Independent measurement prerequisite: stable E7006 reasons.** At the review baseline, frontend E7006 diagnostics did not provide a stable `reason` discriminator. The move rejection in [lower.zig](../../src/frontend/lower.zig) exposes `name`/`type`, but the same rejection site can cover Copy values and other non-linear forms, and E7006 also covers unrelated constructs across frontend stages. Parsing `message` would violate the machine-readable intent of spec 14 §3.5 and cannot supply a reliable Copy-move incidence metric.
Record a separate diagnostic-schema task, independent of RFC 0038's edits or application workflow, for owner routing to a plan task or RFC. Its proposed completion conditions are:
The review proposed a separate diagnostic-schema task, independent of RFC 0038's edits or application workflow, with these completion conditions:
- Specify stable `reason` values and coverage in spec/reference, distinguishing Copy-move rejection from borrowed/non-Copy moves and other covered invalid constructs. Keep E7006's code/kind and the language's accepted/rejected sets unchanged.
- Emit reasons from explicit frontend error classification, not message parsing or simply assigning one reason to every use of the shared code. Check JSON serialization, original source provenance and positive/negative examples for each specified reason; valid generic Copy transfer remains accepted.
- Keep missing/unclassified reasons explicitly unknown in measurements. Do not relabel historical records or infer their reasons from prose; adding fields to future runs does not recover old data.
- Separately extend evaluation reporting to aggregate affected source runs by `(code, reason)`, alongside existing code counts, with the agreed denominator/cutoff. Merely adding `reason` does not change `_diagnostic_codes`, which currently counts codes only. Both changes must precede the relevant future experiment's freeze.
The reason field improves machine repairability on its own; the reporting follow-up enables the Copy-move branch of 0038's evidence condition. E3101's code-level incidence can already be counted without this prerequisite. No task ID, implementation, new reason name or diagnostic-schema adoption is assigned by this assessment; the owner decides routing and scope.
The reason field improves machine repairability on its own; the reporting follow-up enables the Copy-move branch of 0038's evidence condition. E3101's code-level incidence can already be counted without this prerequisite. The assessment itself assigned no implementation or adoption. Subsequent language work implements the independent schema/reporting increment under [DD-017](decisions.md#dd-017--stable-e7006-reasons-before-repair-frequency-analysis) and [P6-7](../plan/phase-6-source-language.md): every E7006 has a registered reason, and ajieval reports observed occurrences and affected runs with unknown reasons/log availability retained. Code totals are unchanged. The reporting covers the entire recorded transcript; a future cohort must still specify its pre-acceptance cutoff, agent/toolchain strata and missing-data policy. No new experiment, repair-cost evidence or application-usability result is supplied; RFC 0038 remains Proposed with the deferral recommendation.
### C2 — Diagnostic statistics
+2
View File
@@ -47,3 +47,5 @@ Every run test is executed twice by the runner from P0-12 onward and the outputs
## Diagnostics as API
Diagnostic JSON is a stable interface. Snapshot tests on the full JSON (not only the code) belong in unit tests next to the pass that emits them, so field renames are caught.
`python3 tests/hosted/source_diagnostic_reasons.py` checks stable E7006 categories, generic/package propagation and serialization. From `tools/eval`, `python3 -m unittest discover tests` checks reporting alongside the harness. `ajieval summary` reports observed `(code, reason)` occurrences and affected runs with log coverage; `profile` and `checkpoint` expose per-run pairs. Existing compact code extraction is preserved. Only whole JSON diagnostic lines classify a reason: unparsed or historical records remain unknown; new reason strings are retained. Missing logs are unavailable. These counts cover the recorded command outputs, not a pre-acceptance cutoff or the true frequency of unobserved errors; future cohort methodology must specify those separately.
+8
View File
@@ -162,3 +162,11 @@ Validation: unit tests and Zig formatting pass, including 10,000-term expression
Q-040 is resolved in spec 15 §4 and the grammar (DD-016): leading bare `if`, `match` and `{…}` finish before outer expression operations in statement/tail position. The enclosing `}` selects a tail, `;` an explicit discard, otherwise a block statement must yield `void` or diverge. This E7006 guard prevents silent reinterpretation of former expressions such as `{2i64} -3i64`; parenthesized continuations and nested expression contexts remain available. The parser marks block statements, ordinary/generic lowering checks the guard, and the formatter derives line boundaries from statement spans. No AIR feature, diagnostic code or verifier/runtime state is added. P6-1/P6-2 remain open for the rest of their grammar work.
Validation: full conformance passes 1,154/1,154 with no failures or pending tests, including 19 focused source cases covering stores, other unary starts, tails, explicit contexts/discards, generic bodies, mixed diverging/value branches and lexical borrow ends. Unit tests, Zig formatting, bundle/example checks and 120/120 construct coverage pass. The formatter/CLI suite passes 3,267 checks over 872 public files: 860 parse idempotently, 12 syntax-error fixtures reject with E7001, and 557 successful lowerings preserve byte-identical AIR. A before/after comparison over the original 853 public files finds no exit-code changes and identical AIR for all 548 successful lowerings. Independent read-only review by Claude found the silent value-discard risk in the initial design; the guard fixes it, and final review found no remaining issues. Budgets are recorded in docs/agent/README.md; frozen evaluation inputs are unchanged.
## P6-7 E7006 reason increment (2026-10-07)
DD-017/spec 15 §10 registers 28 stable E7006 categories, explicitly selected at all 130 frontend rejection sites. Borrowed and non-materializable moves cannot be counted as `move_copy`; permitted generic Copy transfers remain accepted. The compiler rejects future unclassified E7006 emissions at compilation. The JSON field follows existing code-specific fields, retaining their values, positions and messages. No code, rejection rule, language/AIR syntax or verifier/runtime state changes. P6-7 remains open for its source-span/twin requirements.
ajieval summary adds occurrences and affected runs by `(code, reason)`, with log availability; profile/checkpoint expose per-run counts. Code totals and the historical compact-code extraction stay intact. Whole JSON records provide reasons; historical, malformed or unparsed records remain unknown and missing logs remain unavailable. These are observed outputs over the entire transcript, without a pre-acceptance cutoff; they do not establish repair cost or justify implementing RFC 0038. New cohort timing, strata and missing-data policy remain evaluation decisions. Frozen evaluation inputs and historical records are unchanged.
Validation: full conformance passes 1,154/1,154; CLI passes 130 checks including 72 public E7006 fixtures, generic/package cases, deterministic serialization and non-E7006 preservation. A comparison over 872 public files finds no changes beyond the new reason: all 557 accepted AIR outputs and every original diagnostic payload remain identical. The 26 ajieval self-tests pass (one environment skip), including historical uncertainty, unknown future reasons, native transcripts, code-total conservation, run incidence and checkpoint JSON. Independent read-only review by Claude found no defects in the extension; its registry-scope suggestion was incorporated. Bundle growth is recorded in docs/agent/README.md. This completes the independent instrumentation prerequisite, not RFC 0038 or Phase 6.
+36 -1
View File
@@ -91,7 +91,7 @@ Only problems that exist because of the frontend. Everything the verifier decide
| E7003 | source.missing_move | Named linear value consumed without `move` |
| E7004 | source.not_exhaustive | `match` misses an outcome, variant or default |
| E7005 | source.type_mismatch | Expression has the wrong type in a source position |
| E7006 | source.invalid_construct | Construct not allowed here |
| E7006 | source.invalid_construct | Construct not allowed here; stable `reason` below |
| E7007 | source.ambiguous | Source meaning cannot be determined |
| E7900 | source.internal_compiler_error | The frontend produced invalid AIR for this construct: a compiler bug, not a program error; fields `air_code`, `air_message` |
@@ -111,3 +111,38 @@ Reported in trap records (spec 01 §6), not by the verifier.
| T0008 | trap.out_of_bounds | Runtime bounds check failed |
| T0009 | trap.unsafe_precondition | Unsafe precondition violated (detected) |
| T0010 | trap.foreign_iref | An `iref` was used to access a graph it does not belong to |
## E7006 reasons
These stable categories are part of the diagnostic API (spec 15 §10), not new rejection rules. One reason is selected at the rejection site; messages remain optional explanation.
| Reason | Meaning |
|---|---|
| `move_copy` | Explicit move of a plain Copy value; excludes borrows, void and never. |
| `move_borrow` | Explicit move of a borrow/view. |
| `invalid_move` | Move operand is void or never, rather than a materializable value. |
| `loop_control_outside_loop` | break or continue without an enclosing loop. |
| `zero_not_zeroable` | zero initialization of a type without a zero value. |
| `value_block_statement` | A bare block statement would implicitly discard a non-void value. |
| `unreachable` | Statement or expression after unconditional divergence. |
| `missing_return` | A value-returning function can fall through without a value. |
| `invalid_borrow` | A borrow requires an explicit binding, mode, named parent or argument form. |
| `invalid_borrow_return` | A borrow return violates source origin, binding, return or worker restrictions. |
| `duplicate_declaration` | Duplicate type, function, field, variant or parameter declaration. |
| `invalid_declaration` | An otherwise disallowed declaration shape, such as an empty enum. |
| `invalid_binding` | Invalid binding shape, rebinding or implicit borrow binding. |
| `invalid_assignment` | Assignment requires a mutable variable or a permitted stored element/field. |
| `invalid_place` | Expression is not an addressable place or uses an invalid unchecked projection. |
| `invalid_match` | Invalid, duplicate or misplaced pattern, outcome or select arm. |
| `invalid_unpack` | Invalid complete unpack or multi-result binding form. |
| `invalid_expression` | Value expression uses an unavailable form, such as scalar dereference of a slice. |
| `invalid_operation` | Invalid intrinsic/call, fallibility handler, multi-result handler or ordering spelling. |
| `invalid_literal` | Invalid literal shape, duplicate/missing initializer field or borrowed element. |
| `invalid_generic` | Invalid generic parameter, constraint, argument, entry point or application. |
| `invalid_static_function` | Static callable contract, parameter use or specialization is disallowed. |
| `implementation_limit` | A specified frontend/module/type/specialization size or depth limit is exceeded. |
| `invalid_module_mapping` | Invalid reserved, duplicate or excessive package module mapping. |
| `duplicate_import` | The same module is imported twice. |
| `import_cycle` | Cyclic module import. |
| `module_header_mismatch` | Mapped module header differs from its explicit provider name. |
| `trusted_unavailable` | A source program/template declares an unavailable trusted boundary. |
+2 -2
View File
@@ -13,11 +13,11 @@ The published [native smoke](../evaluation/results/2026-10-05-native-smoke.md),
Reconsider the proposal only after the following evidence is available:
1. **Incidence with an explicit denominator.** Publish aggregate counts for an independently chosen `Aji/source` cohort: runs with at least one eligible E3101 or classified Copy-move E7006, divided by all source runs, failures included, with sample size and agent/toolchain strata. Count affected runs separately from repeated diagnostic occurrences. Report unknown E7006 reasons as unknown, not eligible or zero. Current `ajieval profile` counts codes per run but does not classify Copy-move reasons or guarantee a pre-acceptance cutoff; specify that cutoff and missing-data treatment before collecting a new cohort.
1. **Incidence with an explicit denominator.** Publish aggregate counts for an independently chosen `Aji/source` cohort: runs with at least one eligible E3101 or classified Copy-move E7006, divided by all source runs, failures included, with sample size and agent/toolchain strata. Count affected runs separately from repeated diagnostic occurrences. Report unknown E7006 reasons as unknown, not eligible or zero. `ajieval summary`, `profile` and `checkpoint` now classify structured code/reason counts (DD-017), retaining unknown reasons and log availability; they cover the entire recorded transcript, without a pre-acceptance cutoff. Specify that cutoff and missing-data treatment before collecting a new cohort.
2. **Material repair cost.** Show that the eligible cases cause location/transcription work, failed patches, retries or meaningful tool cost, and compare the proposed workflow against today's `suggested_effects` plus ordinary editing on independent public fixtures/tasks. Frequency alone is insufficient; a syntactically exact edit may cost more to apply than the existing repair.
3. **A usable application path.** Resolve the byte-offset workflow objection below and validate the chosen path with the actual editor/tool interface. Application must remain explicit, stale-input checks must hold, and edited source must be rechecked.
The Copy-move incidence branch has an independent instrumentation prerequisite: E7006 currently has no stable `reason` field, and the harness counts codes only. A separate diagnostic-schema task must specify and emit structured reasons distinguishing Copy moves from other E7006 forms; a reporting follow-up must count affected runs by code/reason without parsing `message`. These tasks are independently useful and do not require implementing this RFC. Their owner routing and completion conditions are recorded in the [assessment](../design/review-2026-10-07-assessment.md). Missing reasons in old records remain unknown. E3101 incidence remains measurable by code without this prerequisite; neither future instrumentation nor existing counts justify relaxing the repair-cost/workflow conditions above.
The independent instrumentation prerequisite is implemented by DD-017/spec 15 §10: E7006 carries a stable `reason`, `move_copy` excludes borrowed and non-materializable operands, and ajieval counts occurrences and affected runs by code/reason without parsing `message`. These changes implement no edits or application workflow. The [assessment](../design/review-2026-10-07-assessment.md) records the baseline gap and subsequent follow-up. Missing reasons in old records remain unknown; no historical data is relabeled and no new incidence experiment is supplied. E3101 remains countable by code. This instrumentation does not satisfy the repair-cost/workflow conditions above or change this RFC's Proposed status and recommendation to defer.
No numeric N% or minimum sample size is justified by the current reports. If the owner chooses an incidence threshold and sample-size gate, record them before evaluating a new cohort rather than selecting them to match observed results. These conditions reopen design review; they do not automatically accept the RFC. Do not change frozen B1 instrumentation or inputs, inspect private held-out material, or use M/C to select or tune the eligible transformations. An authorized independent operator may publish aggregate metadata under the evaluation protocol.
@@ -14,6 +14,8 @@ Every verifier/compiler error has:
- optional human explanation;
- optional non-binding repair candidates.
Code-specific `reason` values MUST be registered and stable; consumers MUST NOT derive them from human messages. E7006 requires the categories in spec 15 §10 and `reference/error-codes.md`.
Example:
```json
+2
View File
@@ -421,6 +421,8 @@ Its diagnostics keep their AIR codes, reported at the source location.
| E7007 | source.ambiguous | Source meaning cannot be determined (e.g. an integer literal with no type from context) |
| E7900 | source.internal_compiler_error | The frontend produced invalid AIR for this construct (a compiler bug, not a program error) |
Every E7006 MUST include a stable string `reason` from the [reason registry](../reference/error-codes.md#e7006-reasons), chosen directly by the rejecting rule, independently of `message`. `move_copy` denotes an explicit rejected move of a plain Copy value; borrows use `move_borrow`, and non-materializable operands use `invalid_move`. Permitted generic transfers MUST NOT emit these errors. Reason meanings MUST remain stable; extensions MAY add registered reasons. Consumers MUST tolerate new reasons. Codes, rejection rules, primary positions and existing fields are unchanged; `reason` is appended after existing code-specific fields. A historical or incomplete record without a reason is unknown, never evidence of `move_copy` or its absence.
## 11. Tooling
| Command | Does |