raz / commit 84f97627

commit
84f976272375fed945ee93be66cfb19326048346
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
3829cbb0
make docker-check, the scripts on BSD's tools, the budget at 18,000

PLAN.md 5, step 2. containers/check/Dockerfile and make docker-check
run make check in a linux/amd64 container, for a Mac until raz runs
there; under Rosetta, test/check.sh skips the 9 tests Rosetta breaks
(its own descriptors 3 to 6, its mmap under ulimit -v, a stack fault's
locals), each saying why. The Makefile and scripts run on BSD's tools:
test/nanos.sh for date +%s%N, shasum where sha256sum isn't, getconf
for nproc. The budget is 18,000 lines of code, by the owner's word.

patch · log

10 files changed, +81 -19

CLAUDE.md modified +3 -2

@@ -10,6 +10,7 @@
1010
1111 make raz # the compiler, ./raz, built from src/ by the release BOOT names; its library is lib/
1212 make check # every example and test against its expected output
13+ make docker-check # make check in a linux/amd64 container, on a Mac; under Rosetta it skips 9 tests, each saying why
1314 make bench # must report at least 400,000 lines a second
1415 make prev-bench # the compiler's speed against BOOT's: more than a tenth slower fails
1516 make kernels # test/bench's kernels against FPC -O2's twins (apt-get install -y fp-compiler)
@@ -60,8 +61,8 @@
6061 `Luis <42945842+ldiaz94@users.noreply.github.com>`, unsigned
6162 (`--no-gpg-sign`), no attribution trailer. Push to `main`. No pull
6263 requests unless asked.
63-- Budget: never past 14,000 lines of code (raised from 8,500, then
64- from 11,000, by the owner's word, who dropped the soft limit; blank and
64+- Budget: never past 18,000 lines of code (raised from 8,500, then
65+ from 11,000 and 14,000, the last for the arm64 macOS port, by the owner's word, who dropped the soft limit; blank and
6566 comment lines not counted), with the compiler documented and
6667 commented throughout, most of all where it is obscure or needs a
6768 compiler writer's knowledge; at least 400,000 lines of raz a second;

Makefile (history) modified +17 -3

@@ -54,9 +54,9 @@
5454 # the best of three runs; fails below 400,000 lines a second
5555 bench: raz | build
5656 sh test/genbench.sh 12000 > build/Bench.raz
57- @lines=$$(wc -l < build/Bench.raz); best=0; \
57+ @lines=$$(($$(wc -l < build/Bench.raz))); best=0; \
5858 for i in 1 2 3; do \
59- start=$$(date +%s%N); ./raz build/Bench.raz || exit 1; end=$$(date +%s%N); \
59+ start=$$(sh test/nanos.sh); ./raz build/Bench.raz || exit 1; end=$$(sh test/nanos.sh); \
6060 t=$$((end - start)); if [ $$best = 0 ] || [ $$t -lt $$best ]; then best=$$t; fi; \
6161 done; \
6262 rate=$$((lines * 1000000000 / best)); \
@@ -207,4 +207,18 @@
207207 site-check: build/site/Verify
208208 build/site/Verify
209209
210-.PHONY: prev-bench fixpoint check gdb bench kernels stress alpine fmt loc man pdf dist site site-source site-check clean install uninstall
210+.PHONY: docker-image docker-check docker-shell prev-bench fixpoint check gdb bench kernels stress alpine fmt loc man pdf dist site site-source site-check clean install uninstall
211+
212+# `make check` in a linux/amd64 container, for a machine that isn't one
213+# (the repository is mounted at its own path, so git and the tests see
214+# the same names). DOCKERFLAGS is for what a host's runtime needs.
215+DOCKER = docker run --rm --platform linux/amd64 $(DOCKERFLAGS) -v $(CURDIR):$(CURDIR) -w $(CURDIR)
216+DOCKERIMAGE = raz-check
217+docker-image:
218+ docker build --platform linux/amd64 -t $(DOCKERIMAGE) containers/check
219+
220+docker-check: docker-image
221+ $(DOCKER) $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && make check"
222+
223+docker-shell: docker-image
224+ $(DOCKER) -it $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && exec bash"

PLAN.md (history) modified +3 -3

@@ -181,8 +181,8 @@
181181 a table of quadwords, as GLOB_DAT does now; every address in data
182182 rebased, since the program is position-independent; its symbol table
183183 for lldb's backtraces; and an ad-hoc code signature, SHA-256 hashes
184- of its pages, without which arm64 macOS won't run it. No line
185- numbers for a debugger at first.
184+ of its pages, without which arm64 macOS won't run it; and line
185+ numbers for lldb, as DWARF in `__DWARF` (below).
186186 - `Host.darwin.raz`: the library beside the compiler by
187187 `_NSGetExecutablePath`, C always, a program run from a file written
188188 and made executable (no `memfd_create`).
@@ -213,7 +213,7 @@
213213 linux/amd64 container on the Mac until there is a Mac compiler):
214214
215215 1. Report 2026-11.0, for the owner's review. (This commit.)
216-2. A container to build and check in on the Mac (`make docker-check`),
216+2. Done. A container to build and check in on the Mac (`make docker-check`),
217217 the budget raised to 18,000 in `CLAUDE.md` and `doc/compiler.md`,
218218 and the Makefile and scripts made to run on BSD's tools as on GNU's
219219 (`sed -i`, `stat`, `sha256sum`).

containers/check/Dockerfile (history) added +8 -0

@@ -0,0 +1,8 @@
1+# What `make check` needs, on the one target raz makes: Linux x86-64.
2+# Used by `make docker-check` to run the checks on a machine of
3+# another kind (an Apple Silicon Mac, over Rosetta).
4+FROM debian:stable-slim
5+RUN apt-get update && apt-get install -y --no-install-recommends \
6+ make curl ca-certificates gcc libc6-dev musl musl-tools \
7+ vim emacs-nox git \
8+ && rm -rf /var/lib/apt/lists/*

doc/compiler.md (history) modified +1 -1

@@ -1,7 +1,7 @@
11 # Reading the raz compiler
22
33 The compiler is twelve files of raz, about 13,100 lines of code (the
4-budget is 14,000). It is its own compiler: a release of it, the one
4+budget is 18,000). It is its own compiler: a release of it, the one
55 `BOOT` names, builds `src/`, and `make fixpoint` checks that what it
66 makes makes itself again, byte for byte. Each release was built by the
77 one before it, back to v0.19.0, which the Pascal compiler it was ported

src/bench.sh (history) modified +2 -2

@@ -8,12 +8,12 @@
88 mkdir -p build/cmp/bench
99 ln -sfn ../../lib build/cmp/lib
1010 sh test/genbench.sh 12000 >build/cmp/bench/Bench.raz
11-echo "$(wc -l <build/cmp/bench/Bench.raz) lines"
11+echo "$(($(wc -l <build/cmp/bench/Bench.raz))) lines"
1212 for t in prev this; do
1313 if [ $t = prev ]; then cp build/boot/raz build/cmp/raz; else cp raz build/cmp/raz; fi
1414 best=0
1515 for i in 1 2 3 4 5; do
16- s=$(date +%s%N); build/cmp/raz -o build/cmp/bench/Bench.$t build/cmp/bench/Bench.raz; e=$(date +%s%N)
16+ s=$(sh test/nanos.sh); build/cmp/raz -o build/cmp/bench/Bench.$t build/cmp/bench/Bench.raz; e=$(sh test/nanos.sh)
1717 d=$(( (e - s) / 1000000 )); if [ $best = 0 ] || [ $d -lt $best ]; then best=$d; fi
1818 done
1919 echo "$t: $best ms"

src/boot.sh (history) modified +3 -1

@@ -34,7 +34,9 @@
3434 { rm -f $d/$t; echo "boot: can't fetch $t; put it in $d" >&2; exit 1; }
3535 fi
3636 fi
37-if ! echo "$sum $d/$t" | sha256sum -c --quiet - >/dev/null 2>&1; then
37+# macOS has shasum, not sha256sum
38+if command -v sha256sum >/dev/null; then got=$(sha256sum < $d/$t); else got=$(shasum -a 256 < $d/$t); fi
39+if [ "${got%% *}" != "$sum" ]; then
3840 echo "boot: $d/$t isn't $tag's tarball: its SHA-256 isn't BOOT's" >&2
3941 exit 1
4042 fi

test/bench/run.sh (history) modified +1 -1

@@ -10,7 +10,7 @@
1010 best() { # best program: the fewest milliseconds of five runs
1111 b=0
1212 for i in 1 2 3 4 5; do
13- s=$(date +%s%N); $1 > /dev/null; e=$(date +%s%N)
13+ s=$(sh test/nanos.sh); $1 > /dev/null; e=$(sh test/nanos.sh)
1414 t=$(( (e - s) / 1000000 ))
1515 if [ $b = 0 ] || [ $t -lt $b ]; then b=$t; fi
1616 done

test/check.sh (history) modified +34 -6

@@ -30,6 +30,26 @@
3030 ulimit -s 8192 # Linux's usual stack: StackOverflow's depth depends on it, and CI's runner gives more
3131 pass=0
3232 fail=0
33+skipped=0
34+
35+# Rosetta, which runs x86 programs on an Apple Silicon Mac, differs from
36+# Linux in these ways; the tests that can't tell so are skipped there,
37+# each with its reason, until raz runs natively on the Mac. Elsewhere
38+# nothing is skipped.
39+rosetta=
40+grep -q VirtualApple /proc/cpuinfo 2>/dev/null && rosetta=1
41+skip() { # skip name: whether to skip it, saying why
42+ [ -n "$rosetta" ] || return 1
43+ case $1 in
44+ test/run/ExecOpened|test/libc/ExecOpenedC) why='keeps descriptors 3 to 6 open' ;;
45+ test/libc/SysTest|lib/Sys.linux-x86_64.raz) why='takes descriptor 9 in a child' ;;
46+ test/run/StackOverflow|test/run/ThreadOverflow) why='reads a trap local as 0 after a stack fault' ;;
47+ "Thread under a memory limit") why="aborts under ulimit -v" ;;
48+ *) return 1 ;;
49+ esac
50+ echo "SKIP $1: Rosetta $why"
51+ skipped=$((skipped + 1))
52+}
3353
3454 conform/check.sh $raz test/msg > $out/conform.out
3555 grep -v '^[0-9]* passed' $out/conform.out
@@ -38,6 +58,7 @@
3858
3959 run() { # run dir name
4060 dir=$1; name=$2
61+ skip $dir/$name && return
4162 flags=
4263 [ $dir = examples ] || [ $dir = test/libc ] && flags=-Werror
4364 if ! $raz $flags $libc -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then
@@ -335,8 +356,12 @@
335356 # raztest, which says what it counted on its last line; Sys over C is
336357 # tested in test/libc
337358 if $raz -Werror -o $out/raztest tools/Test.raz 2>$out/raztest.cerr; then
338- RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || echo 1) -o $out/lib \
339- $(for f in lib/*.raz; do [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && echo $f; done) \
359+ libtests=
360+ for f in lib/*.raz; do
361+ [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && ! skip $f && libtests="$libtests $f"
362+ done
363+ RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) -o $out/lib \
364+ $libtests \
340365 > $out/raztest.out 2>&1
341366 set -- $(tail -1 $out/raztest.out) # N passed, F failed, T timed out, S
342367 if [ "$2" = passed, ] && [ "$6" = timed ]; then
@@ -347,8 +372,8 @@
347372 fi
348373 # and again with the debug heap, RAZ_HEAP=debug: guards after blocks,
349374 # freed blocks filled and quarantined
350- RAZ_HEAP=debug RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || echo 1) -o $out/libdebug \
351- $(for f in lib/*.raz; do [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && echo $f; done) \
375+ RAZ_HEAP=debug RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) -o $out/libdebug \
376+ $libtests \
352377 > $out/raztest-debug.out 2>&1
353378 set -- $(tail -1 $out/raztest-debug.out)
354379 if [ "$2" = passed, ] && [ "$6" = timed ]; then
@@ -427,7 +452,8 @@
427452
428453 # Thread's test again, with too little memory for all its threads:
429454 # spawn must fail, with Thread.Failed
430-if (ulimit -v 60000; $out/lib/Thread.linux-x86_64 fail) > /dev/null 2>&1; then pass=$((pass + 1))
455+if skip "Thread under a memory limit"; then :
456+elif (ulimit -v 60000; $out/lib/Thread.linux-x86_64 fail) > /dev/null 2>&1; then pass=$((pass + 1))
431457 else echo "FAIL Thread under a memory limit"; fail=$((fail + 1)); fi
432458
433459 # the compiler's way of going on after an error, in small: a parser
@@ -463,5 +489,7 @@
463489 # The compiler built with another host (test/host/Host.raz).
464490 if test/compiler-host.sh "$raz"; then pass=$((pass + 1)); else fail=$((fail + 1)); fi
465491
466-echo "$pass passed, $fail failed"
492+summary="$pass passed, $fail failed"
493+[ $skipped = 0 ] || summary="$summary, $skipped skipped"
494+echo "$summary"
467495 [ $fail = 0 ]

test/nanos.sh (history) added +9 -0

@@ -0,0 +1,9 @@
1+#!/bin/sh
2+# The time in nanoseconds, for the timing scripts: date +%s%N is GNU's;
3+# BSD's date prints a literal N there, and perl, which macOS has, then
4+# gives the time.
5+n=$(date +%s%N)
6+case $n in
7+*N) perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1e9' ;;
8+*) echo "$n" ;;
9+esac