Files
aji/docs/rfcs/0029-static-function-parameters.md
T
dev ad75ffe021
ci / build (ubuntu-latest) (push) Successful in 4m52s
ci / extended (push) Failing after 3h0m2s
ci / build (macos-latest) (push) Canceled after 0s
docs: adopt intermediate standard library foundation
Record the owner-requested STD-0..7 merge boundary and adoption of implemented
RFCs 0016-0035, whose normative rules and vertical implementations land together.
Update repository and std status; keep remaining Std 0.1 and service milestones
in the backlog. Track Q-034/P6-11 as the next source-language task and retain
the existing P7/P8 gate.

Implementation checks are recorded in RFC 0035 and the std plan; this change
updates adoption metadata and planning only.
2026-10-07 13:42:50 +03:00

75 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RFC 0029: Explicit static function parameters
Status: Implemented
Scope: vertical Phase 6 source specialization prerequisite for general collections
Language version: 0.1
Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together.
## 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.