code wiki / (root) / nx_effect.nx

nx_effect.nx

buildroot/runtime/nx_effect.nx

4053 B120 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_effect.nx

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

main effect_state sys_mmap effect_mark effect_assert effect_snapshot effect_restore

structs

52struct EffectState

consts

38const EFF_NONE: i64 = 0
39const EFF_FS: i64 = 0x0001 // filesystem
40const EFF_NET: i64 = 0x0002 // network
41const EFF_ALLOC: i64 = 0x0004 // dynamic memory
42const EFF_PROC: i64 = 0x0008 // fork/exec
43const EFF_CLOCK: i64 = 0x0010 // read wall-clock
44const EFF_RANDOM: i64 = 0x0020 // entropy source
45const EFF_IO: i64 = 0x0040 // stdin/stdout/stderr
46const EFF_SYSCALL: i64 = 0x0080 // raw syscall
47const EFF_UNWIND: i64 = 0x0100 // may panic/throw
48const EFF_NONDET: i64 = 0x0200 // nondeterministic result

functions

57func effect_state() -> *EffectState
called by 1: main calls 1: sys_mmap
69func effect_mark(s: *EffectState, eff: i64) -> i64
called by 1: main
75func effect_snapshot(s: *EffectState) -> i64
called by 1: main
79func effect_restore(s: *EffectState, saved: i64) -> i64
called by 1: main
86func effect_assert(s: *EffectState, allowed: i64) -> i64
called by 1: main
93func effect_clear(s: *EffectState) -> i64
99func main() -> i64