cli: add explicit source generics and Copy option/result

Specialize explicit function, struct and enum templates into deterministic
ordinary AIR, with structural constraints and bounded expansion. Preserve
source provenance and readable names in specialization diagnostics.

Add Copy-only std.option/std.result and vertical specification, grammar,
Quick Reference, RFC and source coverage updates. Keep linear aggregates
and existing unsupported source from-returns explicit follow-up work.

Repair the finite-layout check through arrays under the existing E1003
contract, with positive and rejected source/AIR fixtures.

Validation: build, unit tests, 640 conformance cases, 82/82 source constructs,
32-seed generic task stress, agent-reference, formatting, hosted smoke,
20 generic and 36 package CLI checks. Record three-encoding documentation
budgets; AIR reference is unchanged.
This commit is contained in:
dev committed 2026-10-06 19:53:26 +03:00
1 parent c96199e7ec
commit 7eea31518d
93 files changed
+1587 -75

No files matched your search

+13 -7
View File
@@ -18,17 +18,23 @@ item = type_decl | fn_decl ;
path = ident { "." ident } ;
type_decl = struct_decl | enum_decl ;
struct_decl = "struct" ident "{" [ field { "," field } [ "," ] ] "}" ;
struct_decl = "struct" ident [ type_params ] "{" [ field { "," field } [ "," ] ] "}" ;
field = ident ":" type ;
enum_decl = "enum" ident "{" variant { "," variant } [ "," ] "}" ;
enum_decl = "enum" ident [ type_params ] "{" variant { "," variant } [ "," ] "}" ;
variant = ident [ "(" type { "," type } ")" ] ;
fn_decl = "fn" ident "(" [ param { "," param } ] ")" "->" type [ "from" ident ]
fn_decl = "fn" ident [ type_params ] "(" [ param { "," param } ] ")" "->" type [ "from" ident ]
"effects" "[" [ path { "," path } ] "]"
block ; (* `trusted` is reserved and rejected, E7006 *)
param = ident ":" type ;
type_params = "<" type_param { "," type_param } ">" ;
type_param = ident [ ":" property { "+" property } ] ;
property = "Copy" | "Send" | "Share" | "Freeze" | "Local" ;
type_args = "<" type { "," type } ">" ;
application = "::" type_args ; (* explicit; no inference, spec 15 §15 *)
type = int_type | "bool" | "void" | "never" | path
| path type_args
| "[" type ";" int_lit "]"
| wrapper "<" type ">"
| "cap" "<" path ">"
@@ -64,7 +70,7 @@ if_expr = "if" expr block [ "else" ( if_expr | block ) ] ;
match_expr = "match" expr "{" { arm } "}" ;
arm = pattern "=>" ( block | expr "," ) ;
pattern = "_" | int_lit (* integer matches only; `_` is required there *)
| path "::" ident [ "(" ident { "," ident } ")" ] (* enum variant: Shape::Rect(w, h); no `_` in enum matches *)
| path [ application ] "::" ident [ "(" ident { "," ident } ")" ] (* enum variant: Shape::Rect(w, h); no `_` in enum matches *)
| ident [ "(" ident { "," ident } ")" ] ; (* outcome of a fallible operation: ok(n), closed *)
select_stmt = "select" "{" { select_arm } "cancelled" [ "(" ident { "," ident } ")" ] "=>" ( block | expr "," ) "}" ;
@@ -84,12 +90,12 @@ unary = ( "-" | "not" | "*" ) unary
| ( "ref" | "mut" ) [ "unchecked" ] place
| "move" ident
| postfix ;
postfix = primary { "." member | "[" expr [ ".." expr ] "]" | call_args } ;
postfix = primary { application | "." member | "[" expr [ ".." expr ] "]" | call_args } ;
member = ident | keyword ; (* after `.` a keyword is a name: task.cancelled *)
call_args = [ "<" type ">" ] "(" [ expr { "," expr } ] ")" ;
primary = int_lit | "true" | "false" | string
| ident | path "{" [ field_init { "," field_init } [ "," ] ] "}" (* struct literal; uppercase final component *)
| path "::" ident (* enum variant; applied by a call *)
| ident | path [ application ] "{" [ field_init { "," field_init } [ "," ] ] "}" (* struct literal; uppercase final component *)
| path [ application ] "::" ident (* enum variant; applied by a call *)
| "[" expr ";" int_lit "]"
| "(" expr ")"
| if_expr | match_expr | block ;
+13
View File
@@ -214,3 +214,16 @@ effects []
```
This checked program is `examples/std/format.aji` and `tests/conformance/source/std/fmt_example.aji`. It returns 17 without grants. Each operation preserves its own destination on short output; a sequence is not transactional across earlier successful calls. Existing alias checks apply even when a write would return short output. Smaller scalar widths require an explicit widening conversion to an appropriate writer; wider integers, float formatting and parsing are outside this increment.
## Copy option/result templates
Requires direct `import std.option;` / `import std.result;`; explicit generic spelling is spec 15 §15.
| Declaration | Contract |
|---|---|
| `std.option.Option<T: Copy>` | `some(T)`, `none` |
| `std.option.is_some<T: Copy>(value: Option<T>) -> bool` | true for some; false for none; effects [] |
| `std.result.Result<T: Copy, E: Copy>` | `ok(T)`, `err(E)` |
| `std.result.is_ok<T: Copy, E: Copy>(value: Result<T, E>) -> bool` | true for ok; false for err; effects [] |
All are ordinary safe source/static specialization, with no allocation or authority. Generic helper calls use `is_some::<u64>(value)` / `is_ok::<u64, u8>(value)`. Constructors and patterns use `std.option.Option::<u64>::some(value)` or `std.result.Result::<u64, u8>::err(code)`; names and variant matches remain explicit even for none. Extract values by exhaustive match; an err variant is not intrinsic outcome syntax. Owners/resources/endpoints and borrows fail Copy constraints with E7005, until a separate linear-aggregate feature supplies their contracts. No must-use or implicit unwrap/default/conversion is introduced. [Checked example](../../examples/std/generics.aji) returns 42 without grants.
+4
View File
@@ -49,3 +49,7 @@ Because of it, a graph never holds outside authority or a mutable ownership edge
An `ArcSafe` value may be held by an `arc` (spec 03 §24): the last release destroys it by freeing memory only, with no user or resource action. In format 0 it is exactly `IslandSafe`. `Share` alone is not enough; for example, a `mutex<T>` is `Share` but not `ArcSafe`.
## Format-0 source constraints
Spec 15 §15 fixes the exact property queries used by explicit generic specialization. Copy includes integers, booleans, built-in enums, capabilities, `iref` and aggregates of Copy members; borrows and linear values are excluded. Send/Share use spec 04 §35. Freeze currently equals IslandSafe plain graph content; it does not promise conversion of arbitrary owners or resources. Local has task/scope/shield/guard/internal-storage base cases and propagates through borrow/own/own_array/mutex wrappers and arrays/aggregates containing Local content. It is not the complement of Send. These properties add no methods, effects, unsafe declarations or implicit resource actions.