code wiki / (root) / effect.nx

effect.nx

buildroot/runtime/effect.nx

3913 B114 linesdepth 3pulls 3 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

syscalls.nx effect.nx

imports: 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 effect_mark effect_assert effect_snapshot effect_restore

structs

46struct EffectState {

consts

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

functions

51func effect_state() -> *EffectState {
called by 1: main
63func effect_mark(s: *EffectState, eff: i64) -> i64 {
called by 1: main
69func effect_snapshot(s: *EffectState) -> i64 {
called by 1: main
73func effect_restore(s: *EffectState, saved: i64) -> i64 {
called by 1: main
80func effect_assert(s: *EffectState, allowed: i64) -> i64 {
called by 1: main
87func effect_clear(s: *EffectState) -> i64 {
93func main() -> i64 {