Draft specification, RFCs, reference registries and examples, plus the reference-implementation skeleton: build.zig, diagnostic envelope with error-code registry synced to docs, aji CLI, conformance runner with seed tests, CI and contributor docs.
102 lines
1.9 KiB
Markdown
102 lines
1.9 KiB
Markdown
# 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:
|
|
|
|
```aji
|
|
fn checksum(data: slice<u8>) -> u32
|
|
effects []
|
|
```
|
|
|
|
Representative effects:
|
|
|
|
```text
|
|
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:
|
|
|
|
```aji
|
|
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.
|