From 86717da0c82d4165f33ac0dc2618f7b8c289825c Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 30 Oct 2026 09:49:02 -0500 Subject: [PATCH 1/2] seed/omc: bounded recursion fixture and gate (#645) nest.om is a mutually recursive descent evaluator (primary -> expr -> term) with an explicit depth bound (DMAX 16, refused depth 17 -> status 40 before any frame) and a work bound (FUEL 64 -> status 42). gate-recursion.sh runs 25 cases (expected values computed with Wolfram) and 8 one-line source mutants (depth limit, off-by-one, uncounted depth, fuel limit, missing fuel decrement, eval operator, digit order, return value); each must compile and be caught by a non-trap status/stdout mismatch. Added to seed/host/check.sh. OMEGESE 9.2 states that omc itself has no depth limit beyond the 8 MiB stack. Refs #645 --- .crumb | 20 +-- docs/.crumb | 8 +- docs/one_layer/OMEGESE.md | 4 + seed/host/check.sh | 1 + seed/omc/gate-recursion.sh | 99 ++++++++++++++ seed/omc/tests/recursion/cases.tsv | 34 +++++ seed/omc/tests/recursion/nest.om | 208 +++++++++++++++++++++++++++++ 7 files changed, 360 insertions(+), 14 deletions(-) create mode 100755 seed/omc/gate-recursion.sh create mode 100644 seed/omc/tests/recursion/cases.tsv create mode 100644 seed/omc/tests/recursion/nest.om diff --git a/.crumb b/.crumb index f3e51fe46..e5d24e43f 100644 --- a/.crumb +++ b/.crumb @@ -47,7 +47,7 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8", + "digest": "6497f2ad93e97de87710222c507557b4cd6d10983283873e018c741810c84dd7", "last_commit": "dd39bf71f", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." @@ -72,38 +72,38 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", - "last_commit": "bf54b19fa", + "last_commit": "089e5b053", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "children_root": "sha256:f157978ecbfa5e36f8981ac363da20091f8b78a6626dae85a44a18f0ef9c8367", + "compiled_at": "2026-10-30T14:48:52Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", + "digest": "sha256:73fbe165d06fe04770561116cfcb9086254782412cfc7d60b34ee78d2baddd00", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "generated_at_commit": "62d1d0d668f897386a0e311374f8dbcc5c32dde8", + "source_tree": "sha256:c541b517fc0406efd2012a7cbae7b875fc6702b47bcdf33e50de2c8270e132ee" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 433100df5..e847d13a8 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -124,14 +124,14 @@ } ], "children_root": "sha256:c81d43c0c392dfec2b6ed5b38ba95ea7c592782b283950e32b777e7b9cfd9d61", - "compiled_at": "2026-10-30T02:47:38Z", + "compiled_at": "2026-10-30T14:48:52Z", "compiler": "crumb-compile/1", - "digest": "sha256:7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8", + "digest": "sha256:6497f2ad93e97de87710222c507557b4cd6d10983283873e018c741810c84dd7", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", "files": 138, - "generated_at_commit": "e615e9ff47d03199514580f655d7670e61ab7e2f", - "source_tree": "sha256:ba44cf86b50127e2ec3824c2e913e032178628d69910a85ca9125cc1ed960bb5" + "generated_at_commit": "62d1d0d668f897386a0e311374f8dbcc5c32dde8", + "source_tree": "sha256:03fdcd0e8fd1ad61e701efb0f9115e0f8fe9a003073f7e4912be206a30907beb" }, "owner_lane": "", "provenance": { diff --git a/docs/one_layer/OMEGESE.md b/docs/one_layer/OMEGESE.md index 90fa5d0c3..a262520f5 100644 --- a/docs/one_layer/OMEGESE.md +++ b/docs/one_layer/OMEGESE.md @@ -446,6 +446,10 @@ syscall adaptation, seed-chain boundaries and qualification status. may not reuse a name already in scope, a function or a struct: error 10. - In program mode the stack is a fixed 8 MiB pool; a call or a local array that would go below it traps 6 before it writes anything. (s.6 t_stack) +- omc sets no recursion depth limit of its own; only the 8 MiB stack bounds it. A program that takes + input-driven recursion bounds it itself, checking the depth before the call, as + `seed/omc/tests/recursion/nest.om` does: depth 16 accepted, depth 17 refused with status 40 before + any frame for it exists, plus a work bound (fuel, status 42). (`seed/omc/gate-recursion.sh`, #645) ### 9.3 Numbers (decision 19: one meaning per word and width) diff --git a/seed/host/check.sh b/seed/host/check.sh index 4b294cb10..4035bf83d 100644 --- a/seed/host/check.sh +++ b/seed/host/check.sh @@ -21,6 +21,7 @@ sh seed/omc/gate15.sh sh seed/omc/gate16.sh sh seed/omc/gate17.sh sh seed/omc/gate18.sh +sh seed/omc/gate-recursion.sh # Executable contracts use the existing fail-closed Omega conductor. B=build/seed/contracts mkdir -p "$B" diff --git a/seed/omc/gate-recursion.sh b/seed/omc/gate-recursion.sh new file mode 100755 index 000000000..4de25f048 --- /dev/null +++ b/seed/omc/gate-recursion.sh @@ -0,0 +1,99 @@ +#!/bin/sh +# gate-recursion.sh -- bounded recursion in seeded Omegese (issue #645). The compiler under test is +# seed/out/omc (OMC overrides it). seed/omc/tests/recursion/nest.om is a mutually recursive descent +# evaluator (primary -> expr -> term -> primary) with an explicit depth bound (DMAX 16) and a work +# bound (FUEL 64). Every row of cases.tsv must give its exact exit status and stdout: depth 16 is +# accepted and depth 17 is refused with status 40 before any frame for it exists, 64 primaries are +# accepted and the 65th is refused with status 42. Then each source mutant (one line, whose site +# occurs exactly once) must compile and be detected by a wrong status or stdout on some row whose +# status is below 100. A mutant that does not compile, or is noticed only by a trap or a signal, is +# INVALID and fails the gate: a crash is never a killed mutant. RC=0 only when everything passed. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) +cd "$R" +B=build/seed/recursion +T=seed/omc/tests/recursion +S=${OMC:-seed/out/omc} +mkdir -p "$B" +[ -x "$S" ] || { printf 'FAIL: %s missing; run sh seed/omega-from-seed.sh first\n' "$S" >&2; exit 1; } +bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } +say() { printf '%s\n' "$*"; } + +# one input file and one expected-stdout file per row +awk -F '\t' -v d="$B" ' +/^#/ || NF == 0 { next } +NF != 4 { print "bad row " NR > "/dev/stderr"; exit 1 } +{ + x = $2; s = x + if (x ~ /^nest:/ || x ~ /^open:/) { + split(x, f, ":"); s = "" + for (i = 0; i < f[2]; i++) s = s "(" + s = s f[3] + if (f[1] == "nest") for (i = 0; i < f[2]; i++) s = s ")" + } else if (x ~ /^sum:/) { + split(x, f, ":"); s = "1" + for (i = 1; i < f[2]; i++) s = s "+1" + } + printf "%s\n", s > (d "/" $1 ".in"); close(d "/" $1 ".in") + printf "%s\n", $4 > (d "/" $1 ".want"); close(d "/" $1 ".want") + print $1, $3 > (d "/rows") +}' "$T/cases.tsv" || bad "cases.tsv is malformed" + +# build SRC BIN: rc 0 and empty stderr, else returns 1 +build() { + set +e + "$S" < "$1" > "$2" 2> "$2.err" + crc=$? + set -e + [ "$crc" = 0 ] && [ ! -s "$2.err" ] || return 1 + chmod +x "$2" +} + +# check BIN: prints one line per row, "ok", "wrong" (status < 100) or "trap" (status >= 100) +check() { + while read -r name want; do + set +e + "$1" < "$B/$name.in" > "$B/$name.out" + rc=$? + set -e + if [ "$rc" = "$want" ] && cmp -s "$B/$name.out" "$B/$name.want"; then st=ok + elif [ "$rc" -ge 100 ]; then st=trap + else st=wrong; fi + printf '%s %s %s %s\n' "$name" "$st" "$rc" "$want" + done < "$B/rows" +} + +say "omc sha256 $(sha256sum "$S" | cut -d' ' -f1)" +say "source sha256 $(sha256sum "$T/nest.om" | cut -d' ' -f1)" +build "$T/nest.om" "$B/nest" || bad "nest.om: compiler exit $crc ($(cat "$B/nest.err"))" +say "binary sha256 $(sha256sum "$B/nest" | cut -d' ' -f1)" +check "$B/nest" > "$B/base.res" +n=$(wc -l < "$B/rows") +while read -r name st rc want; do + [ "$st" = ok ] || bad "$name: exit $rc (want $want), stdout $(cat "$B/$name.out")" + say "PASS $name exit $rc: $(cat "$B/$name.out")" +done < "$B/base.res" + +# mutant NAME OLD-LINE NEW-LINE +m=0 +mutant() { + m=$((m + 1)) + c=$(grep -cxF -- "$2" "$T/nest.om" || true) + [ "$c" = 1 ] || bad "mutant $1: site found $c times: $2" + awk -v o="$2" -v n="$3" '$0 == o { $0 = n } { print }' "$T/nest.om" > "$B/mut-$1.om" + cmp -s "$T/nest.om" "$B/mut-$1.om" && bad "mutant $1: source unchanged" + build "$B/mut-$1.om" "$B/mut-$1" || bad "mutant $1: INVALID, compiler exit $crc ($(cat "$B/mut-$1.err"))" + check "$B/mut-$1" > "$B/mut-$1.res" + k=$(awk '$2 == "wrong" { print $1 " exit " $3 " want " $4; exit }' "$B/mut-$1.res") + [ -n "$k" ] || bad "mutant $1: not detected ($(awk '$2 != "ok"' "$B/mut-$1.res" | tr '\n' ' '))" + say "PASS mutant $1 detected: $k" +} +mutant depth-limit-17 'const DMAX ulong 16' 'const DMAX ulong 17' +mutant depth-off-by-one 'if gt nd DMAX' 'if ge nd DMAX' +mutant depth-no-count 'nd = add depth 1' 'nd = depth' +mutant fuel-limit-65 'const FUEL ulong 64' 'const FUEL ulong 65' +mutant fuel-no-decrement 'put St 3 sub get St 3 1' 'put St 3 get St 3' +mutant eval-mul-to-add 'v = mul v r' 'v = add v r' +mutant digit-order 'v = add mul v 10 sub c 48' 'v = add mul 10 sub c 48 v' +mutant return-frame 'ret inner' 'ret nd' +say "RECURSION PASS cases=$n mutants=$m/$m" diff --git a/seed/omc/tests/recursion/cases.tsv b/seed/omc/tests/recursion/cases.tsv new file mode 100644 index 000000000..d9d4e5345 --- /dev/null +++ b/seed/omc/tests/recursion/cases.tsv @@ -0,0 +1,34 @@ +# cases for nest.om, run by seed/omc/gate-recursion.sh. Fields are separated by one TAB: +# name input exit stdout +# input: a literal line, or nest:N:X (N open parentheses, X, N closing ones), or open:N:X (N open +# parentheses and X, never closed), or sum:N (N ones joined by +). Each input is followed by one newline. +# Values were computed independently with Wolfram (WolframLanguageEvaluator, 2026-10-30): +# Mod[18446744073709551615 + 1, 2^64] -> 0 Mod[4294967296*4294967296, 2^64] -> 0 +# Mod[99999999999999999999, 2^64] -> 7766279631452241919 Mod[(2^32+3)*(2^32+5), 2^64] -> 34359738383 +# ((1+2)*(3+4))+((5*6)+(7*(8+9))) -> 170 2+3*4 -> 14 (2+3)*4 -> 20 2*3+4*5 -> 26 +# Total[ConstantArray[1,64]] -> 64 +depth0 7 0 value 7 depth 0 fuel 1 +depth1 (7) 0 value 7 depth 1 fuel 2 +depth15 nest:15:7 0 value 7 depth 15 fuel 16 +depth16 nest:16:7 0 value 7 depth 16 fuel 17 +depth17 nest:17:7 40 refused depth +depth100 nest:100:7 40 refused depth +depth2000 nest:2000:7 40 refused depth +depth16sum nest:16:1+2*3 0 value 7 depth 16 fuel 19 +depth17open open:17:7 40 refused depth +depth16open open:16:7 41 refused syntax +fuel64 sum:64 0 value 64 depth 0 fuel 64 +fuel65 sum:65 42 refused fuel +order1 2+3*4 0 value 14 depth 0 fuel 3 +order2 (2+3)*4 0 value 20 depth 1 fuel 4 +order3 2*3+4*5 0 value 26 depth 0 fuel 4 +tree ((1+2)*(3+4))+((5*6)+(7*(8+9))) 0 value 170 depth 3 fuel 16 +wrapadd 18446744073709551615+1 0 value 0 depth 0 fuel 2 +wrapmul 4294967296*4294967296 0 value 0 depth 0 fuel 2 +wrapmul2 (4294967296+3)*(4294967296+5) 0 value 34359738383 depth 1 fuel 6 +wrapdig 99999999999999999999 0 value 7766279631452241919 depth 0 fuel 1 +nobase () 41 refused syntax +noclose (7 41 refused syntax +empty 41 refused syntax +trailing 7) 41 refused syntax +badop 7-1 41 refused syntax diff --git a/seed/omc/tests/recursion/nest.om b/seed/omc/tests/recursion/nest.om new file mode 100644 index 000000000..1c394e11c --- /dev/null +++ b/seed/omc/tests/recursion/nest.om @@ -0,0 +1,208 @@ +note nest.om: a bounded recursive-descent evaluator in seeded Omegese (issue #645). It is the +note teaching fixture for direct and mutual recursion under explicit bounds, checked by +note seed/omc/gate-recursion.sh. The grammar over stdin (one trailing newline is ignored): +note expr = term { + term } term = primary { * primary } primary = digits | ( expr ) +note Arithmetic is ulong, wrapping mod 2^64. Evaluation is left to right. +note Two bounds, each checked before the call or frame it would admit: +note depth: an open parenthesis that would make the nesting deeper than DMAX is refused before +note any frame for it exists (depth 16 is accepted, depth 17 is refused). +note fuel: every primary costs one unit of FUEL; the primary that finds no fuel left is refused. +note The depth bound limits frames (at most 3 calls per level plus main); the fuel bound limits work. +note The first refusal wins and ends the evaluation; a refused input prints no value. +note Exit status and stdout (statuses stay below 100 so they never look like a trap): +note 0 "value V depth D fuel F" accepted; D deepest nesting reached, F primaries evaluated +note 40 "refused depth" nesting over DMAX +note 41 "refused syntax" not in the grammar (incl. empty input, missing base case "()") +note 42 "refused fuel" more than FUEL primaries +note 43 "refused input" stdin unreadable or over 4096 bytes + +const DMAX ulong 16 +const FUEL ulong 64 +global Src uchar 4096 +global St ulong 5 +global Out uchar 32 +global One uchar 1 +text tval "value " +text tdep " depth " +text tfue " fuel " +text tnl "\n" +text rdep "refused depth\n" +text rsyn "refused syntax\n" +text rfue "refused fuel\n" +text rinp "refused input\n" + +note St: 0 cursor, 1 input length, 2 status (0 while evaluating), 3 fuel left, 4 deepest depth + +fn peek to ulong +p = get St 0 +if ge p get St 1 +ret 256 +end +ret ulong get Src p +end + +fn skip to void +put St 0 add get St 0 1 +end + +fn stop code ulong to void +if eq get St 2 0 +put St 2 code +end +end + +fn ok to bool +ret eq get St 2 0 +end + +fn number to ulong +v = ulong 0 +n = ulong 0 +c = peek +while and ge c 48 le c 57 bound 4096 +v = add mul v 10 sub c 48 +skip +n = add n 1 +c = peek +end +if eq n 0 +stop 41 +end +ret v +end + +note the only place a frame deeper than the caller's is admitted: the depth check precedes the call +fn primary depth ulong to ulong +if eq get St 3 0 +stop 42 +ret 0 +end +put St 3 sub get St 3 1 +if ne peek 40 +ret number +end +nd = add depth 1 +if gt nd DMAX +stop 40 +ret 0 +end +if gt nd get St 4 +put St 4 nd +end +skip +inner = expr nd +if not ok +ret 0 +end +if ne peek 41 +stop 41 +ret 0 +end +skip +ret inner +end + +fn term depth ulong to ulong +v = primary depth +while ok bound 4096 +if ne peek 42 +break +end +skip +r = primary depth +v = mul v r +end +ret v +end + +fn expr depth ulong to ulong +v = term depth +while ok bound 4096 +if ne peek 43 +break +end +skip +r = term depth +v = add v r +end +ret v +end + +fn putnum v ulong to void +p = ulong 32 +x = v +while true bound 20 +p = sub p 1 +put Out p uchar add rem x 10 48 +x = div x 10 +if eq x 0 +break +end +end +w = write 1 Out p sub 32 p +end + +fn slurp to ulong +t = ulong 0 +while true bound 4097 +room = sub len Src t +if eq room 0 +r = read 0 One 0 1 +if ne r 0 +ret 4097 +end +break +end +r = read 0 Src t room +if lt r 0 +ret 4097 +end +if eq r 0 +break +end +t = add t ulong r +end +ret t +end + +fn main to int +t = slurp +if gt t 4096 +w = write 1 rinp 0 len rinp +ret 43 +end +if gt t 0 +if eq get Src sub t 1 10 +t = sub t 1 +end +end +put St 1 t +put St 3 FUEL +v = expr 0 +if ok +if ne get St 0 t +stop 41 +end +end +s = get St 2 +if eq s 40 +w = write 1 rdep 0 len rdep +ret 40 +end +if eq s 41 +w = write 1 rsyn 0 len rsyn +ret 41 +end +if eq s 42 +w = write 1 rfue 0 len rfue +ret 42 +end +w = write 1 tval 0 len tval +putnum v +w = write 1 tdep 0 len tdep +putnum get St 4 +w = write 1 tfue 0 len tfue +putnum sub FUEL get St 3 +w = write 1 tnl 0 len tnl +ret 0 +end From eec1823939e4287ef7581ef0c334595c4c65f911 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Fri, 30 Oct 2026 11:04:32 -0500 Subject: [PATCH 2/2] crumb: refresh after recursion-depth gate (Refs #645) crumb compile . on the PR head; crumb verify . was the AIEN Checks failure. --- .crumb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.crumb b/.crumb index e5d24e43f..daf1db17c 100644 --- a/.crumb +++ b/.crumb @@ -48,7 +48,7 @@ }, { "digest": "6497f2ad93e97de87710222c507557b4cd6d10983283873e018c741810c84dd7", - "last_commit": "dd39bf71f", + "last_commit": "86717da0c", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -96,14 +96,14 @@ } ], "children_root": "sha256:f157978ecbfa5e36f8981ac363da20091f8b78a6626dae85a44a18f0ef9c8367", - "compiled_at": "2026-10-30T14:48:52Z", + "compiled_at": "2026-10-30T16:03:54Z", "compiler": "crumb-compile/1", - "digest": "sha256:73fbe165d06fe04770561116cfcb9086254782412cfc7d60b34ee78d2baddd00", + "digest": "sha256:49820da646ee9b6be5fdad1e728a617a490412168bfe186c352a22191844fd88", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "62d1d0d668f897386a0e311374f8dbcc5c32dde8", - "source_tree": "sha256:c541b517fc0406efd2012a7cbae7b875fc6702b47bcdf33e50de2c8270e132ee" + "files": 17852, + "generated_at_commit": "86717da0c82d4165f33ac0dc2618f7b8c289825c", + "source_tree": "sha256:d7db857288c4cb7c161ec53f49864a01273a128c4de8635a53164f47fcb29be8" }, "owner_lane": "", "provenance": {