omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / docs / RUNTIME-POOLS.md
| 1 | # Run-time pools: a global whose length is set while the program runs |
| 2 | |
| 3 | Status: landing 1 (the omc-only words of section 6, gates 1-11 of section 7 and the server case of |
| 4 | section 11) IMPLEMENTED in `seed/omc/omc.om`, gate `seed/omc/gate-pools.sh`, OMEGESE 9.15. Landing 2 |
| 5 | (om4 and the growing compiler arena, gates 12-14) IMPLEMENTED: om4 (`seed/rung4/om4.s`) knows `global |
| 6 | NAME T *`, `get`/`put`/`len` on a pool and `r = enlarge P n`, byte for byte as omc; omc's arena `a_ar` is a |
| 7 | run-time pool grown by `a_need` (doubling, `a_grow`); gates `seed/rung4/gate4.sh` (pool cases), gate5, |
| 8 | `seed/omc/gate-nocaps.sh` section 3, `gate12.sh`, `gate-usage.sh` (absolute words; its mutant control is |
| 9 | a_need's doubling made +512 entries, see section 7 item 14); first user (section 11) compiled and run. |
| 10 | ng-front refuses `global NAME T *` as a scope form (exit 64; the ng lane, NgNoCaps2), so |
| 11 | `seed/omc/omc.om` is a declared `scope 0` row of `seed/ng/front/gate-front.om` (section 6). (Historical state of 2026-11-11; section 12 supersedes the two NG pool scope exclusions.) Amended |
| 12 | 2026-11-11 (section 6, "The memory ceiling"): the growing arena refuses past a caller-stated real-memory |
| 13 | ceiling, `OMC_MEMORY_MAX`. Revision 2 takes in the |
| 14 | independent design review (consult-codex, 2026-11-11, findings B1-B2, S1-S8, N1-N4; recorded in section |
| 15 | 10). Implementation notes (landing 1): `enlarge` is keyword id 244 (above ng's 241..243); a host refusal |
| 16 | returns the host's negative errno, in practice -12 (ENOMEM), the only refusal these mmap and mremap calls can |
| 17 | reach by construction; |
| 18 | the element types are those `global` takes, f32 and f64 included (they use the array path unchanged); |
| 19 | the keyword changes no manifest-c2 row, so section 3.2's manifest-c2 delta has no rows and no file. Section 7 |
| 20 | item 14's mutant control is amended there (2026-11-11). |
| 21 | |
| 22 | Authority: decision 3 in `~/handoffs/yourtrained-cortex/briefs/decisions-20261111.md`. The lead took it |
| 23 | under Drake's delegation of 2026-11-11 ("Do whatever you think is best ... for longterm ... Lift all of |
| 24 | my prior restrictions"): run-time memory growth, in its smallest form. That is "a region whose size is |
| 25 | known at run time, obtained from the host as zero pages, bounds-checked like every array, no `free`, |
| 26 | no general allocator". Tracked as omega-mv #793 (RM4) and #795 (RM6). The change that lands this text |
| 27 | records the delegated decision in `docs/ROADMAP-1.0.md` RM4 (its Decision paragraph); Drake can reverse it. |
| 28 | |
| 29 | ## 1. Why |
| 30 | |
| 31 | A program can only own memory whose size is written in its text: `global NAME T N` (a fixed N, at most |
| 32 | 16777216 elements, at most 1 GiB in all; OMEGESE 9.4) and `new` (4 MiB per function). A program whose |
| 33 | working set depends on its input has to guess a size and then refuse past it. The seeded compiler is the |
| 34 | example. Since 2026-11-11 its tables live in one static arena of 16777216 words (OMEGESE 9.6). "Arena |
| 35 | full" (error 14) is the last capacity it has that grows with the input, and it is not a machine boundary: |
| 36 | it exists only because there is no run-time growth. (omc's other error-14 limits are per-construct |
| 37 | language rules listed in OMEGESE 9.6, the value-nesting bound of its own stack, and the program-image bound |
| 38 | of the branch reach.) |
| 39 | |
| 40 | ## 2. What exists, and why it is not enough |
| 41 | |
| 42 | `mapnew -1 0 BYTES 3 34` (`seed/host/MAPPING.md`) already maps private anonymous zero pages, in up to 128 |
| 43 | owned slots. A mapping is reachable only through copy words (`mapread`, `mapwrite`) and single fenced 4- |
| 44 | or 8-byte accesses (`mapget`, `mapset`, each with DSB SY or MFENCE: device-register semantics). No |
| 45 | ordinary Omega array can live in one. `seed/rung4/om4.s` has none of these words. |
| 46 | |
| 47 | ## 3. The language addition (omc, program mode, AArch64 Linux only in this slice) |
| 48 | |
| 49 | 1. **Declaration.** `global NAME T *` declares a run-time pool of element type T (uchar .. long, f32 and |
| 50 | f64: the types `global` takes; `bool` stays error 9, as `elemtype` gives for every bool array today). Its length is 0 when the program |
| 51 | starts. Like every global it is never passed as an argument and never sliced with `part` (error 19). |
| 52 | Function mode refuses it with error 9, IR mode with error 9, and any `target` other than the default |
| 53 | with error 25. |
| 54 | 2. **Growth.** `r = enlarge NAME n`, with n a ulong and r a long (error 7 otherwise), allowed only as the |
| 55 | whole of an assignment (error 9 otherwise) but anywhere in a function, blocks included. It is error 7 |
| 56 | on any name that is not a run-time pool. Results: |
| 57 | - n <= `len NAME`: r = 0 and nothing changes. `enlarge` means "at least n"; it never shrinks. |
| 58 | - n > `len NAME`: NAME then has n elements. The first `len NAME` keep their values and the rest are 0. |
| 59 | r = 0. |
| 60 | - n times the element size overflows 2^63: r = -22 (EINVAL) and NAME is unchanged. The kernel never |
| 61 | sees an invalid request, so -22 always means the overflow. |
| 62 | - The host refuses (mmap or mremap returns -12 ENOMEM under RLIMIT_AS or vm.overcommit_memory=2): |
| 63 | r = -12 and NAME is unchanged. Note: under a cgroup memory limit (`memory.max`) a private anonymous |
| 64 | mapping is not refused. Pages are charged when they are first touched, and past the limit the |
| 65 | kernel's OOM killer ends the process (SIGKILL). That is physical exhaustion. A program's static |
| 66 | `.bss` behaves the same way today; it is not a new behaviour and not a result `enlarge` can give |
| 67 | (S2). |
| 68 | - The keyword is `enlarge`: zero uses as an identifier in the tracked corpus (`git grep -nw enlarge -- |
| 69 | '*.om' '*.omegese'`, 2026-11-11). `grow` has 9 uses, among them `fn grow` in s3s4 fixtures, so it |
| 70 | would change their C1 verdict (S3). Adding the keyword is still a C1 language decision. It is |
| 71 | recorded as a manifest-c2 delta (om2 spec section 0), and a corpus scan in the gate checks that no |
| 72 | tracked unit names `enlarge`. |
| 73 | 3. **Length.** `len NAME` is the current length, a run-time ulong. It is never folded. |
| 74 | |
| 75 | `get NAME i` and `put NAME i v` behave as for any array and are checked against the current length: an |
| 76 | index at or past it traps 3. A number index is checked at run time too, because the length is not known |
| 77 | at compile time (no error 21, no check elimination), exactly as for an index into an unsized view (spec |
| 78 | section 6). `read fd NAME off n` and `write fd NAME off n` take the pool with the same slice check |
| 79 | against the current length. Every other host word that takes an array (the device and mapping words |
| 80 | `devctl`, `devcall`, `vfioctl`, `uvmctl`, `mapread`, `mapwrite`, `vfioirq`, and the rest) refuses a |
| 81 | pool with error 7 in this slice. |
| 82 | |
| 83 | There is no `free`, no shrinking, and no way to give memory back by hand (decision 24 stands). |
| 84 | |
| 85 | ## 4. Representation and lowering in omc |
| 86 | |
| 87 | **A distinct name kind.** A run-time pool is its own name kind (kind 10, "run-time pool"), not kind 4 |
| 88 | with length 0. Length 0 already means "unsized view" to `unsz` (omc.om `unsz`), and that would route a |
| 89 | pool through count registers that do not exist (B2b). omc.om dispatches on kind with ordered tests, and |
| 90 | 10 sorts above both the struct threshold (`ge k 6`: kinds 6..8 are structs, 9 a constant) and the global |
| 91 | threshold (`ge kind 4`). So the rule is: **at every ordered kind test, the kind-10 branch is written first.** |
| 92 | The sites (omc.om at 3537baad; line numbers approximate, they move with each landing): |
| 93 | |
| 94 | | Site (omc.om) | Kind 10 | |
| 95 | |---|---| |
| 96 | | `unsz` (301), `elemaddr` (6331) | own path: slot load, run-time compare, never a constant index check (no error 21) | |
| 97 | | rdval `get` (9901; today `ge k 6` sends it to the struct-field reader vt_fget) | kind-10 test first: the pool path | |
| 98 | | rdval `len` (9919; today `ge k 6` gives error 7) | kind-10 test first: a run-time load of the slot's length, never `vdone 3` | |
| 99 | | `s_put` (10630; today `ge k 6` sends it to s_putf) | kind-10 test first: the pool path | |
| 100 | | `s_global` / `pinset` / `pinlo` / `eof_prog` | never pinned: no X18..X26 register holds a pool base or length (B2a) | |
| 101 | | `arrarg` (6395), `arrpart` (6452) | kind-10 test before `ge k 6` (which gives 7): error 19, as for any global | |
| 102 | | the struct-argument reader (14549; `if lt k 6 fail 7` lets 10 through) | error 7 for kind 10 | |
| 103 | | `vs_arr` (6889, the read/write array path; `ge k 6` gives 7) | kind-10 test first: `read`/`write` take a pool | |
| 104 | | `harray`, `basearg` (6201), `vs_chk`, `vs_call` | `read`/`write`: slot loaded after every operand (below); any other host word: error 7 | |
| 105 | | `xhb` (16455), x86efi target | error 25 | |
| 106 | | `xelem` / `xepool`, `pl_len`, `vs_chk` / `xio`, `s_enlarge` / `xenlarge` under `target x86linux` (since 2026-11-23) | the same rules as AArch64: slot read after every operand, LEA + MOV + CMP + JAE trap 3, `enlarge` inline with mmap 9 / mremap 25; gate-pools.sh section X | |
| 107 | | contract folding (OMEGESE 12, "Purity, proofs and failure") | `len` of a pool is never constant: `requires eq len P 0` is checked at run time and reported `kept rule=runtime` in om2 diag, never `erased rule=constant-true` | |
| 108 | | unroll and inline folding, check elimination (om2 spec 4) | a pool index is never constant-checked | |
| 109 | | IR mode (`ir_*`) | error 9 | |
| 110 | |
| 111 | Gate 10 (section 7) also covers "a pool passed as a struct argument (7)". |
| 112 | |
| 113 | **Storage.** Each pool has a hidden 16-byte slot in the program's global pool area, zero at start: the |
| 114 | base address, then the length in elements. Capacity is not stored: it is the length's bytes rounded up to |
| 115 | the page (4096) at every moment, because a growth that fits only raises the length and every mapping was |
| 116 | rounded from the length it was made for. The helper recomputes it. Access: LDP base and length, compare |
| 117 | the index (CMP, B.HS to trap 3), then load or store. LDP needs two allocated registers, so an expression |
| 118 | dense with pool accesses reaches the 16-register limit (error 12) sooner (N3). |
| 119 | |
| 120 | **The soundness rule (B1).** A grow moves the pool. Values nest calls (`put P i (f x)`, `get P (f x)`, |
| 121 | `write 1 P 0 (f x)`, an inlined body), so a grow can run between the start and the end of one access. The |
| 122 | move is unobservable only because of this rule, which the lowering must keep and a gate checks: |
| 123 | |
| 124 | > In every lowering that touches a pool (get, put, len, read, write), the slot is loaded after the last |
| 125 | > operand of that access has been evaluated, and the base is used only within that access. A length |
| 126 | > checked earlier stays valid, because no word ever shrinks a pool. |
| 127 | |
| 128 | Today's codegen already loads an array base after the operands: `s_put` reads the index, then the value, |
| 129 | then calls `elemaddr`; `vt_get` calls `elemaddr` after the index; host words check with `harray`/`vs_chk` |
| 130 | and load the base after `save`. Kind 10 must follow that order. The rule holds while omc has no |
| 131 | shared-memory threads and no signal handlers: omc emits no thread creation and installs no signal handler, |
| 132 | its process words (`execprog` 124, `execpure` 198, `execenv` 233) replace the address space, and `fork` |
| 133 | (keyword 107) is clone with SIGCHLD only (no CLONE_VM): the child owns a private copy-on-write copy of the |
| 134 | slot and of the MAP_PRIVATE pool, so a grow in either process never moves the other's pool. If FR-6 |
| 135 | threads or signal handlers ever land, pools must move to a non-moving form (reserve-then-commit, below), |
| 136 | because a stale base in another thread corrupts silently (N1). |
| 137 | |
| 138 | **Growth (S1).** The first growth from length 0 is `mmap(0, bytes, PROT_READ|PROT_WRITE, |
| 139 | MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)` (syscall 222). A later growth that fits in the capacity already mapped |
| 140 | (whole pages; the Spark's page size is 4096, measured with `getconf PAGESIZE`) only stores the new |
| 141 | length: the bytes past the old length are still zero, because they were never written (a pool never |
| 142 | shrinks, and nothing writes past its length). A growth past the capacity is `mremap(old, oldbytes, |
| 143 | newbytes, MREMAP_MAYMOVE)` (syscall 216). It moves page tables, not data, so untouched pages stay |
| 144 | unpopulated, there is no old+new copy peak, and on failure the old mapping is intact and the result is |
| 145 | -12. Byte counts are rounded up to 4096. A kernel with larger pages rounds further, which is still correct. |
| 146 | |
| 147 | The whole growth is emitted as one fixed helper per unit (`omc_enlarge`: X0 the slot address, X1 the |
| 148 | requested count, X2 the log2 of the element size; result in X0), called with BL from every `enlarge` |
| 149 | site. A unit that does not use pools gets neither the helper nor slots, and its code is byte-identical to |
| 150 | today's. |
| 151 | |
| 152 | **Alternatives considered (N2).** Reserve-then-commit (a PROT_NONE reservation, then mprotect to grow in |
| 153 | place) never moves and is the strongest shape for soundness. But the whole reservation counts toward |
| 154 | RLIMIT_AS (MAP_NORESERVE affects only commit accounting), so it fails under omc's 256 MiB salvage limit, |
| 155 | and a per-pool reservation size would be a new fixed number. A view over `mapnew` is bigger (handles and |
| 156 | generations, `mapdrop`, use-after-release traps, 128 slots) and still cannot grow without a copy. |
| 157 | Reserve-then-commit is recorded as the successor shape, tied to FR-6. |
| 158 | |
| 159 | ## 5. Checker, traps and contracts |
| 160 | |
| 161 | - Traps: none new. An index out of range is trap 3, as for every array. Running out of memory is not a |
| 162 | trap: it is `enlarge`'s negative result, which the program must handle like any host-call result. |
| 163 | - Contracts: `len NAME` of a pool is a run-time value, checked at run time, and never proved constant. |
| 164 | - checker2, the C path and IR mode do not see pools (error 9 in IR mode). Pools are an omc-only (seeded) |
| 165 | addition of OMEGESE section 9, like the host words. |
| 166 | - No hidden allocation: no existing word allocates (RM4's condition). Only `enlarge` asks the host for |
| 167 | memory, and its result says what happened. |
| 168 | |
| 169 | ## 6. What it costs the seed chain and om4 (S5), and the staging |
| 170 | |
| 171 | `seed/omc/omc.om` must stay inside om4's language (spec C3), and gate5 (b) requires om4 and omc to build |
| 172 | the same omc from omc.om, byte for byte. omc.om touches its arena only through `get`, `put` and `len` on |
| 173 | `a_ar`. Its I/O goes through the `a_wb` staging buffer, never `read`/`write` on the arena. So om4 needs |
| 174 | only: |
| 175 | |
| 176 | - `global NAME T *` in S_GLOBAL (kind 10, the slot); |
| 177 | - the kind-10 path in ELEMADDR (slot load, register or number index, CMP, B.HS trap 3); |
| 178 | - `len NAME` of a pool; |
| 179 | - `r = enlarge NAME n` as a BL to the fixed helper, emitted once per unit when used, from a word table, so |
| 180 | that byte identity with omc holds by construction. |
| 181 | |
| 182 | om4 refuses `read`/`write` on pools and every other pool word with its own error. The units that only |
| 183 | omc accepts are listed in `seed/omc/tests/om4-superset.tsv`, as gate5 section 3 already allows. Estimate: |
| 184 | 100 to 200 lines of `om4.s` (MODELED, not measured), `mk4.sh` to rebuild `om4.bin`, new gate4 cases |
| 185 | (accept, out of range, host refusal, a grow inside a block), the gate4 section 2 audit (mismatch 0), and |
| 186 | nextfuzz coverage of the new words. `evidence/SEED-0/rung4/` is not rewritten: gate4 reports the |
| 187 | receipt as differing, as it did for the function-table change 646ed1ec. |
| 188 | |
| 189 | Staging, two landings: |
| 190 | |
| 191 | 1. **omc-only words** (omc.om unchanged in what it uses; the precedent is OMEGESE 9.7 and 9.8, which |
| 192 | needed no om4 change), with all the gates of section 7 except the arena switch. |
| 193 | 2. **om4 learns the minimal subset**, then omc.om declares `global a_ar ulong *` and enlarges it in |
| 194 | `a_need` (doubling). The static 128 MiB arena and its RLIMIT_AS bound go away, and omc's image shrinks |
| 195 | by 128 MiB of `.bss`. The new boundary is the machine's. A refused `enlarge` is error 14 with the |
| 196 | omc-use record (`full=1`, now meaning "the host refused"). Under a cgroup memory limit the host never |
| 197 | refuses; the memory ceiling below turns that case into the same error 14. |
| 198 | |
| 199 | **The memory ceiling (amendment, 2026-11-11; Main: "refusals stay defined").** Reason, measured on the Spark |
| 200 | with the landing-2 compiler (omc 59d7cb5e) and the 87,019,650-byte first-user unit (section 11), which peaks |
| 201 | at 557,184 KiB resident (GNU time; cgroup memory.peak 573,169,664 bytes, of which anon 570,486,784, kernel |
| 202 | 1,826,816, page tables 1,658,880): |
| 203 | - under `prlimit --as=268435456` it is a clean error 14 with `full=1` in about 1 s: RLIMIT_AS makes mremap |
| 204 | fail, and the arena's growth is refused; |
| 205 | - under `systemd-run --user --scope -p MemoryMax=536870912 -p MemorySwapMax=0` it is not refused: pages are |
| 206 | charged when they are touched, so mmap and mremap never fail inside a cgroup. The kernel reclaimed and |
| 207 | refaulted omc's own file pages (D state; at 105 s memory.events max=333531, oom_kill=0, |
| 208 | workingset_refault_file 10869949, pgmajfault 346042) for about 175 s and then the memcg OOM killer ended |
| 209 | it (SIGKILL, exit 137; 1 min 2.9 s of CPU, no output). The design review's run of the same case was killed |
| 210 | after 2.36 s: the outcome is an OOM kill either way, after a delay that varies; |
| 211 | - with MemoryMax=1073741824 it compiles and the round trip `cmp`s. |
| 212 | |
| 213 | RLIMIT_AS bounds address space, not memory, and decision 2 asks the sandboxes to move to real-memory limits |
| 214 | (cgroup `memory.max`), where the growing arena would be killed or stalled rather than refused. So: |
| 215 | |
| 216 | - **The rule.** When a real-memory ceiling C (bytes) is known, every growth keeps the budget H + M + R <= C: |
| 217 | H the most arena bytes ever handed out (the pages above them were never touched; a compaction lowers the |
| 218 | words handed out, not the pages it touched), M the margin on H, and R the output reserve, the capacities of |
| 219 | the artifact's region and of the om2 diag site records' region, which omc writes after the artifact (written |
| 220 | to a file, both are page cache charged to the same cgroup, dirty until written back). The artifact and the |
| 221 | site records never pass their regions, so once every growth kept the budget, writing them keeps it: the |
| 222 | check before the write (H, M, the artifact and the site records) is a guard that does not refuse. Under a |
| 223 | ceiling, a growth that would move a group to the top past H compacts and grows it in place instead, and a |
| 224 | group grows to its doubling or not at all: the words handed out then follow the same course for every C, |
| 225 | so the refusal is monotonic in C (a unit refused at C is refused at every lower C). A growth that does not |
| 226 | fit is refused as a host refusal is, and the unit is error 14 with the omc-use record, `full=1`. Measured |
| 227 | with stdout on an ext4 file before this rule (review of 04e6492f): counting only the artifact written so |
| 228 | far, MemoryMax at the compile's peak + 4 MiB and + 1 MiB was still OOM-killed in about 2.4 s while the |
| 229 | artifact was written, an om2 diag unit was killed while its site records were written, and the refusal had |
| 230 | bands (the page unit compiled at 504 and 512 MiB, was refused at 520 to 536, compiled from 544). With it: |
| 231 | over 384 .. 640 MiB the page unit is refused below 512 MiB and compiles from 512 MiB, and the om2 diag unit |
| 232 | of 1,200,000 lines below 496 MiB and from 496 MiB, every run with oom_kill 0. The record gains one |
| 233 | last field, `ceiling=C` (0 when none is known), after the groups; readers take fields by name (gate-usage |
| 234 | treats it as a group holding 0 words, which no threshold trips). Without a known ceiling the arena grows |
| 235 | until the host refuses, as designed above. |
| 236 | - **The margin.** M = 16 MiB + (arena bytes) / 128. What is resident beyond the arena's touched words is |
| 237 | omc's image (read/write part at most 11,196,912 bytes, `memsz` 0xaad9f0, the 8 MiB stack pool included; |
| 238 | resident on a tiny unit about 0.4 to 0.6 MiB), its file (750,532 bytes), and kernel memory charged to the |
| 239 | cgroup, mostly page tables: measured 1,826,816 bytes on the first-user unit, 1,474,560 on 1,500,000 |
| 240 | globals and 548,864 on a 64 MiB input, which is 1/441, 1/546 and 1/183 of their final arena bytes, so |
| 241 | arena / 128 bounds it. The arena's touched words are at most its length, and after a doubling usually |
| 242 | far less (first-user unit: 570 MB resident against an arena of 805,371,904 bytes). The fixed 16 MiB covers |
| 243 | the image and text with about 4 MiB left for reclaim of clean page cache; measured: with MemoryMax set |
| 244 | 1 MiB, 4 MiB, 8 MiB and 20 MiB above that unit's own peak and stdout on /dev/null, it compiles in 2.1 to 2.7 s |
| 245 | (2.09 s with no limit), oom_kill 0 (with stdout on a file the artifact counts too: "The rule"). A file on omc's stdin is page cache charged to the cgroup that read it; it is clean and |
| 246 | reclaimable and does not count toward the rule. |
| 247 | - **Why the environment and not a lead line.** A lead line (as `usage`, `om2 diag`, read by chk_mode) would |
| 248 | cost om4 nothing, but omc reads the whole input into the arena (region 0, a_rdin) before it reads any line, |
| 249 | and the input can itself be the largest region (gate 13's 512 MiB input): the ceiling must be known before |
| 250 | the input is read, which a line of that input cannot do. |
| 251 | - **The explicit form (this landing).** The environment variable `OMC_MEMORY_MAX`: decimal bytes, 1 to 19 |
| 252 | digits, no sign or spaces, read once when omc starts, before the input, with `envcnt` and `envread` |
| 253 | (OMEGESE 10, omc host words); the first entry named `OMC_MEMORY_MAX` wins. Absent, empty or `0`: no ceiling. |
| 254 | Anything else (a non-digit, a sign or space, more than 19 digits, or 2^63 and above) is error 26 on line 0 |
| 255 | before any input is read, so a caller's typo is loud rather than an unbounded compile. Each entry is read |
| 256 | whole into a buffer of 131072 bytes (Linux keeps an entry below that, MAX_ARG_STRLEN); one that does not fit |
| 257 | is error 26 too. Code 26 was unused; |
| 258 | it becomes an io-class row of `seed/omc/error-codes.reg` like 1 and 2 (the compiler's environment, not a |
| 259 | language input; gate15 case), and row 14's meaning names the ceiling. A ceiling too small for the first |
| 260 | room is error 14 `full=1` at the first growth. omc.om must stay inside om4's language (spec C3), so om4 |
| 261 | learns `envcnt` and `envread` with words byte-identical to omc's in an OM-1 unit, as it learned the pool |
| 262 | subset (omc's lowering is about 90 lines of omc.om, about 60 machine words with its argument and range |
| 263 | checks; estimate 150 to 300 lines of `om4.s`, MODELED). Units compile to the same bytes with or without |
| 264 | the variable; it changes only whether a large one is refused. |
| 265 | - **The automatic form (successor, not now).** Reading `/proc/self/cgroup`, then `memory.max` and |
| 266 | `memory.swap.max` under `/sys/fs/cgroup`, would find the ceiling without the caller. It needs `fopen` and |
| 267 | `read` on a path in omc.om, so om4 must also learn `fopen`; sandboxes may hide `/proc` or the cgroup files |
| 268 | (bwrap `--unshare-all` without a cgroup mount), so the explicit form stays the contract and the automatic |
| 269 | one only fills in when the variable is absent. |
| 270 | - **The sandboxes.** The interplane-forge salvage compile (`prlimit --as=268435456`), the omega-mcp compile |
| 271 | (`--as=536870912`) and forged (`--as=4294967296`) keep a clean error 14 from RLIMIT_AS with nothing to |
| 272 | change. bench/inference_cost (`driver.sh` `mem_scope`, MemoryMax 536870912 with swap 0 since 15760b50) is |
| 273 | the case this fixes: its sandboxed compiles run under `bwrap --clearenv`, so the driver must add |
| 274 | `--setenv OMC_MEMORY_MAX "$MEM_MAX"` (minus whatever else shares the scope) to get error 14 in place of a |
| 275 | timeout or a kill (its compile timeout is 10 s, `driver.sh`). Every caller that clears the environment (`bwrap --clearenv`, `execenv`, `execpure`) |
| 276 | passes the variable explicitly; each owner makes that change. |
| 277 | |
| 278 | Historical landing-2 consumer handling (superseded for NG pools by section 12): `seed/ng/front/cases-front.txt` runs |
| 279 | `seed/omc/omc.om` as an ng parity case (`gate-front.om`), so a pool in omc.om needs ng-front to treat |
| 280 | `global NAME T *` as a scope form (exit 64; the ng lane, NgNoCaps2, landed it with `seed/ng/front/cases/pool_runtime.om`). Landing 2 carries the row |
| 281 | `seed/omc/omc.om scope 0` in `seed/ng/front/declared.txt`. |
| 282 | A second consumer is ng's no-caps gate: `seed/ng/tests/nocaps/gate.om` (unit 0, gn_uin) feeds `seed/omc/omc.om` to |
| 283 | ng front-check in usage mode as a large real unit, which ng refuses as a scope form (exit 64) once omc.om |
| 284 | holds a pool; the ng lane (NgNoCaps2) chooses between a pinned pre-pool omc.om as that unit and accepting 64. |
| 285 | (Current gate: `gn_uin` uses `seed/node/journal-gate.om` and ng itself for the usage alarm. The earlier omc-based description is historical.) |
| 286 | |
| 287 | ## 7. Gates, all with negative controls (S7) |
| 288 | |
| 289 | 1. **Growth and contents.** A pool enlarged from 0 to 1, 4096, 2^20 and 2^27 elements (a loop over more |
| 290 | than 1000000 elements needs `bound`, OMEGESE 63-67). Values written and read back; old values kept; |
| 291 | new elements zero. A pool past the 16777216-element limit of sized pools. |
| 292 | 2. **Range.** Index = length traps 3 (exit 103) with no write past it; length + 1 is in range after a |
| 293 | grow; a number index past the length traps 3 at run time. Mutant: the length compare removed, caught. |
| 294 | 3. **Stale base (B1).** `enlarge` inside f, where f is called from the value of `put P i (f)`, from the |
| 295 | index of `get P (f)`, and from the count of `write 1 P 0 (f)` and `read`. Plain and as an OM-2 inline |
| 296 | body, repeated until mremap has moved the region and its address has been reused. The results must |
| 297 | be right. Mutant: the slot loaded before the operands, caught. |
| 298 | 4. **Pinning (B2a).** An OM-2 unit whose first global is a pool, with sized globals after it; objdump shows |
| 299 | no X18..X26 base for the pool. Mutant: the pool pinned, caught. |
| 300 | 5. **Contracts (B2c).** `requires eq len P 0` and `invariant le i len P` are reported `kept rule=runtime` in om2 diag |
| 301 | and evaluated at run time; a constant index under unroll and inline keeps its run-time check. |
| 302 | 6. **Mutants (RM4).** The n-below-length case, the overflow check, the slot not updated after a failure, |
| 303 | capacity and length swapped: each caught. |
| 304 | 7. **Fuzz differential (RM4).** A seeded random sequence of enlarge/get/put/len against an independent |
| 305 | model (a Python list), compared at every step. |
| 306 | 8. **Host refusal (S2).** Under `prlimit --as` set low, `enlarge` returns -12 and the program goes on |
| 307 | with the pool unchanged (its own exit status, never a trap); the overflow case gives -22. Under |
| 308 | `systemd-run --user -p MemoryMax=64M` a program that touches 128 MiB is recorded with its actual |
| 309 | result (expected: killed, 137), so the documented behaviour cannot drift. |
| 310 | 9. **Untouched pages (S1).** A pool enlarged to 2 GiB with one page touched shows VmRSS of about one page |
| 311 | (`/proc/self/status`). |
| 312 | 10. **Refusals (S4).** Function mode (9), IR mode (9), `target x86efi` (25; `target x86linux` compiles pools |
| 313 | since 2026-11-23, section X), passing or slicing a pool |
| 314 | (19), `enlarge` not as a whole assignment (9), `enlarge` on a sized global, a local or a view (7), a |
| 315 | `bool` pool (9), n not ulong or r not long (7), a pool given to a device or mapping word (7). |
| 316 | 11. **Byte identity.** Every tracked `.om` that compiled before compiles to the same bytes, except the |
| 317 | files that name `enlarge`, listed by name (none on 2026-11-11). The corpus scan for `enlarge` is part |
| 318 | of the gate. |
| 319 | 12. **Seed chain (landing 2).** om4 = omc on the new words (gate5); the fixpoint holds; gate4 cases and the |
| 320 | audit pass. |
| 321 | 13. **The arena (landing 2).** gate-nocaps units far past 128 MiB (a 512 MiB input) compile and run. Under |
| 322 | `prlimit --as` set too low the result is error 14 with `full=1`. The forged salvage compile, under |
| 323 | `prlimit --as=268435456`, still passes every unit it passes today. The memory ceiling (section 6): under |
| 324 | `systemd-run --user --scope -p MemoryMax=C -p MemorySwapMax=0` with `OMC_MEMORY_MAX=C` and stdout on a |
| 325 | real file, the first-user unit at C = 256 MiB and 448 MiB is error 14 `full=1` with `ceiling=C`, |
| 326 | oom_kill 0 in memory.events and a wall time under 30 s (the unconstrained compile takes about 2.5 s); |
| 327 | at a sufficient C it compiles and round-trips (`cmp`); over C = 384 .. 640 MiB every result is 0 or 14 with |
| 328 | oom_kill 0 and none is 14 above a 0; an om2 diag unit with stderr on a file is 0 or 14 with oom_kill 0; a |
| 329 | capped doubling that still fits compiles (a |
| 330 | unit whose doubled arena would pass C, at a C between its need and the doubled size); the `ceiling=` |
| 331 | field parses in gate-usage; the malformed values (a non-digit, a sign, a leading or trailing space, 20 digits, 2^63, |
| 332 | an entry too long to read whole) are error 26 on line 0, and empty and 0 mean no ceiling. Mutants: the |
| 333 | ceiling ignored, caught (killed, or past the 30 s bound); the margin dropped, caught as a differential |
| 334 | control (at some C omc refuses and the mutant compiles; measured, the mutant is not killed there either, |
| 335 | because the kernel writes back and reclaims the artifact's pages). Without `systemd-run --user` those rows are NOT_RUN and |
| 336 | the variable is still checked under `prlimit --as`: with `OMC_MEMORY_MAX` = C and `--as` far above it, |
| 337 | the unit is error 14 whose record says `ceiling=C` and whose arena never passed the cap, so the ceiling, |
| 338 | not mremap, refused it. |
| 339 | 14. **The alarm, redefined (S6).** Once the arena grows to fit, "top / arena" is near 50 to 100 percent |
| 340 | by construction. gate-usage then alarms on absolute words in use per group and in all, on compile |
| 341 | time and on RSS, measured on the largest real units. Its mutant control is a table growth in `a_need` |
| 342 | that never doubles (+512 words each time, `c = add c 512` in place of `c = shl c 1`): it must trip |
| 343 | the RSS or absolute-words alarm, and its compile time is recorded. Amended 2026-11-11 (landing 1): the |
| 344 | first form, the arena itself growing by +1 page instead of doubling, cannot trip any alarm, because |
| 345 | the arena grows only when a group's doubling does not fit (about log2 of its size times per compile) |
| 346 | and mremap copies no data; measured on the Spark, the in64m unit took 1.06 s against 1.26 s and |
| 347 | forged, omc.om, cortex and omega-mcp were within 0.01 to 0.09 s with identical output, while the |
| 348 | a_need mutant takes globals100k from 26 MB to 1.0 GB resident (0.07 to 0.53 s). omc's self-compile |
| 349 | time and RSS before and after the switch are recorded (each arena access gains a slot load). |
| 350 | |
| 351 | ## 8. What #793 and #795 decided, and what they left open |
| 352 | |
| 353 | The issue bodies are not readable: GitHub is frozen and hidden, and the Radicle copy has no issues. |
| 354 | `docs/ROADMAP-1.0.md` RM4 and RM6 link them and record: |
| 355 | |
| 356 | - **RM4 / #793.** Open until a decision: keep decision 24, or replace it with a named model (the options |
| 357 | are region/arena with whole-region release, or generation-checked handles `HALLOC/HGEN/HFREE`). Already |
| 358 | decided as conditions on any model, and met here: exhaustion returns a status and never overruns; no |
| 359 | existing word gains hidden allocation; use-after-release is refused or trapped (here no release is |
| 360 | reachable by the program, so there is nothing to use after it); mutants that remove each check; a fuzz |
| 361 | differential against an independent model (section 7, items 6 and 7). This design is the "region" |
| 362 | option without release, the smallest form that lifts fixed sizing. |
| 363 | - **RM6 / #795.** Modules by digest. Its acceptance line "per-unit capacities chosen by measurement ... |
| 364 | gated at their boundary (accept N, refuse N+1 with error 14)" is superseded by the no-caps rule |
| 365 | (OMEGESE 9.6); this change amends that bullet in RM6. The rest of RM6 does not depend on this design. |
| 366 | |
| 367 | ## 9. What it does not add |
| 368 | |
| 369 | No `free`, no shrinking, no general allocator, no objects, no pointers, no address arithmetic, no |
| 370 | pointer-typed values. No run-time-sized locals (`new` keeps a compile-time size). No change to sized |
| 371 | globals, to any existing word's code, to function mode, IR mode or x86. No garbage collection, no |
| 372 | reference counting, no aliasing. A run-time pool is a global whose length is a run-time value, and |
| 373 | nothing more. |
| 374 | |
| 375 | Documents the landings update with it (S8): OMEGESE 9.4 ("no heap, no allocation call"; "no word turns |
| 376 | an array into an address" stays true) and 9.6 (the arena), the error-code registry rows, the `omc.om` |
| 377 | header notes, `docs/ROADMAP-1.0.md` RM4, and the omega-harness guides (omega-encoding, writing-omega), |
| 378 | which are sent to their owner. |
| 379 | |
| 380 | ## 10. Review record |
| 381 | |
| 382 | Independent design review by consult-codex, 2026-11-11, of revision 1 (mmap + copy + munmap, keyword |
| 383 | `grow`, the kind unspecified). Its recommendation was "build after the listed changes". Taken in: |
| 384 | |
| 385 | - B1: the soundness rule, with its gate and mutant. |
| 386 | - B2: a distinct kind and the list of sites. |
| 387 | - S1: mremap; no copy loop and no old+new peak. |
| 388 | - S2: the cgroup behaviour stated, with a measured gate. |
| 389 | - S3: the keyword `enlarge`, a scanned corpus and a C1 delta. |
| 390 | - S4: the edge cases and refusals specified. |
| 391 | - S5: om4's minimal subset, a fixed helper, and staging in two landings. |
| 392 | - S6: the alarm redefined in absolute terms. |
| 393 | - S7: the gates added. |
| 394 | - S8: the documents listed. |
| 395 | - N1-N4: recorded above. |
| 396 | |
| 397 | Not measured in that review, and to be measured when building: the mremap and RLIMIT_AS behaviour, the |
| 398 | cgroup OOM behaviour, and RSS after a large enlarge. |
| 399 | |
| 400 | Recheck of revision 2 (consult-claude, 2026-11-11, at e307a4e1): MERGE_AFTER_FIX. Fixed in this text: |
| 401 | - F1: the ordered kind tests and the missing sites. |
| 402 | - F2: the RM4 wording. |
| 403 | - F3: the slot is base and length, with capacity derived. |
| 404 | - F4: the contract citation. |
| 405 | - F5: the soundness facts about threads and signals. |
| 406 | - F6: "the last capacity that grows with the input". |
| 407 | |
| 408 | F7 asked for the corpus scan. `git grep -nw enlarge -- '*.om' '*.omegese'` returns no lines (run before landing). |
| 409 | |
| 410 | Final check of this text (consult-claude, at 7b816f20): MERGE_AFTER_FIX. Fixed: |
| 411 | - N1: a bool pool is error 9, as elemtype gives. |
| 412 | - N2: `fork` is clone with SIGCHLD only. |
| 413 | - N3: the om2 diag record words. |
| 414 | - N4: the program-image bound. |
| 415 | - N5: the decision's exact words. |
| 416 | - N6: RM4 says how the decision settled. |
| 417 | - N7: the RM6 per-unit-capacity bullet is amended. |
| 418 | |
| 419 | ## 11. First users, and programs that keep running |
| 420 | |
| 421 | The first inputs waiting for this design, reported 2026-11-11: |
| 422 | - A 64 MiB page encoded by cortex's streaming encoder gives an 87.7 MB unit. omc refuses it cleanly with |
| 423 | error 14 and a usage record (`namehash=131072/131072`, the arena full). It is the first real input that |
| 424 | needs the growable arena (landing 2). |
| 425 | - omega-mcp's request path (512 KiB of source, a line of about 960 KiB, fixed buffers) and cortex's store |
| 426 | capacities. Their owners list both as liftable only with pools. |
| 427 | |
| 428 | So the pool form must serve a server unit that keeps running, not only a compiler that exits. As |
| 429 | designed, it does: |
| 430 | - `enlarge` may be called at any time, in any function, as often as needed. |
| 431 | - A pool holds its memory until the process ends, because there is no `free` (decision 24). A server |
| 432 | should therefore size a pool to its high-water mark and reuse it, writing over it and tracking its own |
| 433 | used length, rather than enlarging per request. |
| 434 | - A refusal is a status the server handles, for example by answering "too large" to that request and |
| 435 | going on. It is never a trap. |
| 436 | - The gates of the first landing add a server-shaped case: a loop that serves requests of growing and |
| 437 | shrinking size from one pool, enlarging only past its high-water mark, with RSS checked to stay at that |
| 438 | mark. |
| 439 | |
| 440 | ## 12. NG runtime pools |
| 441 | |
| 442 | NG represents each pool as a class 2 global whose type is the scalar element type, with six |
| 443 | token-ordered operations (111..116). See [the complete IR contract](../seed/ng/IR.md#713-run-time-pool-ops-111116). |
| 444 | No REF or SLICE exposes the storage. Each access resolves the descriptor and checks bounds after |
| 445 | its operands, preserving section 4's store order even when an operand grows a pool. |
| 446 | |
| 447 | Linux AArch64 uses the canonical mmap/mremap growth helper. The reference interpreter stores pools |
| 448 | separately from frames while enforcing one 16 MiB live-storage budget; allocation refusal preserves |
| 449 | all existing contents. Mach-O pool ops are explicitly unsupported. Native support for other host |
| 450 | words is unchanged. Pool ops are host-only and have no GPU lowering. |
| 451 | |
| 452 | `ngcheck` rejects illegal element types, pointer escape, kernel placement, argument types and token |
| 453 | use. Text tools preserve type-invalid inputs for independent validation; they reject unknown wire |
| 454 | classes. The front end removes its old pool scope exclusions, while existing x86/EFI and IR v1 scope |
| 455 | exclusions remain. |
| 456 | |
| 457 | The IR, front-lowering and AArch64 gates contain the regression cases and negative controls. |
| 458 | The canonical pool source fixtures are reused for differential execution. Release evidence records |
| 459 | their results and source/compiler identities. Memory measurements can use an external /proc reader |
| 460 | when the native back end cannot yet lower the RSS fixture's `fopen`; that adaptation must be recorded. |