Phase 2: effects and capabilities (RFC 0006)

- air: cap<K> and built-in enums (cap_error) as types; enum.switch over
  built-in enums; cap.narrow terminator with ok/err targets; intrinsic
  syntax (registry still empty: E0004); registries for effects,
  capability kinds and built-in enums, synced with reference docs
- verifier: effect stage (E3101, flat, direct callees); cap.narrow form
  check (E3202) and ok/err parameter rules (E5002, E1001); capabilities
  are copyable, not zeroable, not comparable; sizes cap 8, built-in tag
- interp: host authority table; @main instantiation from grants by
  parameter name with not_instantiated reasons; capabilities render as
  opaque
- CLI: --grant P=KIND[:SCOPE], exit code 6; runner: grant: and
  not_instantiated: headers, pending only for unsupported features
- conformance: 18 Phase 2 tests; 4000 mutants without a crash
This commit is contained in:
dev committed 2026-10-04 13:42:35 +03:00
1 parent fb4338cea6
commit 9c29a80b72
41 files changed
+908 -58

No files matched your search

@@ -0,0 +1,23 @@
; Capabilities are copyable values: passed, copied and stored in a struct.
; expect: accept
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.capability_values
air 0
lang 0.1
features [capabilities, effects, ownership]
type @Logger = struct { out: cap<io.write> }
fn @make(%out: cap<io.write>) -> @Logger
effects []
entry:
%c = copy %out
%l = struct.make @Logger(%c)
ret %l
fn @use(%l: @Logger) -> cap<io.write>
effects []
entry:
%o = struct.get @Logger.out, %l
ret %o
@@ -0,0 +1,20 @@
; Effects declared along a call chain, including recursion.
; expect: accept
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.transitive_effects
air 0
lang 0.1
features [effects]
fn @a() -> void
effects [io.write]
entry:
call @b()
ret
fn @b() -> void
effects [io.write]
entry:
call @b()
ret
@@ -0,0 +1,13 @@
; cap<K> belongs to the feature capabilities, which is not declared.
; expect: reject E0006
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.cap_without_feature
air 0
lang 0.1
features [effects]
fn @f(%c: cap<io.write>) -> void
effects []
entry:
ret
@@ -0,0 +1,17 @@
; A struct holding a capability is authority-bearing and cannot be zeroed.
; expect: reject E1001
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.capability_not_zeroable
air 0
lang 0.1
features [capabilities, effects, ownership]
type @Logger = struct { out: cap<io.write> }
fn @f() -> void
effects []
entry:
%x = local.alloc @Logger
local.zero %x
ret
@@ -0,0 +1,19 @@
; atomic does not imply atomic.weak.
; expect: reject E3101
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.flat_effects
air 0
lang 0.1
features [effects]
fn @f() -> void
effects [atomic]
entry:
call @g()
ret
fn @g() -> void
effects [atomic.weak]
entry:
ret
@@ -0,0 +1,17 @@
; The ok target of cap.narrow takes exactly one parameter.
; expect: reject E5002
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.narrow_ok_arity
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @f(%c: cap<io.write>, %n: usize) -> void
effects []
entry:
cap.narrow.budget %c, %n, ok -> @ok, err -> @err
ok:
ret
err(%e: cap_error):
ret
@@ -0,0 +1,14 @@
; Capabilities cannot be compared: there is no eq.cap.
; expect: reject E0004 E5001
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.no_capability_comparison
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @f(%a: cap<io.write>, %b: cap<io.write>) -> bool
effects []
entry:
%r = eq.cap %a, %b
ret %r
@@ -0,0 +1,19 @@
; The caller does not declare the effect of its callee.
; expect: reject E3101
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.undeclared_effect
air 0
lang 0.1
features [effects]
fn @f() -> void
effects []
entry:
call @g()
ret
fn @g() -> void
effects [io.write]
entry:
ret
@@ -0,0 +1,13 @@
; cap<root> is not a registered capability kind.
; expect: reject E0004
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.unknown_capability_kind
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @f(%c: cap<root>) -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; teleport is not a registered effect.
; expect: reject E0004
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.unknown_effect
air 0
lang 0.1
features [effects]
fn @f() -> void
effects [teleport]
entry:
ret
@@ -0,0 +1,14 @@
; No intrinsic is registered yet; unknown names are E0004.
; expect: reject E0004
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.unknown_intrinsic
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @f(%c: cap<io.write>) -> void
effects [io.write]
entry:
intrinsic io.teleport(%c)
ret
@@ -0,0 +1,17 @@
; io.write has no narrowing forms; any form is reported as widening.
; expect: reject E3202
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.unknown_narrowing_form
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @f(%c: cap<io.write>, %n: usize) -> void
effects []
entry:
cap.narrow.budget %c, %n, ok -> @ok, err -> @err
ok(%d: cap<io.write>):
ret
err(%e: cap_error):
ret
@@ -0,0 +1,16 @@
; A granted capability parameter instantiates @main.
; expect: run
; grant: out=io.write
; result: 1
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.instantiate
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @main(%out: cap<io.write>) -> u8
effects [io.write]
entry:
%v = const.u8 1
ret %v
@@ -0,0 +1,16 @@
; A path scope with .. cannot be granted.
; expect: run
; grant: data=fs.read:/var/../etc
; not_instantiated: invalid_scope
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.invalid_scope
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @main(%data: cap<fs.read>) -> u8
effects [fs.read]
entry:
%v = const.u8 1
ret %v
@@ -0,0 +1,16 @@
; The grant is of a different kind than the parameter.
; expect: run
; grant: out=fs.read:/tmp
; not_instantiated: kind_mismatch
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.kind_mismatch
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @main(%out: cap<io.write>) -> u8
effects [io.write]
entry:
%v = const.u8 1
ret %v
@@ -0,0 +1,15 @@
; No grant for the parameter: the program does not start.
; expect: run
; not_instantiated: missing_capability
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.missing_capability
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @main(%out: cap<io.write>) -> u8
effects [io.write]
entry:
%v = const.u8 1
ret %v
@@ -0,0 +1,17 @@
; Two parameters of the same kind get different scopes by name.
; expect: run
; grant: config=fs.read:/etc/app
; grant: data=fs.read:/var/data
; result: 1
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.two_scopes
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @main(%config: cap<fs.read>, %data: cap<fs.read>) -> u8
effects [fs.read]
entry:
%v = const.u8 1
ret %v
@@ -0,0 +1,17 @@
; A grant naming no parameter is an error, so typos are not ignored.
; expect: run
; grant: out=io.write
; grant: ouy=io.write
; not_instantiated: unknown_parameter
; phase: 2
; spec: docs/spec/05-effects-and-capabilities.md
module test.unknown_parameter
air 0
lang 0.1
features [capabilities, effects, ownership]
fn @main(%out: cap<io.write>) -> u8
effects [io.write]
entry:
%v = const.u8 1
ret %v