- reference/air-features.md: normative feature registry (arrays, atomics, capabilities, channels, effects, islands, ownership, regions, sync, tasks; all reserved), dependency closures, reasons for E0006 - spec 07 §8.1/§8.5/§8.7: features are mandatory, validated before the body, full dependency closure declared, sorted canonically; every extension belongs to a feature; published feature semantics immutable - spec 05 §8: features vs effects vs capabilities - src/air/features.zig: registry, validation, sync test with the docs - parser validates features first; E0006 carries `reason` - `aji features` prints supported AIR format, language and features - conformance: unknown, reserved and duplicate feature tests - plan: feature publication tasks in phases 1-5
2.2 KiB
05. Effects and Capabilities
1. Rationale
Effects answer: what can this function do?
Capabilities answer: what authority does this invocation possess?
Both are part of the program contract.
2. Effects
Every function has an effect set.
Pure example:
fn checksum(data: slice<u8>) -> u32
effects []
Representative effects:
mem.alloc
mem.map
fs.read
fs.write
io.read
io.write
net.connect
net.listen
net.read
net.write
clock.read
random.read
task.spawn
thread.spawn
thread.block
atomic
atomic.weak
process.spawn
ffi
unsafe
A caller's effect set must cover transitive callee effects unless the effect is discharged by a verifier-recognized boundary.
3. Capabilities
Capabilities are unforgeable values created by the host/runtime or delegated by existing authority.
Example:
fn load(
fs: cap<fs.read>,
path: slice<u8>
) -> Result<Data, IoError>
effects [fs.read]
Without the capability, the operation cannot be performed even if the function declares the effect.
4. Narrowing
Capabilities may be narrowed but not widened.
A broad filesystem capability may yield a capability limited to:
- read-only access;
- a path prefix;
- a mount;
- an already-open resource;
- a bounded operation set.
5. Capability transfer
Capabilities may have ownership semantics:
- copyable/read-only authority;
- move-only authority;
- local-only authority;
- delegatable authority.
The capability type defines its transfer rules.
6. Build/runtime separation
Compilation does not imply runtime authority.
A program may compile with a declared effect set yet fail to instantiate because the host does not grant matching capabilities.
7. Auditability
The toolchain should be able to emit:
- declared effect graph;
- capability requirements per entry point;
- effective transitive authority;
- unsafe/FFI authority boundaries.
8. Relation to AIR features
AIR features (spec 07 §8.1) are a third, separate concept. A feature says which semantics the implementation must understand; it grants no authority and adds no effect. Declaring features [capabilities, effects, ownership] does not let a program read a file: the function still needs effects [fs.read] and a cap<fs.read> value.