From 4efc5101b539a5e8935ce12e366e034be479cd8b Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:43:50 +0100 Subject: [PATCH] Docs: tidy CLAUDE.md, PLAN.md and README CLAUDE.md says where things stand in a paragraph, leaving the history to git and doc/report-history.md, and names sbcl/. PLAN.md cuts Self, which is done, and shortens the dropped inline wish. The finished audit, doc/proposal-10.22.md, goes; gen.pas is Gen.raz; the library is volume 2, not section 11; X64.raz is 1,237 lines. --- diff --git a/CLAUDE.md b/CLAUDE.md index 5b3a6ab..bb30bfe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,50 +78,26 @@ ## Where things stand -Steps 1-18 are done: the language, the tools (`tools/Doc.raz`, and -the formatter, `tools/Pretty.raz`, over the shared `tools/Scan.raz`), -`README.md` and the guide to the compiler, `doc/compiler.md`. Stage 5 -made two editors, which now live in repositories of their own, each -pinning the raz commit it builds with: rmacs (emacs's keys) and -ravite (vim's). What they needed of the system went into `Sys` (report -2026-10.2, approved): the terminal, files, directories and the -environment. `tools/Scan.raz` is theirs to use, as a tool, not part of -the library. Stage 4, diagnostics (steps 19-27), is done; so are -stage 6, the language of report 2026-10.3 (steps 42-47), and stage 8, -one module to a name (report 2026-10.5, step 51), and stage 7, `Sys` -for rlX11 and rat (reports 2026-10.4 and 10.7, steps 49a-c), with -`Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d), and -stage 9, several results in place of var parameters (2026-10.8, -steps 52-53), and v0.5.0, the library of report 2026-10.9, which the -compiler says it follows, and v0.7.0, better code, and v0.7.1, the manual: `raz(1)`, -`raz-tutorial(7)`, `raz(7)` and `raz-lib(3)`, made by `tools/Doc.raz` -from `lib/`, and v0.8.0, better code again: slices in registers, -parameters left in rdi and rsi, operands as the machine has them, -`while` tested at the bottom, and one line table, DWARF's, and -v0.9.0, better code for reals: reals on the stack and the -busiest real variables in xmm registers, and an array's element and a -constant offset as operands, measured on two kernels of reals, -`Jacobi` and `NBody`. `make kernels` measures `test/bench` against -FPC `-O2`. Self (`PLAN.md`) is done: `src/` is the compiler in raz, and -the seed in `seed/` is frozen. Next, by `PLAN.md`: what the owner chooses. +v0.11.1, report 2026-10.23, is the latest release. `src/` is the +compiler in raz, built by itself (Self, done); the seed in `seed/` is +frozen, and v0.9.1 was the last release it built. The compiler takes +1.4 times the Pascal one's time; `make kernels` measures `test/bench` +against FPC `-O2`. Next, by `PLAN.md`: what the owner chooses. What +each version of the report changed is in `doc/report-history.md`, and +what each step did is in git; don't repeat it here. +rmacs (emacs's keys) and ravite (vim's), the two editors written in +raz, live in repositories of their own, each pinning the raz commit it +builds with; they use `tools/Scan.raz` as a tool, not part of the +library. rat, rlX11 and rloc are other users of `Sys`. + **The freeze.** Since v0.5.0 the language changes only to mend a defect, and the library grows only by what breaks no program written for it. A wish for more, the owner's or yours, goes on the list in -`PLAN.md`, for a later thaw; it isn't built. v0.6.0 was such a thaw, -by the owner's word: report 2026-10.12; the compiler follows 2026-10.23, whose `Math` exports `bits`, `fromBits` and `mul` for reading reals exactly, and 2026-10.22, an audit of the report (mends, trims, -two volumes, status 2 for every stop), and 2026-10.21, whose `match` on an enumeration takes -several names to an arm (10.21), and 2026-10.20, whose `try` returns an error that isn't -nil from the procedure it stands in (10.20, the owner's word), and 2026-10.19, -whose `Sys` writes without waiting, for rat's pastes (10.13), and -whose blank, `_ := f(x)`, drops a result that is otherwise warned of -(10.14), and whose `Math` has `pow`, the logarithms to 2 and 10, -rounding and the inverse functions, and `Sys` `space` (10.15), and -whose constants may be records and tables of them, with `Str.copy` -(10.16), and `COPY` (10.17), also by the owner's word, and whose code -procedures take and return slices (10.18), and whose library has -`Bytes` (10.19). Its parser -reaches the machine only through `gen.pas`. Keep +`PLAN.md`, for a later thaw; it isn't built. Thaws happen only by the +owner's word (v0.6.0, and reports 2026-10.13 to 10.23). + +The parser reaches the machine only through `Gen.raz`. Keep `doc/compiler.md`'s table of lines and its routine names true when the compiler changes. @@ -132,10 +108,8 @@ `.github/workflows/ci.yml`, which checks it and makes the GitHub release with a tarball of `raz` and `lib/`; it also checks every push to `main`. `README.md`'s "Versions" gives the commands. v0.3.0 is -the first; v0.11.1, report 2026-10.23, the latest: the compiler in raz, -built by itself, and 1.4 times the Pascal one's time (v0.9.1 was the last -built by the Pascal seed). The tarball has `tools/`, which the website -offers from 0.7.1 on. +the first. The tarball has `tools/`, which the website offers from +0.7.1 on. `test/libc` runs its programs over `lib/Sys.raz`, the C one, through a link in its `mods`. A test or example without `.expect` is only @@ -149,6 +123,10 @@ `src/` the first time and as the reference its units are tested against, and to be dropped in time. Never edit the seed; a difference found goes on the plan, for the owner. + +`sbcl/` is an example, not part of the build: a second compiler, in +Common Lisp, written from the report alone and kept as a reference +(`sbcl/README.md`). ## Readings of the report already taken diff --git a/PLAN.md b/PLAN.md index 65692ab..dad5144 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,66 +5,11 @@ stopping for the owner's review. A finished milestone is cut from this file: git keeps the history, and the report's history, `doc/report-history.md`, the language's. -v0.11.1, report 2026-10.23 (`Math` exports `bits`, `fromBits` and `mul`), is the latest release; v0.11.0, report 2026-10.22, was the audit of `doc/proposal-10.22.md`; v0.9.1 was the last built by the seed. All before -v0.7.1 is approved by the owner; v0.7.1, v0.8.0, v0.9.0 and v0.9.1 wait -for the owner's review. One milestone is under way: Self. - -## Self: the compiler in raz (under way) - -For: a compiler written in raz that compiles itself, so that raz needs -no Free Pascal. The Pascal compiler in `seed/` is the **seed**: it is -never edited for this, and stays the one `make check` builds. The new -compiler lives in `src/`, one raz module to a seed unit, the same -names, and has its own targets; nothing in `seed/` or `lib/` changes. - -The language gained `try` (report 2026-10.20) for this: the parser's -errors return an `ERROR` (`Scan.Failed`) that `try` passes up to where -it reads on, in place of the seed's `longjmp`. - -Each unit is ported in the seed's order (leaves first) and tested on -its own against the seed's, on the same inputs, since no program can -link both. The language and the library are frozen: a gap found goes -on the wish list, a defect is mended. - -Steps: - -1. `diag` and `scan` (done): the trial. Measure `scan`'s speed against the - seed's and list what `Sys` and the library lacked. Stop for review: - if the cost is too high, mend the code generator first. -2. `chunk`, `sym` (2a, done); `link`, `elf`, `x64` (2b, done). -3. `gen` (3a, done: `Gen.raz`, tested by `test/GenDump`, a script of - calls whose bytes and listing are the same), `item` (3b, done: `Item.raz`, tested by - `test/ItemDump`, 60 scripts of operations with mistakes in them). -4. `parse`, `raz` (done: `Parse.raz`, `Raz.raz`): the first compiler that - builds, tested by compiling 409 programs, the library and the compiler - itself with both and comparing the executables, messages and status; - 452,000 lines a second, the seed's 815,000. -5. Fixpoint (done: `src/fixpoint.sh`, `make fixpoint`): the seed builds `src`, that builds `src`, that builds - `src` again, and the last two are byte for byte the same (all - three are, 547,000 bytes: the seed and this compiler make the same - code from `src/`). `make check` passes on the compiler it made, - 661 tests, and `make bench` gives 493,000 to 870,000 lines a second. - Then `seed/` is frozen and `self/` is `src/` (the owner's word, - 2026-10-13); the seed is dropped in time, its last tag the bootstrap. +v0.11.1, report 2026-10.23, is the latest release. All before v0.7.1 +is approved by the owner; v0.7.1, v0.8.0, v0.9.0 and v0.9.1 wait for +the owner's review. No milestone is under way: the last, Self (the +compiler in raz, built by itself), is done, and `seed/` is frozen. -6. Faster (done, the owner's word, 2026-10-13: the compiler built by - itself took 1.8 times as long as the Pascal one, and 1.3 was the aim). - `perf` found no hot spot but habits of the code: small blocks cleared - and copied by `rep`, a record literal made in a temporary and copied, - an element through a pointer worked out, `try` through a slot of the - frame, a `var` parameter's address loaded at each use, and a few - routines of the scanner. `doc/compiler.md`, "Better code, for the - compiler itself", has each, with what it measured and what did not - help. The compiler takes 506 ms of 359 for the 348,025-line program, - 1.4 times (1.36 by cycles; before 657 of 359, 1.8 times); `make - bench`, 678,000 lines a second. The seed's code is no longer what - `src/` makes, so `seed-check` no longer compares `Gen`, `Item` or - the executables, only messages and statuses, and the fixpoint is of - stage 2 and 3. - -Done when step 5 passes with `make check` and `make bench` on the -compiler it made, and the budget of lines kept. - ## Next, when the owner says - The book, "Compiling Raz": its brief is `doc/book/PLAN.md`. @@ -73,7 +18,7 @@ would take call overhead off some 15% of the instructions; `chooseRegs` reads each procedure twice, which is 13% of the time; and `Mem`, `Item` and `Adr` are records copied at each call that passes them on. -- A port to aarch64, to measure one: a new `gen.pas`, an encoder and +- A port to aarch64, to measure one: a new `Gen.raz`, an encoder and assembler for it, and its ELF. ## Wishes, for a later thaw @@ -81,35 +26,13 @@ What the language or the library might have, met while writing raz; none is built while the freeze holds. -- **`inline`, a hint.** `proc zeros(v: U64): U64; inline;`, placed as - `forward` is: the compiler copies the procedure into each call - instead of calling it. A hint an implementation may ignore, so a - program means the same everywhere and `conform/` is untouched. This - compiler would take it for a procedure whose body is a single - `return e`, with value parameters, in the same module, and refuse - the mark on any other: the call site's arguments go to temporaries - and `e` is read again there (`SaveScan`/`RestoreScan`, as for - generic instances), its parameters bound to them. About 100 lines. - Measured (2026-10-13): `test/bench/Grep` with its two helpers - inlined by hand ran 188 ms against 250, 30% off the kernel's own - time, since the loop's values then stay in registers, not the - frame; FPC `-O2` with `inline` gains as much. `tools/Pretty` gained - nothing: its small procedures cost their work, not their calls. - Dropped as a language change (2026-10-13): a hint means nothing a +- **`inline`, a hint** (dropped, 2026-10.13): a hint means nothing a program can see, and this compiler can inline by itself, with no - keyword. Debugging would be settled by keeping the callee's lines - in the line table as rows that aren't statements (DWARF's - `is_stmt`): gdb steps over them, `Rt` still tells a failure at its - expression; only `Rt.trace` loses the callee's frame. - Measured on rat's 26 MB workload (477 ms): its hot procedures are - almost never a single `return e`, and inlining those by hand gained - nothing. What did gain, 12%, was hoisting the fast path of two small - procedures into their callers by hand: `Width.cells` (`if c < 300H - then return 1`) and `Screen.unsplit` (a guard, then rare work), - called for every character. An inliner for that, statements and - early returns and procedures without results, is several times the - size; the same 12% is a few lines in rat. Revisit only if more - programs show it. + keyword. Measured: `test/bench/Grep` with its helpers inlined by hand + ran 30% faster; rat's hot procedures gained nothing from it, but 12% + from hoisting two fast paths by hand (`Width.cells`, + `Screen.unsplit`), which is an inliner several times the size. Revisit + only if more programs show it. - **A `const` parameter.** `proc what(const x: Item): []U8;`: the callee may not change `x` (nor take its address), so the caller may pass the address of a record or array without a copy, and the program means the diff --git a/README.md b/README.md index 8442efc..0a3e978 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ (buffered output), `C`, `Lock`, `Thread` (threads without C), `Mem`, `Heap`, `Arena`, `Str`, `Bytes`, `Buf`, `Fmt`, `Math`, `Files`, `Opt` (a command line read through one table), `List(T)`, `Map(K, V; hash, eq)` and -`Sort(T; less)`. Section 11 of the report gives each one's interface, +`Sort(T; less)`. Volume 2 of the report, `doc/raz-lib.md`, gives each one's interface, and `tools/Doc.raz` prints it from the module's file: $ ./raz -o Doc tools/Doc.raz && ./Doc lib/Str.raz diff --git a/doc/compiler.md b/doc/compiler.md index 1b981b7..11d39d2 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -17,7 +17,7 @@ | `src/Scan.raz` | 1,062 | 886 | Symbols, literals, comments, positions | | `src/Sym.raz` | 684 | 555 | Types, objects, scopes, layout | | `src/Chunk.raz` | 354 | 272 | The compiled program: chunks, fixups, line notes | -| `src/X64.raz` | 1,493 | 1,238 | The instruction encoder, jumps within a procedure, the assembler | +| `src/X64.raz` | 1,493 | 1,237 | The instruction encoder, jumps within a procedure, the assembler | | `src/Gen.raz` | 2,471 | 1,778 | The stack machine, for x86-64: values, operations, checks, calls, frames | | `src/Item.raz` | 1,763 | 1,458 | Items: types, constants, variables, operators, conversions, calls | | `src/Parse.raz` | 3,846 | 3,355 | Declarations, statements, expressions, built-ins, recovery, warnings | diff --git a/doc/proposal-10.22.md b/doc/proposal-10.22.md deleted file mode 100644 index 6beeaae..0000000 --- a/doc/proposal-10.22.md +++ /dev/null @@ -1,119 +0,0 @@ -# Proposal: report 2026-10.22 - -Made from an audit of `doc/raz.md` against `conform/` and `test/` -(about 500 rules: ~260 pinned by `conform/`, ~130 only by `test/`, ~60 -by no test, ~25 unsettled or in conflict). It mends defects in the -report and trims it; it adds no feature. Nothing in `doc/raz.md` or the -code changes until the owner approves each part (CLAUDE.md: a thaw). - -Decided by the owner (2026-10-14): - -- `INT` and `UINT` stay distinct from `I64` and `U64`. (The first - version of this proposal made them aliases; dropped.) -- Exported variables stay as they are. (The first version banned them; - dropped. Exported constants stay on `PLAN.md`'s wishes list.) -- Conformance keeps the error programs, but only for errors that - change a program's meaning; warnings and the form of messages leave - the report. -- Every run-time stop exits with status 2. -- The library past the core leaves `conform/`. -- The report is split in two volumes, after the fixes. - -## 1. What is an error, and what is free - -**Now.** Section 10 tells the compiler what to say (the form of a -message, "up to 20" errors, skipping to the next statement, "did you -mean", which warnings, `-Werror`), and Appendix A says all of that is -the implementation's. The two contradict. - -**Proposed.** - -- Section 10's "Messages" and warnings paragraphs move to - `doc/compiler.md`, "This compiler's choices". `-Werror` is this - compiler's option. Appendix A's line becomes "the text and number of - its messages, and which warnings it gives". -- The report states the rule once: an implementation must reject a - program that is an error because accepting it would give it a - meaning the report cannot define: a type error, an undefined or - repeated name, an assignment to what is read-only, a missing or - wrong `main`, a cycle of modules. A fault that is only a lint (an - unused name, a dropped result) is not an error of the language. -- `conform/err` is sorted by that rule: what is a language error stays - and is judged by status alone; a lint-like test moves to `test/err`. - -**Costs.** A pass over the 235 error tests. Nothing for a valid program. - -## 2. Run-time stops exit with status 2 - -**Now.** A failed check exits with status 2 (6.8, `Rt.stop`); a nil -pointer, division by zero or stack overflow stops the program "on -every target", and this compiler dies by the signal (139, 136), so -`conform/` cannot pin it. - -**Proposed.** Section 10: any stop of a running program (a failed -check, a nil pointer, a division by zero, a stack overflow) says why on -standard error, whose text is free, and exits with status 2. The -compiler's handlers (`Rt`) end the program with status 2 rather than by -the signal; `conform/` gets a program for each. - -**Costs.** `Rt`'s handlers and the tests that expect 139/136 (`test/`); -a stack overflow in a C thread still ends by the signal (no handler -stack there, CLAUDE.md). - -## 3. Readings the report doesn't have - -CLAUDE.md lists readings the compiler took where the report is silent. -They go into the report, short, or the compiler changes: - -- 5.10 and 6.1: where `INT` widens to `I64` (assignment, argument, - `return a, b`) and where it does not (`a, b := f(x)`, `return f(x)`, - `for`, `INC`/`DEC`); an untyped constant converts to a pointer. -- 3: another module's exported variable is read-only: an array or - record in it cannot be sliced or `match`ed in place. -- 2: the non-reserved words are `static`, `check` and `off` (the - report says only `static` in one place). -- 7.4: which types `match` takes; `lo .. hi` with `lo > hi` is an - error; `defer defer f` is an error ("that would leave it" says less). -- 10: `main` takes no parameters. -- 6.1: the type of a shift whose left operand is an untyped constant. -- 2: a real constant of type `F32` is the nearest `F32` (the compiler - rounds twice, through `F64`: it follows the report or the report - says so). - -## 4. The library core, and the second volume - -Appendix A's core is `Rt`, `Out`, `Mem`, `Arena`, `Lock`, `Str` and -`Buf`. `conform/run` imports `Heap`, `Fmt`, `List`, `Map` and `Sort` -too. The five leave `conform/` (their tests go to `test/`; each -module's own `main` stays its test). The report still defines them. - -## 5. Trimming - -To `doc/compiler.md`, or out: the "Separate compilation" paragraph and -its twin in Appendix A, the executable and gdb sentences, the NASM -bullet (kept short), the library table that repeats the listings, -`Heap`'s nine sizes, the 64-descriptor and 107-byte numbers, `Sort`'s -complexity claim, `Sys.rawMode`'s key list, and the version history of -section 12 (a changelog, not the language). Whether `Opt` stays in -the report or only in `raz-lib(3)` is open. - -## 6. Two volumes - -After 1-5: volume one is sections 1-10, the core library, the grammar -and Appendix A; volume two is the rest of the library. `tools/Doc.raz`, -`make check`'s example runs and `README.md` follow the files. - -## Tests to add (conform/) - -From the audit's NONE rows that the report fixes: zero initial values -per kind, order of evaluation, a variant `match` that runs, generic -instances run once, a `defer` not reached doesn't run, a failed check -skips pending defers, `Sys.exit` skips `atExit`, `Str`'s byte-order -procedures (core), and the run-time stops of 2. - -## Order, if approved - -1. Report 1, 2, 3 and 5, in `doc/raz.md` and `doc/compiler.md`: one commit each; stop for review. -2. `conform/` and `test/`: the sorting of 1, the moves of 4, the tests above. -3. The compiler: `Rt`'s status (2), the readings that change code. -4. The split (6).