frontend: validate unknown effect names before body lowering

This commit is contained in:
dev committed 2026-10-08 14:49:49 +03:00
1 parent 4c9c5626c9
commit 762c5abe7b
40 files changed
+335 -9

No files matched your search

+2
View File
@@ -168,3 +168,5 @@ Q-047 non-value operands (cl100k): Quick Reference stays 8,948; other source doc
Q-048 source access modes (cl100k): Quick Reference stays 8,948; other source docs 67,258 → 67,343 (+85), full source 76,206 → 76,291 (+0.11%). o200k groups are 8,984 / 67,546 / 76,530; Qwen2.5 9,226 / 69,001 / 78,227. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Shared places reject at source stores and explicit mut bindings/arguments before array shape conversion; valid canonical AIR is preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added. No empirical MCC benefit is claimed.
DD-022 grammar surface (cl100k): Quick Reference stays 8,948; other source docs 67,343 → 68,219 (+876), full source 76,291 → 77,167 (+1.15%). o200k groups are 8,984 / 68,422 / 77,406; Qwen2.5 9,226 / 69,887 / 79,113. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing syntax and ordered parsing choices replace incomplete grammar descriptions. Empty qualified enum payload lists now reject E7001; accepted public-source canonical AIR is preserved. No new programming concept, feature, diagnostic code or verifier/runtime state is added. The grammar stays a reference read on demand; no empirical MCC benefit is claimed.
Q-051 source effect names (DD-023, cl100k): Quick Reference 8,948 → 8,955 (+7); other source docs 68,219 → 68,323 (+104), full source 77,167 → 77,278 (+0.14%). o200k groups are 8,991 / 68,526 / 77,517; Qwen2.5 9,233 / 69,994 / 79,227. AIR grows 47,445 → 47,458 (+13), 184,628 → 184,678 bytes, through the shared E7002 registry description; library/std.md is unchanged. Unknown effects use existing E7002 with structured `name`/`effect`, replacing erroneous source E7900 or E0006. Accepted canonical AIR and authority/effect semantics are preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added; no empirical MCC benefit is claimed.
+1 -1
View File
@@ -309,7 +309,7 @@ scope s { // every task spawned in s must
| Code | Meaning | Usual repair |
|---|---|---|
| E7001 | syntax | check `;`, braces, `=>` in `match` |
| E7002 | unknown name | spelling; declare the variable or function |
| E7002 | unknown name | spelling; declare missing bindings; for `effect`, use a registered atom |
| E7003 | linear value consumed without `move` | write `move x` (or borrow it with `ref`/`mut` if it must stay) |
| E7004 | `match` not exhaustive | add the arms listed in `missing` (integers: add `_`) |
| E7005, E1001 | type mismatch | convert with `as`, `as!`, `as%`; check borrow vs value |
+6
View File
@@ -137,3 +137,9 @@ Compatibility: formerly rejected array-borrow calls become available; accepted s
P6-1/P6-2 synchronizes the grammar with implemented syntax: graph/atomic wrappers, binary literals, signed integer patterns, parenthesized places, declared borrow-return calls and existing list/arm punctuation. Contextual words and the ordered choices for statements, body-opening braces and typed built-ins are explicit. The grammar is not claimed to be LL(k). Existing grouping and optional list delimiters introduce no operation; formatter token preservation remains mandatory.
Q-050 corrects empty parentheses on qualified enum variants, contrary to spec 15 §5–§6. Construction and pattern parsing reject E7001 at the opening parenthesis without symbol lookup, including generic, qualified and built-in variants. Payload-bearing variants with empty lists change from E7005 to E7001; non-empty arity/type checks remain. Bare variants, ordinary zero-argument calls and empty outcome bindings retain their meanings. No AIR, verifier, runtime, ownership/concurrency, feature or code changes; accepted public-source canonical AIR is preserved. Source grammar/CLI tests cover both sides and formatting. Bundle growth is recorded in docs/agent/README.md. Future grammar features still require their RFCs; P6-1 remains open. Q-051 separately records unknown ordinary-function effects.
## DD-023 — Unknown source effects are name errors
Q-051 validates ordinary effect names before body lowering using the existing closed registry. Templates/static contracts use the same E7002 with `name` and `effect`; legacy E0006 without a feature reason was incorrect. Function/template positions remain declaration starts, static contracts use their parameter start. Ordinary parameter/return/from checks retain priority; existing template/header ordering remains. Unknown effects cannot generate malformed AIR or E7900. AIR E0004 and its registry contract are unchanged.
Only invalid-source codes/priority/fields change. Registered effects, explicit authority, effect coverage, duplicate-list set semantics and static-contract uniqueness remain unchanged; no code, reason, syntax, AIR feature, verifier/runtime or ownership/concurrency state is added. Positive/rejected source tests and CLI/package tests cover headers, unused declarations, priority, missing-effect/capability diagnostics, formatting and source/AIR execution. Budget growth is measured in docs/agent/README.md. This completes this diagnostic correction, not P6-2 or an empirical MCC claim.
+2
View File
@@ -372,3 +372,5 @@ The parser accepted `E::Empty()` and the corresponding match pattern, although s
## Q-051 — Unknown effects in ordinary source signatures
An ordinary function declaring `effects [bogus.effect]` reaches AIR and reports E7900 with `air_code: E0004`; templates/static contracts reject the same known-invalid effect directly with E0006. Effect membership is determined entirely from source and the registry. A P6-2 task should align ordinary signature validation with the existing template contract, preserving effect/capability semantics and checking diagnostic priority/positions. No implementation is included in DD-022.
**Resolved (DD-023, spec 15 §9):** ordinary signatures validate the existing effect registry before body lowering; templates/static contracts replace the incorrect E0006 with E7002. Fields `name` and `effect` identify the atom without prose; locations retain declaration/parameter starts. Signature/type/from and template/header priority, accepted AIR, effect/capability semantics and AIR E0004 are preserved. Invalid-source diagnostics can change; no new code or reason.
+6
View File
@@ -297,3 +297,9 @@ Validation: units and Zig formatting pass; full conformance is 1,560/1,560, with
DD-022 synchronizes the grammar/spec 15 with implemented wrappers, binary literals, negative patterns, parenthesized places, declared borrow-return calls and list/arm delimiters. Ordered statement, header-brace and typed-built-in choices are documented; no LL(k) claim is made. Q-050 rejects empty qualified enum payload lists with E7001 at `(`, including generic/grouped/built-in variants and patterns. Ordinary `f()`, bare variants, non-empty payloads and outcome bindings retain their rules. No AIR, verifier/runtime, ownership/concurrency, feature or diagnostic-code changes.
Validation: units and Zig formatting pass; full conformance is 1,594/1,594, and all 34 new fixtures pass collection before every instruction, including select schedules. CLI integration passes 288 checks for syntax locations, packages, formatting and source/AIR execution. Old/new comparison changes zero check/lower outputs on 1,269 public sources (695 old lowerings); source coverage remains 121/121. The public formatter corpus passes 5,435 checks on 1,303 files, preserving 709 lowered outputs. Claude independently reviewed the change and reran units and CLI checks. Bundle growth is recorded in docs/agent/README.md. P6-1/P6-2 remain open; future syntax still needs its RFCs, and Q-051 is a separate ordinary-effect validation task.
## P6-2 effect-name diagnostic increment (2026-10-08)
DD-023 resolves Q-051: ordinary effect declarations validate the existing registry after signature types/from and before body lowering. Templates/static contracts replace incorrect E0006 with E7002; `name` and `effect` identify the atom. Declaration/parameter positions and prior signature/template check order remain. Registered atoms, flat effect sets, static-contract uniqueness, effect coverage, explicit capabilities and AIR E0004 remain unchanged. No new code/reason, syntax, feature, verifier/runtime, ownership/concurrency or evaluation input changes.
Validation: units and Zig formatting pass; full conformance is 1,618/1,618, and all 24 new fixtures pass collection before every instruction. CLI integration passes 236 checks, including unused/package headers, diagnostic priority, formatter preservation, source/AIR execution, instantiation and independent AIR rejection. Existing generic/static-function/grammar suites pass 32/25/288 checks. Old/new comparison on 1,303 public sources (709 old lowerings) changes only the two corrected E0006 fixtures, preserving their primary positions and `name`; accepted AIR is byte-identical. Claude independently reviewed the change and ran units/fixtures and all 236 CLI checks. Bundle growth is recorded in docs/agent/README.md; P6-2 remains open.
+1 -1
View File
@@ -87,7 +87,7 @@ Only problems that exist because of the frontend. Everything the verifier decide
| Code | Kind | Meaning |
|---|---|---|
| E7001 | source.syntax | Malformed `.aji` source |
| E7002 | source.unknown_name | Undefined variable, function, type, field or variant; an unknown capability kind is `capability_kind` |
| E7002 | source.unknown_name | Undefined variable, function, type, field, variant or effect; an unknown capability kind is `capability_kind`, an unknown effect is `name` and `effect` |
| 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 |
+2 -2
View File
@@ -387,7 +387,7 @@ A byte string or array used where a `slice<u8>` is expected is materialized in f
- **Frame storage.** Addressability is a property of lowering, not of source types. Linear values (owners, regions, resources, endpoints, tasks, mutexes) never get frame storage: they are borrowed in place. A variable whose name is borrowed, indexed, or written through a field or element anywhere in the function lowers to `local<T>` storage, allocated in the entry block (spec 08 §11.5). Every other variable is an SSA value. The decision is by name, so the same source always gives the same placement. The frame-size limit applies to the lowered AIR. There is no implicit heap allocation.
- **Borrow scopes.** A borrow bound by `ref`/`mut` ends at the end of the block that contains the binding. Because a borrow's name is not visible after its scope, a use after the borrow ended (`E2106`) cannot be written in source. A temporary borrow, used directly as an operand, ends at the end of its statement. Both end at every normal exit from their scope, except the named returned borrow and its owned ancestors transferred under §19. The frontend emits `borrow.end` in reverse order of creation. A borrow that must end earlier is placed in an inner block. Borrows lent to tasks end at the join (spec 04 §34).
- **Features.** The frontend emits the `features [...]` header as the dependency closure of the constructs used, always including `effects`.
- **Effects.** They are declared by the programmer. `E3101` names the missing effect and suggests the complete effect list (`suggested_effects`).
- **Effects.** They are declared by the programmer. Every function/template/static-function contract MUST use registered atoms (`reference/effects.md`); an unknown atom MUST reject E7002 with `name` and `effect`, before body lowering. The source position is the function start, or the static parameter start for its contract. Ordinary signature type/`from` checks and existing template/header check order remain prior checks. Ordinary effect lists retain AIR set semantics; static-function contract effects remain unique (§18). `E3101` names the missing effect and suggests the complete effect list (`suggested_effects`).
## 10. Diagnostics
@@ -431,7 +431,7 @@ Its diagnostics keep their AIR codes, reported at the source location.
| Code | Kind | Meaning |
|---|---|---|
| E7001 | source.syntax | Malformed `.aji` source |
| E7002 | source.unknown_name | Undefined variable, function, type, field or variant |
| E7002 | source.unknown_name | Undefined variable, function, type, field, variant or effect |
| 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 |