| | @@ -1,175 +1,119 @@ |
| 1 | 1 | # Proposal: report 2026-10.22 |
| 2 | 2 | |
| 3 | | -Three changes that take rules out of the language and the conformance suite. Neither adds a feature. |
| 4 | | -Nothing in `doc/raz.md` or the code changes until the owner approves |
| 5 | | -this; it is a thaw of the freeze (CLAUDE.md), so it needs the owner's |
| 6 | | -word. |
| 3 | +Made from an audit of `doc/raz.md` against `conform/` and `test/` |
| 4 | +(about 500 rules: ~260 pinned by `conform/`, ~130 only by `test/`, ~60 |
| 5 | +by no test, ~25 unsettled or in conflict). It mends defects in the |
| 6 | +report and trims it; it adds no feature. Nothing in `doc/raz.md` or the |
| 7 | +code changes until the owner approves each part (CLAUDE.md: a thaw). |
| 7 | 8 | |
| 8 | | -## 1. `INT` and `UINT` are names for `I64` and `U64` |
| 9 | | - |
| 10 | | -**Now.** `INT` and `I64` are two types of one size. An `INT` goes |
| 11 | | -silently into an `I64`, and the two never mix in an expression |
| 12 | | -(5.1, 5.10, 6.1). The widening applies to assignment, arguments and |
| 13 | | -`return n, m`, and not to `a, b := f(x)`, `return f(x)`, `for` or |
| 14 | | -`INC`/`DEC`. A program that holds an `I64` from a library next to a |
| 15 | | -length gets `I64 and INT are different types` (`conform/err/IntMix`). |
| 9 | +Decided by the owner (2026-10-14): |
| 16 | 10 | |
| 17 | | -**Proposed.** `INT` is another name for `I64`, and `UINT` for `U64`, |
| 18 | | -as `type Count = I64;` already is (5.10). A target has 64-bit |
| 19 | | -addresses (appendix A no longer lets the target choose their size); |
| 20 | | -no target of this compiler has had any other. |
| 11 | +- `INT` and `UINT` stay distinct from `I64` and `U64`. (The first |
| 12 | + version of this proposal made them aliases; dropped.) |
| 13 | +- Exported variables stay as they are. (The first version banned them; |
| 14 | + dropped. Exported constants stay on `PLAN.md`'s wishes list.) |
| 15 | +- Conformance keeps the error programs, but only for errors that |
| 16 | + change a program's meaning; warnings and the form of messages leave |
| 17 | + the report. |
| 18 | +- Every run-time stop exits with status 2. |
| 19 | +- The library past the core leaves `conform/`. |
| 20 | +- The report is split in two volumes, after the fixes. |
| 21 | 21 | |
| 22 | | -**Report text.** |
| 22 | +## 1. What is an error, and what is free |
| 23 | 23 | |
| 24 | | -- 5.1: the table rows become `INT` = `I64` and `UINT` = `U64`. The |
| 25 | | - paragraph after the table reads: "`INT` is the everyday integer: |
| 26 | | - lengths, indexes and sizes are `INT`s. It is the integer a pointer |
| 27 | | - converts to (6.7), and a word the atomic built-ins work on (6.8). |
| 28 | | - `INT` is `I64`, `UINT` is `U64`." Drop "`INT` and `I64` are two |
| 29 | | - types … which may drop bits on a smaller target" and "A type bigger |
| 30 | | - than the largest `INT` in bytes is an error". |
| 31 | | -- 5.10: drop the last bullet (`INT` to `I64`), and the paragraph's |
| 32 | | - "Results passed on whole need the same types exactly … an `INT` |
| 33 | | - widens as above". |
| 34 | | -- 6.1: drop "whatever their sizes", and the example `i < LEN(s)`; |
| 35 | | - "Two integer types of different names are one type if one is |
| 36 | | - another name for the other" is already 5.10's rule. Drop "On a |
| 37 | | - target whose `INT` is narrower, a pointer's offset is cut". |
| 38 | | -- Appendix A, "The target": drop "the size of an address, and so of |
| 39 | | - `INT`". |
| 24 | +**Now.** Section 10 tells the compiler what to say (the form of a |
| 25 | +message, "up to 20" errors, skipping to the next statement, "did you |
| 26 | +mean", which warnings, `-Werror`), and Appendix A says all of that is |
| 27 | +the implementation's. The two contradict. |
| 40 | 28 | |
| 41 | | -**What it costs.** |
| 29 | +**Proposed.** |
| 42 | 30 | |
| 43 | | -- Every valid program stays valid and means the same. A program |
| 44 | | - that had two procedures' types, or two generic instances, told |
| 45 | | - apart by `INT` against `I64` now has one type (no such program is |
| 46 | | - in `lib/`, `src/`, `examples/` or `tools/`). |
| 47 | | -- A target with 32-bit addresses is no longer expressible. None is |
| 48 | | - planned. |
| 49 | | -- Messages say `I64` where they said `INT`; `test/msg` changes with |
| 50 | | - them. |
| 51 | | -- `conform/err/IntMix` stops being an error and goes; `test/` gets |
| 52 | | - the same for `UINT`. No new tests. |
| 31 | +- Section 10's "Messages" and warnings paragraphs move to |
| 32 | + `doc/compiler.md`, "This compiler's choices". `-Werror` is this |
| 33 | + compiler's option. Appendix A's line becomes "the text and number of |
| 34 | + its messages, and which warnings it gives". |
| 35 | +- The report states the rule once: an implementation must reject a |
| 36 | + program that is an error because accepting it would give it a |
| 37 | + meaning the report cannot define: a type error, an undefined or |
| 38 | + repeated name, an assignment to what is read-only, a missing or |
| 39 | + wrong `main`, a cycle of modules. A fault that is only a lint (an |
| 40 | + unused name, a dropped result) is not an error of the language. |
| 41 | +- `conform/err` is sorted by that rule: what is a language error stays |
| 42 | + and is judged by status alone; a lint-like test moves to `test/err`. |
| 53 | 43 | |
| 54 | | -**What it saves.** The compiler's `coerce` and its exact twin, the |
| 55 | | -list of places that widen and the list that don't, the `INT`/`UINT` |
| 56 | | -cases in constant folding and the `Results passed on whole` rule: an |
| 57 | | -estimated 150–250 lines in this compiler, and one rule fewer for |
| 58 | | -every reader. |
| 44 | +**Costs.** A pass over the 235 error tests. Nothing for a valid program. |
| 59 | 45 | |
| 60 | | -## 2. A variable is not exported |
| 46 | +## 2. Run-time stops exit with status 2 |
| 61 | 47 | |
| 62 | | -**Now.** `var x*: T;` exports `x` read-only: other modules read it but |
| 63 | | -can't assign it, pass it by `var`, `INC` it, take its `ADR`, slice an |
| 64 | | -array in it or `match` it in place (3, "Exports"). The rule is one |
| 65 | | -paragraph and a handful of conditions in every place that names a |
| 66 | | -variable. |
| 48 | +**Now.** A failed check exits with status 2 (6.8, `Rt.stop`); a nil |
| 49 | +pointer, division by zero or stack overflow stops the program "on |
| 50 | +every target", and this compiler dies by the signal (139, 136), so |
| 51 | +`conform/` cannot pin it. |
| 67 | 52 | |
| 68 | | -**Proposed.** Only constants, types, procedures and the fields of |
| 69 | | -records are exported. `*` after a variable's name is an error: "a |
| 70 | | -variable isn't exported; export a procedure that returns its value". |
| 71 | | -A module shares state through procedures (`Heap.heap()` for |
| 72 | | -`Heap.heap`), or a pointer to the data. |
| 53 | +**Proposed.** Section 10: any stop of a running program (a failed |
| 54 | +check, a nil pointer, a division by zero, a stack overflow) says why on |
| 55 | +standard error, whose text is free, and exits with status 2. The |
| 56 | +compiler's handlers (`Rt`) end the program with status 2 rather than by |
| 57 | +the signal; `conform/` gets a program for each. |
| 73 | 58 | |
| 74 | | -**Report text.** |
| 59 | +**Costs.** `Rt`'s handlers and the tests that expect 139/136 (`test/`); |
| 60 | +a stack overflow in a C thread still ends by the signal (no handler |
| 61 | +stack there, CLAUDE.md). |
| 75 | 62 | |
| 76 | | -- 3, "Exports": replace the paragraph from "An exported variable can |
| 77 | | - be read" to "…or a procedure that returns a slice of it." with "A |
| 78 | | - variable can't be exported; a module shares its state by exporting |
| 79 | | - procedures that read and change it." |
| 80 | | -- 5.x and appendix B: `*` is not part of the grammar of a variable's |
| 81 | | - name. |
| 82 | | -- 12: drop "An exported variable can't be changed, passed by `var` |
| 83 | | - or …" from 2026-10.x's entry; it describes a rule that is gone. |
| 63 | +## 3. Readings the report doesn't have |
| 84 | 64 | |
| 85 | | -**What it costs.** This one is real work in what is already written: |
| 65 | +CLAUDE.md lists readings the compiler took where the report is silent. |
| 66 | +They go into the report, short, or the compiler changes: |
| 86 | 67 | |
| 87 | | -- `lib/` has one exported variable, `Heap.heap`. It becomes |
| 88 | | - `Heap.allocator()`. |
| 89 | | -- `src/` has some sixty, most of them the compiler's own state: |
| 90 | | - `Scan.tok`, `Scan.ival`, `Chunk.pc`, `Gen.depth`, `Link.textOff`, |
| 91 | | - `Diag.errors`, `Sym.tInt` and the like. Each becomes a procedure |
| 92 | | - or, for a group, one record the module owns and exports a pointer |
| 93 | | - to. The compiler reads `Scan.tok` in its inner loops; each read |
| 94 | | - becomes a call (the compiler has no inliner; PLAN.md, "Next"), |
| 95 | | - and the compiler's 650,000 lines a second would drop by an amount |
| 96 | | - I haven't measured. That is the reason to weigh this change. |
| 97 | | -- A program that exports a variable no longer compiles. The fix is |
| 98 | | - mechanical and the error says it. |
| 99 | | -- `conform/err/Export{Adr,AsSlice,Assign,Elem,Inc,Slice,VarParam}`, |
| 100 | | - `NoteExport` and their `test/msg` twins become one test: that `*` |
| 101 | | - on a variable is an error. |
| 68 | +- 5.10 and 6.1: where `INT` widens to `I64` (assignment, argument, |
| 69 | + `return a, b`) and where it does not (`a, b := f(x)`, `return f(x)`, |
| 70 | + `for`, `INC`/`DEC`); an untyped constant converts to a pointer. |
| 71 | +- 3: another module's exported variable is read-only: an array or |
| 72 | + record in it cannot be sliced or `match`ed in place. |
| 73 | +- 2: the non-reserved words are `static`, `check` and `off` (the |
| 74 | + report says only `static` in one place). |
| 75 | +- 7.4: which types `match` takes; `lo .. hi` with `lo > hi` is an |
| 76 | + error; `defer defer f` is an error ("that would leave it" says less). |
| 77 | +- 10: `main` takes no parameters. |
| 78 | +- 6.1: the type of a shift whose left operand is an untyped constant. |
| 79 | +- 2: a real constant of type `F32` is the nearest `F32` (the compiler |
| 80 | + rounds twice, through `F64`: it follows the report or the report |
| 81 | + says so). |
| 102 | 82 | |
| 103 | | -**What it saves.** The read-only flag and its checks in `ADR`, |
| 104 | | -slicing, `var` arguments, `INC`, `NEW`, assignment and `match`, and |
| 105 | | -the message for each, in every implementation: an estimated 120–200 |
| 106 | | -lines in this compiler, and eight of the 235 error tests. |
| 83 | +## 4. The library core, and the second volume |
| 107 | 84 | |
| 108 | | -**An alternative that keeps most of the saving.** Keep exported |
| 109 | | -variables read-only, as now, and drop only the cases that need a |
| 110 | | -special rule: no array or record is exported by value (a module |
| 111 | | -exports a pointer to it, as the report already advises), so |
| 112 | | -"slice an array in it" and "`match` on a copy" can't arise. That |
| 113 | | -keeps `Scan.tok` and the compiler's speed, and removes the odd cases, |
| 114 | | -for about half the saving. |
| 85 | +Appendix A's core is `Rt`, `Out`, `Mem`, `Arena`, `Lock`, `Str` and |
| 86 | +`Buf`. `conform/run` imports `Heap`, `Fmt`, `List`, `Map` and `Sort` |
| 87 | +too. The five leave `conform/` (their tests go to `test/`; each |
| 88 | +module's own `main` stays its test). The report still defines them. |
| 115 | 89 | |
| 116 | | -## 3. Conformance covers valid programs only; warnings leave the report |
| 90 | +## 5. Trimming |
| 117 | 91 | |
| 118 | | -**Now.** `conform/err/` holds 235 programs the report calls errors, and |
| 119 | | -an implementation passes only if each one fails to compile |
| 120 | | -(`conform/check.sh`; appendix A: "A program that is an error in this |
| 121 | | -report is one in every implementation"). Section 10 also tells the |
| 122 | | -compiler what to warn of (unused names, a dropped result) and defines |
| 123 | | -`-Werror`. |
| 92 | +To `doc/compiler.md`, or out: the "Separate compilation" paragraph and |
| 93 | +its twin in Appendix A, the executable and gdb sentences, the NASM |
| 94 | +bullet (kept short), the library table that repeats the listings, |
| 95 | +`Heap`'s nine sizes, the 64-descriptor and 107-byte numbers, `Sort`'s |
| 96 | +complexity claim, `Sys.rawMode`'s key list, and the version history of |
| 97 | +section 12 (a changelog, not the language). Whether `Opt` stays in |
| 98 | +the report or only in `raz-lib(3)` is open. |
| 124 | 99 | |
| 125 | | -**Proposed.** |
| 100 | +## 6. Two volumes |
| 126 | 101 | |
| 127 | | -- `conform/` holds `run/` only. An implementation conforms if it |
| 128 | | - compiles every valid program there and each runs as the report |
| 129 | | - says, with the output and status expected. `conform/err/` and the |
| 130 | | - loop that runs it in `check.sh` go; the programs move to `test/err/` |
| 131 | | - with their `.err` files, where this compiler's own tests live, and |
| 132 | | - `test/msg`'s twins merge with them. |
| 133 | | -- The report still says what is not valid raz ("is an error"). What an |
| 134 | | - implementation does with an invalid program is its own: it should |
| 135 | | - say so and stop, as this compiler does, but one that compiles it, |
| 136 | | - or compiles it to something else, still conforms. Appendix A's |
| 137 | | - "Messages and warnings" line becomes "What it does with a program |
| 138 | | - that isn't valid, the text of its messages, and which warnings it |
| 139 | | - gives". |
| 140 | | -- Section 10's "Messages" paragraph, on the form of an error, the 20 |
| 141 | | - errors, skipping to the next statement and "did you mean", and the |
| 142 | | - paragraph on warnings, are moved to `doc/compiler.md` under "This |
| 143 | | - compiler's choices". `-Werror` is an option of this compiler's, not |
| 144 | | - of the language (it is already a command-line matter, appendix A). |
| 145 | | -- Failed checks at run time (an index out of range, a nil pointer, a |
| 146 | | - division by zero) stay in the report and in `conform/run`: they are |
| 147 | | - how a valid program behaves, with status 2 and a message on |
| 148 | | - standard error whose text is the implementation's. |
| 102 | +After 1-5: volume one is sections 1-10, the core library, the grammar |
| 103 | +and Appendix A; volume two is the rest of the library. `tools/Doc.raz`, |
| 104 | +`make check`'s example runs and `README.md` follow the files. |
| 149 | 105 | |
| 150 | | -**What it costs.** An implementation can no longer be shown to reject |
| 151 | | -what the report forbids, so a program valid on one compiler may not |
| 152 | | -be on another; this compiler keeps its diagnostics and its tests, and |
| 153 | | -that is where portability is held. Nothing changes for a program that |
| 154 | | -compiles today. |
| 106 | +## Tests to add (conform/) |
| 155 | 107 | |
| 156 | | -**What it saves.** For another implementation, the whole checker's |
| 157 | | -rejecting half: it needs to resolve names and types of valid programs, |
| 158 | | -not to find the fault in an invalid one. In the Ref compiler that |
| 159 | | -half (every `error_at`, `suggest`, the warning pass, unused-name |
| 160 | | -tracking and `coerce`'s rejections) is a large share of the 3,000 |
| 161 | | -lines of `expr.c` and `check.c`; I'd put it at a third, but have not |
| 162 | | -counted. For this compiler nothing is removed by the change itself. |
| 108 | +From the audit's NONE rows that the report fixes: zero initial values |
| 109 | +per kind, order of evaluation, a variant `match` that runs, generic |
| 110 | +instances run once, a `defer` not reached doesn't run, a failed check |
| 111 | +skips pending defers, `Sys.exit` skips `atExit`, `Str`'s byte-order |
| 112 | +procedures (core), and the run-time stops of 2. |
| 163 | 113 | |
| 164 | 114 | ## Order, if approved |
| 165 | 115 | |
| 166 | | -1. Report: `doc/raz.md` (the sections above and an entry in 12), the |
| 167 | | - grammar in appendix B, `doc/compiler.md` where it names the rules. |
| 168 | | -2. `conform/` and `test/`: the tests named above. |
| 169 | | -3. `conform/check.sh` and the move of `conform/err` to `test/err`. |
| 170 | | -4. The compiler: `src/`, one commit per step as CLAUDE.md says; then |
| 171 | | - `make check`, `make fixpoint`, `make bench`. |
| 172 | | -5. Library and `src/` rewrites for change 2. |
| 173 | | - |
| 174 | | -Changes 1 and 3 can go alone; change 2 should wait for a measurement of what |
| 175 | | -the accessors cost the compiler. |
| 116 | +1. Report 1, 2, 3 and 5, in `doc/raz.md` and `doc/compiler.md`: one commit each; stop for review. |
| 117 | +2. `conform/` and `test/`: the sorting of 1, the moves of 4, the tests above. |
| 118 | +3. The compiler: `Rt`'s status (2), the readings that change code. |
| 119 | +4. The split (6). |