frontend: align source grammar and reject empty enum payload lists

This commit is contained in:
dev committed 2026-10-08 14:14:45 +03:00
1 parent 48b9b42fed
commit 4c9c5626c9
44 files changed
+501 -33

No files matched your search

+11 -6
View File
@@ -32,7 +32,7 @@ Rules:
1. Lowering is a pure function of its explicit source inputs: the same module graph gives byte-identical canonical AIR (spec 07 §8.5).
2. No source construct admits a program whose AIR the verifier rejects. Errors the verifier would find are reported with the verifier's code (§9).
3. `.aji` 0.1 covers the published features of Phases 0–3 and nothing else.
4. Every construct has **one canonical spelling**. There are no alternative forms of the same operation.
4. Every construct has **one canonical spelling**. There are no alternative forms of the same operation. Parentheses for expression grouping and the optional list delimiters of §2 do not introduce operations.
## 2. Modules and declarations
@@ -59,7 +59,8 @@ effects [io.read, io.write]
- A file holds one module: `module <dotted.path>`, then type and function declarations in any order.
- Between the module header and declarations, `import <dotted.path>;` imports a standard (§13) or explicitly supplied package module (§14). `import` is contextual at this position; it remains an ordinary identifier elsewhere.
- `//` starts a line comment.
- `//` starts a line comment. `recv` and `send` are contextual in `select`, and remain identifiers elsewhere; a lone `_` is a wildcard/discard, not an identifier. Keywords are listed in the grammar; after `.` they may name a member.
- Trailing commas MAY appear in parameter, argument, effect, field, variant, array-literal element and binding lists, including static-function contract parameters/effects. Type parameter/argument lists and enum declaration payload-type lists MUST NOT have trailing commas. Empty outcome/tuple/select-cancellation binding lists MAY retain `()`; the operation still checks the number and kinds of bindings. Enum payload lists MUST NOT be empty (§5–§6).
- Function `f` lowers to `@f`; type `T` to `@T`.
- **Signature.** `fn name(params) -> type`, then optionally `from p` for a borrow return (spec 08 §11.3), then the line `effects [...]`, then the body block.
- **Parameter names are preserved.** A parameter `p` lowers to `%p`. Names the compiler generates are chosen so that they never equal a parameter name of the function. The names of `@main`'s parameters are part of the instantiation contract.
@@ -80,6 +81,7 @@ The AIR spellings are used (spec 07 §8):
- `cap<K>`;
- `file<read|write|append>`, `listener`, `stream`;
- `task<T>`, `sender<T>`, `receiver<T>`, `mutex<T>`;
- `island<T>`, `frozen<T>`, `arc<T>`, `iref<T>`, `atomic<T>`;
- the built-in enums `io_error`, `alloc_error`, `cap_error`.
Arrays are written `[T; N]`. `scope`, `shield` and `guard<T>` are not source types: they exist only inside the block forms of §7.
@@ -150,14 +152,14 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass
**Literals:**
- integers (`42`, `0xff`, `1_000`) take their type from context, or a suffix (`42u8`);
- integers (`42`, `0xff`, `0b101`, `1_000`) take their type from context, or a suffix (`42u8`);
- `true`, `false`;
- `b"…"`: a byte string, of type `[u8; N]`, with escapes `\n`, `\t`, `\\`, `\"`, `\xHH`.
**Aggregates.**
- **Struct values.** `Pair { a: 1, b: 2 }` is the only way to build one: every field exactly once, in any order. A missing or repeated field is `E7006`, an unknown one `E7002`. The initializers are evaluated, and lowered, in **declaration order**, so the AIR does not depend on the order the fields are written in. There is no positional constructor.
- **Enum values.** `Shape::Square(4)`, or `Shape::Empty` for a variant without payload, is the only form.
- **Enum values.** `Shape::Square(4)`, or `Shape::Empty` for a variant without payload, is the only form. An empty `()` after a qualified variant MUST reject E7001, including a variant that requires payload values.
- **Arrays.** `[e; N]` is `array.splat`.
- **Field access.** `v.f` on a struct value is `struct.get`.
@@ -171,7 +173,8 @@ Lowering: structured control flow becomes blocks and terminators. A variable ass
- `place.f`;
- `place[i]`;
- `place[a..b]`;
- `*r`.
- `*r`;
- a parenthesized place, such as `(*r).field` or `(*r)[i]`. Dereference consumes a unary operand: `*r.field` means `*(r.field)`.
| Source | Meaning |
|---|---|
@@ -220,6 +223,8 @@ The value is evaluated first, then the place is borrowed for the store and the b
## 6. Fallible operations and `match`
Arm bodies beginning with `{` consume the whole block; a following comma MAY be present. Other expression arms MUST end with a comma unless immediately followed by the enclosing `}`. Integer patterns MAY have a leading minus. Qualified enum patterns use bare names for payload-free variants; an empty payload-binding `()` MUST reject E7001. Payload bindings MAY use `_` to discard a value, subject to the existing linear-value rules.
Every AIR terminator with outcome edges is written as a `match` over its outcomes. The arms are named after the edge roles and the match MUST be exhaustive (`E7004`):
| Operation | Outcomes |
@@ -534,7 +539,7 @@ Module names use source paths. The first component of a package mapping MUST NOT
A module sees its own functions and types by short name, and declarations of directly imported modules by full path. Imports MUST NOT inject short names, aliases or transitive visibility. An entry outside reserved built-in namespaces can also qualify its own declarations with its module name; built-in operations retain precedence. An inaccessible or unknown function/type/member is `E7002`, even if a different module linked the declaration. Qualified names resolve by module identity, independently of local bindings with the same prefix. A value may have a type inferred from a directly imported function contract without importing that type's defining module; spelling the type or its constructors by name still requires a direct import. Module-local calls MUST NOT capture an entry's similarly named function; named types from different modules are nominally distinct.
Type annotations and wrappers use qualified types, for example `app.model.Pair`, `ref<app.model.Pair>` and `[app.model.Pair; 2]`. Enum construction/patterns use `app.model.Result::ok(value)`. Qualified struct construction is `app.model.Pair { a: 1, b: 2 }`, with existing field typing/completeness and ownership rules. The final component must begin with an uppercase ASCII letter, as for current short-name struct literals. Struct literals remain forbidden in unparenthesized conditions, where `{` starts a block. This adds no methods, reflection or permission to store forbidden borrowed values in aggregates; linear members follow §16. Generic forms are specified separately in §15.
Type annotations and wrappers use qualified types, for example `app.model.Pair`, `ref<app.model.Pair>` and `[app.model.Pair; 2]`. Enum construction/patterns use `app.model.Result::ok(value)`. Qualified struct construction is `app.model.Pair { a: 1, b: 2 }`, with existing field typing/completeness and ownership rules. The final component must begin with an uppercase ASCII letter, as for current short-name struct literals. Struct literals MUST NOT consume the body-opening `{` in `if`/`while` conditions, `match` scrutinees, `for` bounds or `lock` places. Parenthesized expressions, call arguments and index expressions within those headers restore ordinary struct-literal parsing. This adds no methods, reflection or permission to store forbidden borrowed values in aggregates; linear members follow §16. Generic forms are specified separately in §15.
A qualified named function MAY be passed as the function operand of `task.spawn(scope, app.work.run, ...)`. Existing Send/effect/structured-lifetime rules still apply; there is no function value, dynamic dispatch or detached task. All other calls use the existing argument, borrow, move, failure and effect rules.