frontend: provide contextual source repair advice

This commit is contained in:
dev committed 2026-10-09 14:04:40 +03:00
1 parent 008867fe48
commit 2c6c7a3dcd
37 files changed
+562 -24

No files matched your search

+15
View File
@@ -4,6 +4,21 @@ Read this first; it covers most programs. Where to find the full rules is at the
Aji makes every significant action explicit — moves, borrows, allocation, closing, authority, effects, tasks, channel transfers, locking, cancellation, every failure outcome — and checks them all before running. The compiler writes the mechanics: SSA, control flow, borrow ends, frame storage, the feature header.
**If you know Rust:** use these Aji spellings. Rejected familiar syntax may carry a `repair_candidates` hint; cast alternatives require your choice.
| Familiar spelling | Aji |
|---|---|
| `!condition` | `not condition` (boolean negation) |
| a narrowing `x as T` | `x as! T` checks/traps; `x as% T` wraps |
| `let mut x = value` / `var x = value` | `var x: T = value;` (type required) |
| immutable `let x = value` | `let x = value;` (type may be inferred) |
| mutable/shared slice type | `slice_mut<T>` / `slice<T>` |
| `s[start..]` | `s[start..end]` (explicit upper bound) |
| `f(&x)` / `f(&mut x)` | `f(ref x)` / `f(mut x)` |
| `let r = &x` / `let r = &mut x` | `ref r = x;` / `mut r = x;` |
| `[zero; N]` | `var storage: [T; N] = zero;` (zeroable T) |
| `-> ()` / implicit effects | `-> void effects [...]` |
## 1. Skeleton
```aji
+9 -1
View File
@@ -6,7 +6,7 @@ Non-normative work item following the owner's 2026-10-09 proposal. This does not
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.
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
@@ -40,3 +40,11 @@ Preserve one diagnostic per code/source location and the E7900 rule replacing al
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. Multi-error collection and the public dev measurement remain 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.
+1 -1
View File
@@ -139,7 +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-12 | doing (advice delivered; collection/measurement pending) | 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.
+26
View File
@@ -112,6 +112,32 @@ Reported in trap records (spec 01 §6), not by the verifier.
| 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 |
## Source repair candidate kinds
These stable kinds use spec 10 §3. `hint` MUST equal the registered text. Alternatives, when present, MUST use the unit below; hints alone are not replacements. Advice is selected at the rejecting rule, never by parsing diagnostic prose. Existing illustrative/non-source kinds are outside this registry.
| Kind | Code | Hint | Alternatives unit |
|---|---|---|---|
| `boolean_negation` | E7001 | Aji boolean negation is `not`; integer complement is not boolean negation. | none |
| `annotate_var_type` | E7001 | Write an explicit type: `var name: T = expression;`. `let` may infer its type. | none |
| `slice_mut_type` | E7001 | Write `slice_mut<T>` for a mutable slice type. | complete type |
| `slice_ref_type` | E7001 | Write `slice<T>` for a shared slice type. | complete type |
| `explicit_range_end` | E7001 | Write both slice bounds: `receiver[start..end]`; choose the upper bound explicitly. | none |
| `borrow_argument` | E7001 | Write `ref place` or `mut place` for an inline borrow argument. | prefix |
| `borrow_binding` | E7001 | Bind a borrow with `ref name = place;` or `mut name = place;`, rather than a let/var initializer. | none |
| `zero_storage` | E7001 | `zero` is only a whole var initializer: `var name: T = zero;`; T must be zeroable. | none |
| `numeric_cast_modes` | E7005 | Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion. | operator |
Closed applicability:
- `boolean_negation`: lone `!` rejected at primary-expression start. Excludes `!=`, `as!` and `!` rejected after an expression (such as `panic!()`). It does not assert that the operand is boolean.
- `annotate_var_type`: `=` found where a `var` declaration requires its type colon. No advice for `let`, a missing name or other found tokens; no initializer type is guessed.
- Slice type kinds: a bare `mut`/`ref` parsed in type position immediately followed by `slice`. Attach at that `slice` token, retaining the caller's expected token. Emit one complete-type alternative only if the following `slice<...>` fragment parses as a single-argument slice type. Keep its token spellings (including nested types), remove comments/whitespace and separate adjacent word/number tokens by one space; replace the outer spelling by `slice_mut`/`slice` respectively. An incomplete/malformed fragment has hint only. Speculative parsing MUST NOT mutate the original tokens, including `>>`.
- `explicit_range_end`: `]` immediately after `..` in index syntax. No advice for an omitted start, inclusive `..=`, missing for-loop bound or another malformed expression. No receiver or `.len` alternative is guessed.
- Borrow kinds: `&` rejected as the first token of a call argument, excluding enum variant payloads (`borrow_argument`) or let/typed-var initializer (`borrow_binding`). Other expression contexts, including the second `&` in `a && b`, have no borrow advice. For an argument whose following token is an ordinary identifier, emit `["ref"]`; for `&mut` followed by an ordinary identifier, emit `["mut"]`. Other operands have hint only, including `&&x`. These prefixes do not imply that the referent/mode verifies; binding advice has no prefix alternative.
- `zero_storage`: keyword `zero` rejected at primary-expression start. Accepted typed-var zero initialization has no advice.
- `numeric_cast_modes`: integer `as` rejected by the lossless-widening rule, with unchanged `from`/`to`. Alternatives MUST be `["as!", "as%"]`. Non-integer casts and other E7005 rules have no such candidate.
## 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.
@@ -45,7 +45,7 @@ Example:
## 3. Repair candidates
The compiler may emit structured suggestions:
The compiler MAY emit structured suggestions. The following kinds are illustrative:
```json
{
@@ -58,6 +58,10 @@ The compiler may emit structured suggestions:
Suggestions never modify semantics automatically.
Each `repair_candidates` element MUST have string `kind`; it MAY additionally have string `hint` and a nonempty ordered array of strings `alternatives`. Serialization order MUST be `kind`, then `hint`, then `alternatives`; absent optional members MUST be omitted. Existing kind-only objects remain valid. Alternatives are spellings for the construct/unit registered for that kind, not byte edits or a claim that the repaired program verifies. Their order MUST be deterministic and implies no preference. In particular, choosing a checked versus wrapping cast remains the agent's semantic decision. Agents MUST select advice by `kind`, not by parsing `hint` or `message`.
Source advice kinds, fixed hints, applicability and alternative units are registered in `reference/error-codes.md`. An E7001/E7005 diagnostic MUST NOT carry more than one registered source advice candidate; when a registered trigger applies, it MUST carry exactly that candidate. Advice MUST come from the rejecting parser/type rule, MUST NOT change accepted syntax or inference, and MUST preserve the existing code, location, payload and message. Imported source and formatter syntax failures MUST carry the same applicable advice; E7900 replacement MUST discard it.
## 4. ajid
`ajid` is the long-running machine interface.
+2
View File
@@ -391,6 +391,8 @@ A byte string or array used where a `slice<u8>` is expected is materialized in f
## 10. Diagnostics
Recognized rejected spellings MUST carry the applicable source advice candidate registered in `reference/error-codes.md`, using spec 10 §3. These candidates describe existing syntax; they MUST NOT accept aliases, infer a missing `var` annotation, invent a slice end, duplicate a receiver expression or select a cast mode. `let` inference remains unchanged. Parser recovery and diagnostic collection are unaffected by this advice requirement.
| Problem | Code |
|---|---|
| found by the verifier on the lowered AIR | the AIR code; the diagnostic's `file`, `line` and `col` are the source location of the construct the instruction came from, and `air_line`/`air_col` locate it in the lowered AIR (`aji lower`); the verifier's own fields (`function`, `block`, `inst`) are kept |