cli: add explicit static function parameters
Bind typed source functions with exact effect contracts during deterministic specialization; retain nominal operation identity and ordinary AIR verification. Add spec/RFC/grammar, checked Quick Reference examples, source/AIR conformance, package/hosted CLI tests, scheduler/GC coverage and documentation budgets.
This commit is contained in:
1 parent
57603860df
commit
f02f4bd55b
72 files changed
+969
-25
No files matched your search
@@ -117,3 +117,5 @@ RFC 0026 std.hash (cl100k, relative to Deque): Quick Reference 7,747 → 7,806 (
|
||||
RFC 0027 explicit error values (cl100k, relative to hashes): Quick Reference 7,806 → 7,863; other source docs 47,475 → 48,061; full source excluding AIR 55,281 → 55,924 (+1.2%). AIR is 179,282 bytes / 51 sections, and its source-bundle copy is 46,300 tokens. The measurement excludes the developing map contract. Existing variant syntax gains pure built-in error values; no authority, resource or ownership state is added. Cumulative source growth is +64.6%; the RFC records the complexity justification, without claiming MCC improvement.
|
||||
|
||||
RFC 0028 numeric-key owning map (cl100k, relative to error_values; includes the separate integer-pattern clarification): Quick Reference stays 7,863, other source docs 48,061 → 50,079, full source excluding AIR 55,924 → 57,942 (+3.6%). The on-demand library page is 14,167 tokens. AIR remains 179,282 bytes / 51 sections. No map-specific instruction, source form, verifier state or diagnostic is added; general keys remain Q-037. Cumulative source growth is +70.5%, with review justification in the RFC and no claimed MCC benefit.
|
||||
|
||||
RFC 0029 static function parameters (cl100k, relative to numeric maps): Quick Reference 7,863 → 8,051 (+2.4%); other source docs 50,079 → 51,002 (+1.8%); full source excluding AIR 57,942 → 59,053 (+1.9%). language/generics.md is 2,194 tokens; AIR remains 179,282 bytes / 51 sections. One explicit operation-selection concept adds two source forms and bounded frontend state, with no runtime/verifier state or new AIR construct/diagnostic. Cumulative growth is +73.8%; the RFC justifies the general hash/equality/order prerequisite, keeps general collections open and makes no empirical MCC claim.
|
||||
@@ -415,6 +415,17 @@ fn main() -> u64 effects [] {
|
||||
|
||||
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.
|
||||
|
||||
An operation is an explicit static parameter, with exact parameter/return types and effect set. Select a declared function with `fn path` (generic: `fn path::<args>`); `fn F` forwards a bound operation. It has no runtime value or captures; F is only a direct call or `task.spawn` worker. Different operations produce distinct nominal instances. Mismatch: `E7005`; escaping/shadowing F or borrowed return contracts: `E7006`. Effects and capability arguments remain explicit.
|
||||
|
||||
```aji
|
||||
module demo.static_functions
|
||||
fn identity(value: u64) -> u64 effects [] { return value; }
|
||||
fn apply<T, F: fn(T) -> T effects []>(value: T) -> T effects [] {
|
||||
return F(move value);
|
||||
}
|
||||
fn main() -> u64 effects [] { return apply::<u64, fn identity>(42u64); }
|
||||
```
|
||||
|
||||
## 13. Linear aggregates
|
||||
|
||||
A struct/enum/fixed array containing owners or resources is linear. Construct with `move`; consume it completely. Read Copy fields normally. A linear enum needs exhaustive `match move`; even none must be consumed. No partial moves or automatic cleanup.
|
||||
|
||||
@@ -31,6 +31,7 @@ docs/spec/03-memory-model.md :: ## 26. Dynamic initialized buffers
|
||||
|
||||
> language/generics.md
|
||||
docs/spec/15-source-language.md :: ## 15. Explicit source generics
|
||||
docs/spec/15-source-language.md :: ## 18. Static function parameters
|
||||
|
||||
> language/modules.md
|
||||
docs/spec/15-source-language.md :: ## 14. Package source modules
|
||||
|
||||
@@ -11,7 +11,7 @@ The other files in `/docs` hold the full rules. Open one only when this page is
|
||||
| built-in bytes/math/text/formatting/hash, option/result, owning Vec and Deque, signatures and failure contracts | `/docs/library/std.md` |
|
||||
| initialized buffer storage, explicit growth/drain and child views | `/docs/language/buffers.md` |
|
||||
| whole-value linear aggregates, unpack, exchange and allocation failure | `/docs/language/linear-aggregates.md` |
|
||||
| generic declarations/applications, property constraints and specialization limits | `/docs/language/generics.md` |
|
||||
| generic declarations/applications, property constraints, static function contracts and specialization limits | `/docs/language/generics.md` |
|
||||
| explicit package imports, qualified types, manifest file inputs | `/docs/language/modules.md` |
|
||||
| exact syntax, every construct, `match` and outcomes | `/docs/language/syntax.md` |
|
||||
| integer semantics, conversions, Copy/Send/Share, traps | `/docs/language/types.md` |
|
||||
|
||||
@@ -31,6 +31,7 @@ Status values: `open`, `resolved`.
|
||||
| Q-035 | resolved | STD-5 | Whole-value linear aggregates |
|
||||
| Q-036 | resolved | STD-6a | Dynamic initialized linear buffer storage and drain |
|
||||
| Q-038 | resolved | STD-6d.2 | Pure construction of built-in errors |
|
||||
| Q-039 | resolved | STD-6d | Explicit static function parameters |
|
||||
|
||||
## Q-001 — Text AIR grammar
|
||||
|
||||
@@ -281,3 +282,9 @@ HashMap<K,V> needs a stable hash/equality pair: equal keys must hash equally, wh
|
||||
STD-6d.2 needs to return allocation-size validation failure without allocating. Existing built-in errors were obtainable only from fallible runtime operations.
|
||||
|
||||
**Resolved (RFC 0027 branch implementation):** spec 05 §14 adds feature `error_values` and pure `error.const B.variant`; source reuses `B::variant`. Every registered payload-free error variant is ordinary Copy data, never authority. Existing `enum.make` and runtime outcome rules are unchanged.
|
||||
|
||||
## Q-039 — Explicit static function parameters
|
||||
|
||||
General collections and algorithms need explicit typed hash/equality/order operations, while current generics carry only types.
|
||||
|
||||
**Resolved contract (RFC 0029 Proposed):** spec 15 §18 permits explicitly selected source functions as static parameters with exact typed/effect contracts. Selection is part of nominal specialization identity and lowers to existing named AIR calls/workers. No function pointers, capture environment, inferred effects or runtime dispatch are introduced. Q-037 remains open until generic map/set storage and APIs are implemented and verified.
|
||||
@@ -141,4 +141,4 @@ Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) a
|
||||
| P6-9 | todo | Port reference programs and examples to `.aji` | P6-5 | `tests/programs/`, `examples/` | exit criterion passes |
|
||||
| P6-10 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||||
|
||||
The [standard-library track](standard-library.md) implements twelve compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch 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 on the branch. 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). General key policy remains Q-037. Remaining maps/sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
|
||||
The [standard-library track](standard-library.md) implements twelve compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch 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 on the branch. 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. General key policy remains Q-037. Remaining maps/sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
|
||||
@@ -61,6 +61,7 @@ SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protob
|
||||
| STD-6d.1 | done (branch implementation; RFC 0026 Proposed) | pure std.hash: FNV-1a 64 / CRC32C, fresh/extend | STD-1b | four safe functions, exact byte/chunk conventions, independent public vectors and CLI/profile checks |
|
||||
| STD-6d.2a | done (branch implementation; RFC 0027 Proposed) | pure built-in error construction prerequisite | STD-6d.1 | vertical error_values feature, no authority/effect/resource changes; preflight allocation validation |
|
||||
| STD-6d.2 | done (numeric-key branch implementation; RFC 0028 Proposed) | U64Map<V> first; general HashMap<K,V> key policy Q-037 | STD-6d.1 | safe map with ownership/failure/collision tests and error_values prerequisite (RFC 0027); general-key gate remains open |
|
||||
| STD-6d.3 | done (branch implementation ; RFC 0029 Proposed) | explicit static hash/equality/order functions | STD-4 | exact callable contracts, ordinary AIR calls/workers and nominal operation identity; general collections remain required |
|
||||
| STD-7 | todo | concrete I/O adapters, buffered I/O and lexical paths | STD-1b/2a/2b; STD-3 for public types | short reads, EOF, capacity and write failures covered; paths never grant filesystem authority |
|
||||
| STD-8 | todo | filesystem gaps, args/env capability RFC, time/random distinctions and structured log | STD-3/7; vertical runtime feature where needed | CLI/storage milestone examples work in deterministic and hosted profiles; all authority is granted at entry |
|
||||
| STD-9 | todo | independent integration application and API review | STD-6/7/8 | integration gate; public application is not private benchmark material |
|
||||
@@ -137,3 +138,8 @@ RFC 0024 records storage/Vec validation. RFC 0025 records the deque API/budget m
|
||||
## Hash foundation and next map contract
|
||||
|
||||
STD-6d.1/RFC 0026 adds safe std.hash with four byte-only fresh/continuation operations, no new semantics or heap authority. FNV/CRC constants and public vectors are independently verified; hashes never replace key equality. [The map design](../design/hash-map.md) specifies numeric-key U64Map<V>, bounded insert, returned replacement/full ownership, tombstone lookup, moving removal/drain and explicit peak-charged rehash. STD-6d.2/RFC 0028 implements safe std.map.U64Map<V> with ten operations, using explicit error construction (RFC 0027) for preflight validation. Independent dictionary traces, collision/tombstone/wrap cases, exact peak/refund accounting, owning/files/sender/task tests and rejected leaks/aliases/Copy uses cover the contract. Q-037 keeps general key policy explicit; HashMap<Key, Own<Value>>/HashSet/BinaryHeap remain required by STD-6d.
|
||||
|
||||
|
||||
## General operation-selection prerequisite
|
||||
|
||||
STD-6d.3/RFC 0029 implements explicitly bound static functions with exact typed/effect contracts, forwarding, generic function arguments, nominal operation identity and named workers. It reuses ordinary AIR and preserves direct-import visibility, capability inputs, ownership and task loans. Source/AIR positives/rejections, recursive/cyclic contracts, GC/scheduler stress, CLI/profile/provenance checks and documentation budgets are recorded in the RFC. General HashMap/HashSet storage/API remains Q-037; BinaryHeap and STD-7 are still required.
|
||||
@@ -28,9 +28,12 @@ fn_decl = "fn" ident [ type_params ] "(" [ param { "," param } ] ")" "->"
|
||||
block ; (* `trusted` is reserved and rejected, E7006 *)
|
||||
param = ident ":" type ;
|
||||
type_params = "<" type_param { "," type_param } ">" ;
|
||||
type_param = ident [ ":" property { "+" property } ] ;
|
||||
type_param = ident [ ":" ( property { "+" property } | function_contract ) ] ;
|
||||
function_contract = "fn" "(" [ type { "," type } ] ")" "->" type
|
||||
"effects" "[" [ path { "," path } ] "]" ;
|
||||
property = "Copy" | "Send" | "Share" | "Freeze" | "Local" ;
|
||||
type_args = "<" type { "," type } ">" ;
|
||||
type_args = "<" generic_arg { "," generic_arg } ">" ;
|
||||
generic_arg = type | "fn" path [ application ] ; (* static function selection; spec 15 §18 *)
|
||||
application = "::" type_args ; (* explicit; no inference, spec 15 §15 *)
|
||||
|
||||
type = int_type | "bool" | "void" | "never" | path
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# RFC 0029: Explicit static function parameters
|
||||
|
||||
Status: Proposed
|
||||
Scope: vertical Phase 6 source specialization prerequisite for general collections
|
||||
Language version: 0.1
|
||||
|
||||
## Motivation
|
||||
|
||||
General maps/sets, ordered heaps and algorithms need user operations without map-specific compiler logic. Copy/Send/Share properties supply no hash/equality/order. Static named functions are the smallest general facility reusing existing AIR calls and verification. They preserve explicit authority, effects and ownership.
|
||||
|
||||
## Precise invariant
|
||||
|
||||
A selected source function has exactly the declared parameter/return types and effect set. Selection grants no authority. It is part of nominal instance identity and has no runtime representation or captured state. All linear transfers and borrows are checked by ordinary AIR verification.
|
||||
|
||||
## Normative rule changes
|
||||
|
||||
Spec 15 §18 and the source grammar define callable contracts in generic declarations and explicit `fn path` arguments. Existing type-only generic syntax/meaning remains unchanged. Declaration, signature, storage, expression and worker rules are integrated in the same phase. Q-039 records the contract; general collections remain Q-037 until implemented.
|
||||
|
||||
## Verifier implications
|
||||
|
||||
No new AIR verifier state or transfer function. Specialization checks exact callable signatures/effect sets and emits ordinary named call/worker operands. Existing ownership, loan, effects, Send/Share, capability and bounded layout verification decides whether the resulting program is valid.
|
||||
|
||||
## Interpreter / runtime implications
|
||||
|
||||
No new runtime state, instruction, allocation, capability, dispatch or destructor. Existing deterministic call/task semantics and fuel apply. Selected operation bodies remain visible AIR.
|
||||
|
||||
## AIR changes
|
||||
|
||||
None; ordinary static call/task operands suffice. Positive AIR equivalents and negative ordinary effect/ownership examples demonstrate the existing boundary. No existing opcode meaning changes and no new instruction is introduced as sugar.
|
||||
|
||||
## Valid example
|
||||
|
||||
`apply<T, F: fn(T) -> T effects []>` can call F with complete transfer; `apply::<u64, fn identity>` selects a named pure function. Borrowed comparators, owning transforms, explicit effectful capability operations and task workers compose with the same mechanism.
|
||||
|
||||
## Rejected example
|
||||
|
||||
A `fn(ref<T>) -> u64 effects []` parameter rejects a mem.alloc function, wrong return type or mut<T> parameter with E7005. Selected functions cannot be stored/returned as values (E7006), forged from capabilities or resolved through unimported modules (E7002). Ordinary missing effects, invalid moves/loans and resource leaks remain rejected after substitution.
|
||||
|
||||
## Diagnostics impact
|
||||
|
||||
No new codes. E7001 syntax, E7002 inaccessible names, E7005 argument/signature/effect mismatch, E7006 forbidden use/limits; existing AIR codes apply after lowering. Diagnostics retain caller argument and template body provenance. Callable mismatch records include the parameter, selected function and expected/found contracts.
|
||||
|
||||
## Compatibility and migration
|
||||
|
||||
Additive explicit source syntax. AIR format 0 and all registered feature meanings remain unchanged. Existing type-only generics, instance identities, capabilities and effect contracts retain meaning. No borrowed returns, methods, traits, overload search, captures or argument inference are added.
|
||||
|
||||
## Agent complexity impact
|
||||
|
||||
One concept: a compile-time named function with an exact contract. Two composed source forms: callable generic declaration and explicit fn argument. No runtime or verifier state, diagnostic code or AIR feature. Frontend state adds callable contracts to the existing bounded environment/cache, with selected function identity in type/function keys. Exact effects avoid variance and effect shims; normal explicit arguments/moves make ownership repairable. Existing AIR primitives suffice, while manual per-key algorithm duplication cannot express a reusable general source container. The facility also serves ordering and transforms, beyond maps. The measured source growth is recorded below; the AIR bundle is unchanged. No empirical MCC benefit is claimed.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
Numeric-only wrappers do not meet the general collection gate. Hash-only identity is incorrect under collisions. Runtime function pointers/closures, trait dictionaries, reflection and type-name conventions require more semantics or hide operation selection. Implicit structural hashing fixes one policy and leaves user ordering/equality unresolved. Exact static contracts use existing calls and public effect declarations.
|
||||
|
||||
## Unresolved questions
|
||||
|
||||
Q-037 remains open for the complete generic map/set library contract. A dense initialized entry buffer plus Copy probe-index metadata permits borrowed arbitrary owning keys without default keys or borrowed enum payloads; that storage design will be specified separately.
|
||||
|
||||
## Branch validation
|
||||
|
||||
The complete regression corpus passes 912 tests; the two subsequently added recursive/cyclic-contract cases pass in the focused 51-case corpus. All 51 static-function/source/AIR/Quick Reference cases also pass with collection before every instruction and 12 schedule seeds under stress quanta 1, 2, 7 and the test quantum. Unit tests, Quick Reference checking, formatting, reference-bundle generation and source coverage pass. CLI integration covers 25 source/AIR/package/hosted/report/explore/diagnostic checks; existing generic (20) and numeric-map (76) CLI checks pass. Type-argument traversal for built-in allocation/channel calls remains covered by the existing container corpus. No wall-clock run limit is used.
|
||||
|
||||
## Documentation budget
|
||||
|
||||
Relative to RFC 0028 (all counts exclude generated AIR from the full source group):
|
||||
|
||||
| Bundle group | cl100k_base before → after | o200k_base before → after | Qwen2.5 before → after |
|
||||
|---|---|---|---|
|
||||
| Quick Reference | 7,863 → 8,051 | 7,894 → 8,082 | 8,102 → 8,300 |
|
||||
| Other source docs | 50,079 → 51,002 | 50,223 → 51,150 | 51,509 → 52,468 |
|
||||
| Full source | 57,942 → 59,053 | 58,117 → 59,232 | 59,611 → 60,768 |
|
||||
|
||||
cl100k growth is +2.4% / +1.8% / +1.9%, respectively. The on-demand generics page is 2,194 cl100k tokens. AIR remains 179,282 bytes / 19 files / 51 sections and 46,300 cl100k tokens in the source bundle. No AIR normative material is added to bundle.txt because ordinary instructions retain their contracts. Cumulative source growth from the pre-stdlib 33,981-token baseline is +73.8%; the rationale is a general operation-selection mechanism needed for arbitrary collection keys and ordering, rather than per-container compiler rules. The Quick Reference remains above its 4–6k target; consolidation/selective reading is separate work. Documentation/fixtures alone are not evidence of an empirical MCC improvement.
|
||||
@@ -522,9 +522,9 @@ The combined AIR MUST pass the ordinary verifier and runs as a single format-0 m
|
||||
|
||||
Functions, structs and enums MAY declare 1–8 type parameters immediately after their name, e.g. `fn identity<T>(value: T) -> T effects [] { return value; }`, `struct Pair<T: Copy> { left: T, right: T }`, `enum Option<T: Copy> { some(T), none }`. Parameters MUST be distinct uppercase identifiers, MUST NOT shadow a visible type/builtin type, and have no default. Constraints are optional compiler-known `Copy`, `Send`, `Share`, `Freeze` or `Local`, joined by `+`; repeated/unknown constraints are `E7006`. Generic `main` is forbidden (`E7006`). No user traits, overloads, type inference, const/lifetime/effect parameters or specialization overrides are introduced.
|
||||
|
||||
Every generic use MUST supply exactly its ordered type arguments. Type annotations use `Pair<u64>`; expression applications use `identity::<u64>(42)`, `Pair::<u64> { left: 20, right: 22 }` and `Option::<u64>::some(42)`. Enum patterns use `Option::<u64>::some(value)` and `Option::<u64>::none`. The `::<...>` spelling separates generic application from comparisons; bare `f<T>(...)` is outside the expression grammar. Qualified forms obey §14's direct-import rules. `task.spawn(s, worker::<u64>, ...)` statically specializes the worker; this creates no function value. Existing `channel.make<T>(...)` retains its spelling and single type argument.
|
||||
Every generic use MUST supply exactly its ordered arguments (type arguments here; static function arguments in §18). Type annotations use `Pair<u64>`; expression applications use `identity::<u64>(42)`, `Pair::<u64> { left: 20, right: 22 }` and `Option::<u64>::some(42)`. Enum patterns use `Option::<u64>::some(value)` and `Option::<u64>::none`. The `::<...>` spelling separates generic application from comparisons; bare `f<T>(...)` is outside the expression grammar. Qualified forms obey §14's direct-import rules. `task.spawn(s, worker::<u64>, ...)` statically specializes the worker; this creates no function value. Existing `channel.make<T>(...)` retains its spelling and single type argument.
|
||||
|
||||
Type parameters are substituted in types, casts, declarations, explicit applications and enum/struct constructors/patterns, including nested templates. A parameter used as a constructor requires its own explicit concrete type arguments if that concrete type is generic; parameters are types, not values or operations. Type arguments MUST be concrete source types after substitution, excluding `void` and `never`. Ordinary type-position, layout, ownership and capability restrictions still apply to every emitted specialization; generics MUST NOT bypass the member restrictions; linear members require §16, and borrowed aggregate members remain forbidden.
|
||||
Type parameters are substituted in types, casts, declarations, explicit applications and enum/struct constructors/patterns, including nested templates. A parameter used as a constructor requires its own explicit concrete type arguments if that concrete type is generic; type parameters are types, not values or operations; static function parameters are separately defined in §18. Type arguments MUST be concrete source types after substitution, excluding `void` and `never`. Ordinary type-position, layout, ownership and capability restrictions still apply to every emitted specialization; generics MUST NOT bypass the member restrictions; linear members require §16, and borrowed aggregate members remain forbidden.
|
||||
|
||||
Templates are parsed and declaration parameter/constraint/duplicate rules, signature type names/arity, effects and the prohibition of trusted clauses are checked even if unused. Generic bodies are type/ownership/effect checked for each required concrete specialization, not abstractly proved for all possible arguments. An unused template body has no emitted code and no runtime effects; successful checking does not claim it is valid for every future instantiation. All non-generic declarations in reachable modules continue to be verified even if unused. A missing generic type argument or wrong arity is `E7006`; unknown/inaccessible templates/types use `E7002`; an unsatisfied constraint is `E7005` at the application, with `parameter`, `constraint` and `found` metadata. Body failures point at template source.
|
||||
|
||||
@@ -560,3 +560,27 @@ Outcomes: new has ok(buffer)/err(alloc_error); reserve has ok()/err(alloc_error)
|
||||
A specialized generic body MAY use `move name` to express complete value transfer for a type parameter. If its concrete binding is Copy, lowering passes the existing Copy value and it remains available; if linear, ordinary transfer/availability applies. This rule applies to complete Copy bindings inside a specialized generic body, not borrows/storage/function-bound values. Outside a specialized generic body, move of a Copy value remains E7006. No AIR ownership rule changes and no implicit destructor/allocation is added. This makes one generic container body correct for both Copy and linear contents; ordinary borrow/effect/type constraints still apply to every specialization.
|
||||
|
||||
The frontend MUST emit linear_buffers and its full dependencies for buffer types/operations. Existing syntax suffices apart from admitting the buffer wrapper and the typed built-in allocator with the existing channel.make<T> type-argument form. General methods, borrowed aggregate storage, recursive ownership and from-return calls are not added.
|
||||
|
||||
## 18. Static function parameters
|
||||
|
||||
Generic structs, enums and functions MAY declare a static function parameter alongside type parameters: `F: fn(ref<T>) -> u64 effects []`. This is a compile-time contract, not a value type. Its ordered parameter types, return type and complete flat effect set MUST be explicit. Static function parameter names MUST be uppercase, distinct, and MUST NOT shadow a visible type or function. All types are checked/substituted like ordinary function signatures; all effect atoms MUST be registered and unique. Borrow returns and `from` contracts are outside this increment (Q-034). A callable parameter MUST NOT carry structural property constraints or be used as a type. The existing maximum of eight generic parameters counts both kinds.
|
||||
|
||||
An explicit argument is `fn path`, or `fn path::<arguments>` for a generic function. The path MUST resolve to a directly accessible declared source function. Built-in operation names, runtime values and captures are not function arguments. `fn F` forwards an already bound static parameter; it cannot be specialized again. A type argument in a function position or a function argument in a type position is `E7005`. Wrong generic arity remains `E7006`; unknown/inaccessible functions remain `E7002`. Signature/effect mismatch diagnostics include `parameter`, `function`, `expected` and `found` contracts.
|
||||
|
||||
After substitution, the selected function MUST have exactly the declared ordered parameter/return types and effect set (`E7005`). Effect order is irrelevant; widening/narrowing of effects or borrow types is not implicit. Exact effect contracts avoid effect shims and ensure that specialization cannot infer effects away from a public contract. Capabilities are ordinary explicit arguments; selecting a function grants no authority. A borrowed input retains ordinary read/exclusive access rules, and linear arguments retain explicit moves and consumption obligations.
|
||||
|
||||
The bound name MAY occur only as a direct call target or named `task.spawn` worker; normal arguments and explicit moves/borrows still apply. It MUST NOT escape into storage, aggregates, returns or runtime expressions (`E7006`). It MUST NOT be shadowed by a runtime binding in a specialized body or its signature (`E7006`). Static parameters have no runtime representation, capture environment, destructor, heap allocation or indirect dispatch. They are not inferred. Templates remain subject to the header/body distinction of §15.
|
||||
|
||||
Function identity, including explicit specialization arguments and defining module, MUST participate in the instance identity of both functions and types. In canonical keys a static argument spells `fn ` followed by the full defining-module/function path, including canonical `<...>` arguments when specialized. Thus two container types with different bound hash/equality functions are nominally distinct, even when their storage layouts agree. Linking retains direct-import restrictions and caller-site provenance for explicit arguments. Limits remain depth 64, 4,096 specializations and 16,384-byte instance keys, including argument/contract resolution; unresolved cyclic contracts MUST reject with `E7006`, never recurse without a bound.
|
||||
|
||||
Lowering MUST replace each bound call/worker with an ordinary named AIR function operand. No new AIR instruction, type, effect, capability, feature or verifier state is added: ordinary `call`, task checking, effects, borrows and ownership validate every resulting specialization. Existing AIR format-0 semantics and type-only source generics are unchanged. AIR equivalence and source rejection tests MUST cover static selection, nominal policy identity, authority, ownership, effects, imports and workers.
|
||||
|
||||
```aji
|
||||
fn identity(value: u64) -> u64 effects [] { return value; }
|
||||
fn apply<T, F: fn(T) -> T effects []>(value: T) -> T effects [] {
|
||||
return F(move value);
|
||||
}
|
||||
// In main: apply::<u64, fn identity>(42u64)
|
||||
```
|
||||
|
||||
General collections MAY use these explicit contracts for hash/equality/order operations. Their algebraic laws remain library preconditions; no compiler magic infers hashing or equality. This facility alone does not complete HashMap/HashSet or resolve their storage/API invariants.
|
||||
Reference in new issue
Block a user