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

+24 -1
View File
@@ -338,7 +338,7 @@ effects []
}
```
`find` returns the searched slice's length when absent; check before indexing. `clamp_u64` traps `T0002` for an inverted range. Missing import/module/member: `E7002`; duplicate import: `E7006`; wrong arguments: `E7005`. There are no aliases or user generics in this increment.
`find` returns the searched slice's length when absent; check before indexing. `clamp_u64` traps `T0002` for an inverted range. Missing import/module/member: `E7002`; duplicate import: `E7006`; wrong arguments: `E7005`. Aliases are unavailable; explicit generics use §12.
Endian reads/writes cover `u16/u32/u64` in LE and BE. Pass a sub-slice for an offset. Reads return `std.bytes.ReadUW` with `ok(uW)`/`short_input`; writes return `std.bytes.WriteResult` with `ok`/`short_output`. A short destination is unchanged. Handle them with qualified enum patterns (not intrinsic outcome patterns):
@@ -387,3 +387,26 @@ effects []
```
Use `aji check|lower|report|run|explore --manifest aji.toml`; `run` and `explore` instantiate manifest grants. A file-only command does not discover packages. Qualified workers work in `task.spawn(s, app.work.run, args)` with ordinary `move`, borrow and join rules. Missing/direct-import names: `E7002`; cycles/header mismatch/duplicates: `E7006`. Read `/docs/language/modules.md` for limits and file-loading rules. `lower --stats` counts entry source against combined AIR, so it is not a whole-package size metric.
## 12. Generics
Declare type parameters on functions, structs or enums: `<T>`, `<T: Copy>` or `<T: Copy + Send>`. Every use supplies all types: `Pair<u64>` in annotations, `Pair::<u64> { ... }`, `identity::<u64>(42)` and `Option::<u64>::some(42)` in expressions/patterns. Qualified forms require a direct import. No inference, traits, defaults or overloads. `task.spawn(s, worker::<u64>, args)` specializes a static worker with the ordinary ownership/effect rules.
```aji
module demo.generic
import std.option;
fn identity<T: Copy>(value: T) -> T effects [] { return value; }
fn main() -> u64 effects [] {
let value = std.option.Option::<u64>::some(identity::<u64>(42));
match value {
std.option.Option::<u64>::some(n) => { return n; }
std.option.Option::<u64>::none => { return 0; }
}
}
```
`std.option.Option<T: Copy>` has `some(T)`/`none`; `std.result.Result<T: Copy, E: Copy>` has `ok(T)`/`err(E)`. `is_some::<T>` and `is_ok::<T, E>` classify them; match to extract payloads. Owning/borrowed payloads still reject. Unknown names: `E7002`; missing/extra arguments, duplicate/unknown constraints or expansion limits: `E7006`; unsatisfied constraints: `E7005` with `parameter`, `constraint`, `found`. Borrow conflicts, moves, effects and cleanup keep their existing rules.
Each required specialization is checked as concrete code; an unused template body is not a proof for future types. `Copy` gives no arithmetic or ordering operation. Read `/docs/language/generics.md` for exact Copy/Send/Share/Freeze/Local rules, deterministic keys and fixed limits; `/docs/library/std.md` for option/result contracts.