Files
aji/docs/design/source-diagnostic-repair.md

11 KiB

Source diagnostic repair and independent-error collection

Non-normative work item following the owner's 2026-10-09 proposal. This does not change accepted syntax, type inference or diagnostic collection. Governing text: spec 15 §4/§10, spec 10 §2 and spec 14 §12; implementation: src/frontend/{parse,lower}.zig. RFC 0038's programmatic repair candidates remain a separate, deferred proposal.

Evidence and limits

The owner reports 15 GLM-5.3-flash sessions on four public dev tasks: of 52 rejected checks, the first diagnostic was E7001 in 30, E7005 in 10 and E7006 in six. Missing var annotations, lossy casts and Rust-style negation were frequent. These aggregates are supplied observations, not independently audited runs. First-code counts are not counts of all errors; one model family does not establish a language-inference policy. No task implementation, private corpus or frozen experiment is inspected or changed for this investigation. The proposed threefold reduction in E7001 checks is an experiment target, not a demonstrated effect.

Twelve minimal current-language probes confirm: prefix !, missing var type, mut slice<T>/ref slice<T>, an omitted range end, [zero; N] and & in arguments/bindings reject E7001; a non-widening integer cast rejects E7005. Three syntactically invalid functions yield one E7001; two independently invalid casts yield one E7005. Crucially, let x = 1u64 already accepts: let inference is specified, and its annotation must not be demanded by a repair hint. These are generic syntax probes, not dev-task reproductions.

First increment: explicit advice without syntax aliases

Use the existing optional repair_candidates envelope (spec 10 §3), rather than introducing parallel hint/suggested envelope fields. Register stable candidate kinds selected by the rejecting rule, with additive explanatory hint text and explicitly ordered suggested alternatives inside each candidate. A hint explains an applicable rule; suggested text is a context-local alternative, not an automatically applicable edit or a claim that the resulting program verifies. Preserve codes, positions, expected/found and messages. Pin candidate field order, types and applicability in spec/reference before implementation; test the structured fields through CLI/package paths, not message parsing. RFC 0038's edits remain separate and deferred.

Rejected context Candidate advice Constraint
prefix ! at expression start hint: Aji boolean negation is not no advice for valid as!; parser-only advice cannot assert a bool operand or translate Rust integer complement
var name = without an annotation hint write var name: T = expression parser does not know the initializer's type; let is excluded
mut slice<T> / ref slice<T> in a type position suggested slice_mut<T> / slice<T> recognize the entire type context; retain the actual element spelling
omitted range end hint requiring an explicit upper bound only suggest name.len after proving the receiver is the suitable named slice; repeating a general receiver can change evaluation
&place / &mut place hint about explicit ref/mut arguments or ref/mut bindings argument replacement and binding-statement replacement are different; let r = ref x is invalid
lossy as T ordered alternatives as!, as% checked versus truncating conversion is a semantic choice; never choose one automatically
[zero; N] hint to initialize named, typed zeroable storage first no invented element type or implicit constructor

Expression and type context must come from the parser/lowerer, not substring searches over messages. Keep accepted contract-free AIR and source spellings unchanged. Any byte-edit schema additionally needs exact source ranges/context and applicability rules; the proposed strings alone do not provide that.

Second increment: independent errors without partial compilation

Investigate parser recovery only between complete top-level declarations. Balanced token delimiters and actual declaration syntax are stronger boundaries than a keyword at the start of a line: static function selections may contain fn, and a broken delimiter may prevent establishing an independent next item. Emit at most one syntax error per failed item; if independence cannot be established, stop. Discard the entire erroneous module and never lower or verify a partial AST. Three balanced function bodies with separate expression errors must produce three E7001s; one broken expression must not manufacture additional errors in that item. Import/header/lexical failures need explicit stopping rules.

For lowering, first validate module names/types/signatures, then investigate collection across independent function bodies. Discard failed bodies and emit no AIR when any source error exists. Specify state reset, generic-specialization failures, dependency suppression, packages, diagnostic ordering and fixed collection bounds before extending the current first-error result. A global signature failure cannot safely be treated as an independent body failure. Two invalid casts in different valid-signature functions are the minimal positive collection target; dependent callers and malformed generic bodies are negative cascade cases.

Preserve one diagnostic per code/source location and the E7900 rule replacing all other diagnostics on an internal frontend error, including imported/std failures. Check/run/report/explore/lower must return identical source diagnostic sets for an erroneous module; fmt still refuses syntactically invalid input. No recovery stub may reach the AIR verifier. Multi-error collection changes previously rejected diagnostic multisets: audit existing conformance, hosted and rejection-twin expectations, and record the compiler/diagnostic version in subsequent evaluation conditions.

Order and validation

  1. Specify and implement structured advice with applicability tests and unchanged acceptance.
  2. Add a compact Quick Reference table describing current Aji spellings; measure bundle growth and compile its Aji examples. Include the already-supported let inference.
  3. Complete the recovery design and implement it with parser/lowering/package/CLI tests.
  4. Have the evaluation owner rerun public dev tasks after the changes; retain both first-code and full diagnostic counts, model/tool settings and frozen input identities. Do not modify a frozen matrix in place.

Var inference remains an optional language-policy question. No change is adopted from these aggregates; the first increment can reduce repair burden while retaining explicit var annotations. Contract research and its full P6-6 exit criterion remain open.

First increment delivered (2026-10-09)

Nine registered kinds now provide contextual E7001/E7005 advice through repair_candidates; argument and binding borrows are separate. Fixed hints and alternative units are specified in spec 10/15 and the registry. Enum variant payloads, &&, unsupported block comments, incomplete types and other nearby spellings have explicit exclusion tests. No syntax alias, var inference, inferred slice end or automatic cast selection was added.

Validation: 1735/1735 conformance, including exact .advice JSON goldens for all kinds; 161 CLI/package advice checks; unit/registry tests, grammar, formatter, hosted smoke and format checks. Independent Claude review caught the enum-payload context and confirmed the static candidate lifetime correction. At this increment's boundary, multi-error collection was still pending; its delivery follows below. The public dev measurement remains pending.

Bundle growth versus the pre-increment generated bundle (whose Quick Reference matched HEAD): Quick Reference cl100k_base 8955 → 9237 (+282, 3.15%), o200k_base 8991 → 9272, Qwen2.5 9233 → 9515. Full Source Reference Bundle excluding AIR: 77358 → 78582 (+1224, 1.58%), 77594 → 78815 and 79315 → 80563 respectively. The table and machine advice registry account for this explicit cost; the proposed reduction in repair rounds has not been measured.

Second increment delivered (2026-10-09)

Spec 15 §10 now defines delimiter-bounded parser recovery, first-error phase stops, collection across validated function bodies, deterministic order and the fixed 32-diagnostic limit. Every failed item/body contributes only its first error. A broken header/import or uncertain delimiter boundary stops collection; no partial AST/AIR reaches another stage. The first failing imported file carries its recovered list. Bodies start with fresh state; failed constants/features/linearity accumulations are restored. Calls read validated signatures, so a bad callee does not create a caller error. Later instances of a failed template are skipped. E7900 still replaces other diagnostics and carries no advice.

Check/lower/run/report/explore and syntax-only fmt now carry the applicable JSON Lines lists. The 12 original mini-probes preserve acceptance and every prior first-diagnostic field; the three-function syntax probe grows from one to three records, and the two-cast probe from one to two. These are compiler observations, not measurements of model repair rounds.

Validation: full conformance 1760/1760; all 25 independent-error fixtures; 234 CLI/package collection checks, 163 advice checks and 5975 formatter checks over 1442 files (770 accepted AIR outputs remain identical). Unit tests compare the next function's complete output/constant tags with fresh lowering after failed borrow/scope/loop bodies, pin constant/feature rollback and no output on error, and test std failure collapse to E7900. Remaining CI Python hosted/oracle checks passed (38 commands, including examples under 200 schedule seeds); source construct coverage remains 121/121. Evaluation harness self-tests also passed (41 tests, one skipped), using scripted/mocked providers rather than model runs. The reason suite's stale void-parameter expectation now pins the earlier E7005, its registry scan selects only the reason section, and the defensive void/never move guard is unit-tested. Claude found no remaining implementation defects after review.

Combined bundle cost for both increments: Quick Reference cl100k_base 8955 → 9255 (+300, 3.35%), o200k_base 8991 → 9290 and Qwen2.5 9233 → 9534. Full Source Reference Bundle excluding AIR: 77358 → 79072 (+1714, 2.22%), 77594 → 79306 and 79315 → 81059. The second increment adds 18 Quick Reference and 490 full-source tokens in cl100k_base; the cost documents recovery boundaries and the JSON Lines contract instead of adding language syntax.

The implementation is ready for a new pinned public dev condition. Gobang is not installed/exposed in this workspace, so no model runs or claimed threefold improvement are recorded here. The evaluation owner should confirm that its tool wrapper retains every diagnostic JSON line and freeze the new compiler commit, docs hashes, model/settings and tool behavior before rerunning the same four public dev tasks. Compare checks/turns and first-code/full-code counts separately; retain the earlier condition unchanged. Ajieval's inspected single-object readers are for documentation/Gobang tool envelopes, not raw compiler stdout; that does not verify the external Gobang wrapper. P6-12 remains open for this measurement, and P6-6 remains open in full.