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.
+1
View File
@@ -139,6 +139,7 @@ Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) a
| P6-8 | done | Formatter for implemented source syntax | P6-2 | `aji fmt`, spec 15 §11 | token/comment/declaration preservation; idempotence, identical AIR and CLI write/check tests |
| P6-9 | done | Port reference programs and examples to `.aji` | P6-5 | `tests/conformance/source/programs/`, `examples/` | all five source/AIR reference pairs and every example source/package pass |
| P6-11 | done (implementation; RFC 0036 Proposed) | Source functions/calls returning borrows with explicit `from` origin; Q-034 | P6-3/4 | spec 15, binding/call/return lowering, Quick Reference and source/AIR conformance | origin/lifetime and temporary-end rules specified; valid/rejected returned views use existing verifier/interpreter semantics |
| P6-12 | doing (design/verification) | Structured source repair advice and independent diagnostic collection; owner proposal 2026-10-09 | P6-2/4/7 | [repair plan](../design/source-diagnostic-repair.md), spec 15 §10, parser/lowering and CLI | advice applicability and additive fields specified/tested; independent item/body errors collected without partial AIR or cascades; bundle growth and public dev effect measured |
| P6-10 | todo | Phase exit review | all | plan status | exit criterion passes |
The [standard-library track](standard-library.md) implements nineteen compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer<T> and safe std.vec, explicit growth, returned failure ownership and draining (spec 15 §17). STD-6c/RFC 0025 adds safe owning Deque with existing source primitives. STD-6d.1/RFC 0026 adds pure std.hash; STD-6d.2/RFC 0028 adds safe owning U64Map<V> after the explicit error_values prerequisite (RFC 0027). STD-6d.3/RFC 0029 adds explicit static function parameters for general hash/equality/order operations with existing AIR calls/workers. STD-6d.4/RFC 0030 implements the general owning-key std.hashmap contract; its full GC/stress validation passes and Q-037 is resolved. STD-6d.5/RFC 0031 implements general owning std.hashset with duplicate input return; its conformance, GC/schedule, CLI and documentation checks pass. STD-6d.6/RFC 0032 implements safe owning std.heap with explicit order; conformance, GC/schedule, CLI and documentation checks pass. STD-7a/RFC 0033 implements bounded std.io composition with explicit progress, resource loans and exact effects; conformance, GC/schedule, CLI and documentation checks pass. STD-7b/RFC 0034 implements safe owning buffered file adapters with explicit finish/discard and first-error/no-retry behavior; conformance, GC/schedule, CLI and documentation checks pass. STD-7c/RFC 0035 adds pure caller-buffer lexical paths and Copy component ranges; conformance, GC/schedule, CLI and documentation checks pass. The owner adopts STD-0..7 as an intermediate foundation and resumes language work (2026-10-07); remaining std system/service milestones stay in the backlog. P6-11 implements explicit borrowed returns over the existing AIR; RFC 0036 remains Proposed pending owner adoption (Q-034). These increments do not complete Phase 6.