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 / seed / omc / gate-usage.sh
| 1 | #!/bin/sh |
| 2 | # gate-usage.sh -- the alarm in place of omc's old capacities (Drake 2026-11-11: "Instead of caps to |
| 3 | # prevent something, just put a TEST that will alarm if it passes the threshold"; OMEGESE 9.6). |
| 4 | # The compiler under test is seed/out/omc (OMC overrides it). A unit whose first line is `usage` is |
| 5 | # compiled as usual, and instead of the program omc writes one omc-use record (OMEGESE 9.6): |
| 6 | # omc-use 1 arena=A top=T waste=W full=F GROUP=N/H ... |
| 7 | # A the arena's 8-byte words (its length now: the arena is a run-time pool that grows, landing 2 of |
| 8 | # docs/RUNTIME-POOLS.md), T the words handed out, W the words left behind when a table moved, F 1 when the |
| 9 | # host refused the arena's growth or its memory ceiling was reached; per group N what the unit asked it to hold and H |
| 10 | # the words it holds; last, ceiling=C, the OMC_MEMORY_MAX in force (0: none), which must parse. |
| 11 | # Units: the largest real units of the stack, composed exactly as their builds compose them: seed/omc/omc.om |
| 12 | # itself, and from sibling checkouts ../omega-mcp (src/UNITS), ../cortex (build.sh SERVER), and |
| 13 | # ../interplane-forge (forged: run.sh units); then the scale units of seed/omc/tests/nocaps/gen.sh. |
| 14 | # Thresholds, for noticing, not for stopping anyone's compile (a real unit never sees them). Since the arena |
| 15 | # grows to fit, T / A is near 50 to 100% by construction, so the words are absolute (the old fractions of the |
| 16 | # 16777216-word static arena, design s7 gate 14): |
| 17 | # arena T at most 4194304 words (32 MiB) for a real unit, 12582912 (96 MiB) for a scale unit |
| 18 | # group H of any one group at most 2097152 words (16 MiB) for a real unit, 16777216 for a scale unit |
| 19 | # full F must be 0 |
| 20 | # time at most 2 s per real unit, 10 s per scale unit (wall clock, one compile) |
| 21 | # memory at most 64 MiB resident per real unit, 256 MiB per scale unit (GNU time %M) |
| 22 | # Past any of them the gate FAILS LOUDLY with the unit, the measure, the number and the threshold. |
| 23 | # A missing sibling checkout is NOT_RUN (status 3 at the end); everything else still runs. |
| 24 | # Mutant control: a compiler built from seed/omc/omc.om whose tables never double (a_need grows a group by 512 |
| 25 | # entries each time, `c = add c 512` for `c = shl c 1`) must make this gate fail on a unit: the moved tables' |
| 26 | # words pile up (absolute words and resident memory alarms); its compile time is recorded beside them. |
| 27 | # (The design's first control, arena growth of one page each time, is not one: the arena grows only when a |
| 28 | # group's doubling does not fit and mremap copies nothing, so it costs no time; measured 2026-11-11.) |
| 29 | # Writes build/seed/usage/usage.tsv: unit, arena, top, waste, top%, largest group, its words, seconds, KB. |
| 30 | # Last line: RC=0 when everything passed. |
| 31 | set -eu |
| 32 | R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 33 | cd "$R" |
| 34 | S=${OMC:-seed/out/omc} |
| 35 | [ -x "$S" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$S" >&2; exit 1; } |
| 36 | command -v /usr/bin/time > /dev/null || { printf 'FAIL: /usr/bin/time (GNU time) is needed for the memory measure\n' >&2; exit 1; } |
| 37 | mkdir -p build/seed/usage |
| 38 | B=$R/$(mktemp -d build/seed/usage/run.XXXXXX) |
| 39 | trap 'rm -rf "$B"' EXIT HUP INT TERM |
| 40 | bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } |
| 41 | say() { printf '%s\n' "$*"; } |
| 42 | P=$(dirname "$R") |
| 43 | skip=0 |
| 44 | |
| 45 | # compose the units |
| 46 | mkdir -p $B/real $B/scale |
| 47 | cp seed/omc/omc.om $B/real/omc.om |
| 48 | if [ -f "$P/omega-mcp/src/UNITS" ]; then |
| 49 | ( cd "$P/omega-mcp" && { printf 'om2\n'; first=1 |
| 50 | while read -r f; do case "$f" in ''|'#'*) continue ;; esac |
| 51 | if [ $first = 1 ]; then sed 's/^export fn /fn /' "$f" | grep -v '^om2$'; first=0; else cat "$f"; fi |
| 52 | done < src/UNITS; } ) > $B/real/omega-mcp.om |
| 53 | else say "NOT_RUN omega-mcp: no sibling checkout $P/omega-mcp"; skip=$((skip + 1)); fi |
| 54 | if [ -f "$P/cortex/build.sh" ]; then |
| 55 | mods=$(sed -n 's/^SERVER="\(.*\)"$/\1/p' "$P/cortex/build.sh") |
| 56 | [ -n "$mods" ] || bad "cortex: no SERVER= line in $P/cortex/build.sh" |
| 57 | { echo om2; for m in $mods; do cat "$P/cortex/om/$m.om"; done; } > $B/real/cortex.om |
| 58 | else say "NOT_RUN cortex: no sibling checkout $P/cortex"; skip=$((skip + 1)); fi |
| 59 | if [ -f "$P/interplane-forge/run.sh" ]; then |
| 60 | sed -n '/^units()/,/^}/p' "$P/interplane-forge/run.sh" > $B/units.sh |
| 61 | [ -s $B/units.sh ] || bad "forged: no units() in $P/interplane-forge/run.sh" |
| 62 | ( cd "$P/interplane-forge" && ROOT=$P/interplane-forge && OMV=$R && . $B/units.sh && { printf 'om2\n'; cat $(units); } ) > $B/real/forged.om |
| 63 | else say "NOT_RUN forged: no sibling checkout $P/interplane-forge"; skip=$((skip + 1)); fi |
| 64 | sh seed/omc/tests/nocaps/gen.sh $B/gen |
| 65 | for u in texts100k globals100k fns50k calls100k view100k traps100k longnames20k in64m; do |
| 66 | mv $B/gen/$u.om $B/scale/$u.om |
| 67 | done |
| 68 | rm -rf $B/gen |
| 69 | |
| 70 | # check COMPILER KIND UNIT -> prints the tsv row; returns 1 (with ALARM lines on stderr) past a threshold |
| 71 | check() { |
| 72 | c=$1; k=$2; f=$3; u=$(basename $f .om) |
| 73 | if [ $k = real ]; then ta=4194304; tg=2097152; ts=2; tm=65536; else ta=12582912; tg=16777216; ts=10; tm=262144; fi |
| 74 | { printf 'usage\n'; cat $f; } > $B/w.om |
| 75 | set +e; "$c" < $B/w.om > $B/w.rec 2> $B/w.err; rc=$?; set -e |
| 76 | if [ $rc != 0 ]; then |
| 77 | printf 'ALARM %s: compile refused, status %s: %s\n' $u $rc "$(head -c 600 $B/w.err)" >&2; return 1 |
| 78 | fi |
| 79 | set +e; /usr/bin/time -f '%e %M' -o $B/t "$c" < $f > /dev/null 2> /dev/null; rc=$?; set -e |
| 80 | [ $rc = 0 ] || { printf 'ALARM %s: plain compile status %s\n' $u $rc >&2; return 1; } |
| 81 | awk -v u=$u -v ta=$ta -v tg=$tg -v ts=$ts -v tm=$tm -v tf=$B/t ' |
| 82 | BEGIN { getline tl < tf; split(tl, tt, " "); sec = tt[1]; kb = tt[2] } |
| 83 | $1 == "omc-use" { |
| 84 | for (i = 3; i <= NF; i++) { split($i, kv, "="); v[kv[1]] = kv[2]; if (i >= 7 && kv[1] != "ceiling") order[++ng] = kv[1] } |
| 85 | a = v["arena"]; t = v["top"]; bad = 0; big = ""; bw = 0 |
| 86 | if (v["ceiling"] !~ /^[0-9]+$/ || $NF !~ /^ceiling=/) { printf "ALARM %s: the record has no last field ceiling=N (%s)\n", u, $NF > "/dev/stderr"; bad = 1 } |
| 87 | for (j = 1; j <= ng; j++) { g = order[j]; split(v[g], nh, "/") |
| 88 | if (nh[2] + 0 > bw) { bw = nh[2] + 0; big = g } |
| 89 | if (nh[2] + 0 > tg) { printf "ALARM %s: group %s holds %d words; threshold %d words\n", u, g, nh[2], tg > "/dev/stderr"; bad = 1 } } |
| 90 | if (t + 0 > ta) { printf "ALARM %s: arena top %d words (arena %d words); threshold %d words\n", u, t, a, ta > "/dev/stderr"; bad = 1 } |
| 91 | if (v["full"] != 0) { printf "ALARM %s: the host refused to grow the arena (full=1)\n", u > "/dev/stderr"; bad = 1 } |
| 92 | if (sec + 0 > ts) { printf "ALARM %s: compile took %.2f s; threshold %d s\n", u, sec, ts > "/dev/stderr"; bad = 1 } |
| 93 | if (kb + 0 > tm) { printf "ALARM %s: compile resident %d KB; threshold %d KB\n", u, kb, tm > "/dev/stderr"; bad = 1 } |
| 94 | printf "%s\t%d\t%d\t%d\t%.2f\t%s\t%d\t%s\t%d\n", u, a, t, v["waste"], 100 * t / a, big, bw, sec, kb |
| 95 | seen = 1; exit bad } |
| 96 | END { if (!seen) { printf "ALARM %s: no omc-use record\n", u > "/dev/stderr"; exit 1 } }' $B/w.rec |
| 97 | } |
| 98 | |
| 99 | printf 'unit\tarena_words\ttop\twaste\ttop_pct\tlargest_group\tits_words\tseconds\tmax_rss_kb\n' > $B/usage.tsv |
| 100 | for f in $B/real/*.om; do |
| 101 | check "$S" real $f >> $B/usage.tsv || bad "alarm on $(basename $f .om) (lines above); compiler $(sha256sum "$S" | cut -c1-16)" |
| 102 | say "PASS $(tail -1 $B/usage.tsv | awk -F'\t' '{ printf "%s: top %s words (arena %s words), largest %s %s words, %s s, %s KB", $1, $3, $2, $6, $7, $8, $9 }')" |
| 103 | done |
| 104 | for f in $B/scale/*.om; do |
| 105 | check "$S" scale $f >> $B/usage.tsv || bad "alarm on scale unit $(basename $f .om) (lines above)" |
| 106 | say "PASS scale $(tail -1 $B/usage.tsv | awk -F'\t' '{ printf "%s: top %s words (arena %s words), %s s, %s KB", $1, $3, $2, $8, $9 }')" |
| 107 | done |
| 108 | cp $B/usage.tsv build/seed/usage/usage.tsv |
| 109 | |
| 110 | # mutant control: tables that never double (a_need +512 entries each time) must be noticed |
| 111 | grep -cx 'c = shl c 1' seed/omc/omc.om | grep -qx 1 || bad "mutant: the doubling line of a_need does not occur exactly once" |
| 112 | sed 's/^c = shl c 1$/c = add c 512/' seed/omc/omc.om > $B/m.om |
| 113 | "$S" < $B/m.om > $B/m.omc 2> $B/m.err || bad "mutant: does not build ($(cat $B/m.err))" |
| 114 | chmod +x $B/m.omc |
| 115 | caught="" |
| 116 | for f in $B/real/*.om $B/scale/*.om; do k=real; case $f in $B/scale/*) k=scale;; esac |
| 117 | if ! check $B/m.omc $k $f > $B/m.row 2> $B/m.why; then caught="$(basename $f .om): $(head -2 $B/m.why | tr '\n' ' ')"; break; fi |
| 118 | done |
| 119 | [ -n "$caught" ] || bad "mutant: tables growing by 512 entries passed every unit; the alarm noticed nothing" |
| 120 | say "PASS mutant a_need +512 (never doubling) caught by $caught (row: unit, top words, seconds, KB: $(cut -f1,3,8,9 $B/m.row | tr "\t" " "))" |
| 121 | [ $skip = 0 ] || { say "NOT_RUN $skip sibling units"; exit 3; } |
| 122 | say "RC=0" |