raz / PLAN.md

705 lines · 36.7 KiB · raw · history · last change baf3942c

raz: the plan to 1.0 #

What is left before raz is 1.0, in order, by the owner's word of 2026-10-23. raz takes no proposals; what is left is the Moss work below, its proposals kept in the appendix, and nothing else is planned. Each step is a release, started on the owner's go-ahead; within it, one commit per piece, the report first for any change to the language.

1. Release what is done: v0.22.0 #

Done 2026-10-23: tagged, its release and tarball made here by make dist (CI was refused by GitHub's billing), and BOOT moved to it. make alpine couldn't pull its image without a Docker Hub login.

Report 2026-10.36, the twelfth thaw: MIN, MAX, ABS, CLZ, CTZ, POPCOUNT, INT(b), OFFSET, SIZE(T.f), BYTES, FILL, a qualified case in an arm, slice and ERROR constants, a record's procedure field that takes the record; the library's growth since v0.21.0 (Fmt, Str, Files, Sys, Math, Opt, Heap.sure, Vec, Arena); inlining a procedure that only returns, and COPY, FILL and array parameters made fast.

2. The safety thaw: v0.23.0, then v0.24.0 #

The scope, by the owner's word of 2026-10-26, after reviewing MEM_PROPOSAL.md (in git to 2026-10-26) whole with its appendices. raz doesn't promise memory safety: free stays, so a program can always keep a pointer to what it freed. The thaw shrinks what is undefined, and fences what can reach memory it shouldn't, so a reader can find it.

What goes in:

What is left out, and why: ret and keep (B) and owners that count what they lend (C), too large for what they close without the rest; the heap without free (D), since free stays; atomic slices and the rest of threads (E), for programs that race only. With them the guarantee of the proposal's section 3.

The survey of 2026-10-26 (the compiler counting each use, across ~/r): about 8,000 fenced uses, 451 of 960 modules. 77% of the ADRs go to a pointer parameter only dereferenced, mended by var or const, as STANDARDS.md asks; what is left for SYSTEM is about 3,000 uses, most in lib/ (Sys, Rt, Heap, Map) and src/ (Scan, Link, Chunk). All 31 atomics take ADR.

Two releases, by the owner's word of 2026-10-26, since src/ and the library it imports (Buf, Files, Fmt, Heap, Mem, Out, Rt, Str, Sys, and Lock and Bytes under them) must build with BOOT, which knows neither []const nor SYSTEM:

  1. The report's text, for the owner to review (drafted 2026-10-26).
  2. v0.23.0, which breaks nothing. The compiler, a commit a piece, each with its part of the report: an array a call returns kept to the end of its procedure; atomics on a variable; []const T; SYSTEM. The old forms are still taken, silently: a string literal into a []U8, ADR and the rest without SYSTEM, an atomic given a pointer. The library: Task, Guarded, Heap's debugging mode. Release, and the report's pages checked. Done 2026-10-26: tagged, released here by make dist (CI refused by GitHub's billing, as for v0.22.0), its SHA-256 103eb421...; the website has v0.22.0 and v0.23.0; 35 pages. No rewriting tool, by the owner's word: v0.24.0's errors point at each place to mend.
  3. BOOT moved to v0.23.0, a step of its own. Done 2026-10-26.
  4. v0.24.0, which enforces it. Steps 1 to 3 done 2026-10-26: raz -strict first, lib/, src/, the tools and tests mended against it by agents, then the old forms made errors and the option gone. Released 2026-10-26 as v0.24.0; the programs in ~/r follow, the owner's five first (dwa, concha, mosaico, rat, notis). lib/, src/, tools/, examples/ and the tests mended where the old forms, made errors, are found (ADR at a parameter only dereferenced becomes var or const; SYSTEM. where an address is kept); the programs in ~/r mended the same way, by agents, each its own commit. Release.

3. The Moss work: v0.25.0 #

The scope, by the owner's word of 2026-10-26: what makes raz a better freestanding and portable compiler, nothing for Moss alone. Host is in. -moss (the branch moss-startup-args-v1) is not: Moss supplies its own start under item 4's contract, so raz knows no system's calls but Linux's. Of the implementation limits, the report's least and this compiler's errors past its own are in; compiling imports from the leaves and queuing instances, so the compiler fits a small stack, are dropped for good: Moss gives the compiler a larger stack instead. Report 2026-10.38 (993cd63) holds the language's part.

  1. Merge the branch moss-platform-boundary's two plain fixes (a file's identity from Sys.info; a main file at the root), rebased on main.
  2. Host, as "The compiler on another host" in the appendix asks: five procedures, Files.argCount, a host chosen by staging, its tests in sh, not Python; rebased and merged. Moss's RAZ_PORT.lock then pins main.
  3. What the compiler asks of Sys, Rt and Files, written down in doc/compiler.md and held by a test.
  4. "A freestanding program, stated", "The assembler's instructions" and "Implementation limits, and a compiler for a small stack" (the report's least and the errors only), in the appendix.
  5. Release. Done 2026-10-26: v0.25.0, report 2026-10.38.

4. The hard freeze #

From v0.25.0 on: no more thaws. The language changes only to mend a defect; the library's core (appendix A) only to mend a defect or plug a very big gap; the rest of the library grows only conservatively, by what breaks no program, on the owner's word.

v0.25.1, 2026-10-29, the report unchanged, on the owner's word:

v0.25.2, 2026-10-29, the report unchanged: raz -q def, where the name at the cursor is declared, for raz-lsp's hover and go to definition. v0.25.3, 2026-10-29: raz -q def on a module, used or imported, gives its module line.

5. arm64 macOS: v0.26.0 #

Started by the owner's word of 2026-11-15: raz on an Apple Silicon Mac, natively, as a second target, darwin-arm64. Report 2026-11.0 names it and changes no language (section 3, appendix A).

The shape. Gen is the only unit that knows the machine, and Exe (Exe.linux.raz, once Elf) the only one that knows the executable, so the port is new units beside them, not a change to Parse or Item:

A compiler compiles for the system it runs on, as now: its target is the one it was built for, its back end and executable chosen at its build by the target's suffixes (section 3), Gen.arm64.raz and Host.darwin.raz as Sys.linux-x86_64.raz is today. No -target. A compiler for one system that runs on another is built by staging, as appendix (b) proposes for Moss: src/cross.sh copies src/ with the other target's files in place. It is needed once, for the first Mac compiler, and wherever a release for one system is made on the other.

The library. Over libSystem, through lib/Sys.raz, the C one, with CAbi.darwin-arm64.raz made by tools/cabi.c on the Mac, never by hand. Rt.darwin-arm64.raz: the signals and their own stack, the place a fault stopped at from the Mac's ucontext, and framePtr, liveRegs, here and sigReturn in arm64. Thread.darwin.raz over pthreads, its Mutex on os_unfair_lock. Bytes.arm64.raz. Math's sqrt, mul and div128 and Str's code procedure move into .x86_64 files with arm64 twins: no generic file keeps machine code. None of it breaks a program.

Steps, one commit each, make check passing first (in a linux/amd64 container on the Mac until there is a Mac compiler):

  1. Report 2026-11.0, for the owner's review. (This commit.)

  2. Done. A container to build and check in on the Mac (make docker-check), the budget raised to 18,000 in CLAUDE.md and doc/compiler.md, and the Makefile and scripts made to run on BSD's tools as on GNU's (sed -i, stat, sha256sum).

  3. Done. Gen.raz to Gen.x86_64.raz, Elf.raz to Exe.linux.raz (the unit Exe), Host.raz to Host.linux.raz, src/cross.sh: what Linux's compiler makes unchanged, byte for byte.

  4. Done. A64.raz: arm64's encoder, jumps within a procedure, and the assembler in Arm's syntax (bl p, b p, adr xN, v for names), checked against Apple's assembler (clang's, llvm-mc's bytes) by test/a64; Chunk's arm64 fixup kinds, fxBranch26, fxPage21 and fxPageOff12, and Scan.setBang for a pre-index's !. What it left for later, Link's patching of those kinds, Gen.arm64.raz importing A64, and padding with brk, came with 5a.

  5. Done. Gen.arm64.raz, in pieces, each run on the Mac (owner, 2026-11-15): first a bare Exe.darwin.raz (a signed Mach-O over libSystem, no line numbers) and an Rt that only exits, built by the staged cross compiler in the container; then values and operations; jumps and checks; calls and frames; reals; atomics, deferred statements, the entry point.

    5a, done: programs made by the cross compiler (src/cross.sh darwin-arm64) run on the Mac, test/mac by make mac-check. In Gen.arm64.raz: frames, constants, variables, the integer operations but division, comparisons and jumps, elements and slices unchecked, calls with arguments in registers, C's calls, code procedures and the entry point; every other routine notes "not yet on arm64" on its procedure, an error if the program uses it. Exe.darwin.raz: a signed Mach-O over libSystem, its rebases and binds dyld's opcodes, no line numbers. Link: arm64's fixups, Mach-O's paged layout, the rebases. lib/Rt.darwin-arm64.raz: exit through C's exit, one procedure at exit, fail and stop by write. As the interface check of Rt reads Rt.raz, and so compiles Sys over C, also lib/CAbi.darwin-arm64.raz, from tools/cabi.c on the Mac, and a code procedure skipped in a file read only for its interface.

    5b, done: division and its checks (by zero, the smallest by -1, in every width), the checks of indexes, slices, views and enumerations with their stubs for Rt.fail, arguments past x7 on the stack, results in memory through x8, Apple's variadic calls, try, deferred statements, jump tables, compareSeq, copies past 256 bytes, ABS of an integer; and, since Out needs them, the atomics and COPY. SYSTEM.SYSCALL is an error on the Mac, Linux's only (report 6.8). lib/Rt.darwin-arm64.raz says what failed with its values, by its address, runs 32 procedures at exit, and tells a nil pointer or procedure and a stack overflow by a handler of SIGSEGV and SIGBUS. make mac-check runs conform/run too and counts it: 91 of 111 pass, the others needing reals (13), FILL (4, Heap's among them), CLZ, ROL, or SYSCALL (SystemImport, Linux's only). Left of step 5 (5c): the reals, FILL, NEW's zeroing, the counts of bits and the rotations.

    5c, done: the reals, F32 and F64, on the stack in v16 to v21 and as variables in d8 to d15, which the prologue saves; their operations, comparisons (a NaN equal to nothing), conversions both ways and between widths, a real out of an I64's range or a NaN mended to the smallest I64 after fcvtzs, ABS and -; real arguments in v0 to v7 and on the stack, results in d0; a code procedure that is fsqrt made in place of its call. FILL, NEW's zeroing, CLZ, CTZ, POPCOUNT (by cnt and addv), ROL and ROR at every width. A C procedure's own arguments past x7 packed by their size, as Apple's convention wants. Nothing of Gen.arm64.raz is "not yet"; only SYSCALL is refused, so test/mac.sh skips conform/run's SystemImport, with the reason. conform/run passes on the Mac, 110 of 110; test/mac has the reals' edges (Reals), rotations and counts of every width (Rotate) and fsqrt in place (Sqrt). Left for later steps: Math's arm64 twin, so that Math.sqrt is made in place (step 7). A rotation of a negative I8 or I16 leaves the bits above its width zero, where x86-64's rol al, cl leaves them as they were.

  6. Done. Exe.darwin.raz's line numbers for lldb, in a __DWARF segment (mapped, read only: dyld refuses a segment bigger in the file than in memory), the compile unit and its abbreviation made by Link for both formats, make lldb; other C libraries (link "X11"; is @rpath/libX11.dylib, four rpaths, binds by flat lookup); test/mac/NarrowArgs, a C library cc builds, narrow arguments past x7, a variadic call and a callback; Host.darwin.raz, and HOST=darwin src/cross.sh darwin-arm64, which stages the first Mac compiler: it runs on the Mac, compiles and runs programs, and builds Procs.

  7. Done. The library: CAbi, Sys, Rt, Thread, Bytes, Math, Str.

  8. test/ and conform/ passing on the Mac; what differs by target (signals' words, errors' numbers) in files of the target's.

  9. The first Mac compiler, by the staged cross compiler; it builds itself; make fixpoint on the Mac; make bench at 400,000 lines a second there.

  10. The release: two tarballs, linux-x86_64 and darwin-arm64; BOOT names one for each host, with its sum.

The owner's answers, 2026-11-15:

a. The budget is 18,000 lines of code. b. The names are darwin-arm64. c. No CI for now: the Mac's tarball is made here by make dist. d. The port is v0.26.0; the clean-up and 1.0 move one on. e. Line numbers for lldb are in v0.26.0 (below).

Line numbers on the Mac. Exe.linux.raz writes DWARF 4 already: the line table makeLines makes, target-blind, and the one compile unit putDebug writes. lldb reads DWARF from an executable's __DWARF segment, as it does Go's, so Exe.darwin.raz writes the same three sections, __debug_line, __debug_info and __debug_abbrev, there, unloaded, before __LINKEDIT; make gdb's twin drives lldb --batch. About 50 lines, makeLines and putDebug shared by the two writers.

Where it stands, 2026-11-15, stopped by the owner's word:

6. Clean-up: v0.27.0, the last before 1.0 #

The files that served the thaws are made a record, short and true:

7. 1.0 #

No date. raz is 1.0 when use shows it: programs written against v0.27.0 for long enough that no defect is outstanding. Until then it is 0.27.x, mending defects only.

Appendix: the Moss work, as proposed #

The four proposals 3 builds, kept from PROPOSALS.md (in git to 2026-10-26) when it and MEM_PROPOSAL.md went: what the thaws built is in the report, doc/report-history.md and git.

The compiler on another host: Host, and what it asks of the library #

Status. Built on the branch moss-platform-boundary (3eded0c), which Moss pins: there raz compiles programs, rebuilds itself byte for byte, and builds again after a restart (moss c606069, docs/native-raz.md). Waiting for the owner's word on the questions below before it is rebased and merged.

The host is the system the compiler runs on; the target, the system its program will run on. Until the branch they were one, Linux, and the compiler reached Linux outside Sys: Parse.identity read a struct stat by SYSCALL(4) into a guessed [18]INT; Raz read ARGC() and ARGV(), found the library through /proc/self/exe, probed two loader paths for musl, and ran a program by memfd_create and execve; Elf set mode 755. The branch does three things.

1. A file's identity from Sys.info (2644329). Its dev and ino, so the parser makes no system call of its own. A plain fix: merge it.

2. A main file at the root, and a directory ending in / (3eded0c). /Main.raz has / as its directory, not "", and a directory given as lib/ doesn't make lib//Sys.raz. A plain fix: merge it.

3. Host, a module of what the compiler asks of its host (bb03e48): argCount, arg, libraryDir, preferMusl, canRun, canLinkC, writeExecutable, prepareRun, execute. src/Host.raz is Linux's; Moss stages the compiler's sources with its own Host.raz (27 lines: the library at /lib, no run, no C, no mode bits) and its own Sys, Rt and Files.

Questions before the merge:

a. A smaller Host. Two of its nine procedures are there only because Raz reads the command line by built-ins:

b. How a host is chosen. The branch stages: copy src/, put the host's Host.raz in place of raz's, build. The main directory is searched first, so -I alone can't replace it, which is right: a module isn't silently replaced. The other way is a target name, as Sys.linux-x86_64.raz is chosen today from fixed suffixes: a -os moss that makes the suffixes .moss-x86_64, .moss, .x86_64, "", so that Host.moss.raz and Sys.moss.raz are found beside the generic files. That puts Moss's files in raz's tree, and raz would then know of Moss. The proposal is to keep staging, raz knowing nothing of any host but Linux, and to document it in doc/compiler.md as the one way to build for another host.

c. What the compiler asks of the library, written down. Moss's Sys has 23 exported procedures against Linux's 104, and is enough. doc/compiler.md should list what the compiler and the modules it imports (Rt, Mem, Heap, Lock, Arena, Out, Fmt, Buf, Str, Bytes, Files) use of Sys, Rt and Files, as Moss's docs/raz-port.md measured it, and a test should hold it: the compiler built against a Sys with only those exports. Then a change to the compiler that reaches for one more of Sys is seen in raz, not in Moss's next build. The test host on the branch (test/host/Host.raz) checks the Host side only.

d. The stack. A self-build passed in 64 KiB of stack on Linux, but 64 nested parentheses don't, and Moss gives a stored program 1 MiB. That is "Implementation limits, and a compiler for a small stack", above; the merge needn't wait for it.

e. The tests in Python. The branch adds test/compiler-host.py (177 lines) and grows test/library-path.py, which came with RAZ_PATH. raz's tests are otherwise sh, as a public project's should be, needing nothing but a shell to run. The proposal is to write both in sh before the merge.

f. Before the merge, in any case. The system call numbers in Host.raz named as constants, as Raz had them (MemfdCreate, MfdCloexec, Execve); a comment on every procedure; the new section of doc/compiler.md made as short and plain as the rest; a rebase on main (doc/compiler.md and src/Raz.raz conflict). Moss's RAZ_PORT.lock then pins a commit on main.

A freestanding program, stated #

Status. Proposed 2026-10-22, collated from RAZ-GAPS.md.

"For a kernel: three changes to the compiler" made a raz program run on the bare machine; Moss, a kernel in raz, now boots on it. What it found is less a missing feature than missing words: what a -bare program must give the compiler, and what it may count on, are known only by reading Gen.entryPoint and Raz. Five items, each standing alone. The sixth thing Moss met, jmp rax read as a jump to a label, was a bug, fixed in ac3c464.

1. The runtime ABI, written down. A section of doc/compiler.md, "A program with its own Rt", saying what the compiler asks of Rt and what a program's start may count on:

A test holds it: test/run/ builds a -bare program against a smallest Rt of exit and fail alone, run under Linux, whose exit and fail make the system call themselves.

Met in Moss (docs/raz-findings.md §2), which copied the stock signatures.

Recommendation: take; it is words and one test, and the contract already exists.

2. A recipe for an interrupt's entry. Before any attribute or generated stub, a tested recipe in doc/compiler.md, beside item 1, stating what the compiler's code may assume and so what a stub must restore:

It is testable on Linux: iretq from ring 3 to ring 3 is allowed, so test/run/Interrupt.raz builds a frame by hand, jumps to the stub, has the handler compute with reals, and checks on return that every register the stub promised to keep is kept. The stub needs items 3 and "The assembler's instructions", 1 (push of a constant, cld).

Met in Moss (docs/raz-findings.md §4): its handlers use only rax and make no call, which is safe but no recipe.

Recommendation: take; a kernel's first stub is where the calling convention is easiest to get wrong, and a test on Linux keeps it right.

3. A code procedure names a procedure or a global. In a code procedure, a name of the module's scope, or a qualified one, that is a procedure or a global variable stands for its address, as an operand of three forms only:

call fault;              (* a procedure, rip-relative *)
jmp fault;
lea rax, [ticks];        (* a procedure or a global *)

Each makes a reference to that chunk, so the linker keeps what is named, as any call does. No other operand takes a name, and no type is checked: a code procedure is the target's, and its author already answers for the convention. The assembler gets the names as it gets constants, by a function the parser hands in beside ConstFn.

Moss stores UINT(fault) in a slot at start and calls through a register (docs/raz-findings.md §5), so the slot must be filled before the first fault, which nothing checks.

Recommendation: take; three operand forms remove a hand-off that can be forgotten, and the recipe in item 2 needs call handle.

4. A program brings its own Rt. A src/Rt.raz beside the main module meets lib/Rt.raz, and "a program has one module of each name" refuses it, rightly. Moss copies the compiler beside an empty lib/. Two ways out:

The option is the smaller for its users and nearly as small in raz; staging stays the way for the compiler on another host, where the whole of src/ is replaced anyway.

Recommendation: take -lib; a few lines save every freestanding program a copy of the compiler.

5. Symbols without Rt's places. Without -s the compiler links places, calls, teller, place and placer and stops with "Rt has no places" where Rt lacks one, and -noprofile doesn't help, so Moss builds with -s and loses the symbol table a debugger reads. Two things are tied that needn't be: the ELF's symbols and lines, for a debugger, and the places, for Rt to say where a check failed. The change: each of the five is linked only when Rt declares it, calls with teller and place with placer, a pair or neither; -s still strips both. A kernel then keeps its symbols for GDB and gives fail the raw address, or declares places and decodes them itself.

A hosted program's Rt is raz's, which declares all five, so no program changes. One that writes its own Rt and misspells places loses its places silently; item 1 lists the names.

Met in Moss (docs/raz-findings.md §3).

Recommendation: take; it is a test on each name in Raz.raz and gives a kernel its symbols back.

The assembler's instructions #

Status. Proposed 2026-10-22, collated from RAZ-GAPS.md.

The report leaves which instructions the assembler knows to the implementation, and db gives any other. That stays. What is missing is a rule for when an instruction joins, and the few that programs have already written in db.

1. push of a constant, and cld and std. push imm8 and push imm32 (6A, 68, sign-extended to 64 bits), and cld and std in Plain. The encoder already writes cld and std for the compiler's copies; only the assembler's table lacks them. Moss's exception stubs write all three with db, and every stub of "A freestanding program, stated", 2, needs them.

Recommendation: take; three entries the encoder half has, and an interrupt stub can't be written without them.

2. When an instruction joins, and the SHA and shuffle ones now. The rule, in doc/compiler.md beside the assembler: an instruction joins when a program writes it in db, it is a family's member the tables already hold (a code in PackedOps, an entry in Plain), and its bytes are checked against GNU as in test/run/, as AsmKernel.raz does. Anything else stays db, which is the permanent answer for an instruction no program uses twice. By that rule, now:

Sauce's SHA-NI hash is 123 db lines assembled by GNU as, nothing checking a byte against its mnemonic; with these it is read as written. AES-NI, pclmulqdq, AVX and the rest wait for a program. (movd and movq, pxor, pshufd, movdqu, movdqa, pmovmskb are there already.)

Recommendation: take; a rule stops the list growing by wish, and eight instructions turn sauce's 123 unchecked lines into checked ones.

3. raz -S's listing, stated. raz(1) gives the listing's form, so a tool may read it:

Only the main module's live procedures, in the order they were made; nothing is disassembled. A change to the form is then a change to the manual, and rcrypto's constant-time guard (tools/branches.sh), which counts conditional jumps by reading these three kinds of line, breaks loudly instead of silently. A test in raz holds the form against a small program's listing.

Recommendation: take; it is a paragraph of raz(1) and one test, for a form that already doesn't change.

Implementation limits, and a compiler for a small stack #

Status. To investigate; nothing decided.

The report names no implementation limits: how deep expressions, statements, imports and generic instances may nest, how long a name or a string may be. A compiler for a small machine that rejects a deep nesting is then arguably not a raz compiler at all. C settles it with its translation limits (C99 §5.2.4.1: 63 levels of nested parentheses, 15 of nested includes, and so on): every compiler must take at least that much, and may take more. The proposal: a short section in the report giving the least each compiler must accept, and saying that a compiler that goes past its own limit stops with an error naming it, never a crash. It changes the report, not the language.

Behind it, three things in this compiler that need no change to the report at all, so that it runs in a small stack:

  1. Nesting. Each level of a nested expression costs about 1 KiB of stack. A constant expression with 64 nested parentheses fails a 64 KiB stack and passes 256 KiB; 256 of them fail 256 KiB and pass 1 MiB. A limit from the section above, checked in the parser, makes the stack a program needs bounded and known.
  2. Imports. importModule compiles an imported module in the middle of the one importing it, on the same stack, so the stack grows with the depth of the chain of imports. Ordering the modules first and compiling them from the leaves, in a loop, keeps whole program compilation and a stack that doesn't grow; symbol files, as Wirth's compilers have, would do it too, but must then carry a generic module's body.
  3. Instances. makeInstance keeps the declaration under way aside in arrays on the stack ([MaxFwd]PType, [MaxFwd]Diag.Pos, [MaxNames]INT, several KiB) for every instance it nests. A list of instances still to make, made between declarations, would keep none.

Not yet measured: which of these filled the stack when the stripped compiler, given one more -I directory, overflowed 64 KiB building itself, where the ordinary self-build fit.

Met in moss (docs/raz-port.md): its stored programs get a guarded 64 KiB stack, and a native compiler must fit, or the stack must grow (2026-10-22).

source
1# raz: the plan to 1.0
2
3What is left before raz is 1.0, in order, by the owner's word of
42026-10-23. raz takes no proposals; what is left is the Moss work below,
5its proposals kept in the appendix, and nothing else is planned.
6Each step is a release, started on the owner's go-ahead; within it, one
7commit per piece, the report first for any change to the language.
8
9## 1. Release what is done: v0.22.0
10
11**Done** 2026-10-23: tagged, its release and tarball made here by `make
12dist` (CI was refused by GitHub's billing), and `BOOT` moved to it.
13`make alpine` couldn't pull its image without a Docker Hub login.
14
15Report 2026-10.36, the twelfth thaw: `MIN`, `MAX`, `ABS`, `CLZ`, `CTZ`,
16`POPCOUNT`, `INT(b)`, `OFFSET`, `SIZE(T.f)`, `BYTES`, `FILL`, a qualified
17case in an arm, slice and `ERROR` constants, a record's procedure field
18that takes the record; the library's growth since v0.21.0 (`Fmt`, `Str`,
19`Files`, `Sys`, `Math`, `Opt`, `Heap.sure`, `Vec`, `Arena`); inlining a
20procedure that only returns, and `COPY`, `FILL` and array parameters made
21fast.
22
23- Check: `make check`, `make fixpoint`, `make bench`, `make prev-bench`,
24 `make kernels`, `make alpine`, the report's pages (35 at 10.36).
25- Tag `v0.22.0`; then, as a step of its own, move `BOOT` to it, so that
26 `src/` and the library it imports may use what 10.36 brought.
27
28## 2. The safety thaw: v0.23.0, then v0.24.0
29
30The scope, by the owner's word of 2026-10-26, after reviewing
31`MEM_PROPOSAL.md` (in git to 2026-10-26) whole with its appendices.
32raz doesn't promise memory safety: `free` stays, so a program can
33always keep a pointer to what it freed. The thaw shrinks what is
34undefined, and fences what can reach memory it shouldn't, so a reader
35can find it.
36
37What goes in:
38
39- **An array a call returns lives to the end of its procedure**
40 ("Less that is undefined", piece 1; the proposal's F.1). Its slot is
41 reserved as a deferred statement's is.
42- **A race tears no slice, said**: 7.6 says a slice or variant read and
43 written in a race is undefined (piece 3). Said, not prevented: no
44 16-byte moves.
45- **`[]const T`**, a slice whose elements can't be written; a `[]T`
46 goes where one is wanted, never back. String literals are `[]const
47 U8`, and a constant's slices `[]const T`, so writing them is an error
48 (piece 2 drops out). `Str.trim`, `cut` and `field` take and return
49 `[]const U8`. "Left out"'s exported array read as a slice comes with
50 it.
51- **The fence, Oberon's way**: the unsafe operations are reached
52 through a pseudo-module, `import SYSTEM`. `SYSTEM.ADR`, `SYSTEM.PTR`,
53 `SYSTEM.SYSCALL`, `SYSTEM.ARGV`; pointer indexing, slicing and
54 arithmetic, conversions to and from pointer and procedure types,
55 views whose type holds a pointer, procedure or slice, `extern`,
56 `link`, code procedures and `check off` are allowed only in a module
57 that imports it. A warning for one release, so that `src/` can come
58 to it once `BOOT` knows it, then an error.
59- **`CAS`, `XCHG` and `XADD` take a variable**, as `INC` does, not an
60 address (the proposal's E.4), so atomics need no `SYSTEM`.
61- **Library**: `Heap`'s debugging mode (G: freed blocks poisoned and
62 held back, guard bytes checked); `Task(T)`, a thread started with no
63 cast; `Lock.Guarded(T)`, a value with its lock.
64
65What is left out, and why: `ret` and `keep` (B) and owners that count
66what they lend (C), too large for what they close without the rest;
67the heap without `free` (D), since `free` stays; atomic slices and the
68rest of threads (E), for programs that race only. With them the
69guarantee of the proposal's section 3.
70
71The survey of 2026-10-26 (the compiler counting each use, across
72`~/r`): about 8,000 fenced uses, 451 of 960 modules. 77% of the `ADR`s
73go to a pointer parameter only dereferenced, mended by `var` or
74`const`, as `STANDARDS.md` asks; what is left for `SYSTEM` is about
753,000 uses, most in `lib/` (`Sys`, `Rt`, `Heap`, `Map`) and `src/`
76(`Scan`, `Link`, `Chunk`). All 31 atomics take `ADR`.
77
78Two releases, by the owner's word of 2026-10-26, since `src/` and the
79library it imports (`Buf`, `Files`, `Fmt`, `Heap`, `Mem`, `Out`, `Rt`,
80`Str`, `Sys`, and `Lock` and `Bytes` under them) must build with
81`BOOT`, which knows neither `[]const` nor `SYSTEM`:
82
831. The report's text, for the owner to review (drafted 2026-10-26).
842. **v0.23.0, which breaks nothing.** The compiler, a commit a piece,
85 each with its part of the report: an array a call returns kept to
86 the end of its procedure; atomics on a variable; `[]const T`;
87 `SYSTEM`. The old forms are still taken, silently: a string literal
88 into a `[]U8`, `ADR` and the rest without `SYSTEM`, an atomic given
89 a pointer. The library: `Task`, `Guarded`, `Heap`'s debugging mode.
90 Release, and the report's pages checked. **Done** 2026-10-26:
91 tagged, released here by `make dist` (CI refused by GitHub's billing,
92 as for v0.22.0), its SHA-256 `103eb421...`; the website has v0.22.0
93 and v0.23.0; 35 pages. No rewriting tool, by the owner's word:
94 v0.24.0's errors point at each place to mend.
953. `BOOT` moved to v0.23.0, a step of its own. **Done** 2026-10-26.
964. **v0.24.0, which enforces it.** Steps 1 to 3 done 2026-10-26: `raz -strict`
97 first, `lib/`, `src/`, the tools and tests mended against it by
98 agents, then the old forms made errors and the option gone.
99 Released 2026-10-26 as v0.24.0; the programs in `~/r` follow, the
100 owner's five first (dwa, concha, mosaico, rat, notis). `lib/`, `src/`, `tools/`,
101 `examples/` and the tests mended where the old forms, made errors,
102 are found (`ADR` at a parameter only dereferenced becomes `var` or
103 `const`; `SYSTEM.` where an address is kept); the programs in `~/r`
104 mended the same way, by agents, each its own commit.
105 Release.
106
107## 3. The Moss work: v0.25.0
108
109The scope, by the owner's word of 2026-10-26: what makes raz a better
110freestanding and portable compiler, nothing for Moss alone. `Host` is
111in. `-moss` (the branch `moss-startup-args-v1`) is not: Moss supplies
112its own start under item 4's contract, so raz knows no system's calls
113but Linux's. Of the implementation limits, the report's least and this
114compiler's errors past its own are in; compiling imports from the
115leaves and queuing instances, so the compiler fits a small stack, are
116dropped for good: Moss gives the compiler a larger stack instead.
117Report 2026-10.38 (993cd63) holds the language's part.
118
1191. Merge the branch `moss-platform-boundary`'s two plain fixes (a file's
120 identity from `Sys.info`; a main file at the root), rebased on main.
1212. `Host`, as "The compiler on another host" in the appendix asks:
122 five procedures, `Files.argCount`, a host chosen by staging, its tests
123 in `sh`, not Python; rebased and merged. Moss's `RAZ_PORT.lock` then
124 pins main.
1253. What the compiler asks of `Sys`, `Rt` and `Files`, written down in
126 `doc/compiler.md` and held by a test.
1274. "A freestanding program, stated", "The assembler's instructions" and
128 "Implementation limits, and a compiler for a small stack" (the
129 report's least and the errors only), in the appendix.
1305. Release. Done 2026-10-26: v0.25.0, report 2026-10.38.
131
132## 4. The hard freeze
133
134From v0.25.0 on: no more thaws. The language changes only to mend a
135defect; the library's core (appendix A) only to mend a defect or plug a
136very big gap; the rest of the library grows only conservatively, by
137what breaks no program, on the owner's word.
138
139v0.25.1, 2026-10-29, the report unchanged, on the owner's word:
140
141- `Sys.errReadOnly* = -30` (EROFS), beside `errNoSpace` in `lib/Sys.raz`
142 and `lib/Sys.linux-x86_64.raz`, and in `doc/raz-lib.md`'s list. It is
143 the standard library's part of `Sys`, not the core, and a new name
144 breaks no program. Done. arkusz's `Asheetio` names it for itself
145 (`ReadOnlyFs`) and may now take `Sys.errReadOnly`.
146- `raz -q check` and `raz -q words`, for an editor's language server
147 (raz-lsp, `~/r/raz-lsp`): the compiler, not the language. Done.
148
149v0.25.2, 2026-10-29, the report unchanged: `raz -q def`, where the name
150at the cursor is declared, for raz-lsp's hover and go to definition.
151v0.25.3, 2026-10-29: `raz -q def` on a module, used or imported, gives
152its `module` line.
153
154## 5. arm64 macOS: v0.26.0
155
156Started by the owner's word of 2026-11-15: raz on an Apple Silicon Mac,
157natively, as a second target, `darwin-arm64`. Report 2026-11.0 names
158it and changes no language (section 3, appendix A).
159
160**The shape.** `Gen` is the only unit that knows the machine, and
161`Exe` (`Exe.linux.raz`, once `Elf`) the only one that knows the executable, so the port is new
162units beside them, not a change to `Parse` or `Item`:
163
164- `A64.raz`, beside `X64.raz`: arm64's instructions encoded, branches
165 within a procedure, and the assembler for code procedures (Arm's
166 syntax, the instructions the library's code procedures use; `db` for
167 any other).
168- `Gen.arm64.raz`, beside `Gen.x86_64.raz`: the same
169 calls, the stack machine kept in arm64's registers; Apple's calling
170 convention (x18 never touched, a frame record in x29, the arguments
171 past a variadic C procedure's own on the stack); every address by
172 `adrp` and `add`, since macOS runs no executable at a fixed address;
173 the atomics by the LSE instructions every Apple processor has.
174 Two things x86 does for free and arm64 doesn't, which the report
175 binds: a division by zero, or the smallest value by -1, stops the
176 program (arm64's `sdiv` gives 0), so it is checked; a real out of an
177 `I64`'s range, or a NaN, gives the smallest `I64` (arm64's `fcvtzs`
178 saturates), so it is mended after.
179- `Exe.darwin.raz`, beside `Exe.linux.raz`: a Mach-O executable for dyld, linked
180 to libSystem, as every macOS program must be; C's symbols bound into
181 a table of quadwords, as GLOB_DAT does now; every address in data
182 rebased, since the program is position-independent; its symbol table
183 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; and line
185 numbers for lldb, as DWARF in `__DWARF` (below).
186- `Host.darwin.raz`: the library beside the compiler by
187 `_NSGetExecutablePath`, C always, a program run from a file written
188 and made executable (no `memfd_create`).
189- `Link`: the places in data that hold an address, listed for
190 `Exe.darwin.raz`'s rebasing.
191
192A compiler compiles for the system it runs on, as now: its target is
193the one it was built for, its back end and executable chosen at its
194build by the target's suffixes (section 3), `Gen.arm64.raz` and
195`Host.darwin.raz` as `Sys.linux-x86_64.raz` is today. No `-target`.
196A compiler for one system that runs on another is built by staging,
197as appendix (b) proposes for Moss: `src/cross.sh` copies `src/` with
198the other target's files in place. It is needed once, for the first
199Mac compiler, and wherever a release for one system is made on the
200other.
201
202**The library.** Over libSystem, through `lib/Sys.raz`, the C one,
203with `CAbi.darwin-arm64.raz` made by `tools/cabi.c` on the Mac, never
204by hand. `Rt.darwin-arm64.raz`: the signals and their own stack, the
205place a fault stopped at from the Mac's `ucontext`, and `framePtr`,
206`liveRegs`, `here` and `sigReturn` in arm64. `Thread.darwin.raz` over
207pthreads, its `Mutex` on `os_unfair_lock`. `Bytes.arm64.raz`. `Math`'s
208`sqrt`, `mul` and `div128` and `Str`'s code procedure move into
209`.x86_64` files with arm64 twins: no generic file keeps machine code.
210None of it breaks a program.
211
212**Steps**, one commit each, `make check` passing first (in a
213linux/amd64 container on the Mac until there is a Mac compiler):
214
2151. Report 2026-11.0, for the owner's review. (This commit.)
2162. Done. A container to build and check in on the Mac (`make docker-check`),
217 the budget raised to 18,000 in `CLAUDE.md` and `doc/compiler.md`,
218 and the Makefile and scripts made to run on BSD's tools as on GNU's
219 (`sed -i`, `stat`, `sha256sum`).
2203. Done. `Gen.raz` to `Gen.x86_64.raz`, `Elf.raz` to `Exe.linux.raz` (the
221 unit `Exe`), `Host.raz` to `Host.linux.raz`, `src/cross.sh`: what
222 Linux's compiler makes unchanged, byte for byte.
2234. Done. `A64.raz`: arm64's encoder, jumps within a procedure, and
224 the assembler in Arm's syntax (`bl p`, `b p`, `adr xN, v` for names),
225 checked against Apple's assembler (clang's, `llvm-mc`'s bytes) by
226 `test/a64`; Chunk's arm64 fixup kinds, `fxBranch26`, `fxPage21` and
227 `fxPageOff12`, and `Scan.setBang` for a pre-index's `!`. What it
228 left for later, `Link`'s patching of those kinds, `Gen.arm64.raz`
229 importing `A64`, and padding with `brk`, came with 5a.
2305. Done. `Gen.arm64.raz`, in pieces, each run on the Mac (owner, 2026-11-15):
231 first a bare `Exe.darwin.raz` (a signed Mach-O over libSystem, no line
232 numbers) and an `Rt` that only exits, built by the staged cross
233 compiler in the container; then values and operations; jumps and
234 checks; calls and frames; reals; atomics, deferred statements, the
235 entry point.
236
237 5a, done: programs made by the cross compiler (`src/cross.sh
238 darwin-arm64`) run on the Mac, `test/mac` by `make mac-check`. In
239 `Gen.arm64.raz`: frames, constants, variables, the integer
240 operations but division, comparisons and jumps, elements and slices
241 unchecked, calls with arguments in registers, C's calls, code
242 procedures and the entry point; every other routine notes "not yet
243 on arm64" on its procedure, an error if the program uses it.
244 `Exe.darwin.raz`: a signed Mach-O over libSystem, its rebases and
245 binds dyld's opcodes, no line numbers. `Link`: arm64's fixups, Mach-O's
246 paged layout, the rebases. `lib/Rt.darwin-arm64.raz`: exit through C's
247 exit, one procedure at exit, fail and stop by `write`. As the interface
248 check of `Rt` reads `Rt.raz`, and so compiles `Sys` over C, also
249 `lib/CAbi.darwin-arm64.raz`, from `tools/cabi.c` on the Mac, and a
250 code procedure skipped in a file read only for its interface.
251
252 5b, done: division and its checks (by zero, the smallest by -1, in
253 every width), the checks of indexes, slices, views and enumerations
254 with their stubs for `Rt.fail`, arguments past x7 on the stack,
255 results in memory through x8, Apple's variadic calls, `try`, deferred
256 statements, jump tables, `compareSeq`, copies past 256 bytes, `ABS`
257 of an integer; and, since `Out` needs them, the atomics and `COPY`.
258 `SYSTEM.SYSCALL` is an error on the Mac, Linux's only (report 6.8).
259 `lib/Rt.darwin-arm64.raz` says what failed with its values, by its
260 address, runs 32 procedures at exit, and tells a nil pointer or
261 procedure and a stack overflow by a handler of SIGSEGV and SIGBUS.
262 `make mac-check` runs conform/run too and counts it: 91 of 111 pass,
263 the others needing reals (13), `FILL` (4, `Heap`'s among them),
264 `CLZ`, `ROL`, or `SYSCALL` (`SystemImport`, Linux's only). Left of
265 step 5 (5c): the reals, `FILL`, `NEW`'s zeroing, the counts of bits
266 and the rotations.
267
268 5c, done: the reals, `F32` and `F64`, on the stack in v16 to v21 and
269 as variables in d8 to d15, which the prologue saves; their
270 operations, comparisons (a NaN equal to nothing), conversions both
271 ways and between widths, a real out of an `I64`'s range or a NaN
272 mended to the smallest `I64` after `fcvtzs`, `ABS` and `-`; real
273 arguments in v0 to v7 and on the stack, results in d0; a code
274 procedure that is `fsqrt` made in place of its call. `FILL`,
275 `NEW`'s zeroing, `CLZ`, `CTZ`, `POPCOUNT` (by `cnt` and `addv`),
276 `ROL` and `ROR` at every width. A C procedure's own arguments past
277 x7 packed by their size, as Apple's convention wants. Nothing of
278 `Gen.arm64.raz` is "not yet"; only `SYSCALL` is refused, so
279 `test/mac.sh` skips conform/run's `SystemImport`, with the reason.
280 conform/run passes on the Mac, 110 of 110; `test/mac` has the reals'
281 edges (`Reals`), rotations and counts of every width (`Rotate`) and
282 `fsqrt` in place (`Sqrt`). Left for later steps: `Math`'s arm64
283 twin, so that `Math.sqrt` is made in place (step 7). A rotation of a
284 negative `I8` or `I16` leaves the bits above its width zero, where
285 x86-64's `rol al, cl` leaves them as they were.
2866. Done. `Exe.darwin.raz`'s line numbers for lldb, in a `__DWARF`
287 segment (mapped, read only: dyld refuses a segment bigger in the file
288 than in memory), the compile unit and its abbreviation made by `Link`
289 for both formats, `make lldb`; other C libraries (`link "X11";` is
290 `@rpath/libX11.dylib`, four rpaths, binds by flat lookup);
291 `test/mac/NarrowArgs`, a C library `cc` builds, narrow arguments past
292 x7, a variadic call and a callback; `Host.darwin.raz`, and `HOST=darwin
293 src/cross.sh darwin-arm64`, which stages the first Mac compiler: it
294 runs on the Mac, compiles and runs programs, and builds `Procs`.
2957. Done. The library: `CAbi`, `Sys`, `Rt`, `Thread`, `Bytes`, `Math`, `Str`.
2968. `test/` and `conform/` passing on the Mac; what differs by target
297 (signals' words, errors' numbers) in files of the target's.
2989. The first Mac compiler, by the staged cross compiler; it builds
299 itself; `make fixpoint` on the Mac; `make bench` at 400,000 lines a
300 second there.
30110. The release: two tarballs, `linux-x86_64` and `darwin-arm64`;
302 `BOOT` names one for each host, with its sum.
303
304**The owner's answers**, 2026-11-15:
305
306a. The budget is 18,000 lines of code.
307b. The names are `darwin-arm64`.
308c. No CI for now: the Mac's tarball is made here by `make dist`.
309d. The port is v0.26.0; the clean-up and 1.0 move one on.
310e. Line numbers for lldb are in v0.26.0 (below).
311
312**Line numbers on the Mac.** `Exe.linux.raz` writes DWARF 4 already: the line
313table `makeLines` makes, target-blind, and the one compile unit
314`putDebug` writes. lldb reads DWARF from an executable's `__DWARF`
315segment, as it does Go's, so `Exe.darwin.raz` writes the same three sections,
316`__debug_line`, `__debug_info` and `__debug_abbrev`, there, unloaded,
317before `__LINKEDIT`; `make gdb`'s twin drives `lldb --batch`. About 50
318lines, `makeLines` and `putDebug` shared by the two writers.
319
320**Where it stands**, 2026-11-15, stopped by the owner's word:
321
322- Done and pushed: steps 1 to 7. A cross compiler, built in the
323 container by `src/cross.sh darwin-arm64`, makes Mach-O programs that
324 run on the Mac: `make mac-check` passes test/mac, all of conform/run
325 (SystemImport aside, SYSCALL being Linux's), the library's tests and
326 test/libc (ExecveC aside, /proc being Linux's); lldb stops at a line.
327 `HOST=darwin src/cross.sh darwin-arm64` stages a native compiler that
328 runs on the Mac. Linux is unchanged: `make docker-check`, the
329 fixpoint, and x86-64's output byte for byte.
330- Step 9, half done, unchecked, on the branch `wip-darwin-step9`
331 (f87c668, pushed): `make raz` on the Mac through
332 `src/bootstrap.sh`, `BOOT` naming a tarball per host, the fixpoint and
333 bench on the Mac, `raz run`'s temporary file, `make dist` for the Mac.
334 To resume: check it out, read `git diff main`, run `make docker-check`
335 and `make mac-check`, finish what's missing, merge.
336- Not started: step 8 (`make check` natively on the Mac, `test/`'s
337 expectations per target where the Mac differs) and step 10 (the
338 release).
339- Known limits on the Mac: a frame of at most 16 MB
340 (test/run/ThreadOverflowC doesn't compile); `Thread.Mutex` is
341 `os_unfair_lock`, unlocked by the thread that locked it; `Bytes` is
342 plain raz, no NEON; `raz run` leaves its file in `$TMPDIR` (fixed on
343 the branch). The compiler is about 16,700 lines of code of 18,000.
344
345## 6. Clean-up: v0.27.0, the last before 1.0
346
347The files that served the thaws are made a record, short and true:
348
349- `PROPOSALS.md` and `MEM_PROPOSAL.md`: gone, done early (2026-10-26);
350 what was built is in the report, `doc/report-history.md` and git.
351- `~/r/RAZ-GAPS.md` and each repository's `RAZ-NOTES.md` (or `RAZ.md`):
352 closed, each saying so at its top; a gap since mended is marked.
353- `CLAUDE.md` (raz's and `~/r`'s): "Where things stand" cut to the
354 present; the readings of the report checked one by one against the
355 compiler and the report, and folded into the report where they are
356 the language's, not this compiler's.
357- `doc/compiler.md`'s table and routine names, `README.md`,
358 `doc/raz-lib.md` and the man pages checked against the code;
359 `STANDARDS.md` against the library.
360- The programs in `~/r` that pin an older raz (rmacs, ravite, rnet, ...)
361 moved to the release.
362
363## 7. 1.0
364
365No date. raz is 1.0 when use shows it: programs written against v0.27.0
366for long enough that no defect is outstanding. Until then it is
3670.27.x, mending defects only.
368
369## Appendix: the Moss work, as proposed
370
371The four proposals 3 builds, kept from `PROPOSALS.md` (in git to
3722026-10-26) when it and `MEM_PROPOSAL.md` went: what the thaws built is
373in the report, `doc/report-history.md` and git.
374### The compiler on another host: `Host`, and what it asks of the library
375
376**Status.** Built on the branch `moss-platform-boundary` (3eded0c),
377which Moss pins: there raz compiles programs, rebuilds itself byte for
378byte, and builds again after a restart (moss c606069,
379`docs/native-raz.md`). Waiting for the owner's word on the questions
380below before it is rebased and merged.
381
382The host is the system the compiler runs on; the target, the system
383its program will run on. Until the branch they were one, Linux, and
384the compiler reached Linux outside `Sys`: `Parse.identity` read a
385`struct stat` by `SYSCALL(4)` into a guessed `[18]INT`; `Raz` read
386`ARGC()` and `ARGV()`, found the library through `/proc/self/exe`,
387probed two loader paths for musl, and ran a program by `memfd_create`
388and `execve`; `Elf` set mode 755. The branch does three things.
389
390**1. A file's identity from `Sys.info`** (2644329). Its `dev` and
391`ino`, so the parser makes no system call of its own. A plain fix:
392merge it.
393
394**2. A main file at the root, and a directory ending in `/`**
395(3eded0c). `/Main.raz` has `/` as its directory, not `""`, and a
396directory given as `lib/` doesn't make `lib//Sys.raz`. A plain fix:
397merge it.
398
399**3. `Host`, a module of what the compiler asks of its host**
400(bb03e48): `argCount`, `arg`, `libraryDir`, `preferMusl`, `canRun`,
401`canLinkC`, `writeExecutable`, `prepareRun`, `execute`. `src/Host.raz`
402is Linux's; Moss stages the compiler's sources with its own
403`Host.raz` (27 lines: the library at `/lib`, no run, no C, no mode
404bits) and its own `Sys`, `Rt` and `Files`.
405
406Questions before the merge:
407
408**a. A smaller `Host`.** Two of its nine procedures are there only
409because `Raz` reads the command line by built-ins:
410- `argCount` and `arg` go if the library has the count beside
411 `Files.arg`: a `Files.argCount()`, which Moss's `Files` gives from
412 `Sys.argc`. `Files.arg` is already the library's, and Moss already
413 replaces it.
414- `preferMusl` and `canLinkC` are one question, which C library to
415 link against: `Host.cLibrary(): CLib` with `CLib = (none, glibc,
416 musl)`, or keep the two booleans.
417- `canRun` goes if `prepareRun` is called while the command line is
418 read, before any source, so that its error is the refusal.
419That leaves `libraryDir`, `cLibrary`, `writeExecutable`, `prepareRun`
420and `execute`: five procedures, each a real difference between hosts.
421
422**b. How a host is chosen.** The branch stages: copy `src/`, put the
423host's `Host.raz` in place of raz's, build. The main directory is
424searched first, so `-I` alone can't replace it, which is right: a
425module isn't silently replaced. The other way is a target name, as
426`Sys.linux-x86_64.raz` is chosen today from fixed suffixes: a
427`-os moss` that makes the suffixes `.moss-x86_64`, `.moss`, `.x86_64`,
428`""`, so that `Host.moss.raz` and `Sys.moss.raz` are found beside the
429generic files. That puts Moss's files in raz's tree, and raz would
430then know of Moss. The proposal is to keep staging, raz knowing
431nothing of any host but Linux, and to document it in
432`doc/compiler.md` as the one way to build for another host.
433
434**c. What the compiler asks of the library, written down.** Moss's
435`Sys` has 23 exported procedures against Linux's 104, and is enough.
436`doc/compiler.md` should list what the compiler and the modules it
437imports (`Rt`, `Mem`, `Heap`, `Lock`, `Arena`, `Out`, `Fmt`, `Buf`,
438`Str`, `Bytes`, `Files`) use of `Sys`, `Rt` and `Files`, as Moss's
439`docs/raz-port.md` measured it, and a test should hold it: the
440compiler built against a `Sys` with only those exports. Then a change
441to the compiler that reaches for one more of `Sys` is seen in raz,
442not in Moss's next build. The test host on the branch
443(`test/host/Host.raz`) checks the `Host` side only.
444
445**d. The stack.** A self-build passed in 64 KiB of stack on Linux,
446but 64 nested parentheses don't, and Moss gives a stored program 1
447MiB. That is "Implementation limits, and a compiler for a small
448stack", above; the merge needn't wait for it.
449
450**e. The tests in Python.** The branch adds `test/compiler-host.py`
451(177 lines) and grows `test/library-path.py`, which came with
452RAZ_PATH. raz's tests are otherwise `sh`, as a public project's
453should be, needing nothing but a shell to run. The proposal is to
454write both in `sh` before the merge.
455
456**f. Before the merge, in any case.** The system call numbers in
457`Host.raz` named as constants, as `Raz` had them (`MemfdCreate`,
458`MfdCloexec`, `Execve`); a comment on every procedure; the new section
459of `doc/compiler.md` made as short and plain as the rest; a rebase on
460main (`doc/compiler.md` and `src/Raz.raz` conflict). Moss's
461`RAZ_PORT.lock` then pins a commit on main.
462### A freestanding program, stated
463
464**Status.** Proposed 2026-10-22, collated from RAZ-GAPS.md.
465
466"For a kernel: three changes to the compiler" made a raz program run on
467the bare machine; Moss, a kernel in raz, now boots on it. What it found
468is less a missing feature than missing words: what a `-bare` program
469must give the compiler, and what it may count on, are known only by
470reading `Gen.entryPoint` and `Raz`. Five items, each standing alone.
471The sixth thing Moss met, `jmp rax` read as a jump to a label, was a
472bug, fixed in ac3c464.
473
474**1. The runtime ABI, written down.** A section of `doc/compiler.md`,
475"A program with its own `Rt`", saying what the compiler asks of `Rt`
476and what a program's start may count on:
477- **Required:** `proc exit*(status: INT);`, which never returns (the
478 compiler puts `ud2` after its call), and
479 `proc fail*(what, a, b, len: INT; at: UINT; name: ^U8; rdi, rsi: UINT);`,
480 with the kinds of `what` as `lib/Rt.raz` gives them (0 an index, 1 a
481 slice, 2 an enumeration, 3 a backward slice of a pointer, 4 a nil
482 pointer, 5 a division by zero, 6 a stack overflow, 7 a view), named
483 constants in the text, not bare numbers.
484- **Optional, found by name when declared:** `places`, `calls`,
485 `teller`, `place`, `placer` (item 5), `startProfile` and `profiler`
486 (never under `-bare`), `cExit` (only with C, which `-bare` refuses).
487- **The entry:** `_start` runs every used module's body but `Rt`'s,
488 then `main`. Under `-bare` it reads nothing from the stack and aligns
489 nothing: the loader or boot stub enters it with the bss zeroed and
490 `rsp` a multiple of 16, as Linux does.
491- **`main` returning:** allowed. `Rt.exit` is then called with `main`'s
492 result, or 0 for `proc main*`.
493- **The panic hook:** `Rt.fail` is it. A kernel's `fail` prints and
494 halts; nothing else is needed, and no second hook is proposed.
495
496A test holds it: `test/run/` builds a `-bare` program against a
497smallest `Rt` of `exit` and `fail` alone, run under Linux, whose
498`exit` and `fail` make the system call themselves.
499
500Met in Moss (`docs/raz-findings.md` §2), which copied the stock
501signatures.
502
503**Recommendation:** take; it is words and one test, and the contract
504already exists.
505
506**2. A recipe for an interrupt's entry.** Before any attribute or
507generated stub, a tested recipe in `doc/compiler.md`, beside item 1,
508stating what the compiler's code may assume and so what a stub must
509restore:
510- **What the compiler's code uses:** System V's caller-saved
511 registers, `rax`, `rcx`, `rdx`, `rsi`, `rdi`, `r8` to `r11`, all of
512 `xmm0` to `xmm15`, and the flags; the direction flag is clear at
513 every call (the compiler's copies use `std` and `cld` and leave it
514 clear).
515- **The red zone:** whether the compiler ever writes below `rsp`. Not
516 checked today ("For a kernel" leaves it open); it is to be checked
517 and the answer written down. If it never does, an interrupt needs no
518 IST stack for that reason.
519- **The stub:** a `code` procedure per vector that pushes 0 where the
520 CPU pushes no error code, pushes the vector, saves the caller-saved
521 registers, aligns `rsp` to 16, saves the SSE state (`fxsave` or
522 `xsave` to an aligned area), `cld`, calls an ordinary procedure
523 `proc handle(vector, code: INT; frame: ^Frame)`, restores, drops the
524 two words and `iretq`.
525
526It is testable on Linux: `iretq` from ring 3 to ring 3 is allowed, so
527`test/run/Interrupt.raz` builds a frame by hand, jumps to the stub, has
528the handler compute with reals, and checks on return that every
529register the stub promised to keep is kept. The stub needs items 3 and
530"The assembler's instructions", 1 (`push` of a constant, `cld`).
531
532Met in Moss (`docs/raz-findings.md` §4): its handlers use only `rax`
533and make no call, which is safe but no recipe.
534
535**Recommendation:** take; a kernel's first stub is where the calling
536convention is easiest to get wrong, and a test on Linux keeps it right.
537
538**3. A code procedure names a procedure or a global.** In a code
539procedure, a name of the module's scope, or a qualified one, that is a
540procedure or a global variable stands for its address, as an operand
541of three forms only:
542
543 call fault; (* a procedure, rip-relative *)
544 jmp fault;
545 lea rax, [ticks]; (* a procedure or a global *)
546
547Each makes a reference to that chunk, so the linker keeps what is
548named, as any call does. No other operand takes a name, and no type is
549checked: a code procedure is the target's, and its author already
550answers for the convention. The assembler gets the names as it gets
551constants, by a function the parser hands in beside `ConstFn`.
552
553Moss stores `UINT(fault)` in a slot at start and calls through a
554register (`docs/raz-findings.md` §5), so the slot must be filled
555before the first fault, which nothing checks.
556
557**Recommendation:** take; three operand forms remove a hand-off that
558can be forgotten, and the recipe in item 2 needs `call handle`.
559
560**4. A program brings its own `Rt`.** A `src/Rt.raz` beside the main
561module meets `lib/Rt.raz`, and "a program has one module of each name"
562refuses it, rightly. Moss copies the compiler beside an empty `lib/`.
563Two ways out:
564- **Staging,** as "The compiler on another host" proposes for the
565 compiler's own sources: copy `raz` beside a library of the program's
566 own. Nothing in raz changes; only words in `doc/compiler.md`. Every
567 freestanding project then carries a copied compiler, and its library
568 is all or nothing.
569- **`raz -lib DIR`:** the library is `DIR`, not the one beside the
570 compiler. A kernel's `-lib` is a directory holding its own `Rt` and
571 `Sys` and, by symbolic links, whichever of raz's modules it takes
572 (`Str`, `Fmt`, `Buf`). The duplicate check stays as it is. On the
573 `Host` branch it is one line over `Host.libraryDir`; today a few
574 lines in `Raz.raz` and raz(1).
575
576The option is the smaller for its users and nearly as small in raz;
577staging stays the way for the compiler on another host, where the
578whole of `src/` is replaced anyway.
579
580**Recommendation:** take `-lib`; a few lines save every freestanding
581program a copy of the compiler.
582
583**5. Symbols without `Rt`'s places.** Without `-s` the compiler links
584`places`, `calls`, `teller`, `place` and `placer` and stops with "Rt
585has no places" where `Rt` lacks one, and `-noprofile` doesn't help, so
586Moss builds with `-s` and loses the symbol table a debugger reads.
587Two things are tied that needn't be: the ELF's symbols and lines, for
588a debugger, and the places, for `Rt` to say where a check failed.
589The change: each of the five is linked only when `Rt` declares it,
590`calls` with `teller` and `place` with `placer`, a pair or neither; `-s`
591still strips both. A kernel then keeps its symbols for GDB and gives
592`fail` the raw address, or declares `places` and decodes them itself.
593
594A hosted program's `Rt` is raz's, which declares all five, so no
595program changes. One that writes its own `Rt` and misspells `places`
596loses its places silently; item 1 lists the names.
597
598Met in Moss (`docs/raz-findings.md` §3).
599
600**Recommendation:** take; it is a test on each name in `Raz.raz` and
601gives a kernel its symbols back.
602
603### The assembler's instructions
604
605**Status.** Proposed 2026-10-22, collated from RAZ-GAPS.md.
606
607The report leaves which instructions the assembler knows to the
608implementation, and `db` gives any other. That stays. What is missing
609is a rule for when an instruction joins, and the few that programs
610have already written in `db`.
611
612**1. `push` of a constant, and `cld` and `std`.** `push imm8` and
613`push imm32` (6A, 68, sign-extended to 64 bits), and `cld` and `std`
614in `Plain`. The encoder already writes `cld` and `std` for the
615compiler's copies; only the assembler's table lacks them. Moss's
616exception stubs write all three with `db`, and every stub of
617"A freestanding program, stated", 2, needs them.
618
619**Recommendation:** take; three entries the encoder half has, and an
620interrupt stub can't be written without them.
621
622**2. When an instruction joins, and the SHA and shuffle ones now.**
623The rule, in `doc/compiler.md` beside the assembler: an instruction
624joins when a program writes it in `db`, it is a family's member the
625tables already hold (a code in `PackedOps`, an entry in `Plain`), and
626its bytes are checked against GNU `as` in `test/run/`, as
627`AsmKernel.raz` does. Anything else stays `db`, which is the permanent
628answer for an instruction no program uses twice. By that rule, now:
629- `paddd`, `punpcklqdq`, `punpckhqdq` into `PackedOps` (66 0F FE, 6C,
630 6D);
631- `pshufb` (66 0F 38 00) and `palignr` (66 0F 3A 0F, with a byte),
632 two more forms, three-byte opcodes;
633- `sha256rnds2` (0F 38 CB, `xmm0` implied), `sha256msg1` (0F 38 CC),
634 `sha256msg2` (0F 38 CD).
635
636Sauce's SHA-NI hash is 123 `db` lines assembled by GNU `as`, nothing
637checking a byte against its mnemonic; with these it is read as written.
638AES-NI, `pclmulqdq`, AVX and the rest wait for a program. (`movd` and
639`movq`, `pxor`, `pshufd`, `movdqu`, `movdqa`, `pmovmskb` are there
640already.)
641
642**Recommendation:** take; a rule stops the list growing by wish, and
643eight instructions turn sauce's 123 unchecked lines into checked ones.
644
645**3. `raz -S`'s listing, stated.** raz(1) gives the listing's form, so
646a tool may read it:
647- a blank line, then a procedure's name as `Module.name:`;
648- a source line: its number right-aligned in 6 columns, two spaces,
649 the line's text;
650- an instruction: its offset in the procedure right-aligned in 14
651 columns, two spaces, the instruction as the assembler would read it,
652 a jump within the procedure giving its target as an offset.
653
654Only the main module's live procedures, in the order they were made;
655nothing is disassembled. A change to the form is then a change to the
656manual, and rcrypto's constant-time guard (`tools/branches.sh`), which
657counts conditional jumps by reading these three kinds of line, breaks
658loudly instead of silently. A test in raz holds the form against a
659small program's listing.
660
661**Recommendation:** take; it is a paragraph of raz(1) and one test,
662for a form that already doesn't change.
663### Implementation limits, and a compiler for a small stack
664
665**Status.** To investigate; nothing decided.
666
667The report names no implementation limits: how deep expressions,
668statements, imports and generic instances may nest, how long a name or
669a string may be. A compiler for a small machine that rejects a deep
670nesting is then arguably not a raz compiler at all. C settles it with
671its translation limits (C99 §5.2.4.1: 63 levels of nested parentheses,
67215 of nested includes, and so on): every compiler must take at least
673that much, and may take more. The proposal: a short section in the
674report giving the least each compiler must accept, and saying that a
675compiler that goes past its own limit stops with an error naming it,
676never a crash. It changes the report, not the language.
677
678Behind it, three things in this compiler that need no change to the
679report at all, so that it runs in a small stack:
680
6811. **Nesting.** Each level of a nested expression costs about 1 KiB
682 of stack. A constant expression with 64 nested parentheses fails a
683 64 KiB stack and passes 256 KiB; 256 of them fail 256 KiB and pass
684 1 MiB. A limit from the section above, checked in the parser, makes
685 the stack a program needs bounded and known.
6862. **Imports.** `importModule` compiles an imported module in the
687 middle of the one importing it, on the same stack, so the stack
688 grows with the depth of the chain of imports. Ordering the modules
689 first and compiling them from the leaves, in a loop, keeps whole
690 program compilation and a stack that doesn't grow; symbol files, as
691 Wirth's compilers have, would do it too, but must then carry a
692 generic module's body.
6933. **Instances.** `makeInstance` keeps the declaration under way aside
694 in arrays on the stack (`[MaxFwd]PType`, `[MaxFwd]Diag.Pos`,
695 `[MaxNames]INT`, several KiB) for every instance it nests. A list
696 of instances still to make, made between declarations, would keep
697 none.
698
699Not yet measured: which of these filled the stack when the stripped
700compiler, given one more `-I` directory, overflowed 64 KiB building
701itself, where the ordinary self-build fit.
702
703Met in moss (`docs/raz-port.md`): its stored programs get a guarded
70464 KiB stack, and a native compiler must fit, or the stack must grow
705(2026-10-22).