interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / compiler / osc3_receipt.sh

170 lines · 10114 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# OSC-3 compiler slice receipt, one per item (docs/osc/OSC-3-DESIGN.md).
18# OSC-3 slice; not a general Omega compiler; no self-hosting.
19# Usage: tests/compiler/osc3_receipt.sh ITEM
20# ITEM: review | split | handles | dropflags | effects | identity | module
21# 1. refuses a dirty tree: receipts record an exact commit
22# 2. runs `make test-compiler-full` (everything, full counts) into a temporary OUT_DIR,
23# and `make test-compiler-quick` (wall time recorded; quick is never the evidence)
24# 3. compiles every golden program with oscc; records IR and code digests and compares
25# every program that the OSC-2 baseline receipt lists (tests/compiler/osc3_baseline.json
26# names it) against its OSC-2 digests: identical unless OSC3_CODE_CHANGE_OK=1 and the
27# item states why (the receipt then lists the programs that changed)
28# 4. runs the M6/M9/M14 gates (PHYSICS_DIR must point at the pinned physics checkout)
29# and compares each normalised gate log sha256 with the OSC-2 encoder receipt values
30# 5. records every "^<item evidence>" line the test binaries print for this item
31# (lines starting with "osc3 <ITEM>:"), plain and ASan
32# 6. writes evidence/OSC-3/receipts/osc3-<ITEM>-<sha256>.json; never overwrites evidence
33set -eu
34ITEM=${1:-}
35case "$ITEM" in review|split|handles|dropflags|effects|identity|module) ;; *) echo "osc3-receipt: REFUSED: unknown ITEM '$ITEM'" >&2; exit 2 ;; esac
36ROOT=$(cd "$(dirname "$0")/../.." && pwd -P)
37cd "$ROOT"
38EVD=evidence/OSC-3/receipts
39BASEREC=$(ls evidence/OSC-2/receipts/osc2-encoder-*.json | head -1)
40die() { echo "osc3-receipt: REFUSED: $*" >&2; exit 2; }
41[ -n "${PHYSICS_DIR:-}" ] && [ -d "$PHYSICS_DIR" ] || die "PHYSICS_DIR must point at the pinned physics checkout (M6/M9/M14 gates are part of every OSC-3 receipt)"
42[ -z "$(git status --porcelain --untracked-files=all)" ] || die "dirty tree; commit first (receipts record an exact commit)"
43COMMIT=$(git rev-parse HEAD)
44BASE=$(git merge-base HEAD origin/main) || die "no merge base with origin/main"
45
46T=$(mktemp -d)
47trap 'rm -rf "$T"' EXIT
48O="$T/build/compiler"
49nice make --no-print-directory OUT_DIR="$T/build" PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-compiler-full \
50 >"$T/make.log" 2>&1 || { tail -30 "$T/make.log"; die "make test-compiler-full failed"; }
51grep -q '^test-compiler: PASS' "$T/make.log" || die "no test-compiler (full) PASS line"
52q0=$(date +%s)
53nice make --no-print-directory OUT_DIR="$T/build" PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-compiler-quick \
54 >"$T/quick.log" 2>&1 || { tail -30 "$T/quick.log"; die "make test-compiler-quick failed"; }
55q1=$(date +%s)
56grep -q '^test-compiler-quick: PASS' "$T/quick.log" || die "no test-compiler-quick PASS line"
57QSECS=$((q1 - q0))
58
59MSUM=$(grep '^OSC0B_MODEL_SEED=' "$O/model.out" | tail -1)
60CLINE=$(grep '^golden=' "$O/compiler.out" | tail -1 | sed 's/ time=.*//')
61CLINE_ASAN=$(grep '^golden=' "$O/compiler_asan.out" | tail -1 | sed 's/ time=.*//')
62DLINE=$(grep '^programs=' "$O/determinism.out" | tail -1)
63for v in "$MSUM" "$CLINE" "$CLINE_ASAN" "$DLINE"; do [ -n "$v" ] || die "cannot parse test output"; done
64fz() { grep "^$1 fuzz:" "$2" | tail -1; }
65for k in contract struct arena; do
66 for f in "$O/compiler.out" "$O/compiler_asan.out"; do
67 l=$(fz $k "$f"); [ -n "$l" ] || die "no $k fuzz line in $f"
68 case "$k:$l" in contract:*) ;; *" mismatches=0") ;; *) die "$k fuzz mismatches in $f" ;; esac
69 done
70done
71for f in "$O/compiler.out" "$O/compiler_asan.out"; do
72 case "$(grep '^runtime model replay:' "$f" | tail -1)" in *" rejected=0") ;; *) die "runtime model replay rejected runs ($f)" ;; esac
73done
74case "$(grep '^legacy a64 differential:' "$O/legacy_a64.out" | tail -1)" in *" mode=full "*" mismatches=0") ;; *) die "legacy a64 full differential" ;; esac
75
76# golden corpus vs the OSC-2 baseline receipt
77# every program the OSC-2 baseline receipt lists must still exist (a deleted or renamed
78# golden program must not silently drop out of the comparison)
79for bp in $(grep -o '"program": "[^"]*"' "$BASEREC" | sed 's/"program": "//; s/"$//'); do
80 [ -f "$bp" ] || die "OSC-2 baseline golden program $bp is missing (renamed or deleted)"
81done
82: >"$T/corpus.txt"; : >"$T/changed.txt"
83NSAME=0; NBASE=0
84for f in tests/compiler/progs/*.osc; do
85 out=$("$O/oscc" "$f") || die "oscc refused golden program $f"
86 ir=$(echo "$out" | sed -n 's/^ir_sha256=//p'); code=$(echo "$out" | sed -n 's/^code_sha256=//p')
87 printf '%s %s %s %s\n' "$f" "$(sha256sum "$f" | cut -d' ' -f1)" "$ir" "$code" >>"$T/corpus.txt"
88 b=$(grep "\"program\": \"$f\"" "$BASEREC" || true)
89 if [ -n "$b" ]; then
90 NBASE=$((NBASE + 1))
91 case "$b" in *"\"ir_sha256\": \"$ir\", \"code_sha256\": \"$code\""*) NSAME=$((NSAME + 1)) ;; *) echo "$f" >>"$T/changed.txt" ;; esac
92 fi
93done
94NCHG=$(wc -l <"$T/changed.txt" | tr -d ' ')
95NBL=$(grep -c "\"program\": " "$BASEREC"); [ "$NBASE" = "$NBL" ] || die "compared $NBASE of $NBL OSC-2 baseline programs"
96[ "$NCHG" = 0 ] || [ "${OSC3_CODE_CHANGE_OK:-0}" = 1 ] || { cat "$T/changed.txt"; die "$NCHG OSC-2 golden programs compile differently (set OSC3_CODE_CHANGE_OK=1 only if the item states why)"; }
97CORPUS_SHA=$(sha256sum "$T/corpus.txt" | cut -d' ' -f1)
98NPROG=$(wc -l <"$T/corpus.txt" | tr -d ' ')
99NNEG=$(ls tests/compiler/neg/*.osc | wc -l | tr -d ' ')
100
101# M6/M9/M14 gates, normalised log hash vs the OSC-2 encoder receipt
102G=""
103rm -rf build/osc3-receipt-gates; mkdir -p build/osc3-receipt-gates
104for m in m6 m9 m14; do
105 nice make --no-print-directory OUT_DIR=build/osc3-receipt-gates PHYSICS_DIR="$PHYSICS_DIR" "test-$m" >"$T/$m.log" 2>&1 \
106 || { tail -20 "$T/$m.log"; die "test-$m failed"; }
107 tot=$(grep 'TOTAL GATES' "$T/$m.log" | head -1 | sed 's/.*TOTAL GATES: \([0-9]*\) | PASSED: \([0-9]*\) | FAILED: \([0-9]*\).*/{"total": \1, "passed": \2, "failed": \3}/')
108 case "$tot" in "{\"total\": "*", \"failed\": 0}") ;; *) die "test-$m: no gate total line with failed=0" ;; esac
109 sed -n "/omegatool --run/,\$p" "$T/$m.log" | sed 's|\./build/[^/ ]*/omegatool|./OUT/omegatool|g' >"$T/$m.norm"
110 gsha=$(sha256sum "$T/$m.norm" | cut -d' ' -f1)
111 grep -q "\"$m\": {[^}]*\"gate_log_sha256\": \"$gsha\"" "$BASEREC" || die "test-$m gate log differs from the OSC-2 baseline ($gsha)"
112 G="$G\"$m\": ${tot%\}}, \"gate_log_sha256\": \"$gsha\", \"identical_to_osc2_baseline\": true}, "
113done
114GATES="{${G%, }}"
115
116esc() { sed 's/\\/\\\\/g; s/"/\\"/g'; }
117R="$T/receipt.json"
118{
119 printf '{\n'
120 printf ' "schema": "omega.osc3.compiler.receipt.v1",\n'
121 printf ' "verdict": "PASS",\n'
122 printf ' "item": "%s",\n' "$ITEM"
123 printf ' "statement": "OSC-3 slice; not a general Omega compiler; no self-hosting.",\n'
124 printf ' "design": "docs/osc/OSC-3-DESIGN.md",\n'
125 printf ' "repo_commit": "%s",\n' "$COMMIT"
126 printf ' "base_commit": "%s",\n' "$BASE"
127 printf ' "tree_clean": true,\n'
128 printf ' "host_arch": "%s",\n' "$(uname -m)"
129 printf ' "c_compiler": "%s",\n' "$(${CC:-cc} --version 2>/dev/null | head -1 | esc)"
130 printf ' "test_compiler_full": "PASS",\n'
131 printf ' "test_compiler_quick": {"result": "PASS", "wall_seconds": %s, "budget_seconds": 60, "note": "nice, one make job; smoke counts, not evidence"},\n' "$QSECS"
132 printf ' "osc0b_model": "%s",\n' "$(echo "$MSUM" | esc)"
133 printf ' "compiler": "%s",\n' "$(echo "$CLINE" | esc)"
134 printf ' "compiler_asan": "%s",\n' "$(echo "$CLINE_ASAN" | esc)"
135 for k in contract struct arena; do
136 printf ' "%s_fuzz": "%s",\n' "$k" "$(fz $k "$O/compiler.out" | esc)"
137 printf ' "%s_fuzz_asan": "%s",\n' "$k" "$(fz $k "$O/compiler_asan.out" | esc)"
138 done
139 printf ' "runtime_model_replay": "%s",\n' "$(grep '^runtime model replay:' "$O/compiler.out" | tail -1 | esc)"
140 printf ' "runtime_model_replay_asan": "%s",\n' "$(grep '^runtime model replay:' "$O/compiler_asan.out" | tail -1 | esc)"
141 printf ' "legacy_a64_differential": "%s",\n' "$(grep '^legacy a64 differential:' "$O/legacy_a64.out" | tail -1 | esc)"
142 printf ' "item_evidence": [\n'
143 { grep -h "^osc3 $ITEM:" "$O/compiler.out" | sed 's/^/plain: /'; grep -h "^osc3 $ITEM:" "$O/compiler_asan.out" | sed 's/^/asan: /'; } | esc | sed 's/.*/ "&",/' >"$T/ev.txt" || true
144 sed '$ s/,$//' "$T/ev.txt"
145 printf ' ],\n'
146 printf ' "determinism": "%s",\n' "$(echo "$DLINE" | esc)"
147 printf ' "golden_programs": %s,\n' "$NPROG"
148 printf ' "negative_programs": %s,\n' "$NNEG"
149 printf ' "osc2_baseline_receipt": "%s",\n' "$BASEREC"
150 printf ' "osc2_programs_identical": "%s of %s",\n' "$NSAME" "$NBASE"
151 printf ' "osc2_programs_changed": [%s],\n' "$(sed 's/.*/"&"/' "$T/changed.txt" | paste -sd, -)"
152 printf ' "golden_corpus_sha256": "%s",\n' "$CORPUS_SHA"
153 printf ' "golden_corpus": [\n'
154 n=0
155 while read -r f src ir code; do
156 n=$((n + 1)); sep=,; [ "$n" = "$NPROG" ] && sep=
157 printf ' {"program": "%s", "source_sha256": "%s", "ir_sha256": "%s", "code_sha256": "%s"}%s\n' "$f" "$src" "$ir" "$code" "$sep"
158 done <"$T/corpus.txt"
159 printf ' ],\n'
160 printf ' "m6_m9_m14_gates": %s,\n' "$GATES"
161 printf ' "self_host": "no: the OSC-3 compiler slice cannot compile any part of itself (docs/osc/OSC-1-SELF-HOST-STATEMENT.md)",\n'
162 printf ' "timing_measured": "quick wall time only"\n'
163 printf '}\n'
164} >"$R"
165mkdir -p "$EVD"
166RSHA=$(sha256sum "$R" | cut -d' ' -f1)
167OUT="$EVD/osc3-$ITEM-$RSHA.json"
168[ -e "$OUT" ] && { echo "osc3-receipt: identical receipt already present: $OUT"; exit 0; }
169cp "$R" "$OUT"
170echo "osc3-receipt: PASS receipt=$OUT"