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 / osc1_receipt.sh

131 lines · 8200 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-1 compiler slice receipt (docs/osc/OSC-1-DESIGN.md).
18# OSC-1 slice; not a general Omega compiler; no self-hosting.
19# 1. refuses a dirty tree (any tracked or untracked change): receipts record an exact commit
20# 2. runs `make test-compiler` into a temporary OUT_DIR (model sweep, back end,
21# compiler golden/negative/model agreement, determinism; plain + ASan/UBSan)
22# 3. compiles every golden program with oscc and records its IR and machine-code digests
23# 4. checks that the existing Omega core sources (src/omega_*, src/aarch64_*,
24# src/language/, tools/omegatool.c, Makefile) are unchanged against the merge
25# base with origin/main, so the M6/M9/M14 gates cannot have changed; if
26# PHYSICS_DIR points at the pinned physics checkout it also runs those gates
27# 5. writes a content-addressed receipt evidence/OSC-1/receipts/osc1-compiler-<sha256>.json
28# Never overwrites existing evidence. Timing is not recorded.
29set -eu
30ROOT=$(cd "$(dirname "$0")/../.." && pwd -P)
31cd "$ROOT"
32EVD=evidence/OSC-1/receipts
33die() { echo "osc1-receipt: REFUSED: $*" >&2; exit 2; }
34
35[ -z "$(git status --porcelain --untracked-files=all)" ] || die "dirty tree; commit first (receipts record an exact commit)"
36COMMIT=$(git rev-parse HEAD)
37BASE=$(git merge-base HEAD origin/main) || die "no merge base with origin/main"
38
39T=$(mktemp -d)
40trap 'rm -rf "$T"' EXIT
41O="$T/build/compiler"
42nice make --no-print-directory OUT_DIR="$T/build" PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-compiler \
43 >"$T/make.log" 2>&1 || { tail -30 "$T/make.log"; die "make test-compiler failed"; }
44grep -q '^test-compiler: PASS' "$T/make.log" || die "no test-compiler PASS line"
45
46MSUM=$(grep '^OSC0B_MODEL_SEED=' "$O/model.out" | tail -1)
47mf() { echo "$MSUM" | sed -n "s/.*$1=\([0-9a-fx]*\).*/\1/p"; }
48BCOUNTS=$(grep '^units=' "$O/backend.out" | tail -1)
49BCHECKS=$(grep '^checks=' "$O/backend.out" | tail -1 | sed 's/ time=.*//')
50CLINE=$(grep '^golden=' "$O/compiler.out" | tail -1 | sed 's/ time=.*//')
51DLINE=$(grep '^programs=' "$O/determinism.out" | tail -1)
52tc() { grep "^ $1 " "$O/compiler.out" | awk '{print $2}'; }
53for v in "$MSUM" "$BCOUNTS" "$BCHECKS" "$CLINE" "$DLINE"; do [ -n "$v" ] || die "cannot parse test output"; done
54for k in OVERFLOW DIV0 BOUNDS LOOP_BOUND CAST OOM SHIFT; do
55 n=$(tc $k); [ -n "$n" ] && [ "$n" -gt 0 ] || die "trap $k not observed in golden corpus"
56done
57
58# golden corpus digests (oscc, one process per program)
59: >"$T/corpus.txt"
60for f in tests/compiler/progs/*.osc; do
61 out=$("$O/oscc" "$f") || die "oscc refused golden program $f"
62 ir=$(echo "$out" | sed -n 's/^ir_sha256=//p'); code=$(echo "$out" | sed -n 's/^code_sha256=//p')
63 printf '%s %s %s %s\n' "$f" "$(sha256sum "$f" | cut -d' ' -f1)" "$ir" "$code" >>"$T/corpus.txt"
64done
65CORPUS_SHA=$(sha256sum "$T/corpus.txt" | cut -d' ' -f1)
66NPROG=$(wc -l <"$T/corpus.txt" | tr -d ' ')
67NNEG=$(ls tests/compiler/neg/*.osc | wc -l | tr -d ' ')
68
69CORE="src/omega_*.c src/omega_*.h src/aarch64_* src/language tools/omegatool.c Makefile"
70# shellcheck disable=SC2086
71if git diff --quiet "$BASE" HEAD -- $CORE; then CORE_UNCHANGED=true; else die "existing Omega core sources changed vs $BASE"; fi
72
73GATES='"NOT_RUN (PHYSICS_DIR not set; core sources unchanged vs merge base)"'
74if [ -n "${PHYSICS_DIR:-}" ] && [ -d "$PHYSICS_DIR" ]; then
75 G=""
76 rm -rf build/osc1-receipt-gates; mkdir -p build/osc1-receipt-gates # gate targets need a relative OUT_DIR (./$(OUT_DIR)/omegatool); build/ is ignored
77 for m in m6 m9 m14; do
78 nice make --no-print-directory OUT_DIR=build/osc1-receipt-gates PHYSICS_DIR="$PHYSICS_DIR" "test-$m" >"$T/$m.log" 2>&1 \
79 || { tail -20 "$T/$m.log"; die "test-$m failed"; }
80 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}/')
81 sed -n "/omegatool --run/,\$p" "$T/$m.log" >build/osc1-receipt-gates/$m.gate.log
82 G="$G\"$m\": $tot, "
83 done
84 GATES="{${G%, }}"
85fi
86
87R="$T/receipt.json"
88{
89 printf '{\n'
90 printf ' "schema": "omega.osc1.compiler.receipt.v1",\n'
91 printf ' "verdict": "PASS",\n'
92 printf ' "statement": "OSC-1 slice; not a general Omega compiler; no self-hosting",\n'
93 printf ' "subset": "integer scalars u8 u16 u32 u64 (wrap) and i8 i16 i32 i64 (checked, trap on overflow), bool; let / let mut; arithmetic, bitwise, shift, compare, logical (short-circuit), checked as-casts; if/else; while with static bound N (trap past N) and for over literal ranges; calls to earlier functions in the unit (no recursion, <= 6 params); unique allocation own [T; N] (N <= 64), moves, shared and mutable borrows with lexical lifetimes, bounds-checked indexing, deterministic destruction at scope end; requires/ensures recorded as text, not checked",\n'
94 printf ' "pipeline": "surface text -> lexer/parser -> typed AST -> name/type + ownership/borrow analysis -> typed IR (canonical encoding + sha256) -> AArch64 via src/compiler/osc_a64 (validating encoder, decoder mirror)",\n'
95 printf ' "repo_commit": "%s",\n' "$COMMIT"
96 printf ' "base_commit": "%s",\n' "$BASE"
97 printf ' "tree_clean": true,\n'
98 printf ' "host_arch": "%s",\n' "$(uname -m)"
99 printf ' "c_compiler": "%s",\n' "$(${CC:-cc} --version 2>/dev/null | head -1 | sed 's/"/\\"/g')"
100 printf ' "osc0b_model": {"seed": "0x%s", "sequences": %s, "steps": %s, "false_accepts": %s, "wrong_name": %s, "false_rejects": %s, "result": "OSC0B_MODEL_PASS"},\n' \
101 "$(mf OSC0B_MODEL_SEED)" "$(mf SEQUENCES)" "$(mf STEPS)" "$(mf FALSE_ACCEPTS)" "$(mf WRONG_NAME)" "$(mf FALSE_REJECTS)"
102 printf ' "backend": "%s; %s; native == interpreter on every run",\n' "$BCOUNTS" "$BCHECKS"
103 printf ' "compiler": "%s",\n' "$CLINE"
104 printf ' "golden_trap_coverage": {"none": %s, "overflow": %s, "div0": %s, "bounds": %s, "loop_bound": %s, "cast": %s, "oom": %s, "shift": %s, "runtime": %s},\n' \
105 "$(tc none)" "$(tc OVERFLOW)" "$(tc DIV0)" "$(tc BOUNDS)" "$(tc LOOP_BOUND)" "$(tc CAST)" "$(tc OOM)" "$(tc SHIFT)" "$(tc RUNTIME)"
106 printf ' "determinism": "%s (oscc in separate processes, byte-identical IR digest and machine code)",\n' "$DLINE"
107 printf ' "sanitizers": "all three test binaries also pass under -fsanitize=address,undefined -fno-sanitize-recover=all (model sweep at 10^5)",\n'
108 printf ' "golden_programs": %s,\n' "$NPROG"
109 printf ' "negative_programs": %s,\n' "$NNEG"
110 printf ' "golden_corpus_sha256": "%s",\n' "$CORPUS_SHA"
111 printf ' "golden_corpus": [\n'
112 n=0
113 while read -r f src ir code; do
114 n=$((n + 1)); sep=,; [ "$n" = "$NPROG" ] && sep=
115 printf ' {"program": "%s", "source_sha256": "%s", "ir_sha256": "%s", "code_sha256": "%s"}%s\n' "$f" "$src" "$ir" "$code" "$sep"
116 done <"$T/corpus.txt"
117 printf ' ],\n'
118 printf ' "omega_core_sources_unchanged_vs_base": %s,\n' "$CORE_UNCHANGED"
119 printf ' "m6_m9_m14_gates": %s,\n' "$GATES"
120 printf ' "self_host": "no: the OSC-1 compiler cannot compile any part of itself (docs/osc/OSC-1-SELF-HOST-STATEMENT.md)",\n'
121 printf ' "not_covered": "contract enforcement (OSC-2), effects/capabilities, structs, strings, generations, arenas, unsafe physical, FFI, Flow IR optimisation, self-hosting (OSC-14); not a general Omega compiler",\n'
122 printf ' "timing_measured": false\n'
123 printf '}\n'
124} >"$R"
125
126mkdir -p "$EVD"
127RSHA=$(sha256sum "$R" | cut -d' ' -f1)
128OUT="$EVD/osc1-compiler-$RSHA.json"
129[ -e "$OUT" ] && { echo "osc1-receipt: identical receipt already present: $OUT"; exit 0; }
130cp "$R" "$OUT"
131echo "osc1-receipt: PASS receipt=$OUT"