code wiki / (root) / nx_hygiene_prims.nx

nx_hygiene_prims.nx

buildroot/runtime/nx_hygiene_prims.nx

13149 B351 linesdepth 2pulls 2 transitivereach 16 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_hygiene_prims.nx -- foundational primitives for the NISHI_CODE_HYGIENE_STANDARD.md (nishi-silicon commit f4cc144). Provides the building blocks new code MUST use to satisfy hygiene classes M1 (null safety), M2 (overflow safety), M4 (alloc safety), M5 (index safety). Once this ships, every commit going forward starts born-clean per the ยง4.1 MUST set. WINNER-TIER: WINNER-A (preserves the cardinal); paired with the standards docs that establish the bar INCUMBENTS: Rust std::option::Option, Rust checked_arithmetic, Ada SPARK contracts, MISRA C INT30-C rule, CERT INT32-C, libstd's bounds-checked indexer NUMBERS: V1 ships the primitives; benchmark vs Rust's checked_mul + alloc + Option pending paired bench GAP: Rust's Option<T> is language-built-in; this is a substrate-level convention. Future M3 milestone lifts NxOpt into a language-level type. PLAN: M-next: per-file remediation using these primitives; ratchet metric tracks count of null-creation + unchecked-alloc + raw-multiply sites going down per commit EXEMPTION REASON: n/a; provisional pending measurement Status: SEED v0.1.0. 2026-05-27.

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_hygiene_prims.nx nx_search_query_parser.nx

imports: nx_syscalls.nx

imported by: nx_search_query_parser.nx

structs

83struct NxOptPtr
329struct NxLoopBudget

consts

30const NX_HYG_OK: i64 = 0
31const NX_HYG_OVERFLOW: i64 = 600
32const NX_HYG_LOOP_BUDGET_EXCEEDED: i64 = 601
33const NX_HYG_BAD_INDEX: i64 = 602
34const NX_HYG_ALLOC_FAILED: i64 = 603
35const NX_HYG_NOT_IMPLEMENTED: i64 = 604
36const NX_HYG_BAD_TRUNCATION: i64 = 605
37const NX_HYG_USE_AFTER_RELEASE: i64 = 606
38const NX_HYG_DOUBLE_RELEASE: i64 = 607
39const NX_HYG_NULL_DEREF: i64 = 608
40const NX_HYG_UNCHECKED_RETURN: i64 = 609
43const NX_INT64_MAX: i64 = 9223372036854775807
44const NX_INT64_MIN: i64 = 0x8000000000000000
45const NX_BYTE_MAX: i64 = 255
46const NX_U16_MAX: i64 = 65535
47const NX_U32_MAX: i64 = 4294967295
52const NX_MAX_SINGLE_ALLOC_BYTES: i64 = 268435456 // 256 MiB
61const NX_SIZEOF_NXOPT_T: i64 = 16 // discriminant + value pointer
62const NX_SIZEOF_SAFE_INT_OUT: i64 = 8 // single i64 out-param

functions

88func nx_opt_none(opt: *NxOptPtr) -> i64
95func nx_opt_some(opt: *NxOptPtr, ptr: *u8) -> i64
called by 1: nx_alloc_checked
103func nx_opt_is_some(opt: *NxOptPtr) -> i64
113func nx_opt_unwrap(opt: *NxOptPtr) -> *u8
121func nx_opt_map(opt_in: *NxOptPtr, transform_fn: i64,
calls 1: nx_opt_none
146func nx_safe_add(a: i64, b: i64, out: *i64) -> i64
called by 1: nx_safe_sub
164func nx_safe_sub(a: i64, b: i64, out: *i64) -> i64
calls 1: nx_safe_add
177func nx_safe_mul(a: i64, b: i64, out: *i64) -> i64
212func nx_alloc_checked(size: i64, out_opt: *NxOptPtr) -> i64
240func nx_arr_get_i64(arr: *i64, cap: i64, idx: i64, out: *i64) -> i64
249func nx_arr_set_i64(arr: *i64, cap: i64, idx: i64, value: i64) -> i64
257func nx_arr_get_u8(arr: *u8, cap: i64, idx: i64, out: *i64) -> i64
266func nx_arr_set_u8(arr: *u8, cap: i64, idx: i64, value: i64) -> i64
289func nx_truncate_to_u8(v: i64, out: *i64) -> i64
297func nx_truncate_to_u16(v: i64, out: *i64) -> i64
305func nx_truncate_to_u32(v: i64, out: *i64) -> i64
335func nx_loop_budget_init(budget: *NxLoopBudget, max_iter: i64) -> i64
344func nx_loop_budget_step(budget: *NxLoopBudget) -> i64