nx_effect.nx
buildroot/runtime/nx_effect.nx
about
effect.nx -- typed effects tracking (phase A: runtime log).
EFFICIENCY_ROADMAP ยง3.4 -- algebraic effects / typed IO so
function signatures disclose their side effects. Pure-
function reasoning becomes possible; unexpected I/O from a
callee no longer hides.
Phase A: a process-wide effect log. Functions that touch
FS/NET/ALLOC call `effect_mark(EFF_*)` at entry; unit tests
assert the log is empty after a computation that claims
purity. Cheap to adopt incrementally; no compiler changes
needed.
Phase B (parser + typechecker): `can [FS, ALLOC]` row-type
on function signatures. Caller inherits the UNION of callee
effects automatically. Koka / Eff / OCaml-effects style.
Phase C: handler syntax. `try { ... } with FS_open -> ... `
for mocking / redirection / sandboxing without globals.
Invariants:
EF1 `effect_mark` is O(1) + non-allocating -- safe in
hot paths.
EF2 `effect_snapshot` captures the current effect set;
`effect_restore` rolls back. Enables nested purity
zones.
EF3 Effect constants are bitflags so multi-effect code
records a union with one OR.
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 52 | struct EffectState |
consts
| 38 | const EFF_NONE: i64 = 0 |
| 39 | const EFF_FS: i64 = 0x0001 // filesystem |
| 40 | const EFF_NET: i64 = 0x0002 // network |
| 41 | const EFF_ALLOC: i64 = 0x0004 // dynamic memory |
| 42 | const EFF_PROC: i64 = 0x0008 // fork/exec |
| 43 | const EFF_CLOCK: i64 = 0x0010 // read wall-clock |
| 44 | const EFF_RANDOM: i64 = 0x0020 // entropy source |
| 45 | const EFF_IO: i64 = 0x0040 // stdin/stdout/stderr |
| 46 | const EFF_SYSCALL: i64 = 0x0080 // raw syscall |
| 47 | const EFF_UNWIND: i64 = 0x0100 // may panic/throw |
| 48 | const EFF_NONDET: i64 = 0x0200 // nondeterministic result |
functions
| 57 | func effect_state() -> *EffectState |
| 69 | func effect_mark(s: *EffectState, eff: i64) -> i64 called by 1: main |
| 75 | func effect_snapshot(s: *EffectState) -> i64 called by 1: main |
| 79 | func effect_restore(s: *EffectState, saved: i64) -> i64 called by 1: main |
| 86 | func effect_assert(s: *EffectState, allowed: i64) -> i64 called by 1: main |
| 93 | func effect_clear(s: *EffectState) -> i64 |
| 99 | func main() -> i64 |