docs: plan structured source advice and independent errors

This commit is contained in:
dev committed 2026-10-09 13:28:09 +03:00
1 parent 111a3861f9
commit 008867fe48
2 files changed
+43

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
# 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 lossy widening 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.