| | @@ -10,30 +10,20 @@ |
| 10 | 10 | 2026-10-17 (the second review's findings are under "Open questions", |
| 11 | 11 | at the end of part 1). The owner judged the feature, and its use, not |
| 12 | 12 | settled: no change is made for the marks at the call, `ret` or `keep`. |
| 13 | | -Parts 2, 4 and 5, the library by `var`, a `const` parameter and a |
| 14 | | -variant in a constant, went into report 2026-10.33 on their own, |
| 15 | | -without the marks, and are no longer here. |
| 16 | | -As drafted, it is five parts, to be made in one thaw so that programs |
| 17 | | -break once: |
| 13 | +It was drafted as five parts. Three of them went into report |
| 14 | +2026-10.33 on their own, without the marks: the library's parameters |
| 15 | +by `var` (part 2), a `const` parameter (part 4), and a variant in a |
| 16 | +constant (part 5). What is left are the two parts not approved, kept |
| 17 | +by their numbers: |
| 18 | 18 | |
| 19 | 19 | 1. **Marks at the call** (this section): an argument for a `var` |
| 20 | 20 | parameter is written `var x`, and one for a `keep` parameter |
| 21 | 21 | `keep x`. |
| 22 | | -2. **The library's parameters by `var`, not by pointer** (now in the |
| 23 | | - report, 2026-10.33): the |
| 24 | | - `ADR` that stands at nearly every call to the library goes. |
| 25 | 22 | 3. **`ret` and `keep`** (below): a heading says what a procedure does |
| 26 | 23 | with what it is given, and the compiler holds the body to it. |
| 27 | | -4. **A `const` parameter** (now in the report): a record or array only read is |
| 28 | | - passed in place, unmarked, so that `var` at a call always means a |
| 29 | | - change. |
| 30 | | -5. **A constant holds a variant** (now in the report): so that a table a procedure |
| 31 | | - keeps, as `Opt.init`'s, can be a constant, not a literal in the |
| 32 | | - frame. |
| 33 | 24 | |
| 34 | | -Nothing is built until the owner starts the milestone. The report |
| 35 | | -changes first, as always; the documentation listed below comes with |
| 36 | | -it. |
| 25 | +Nothing is built unless the owner starts it. The report changes first, |
| 26 | +as always; the documentation listed below comes with it. |
| 37 | 27 | |
| 38 | 28 | ### The problem: a call hides what it does |
| 39 | 29 | |
| | @@ -67,7 +57,7 @@ |
| 67 | 57 | | Heading | The procedure | At the call | Example | |
| 68 | 58 | |---|---|---|---| |
| 69 | 59 | | no mark | reads it while the call runs, then lets go | nothing | `Str.eq(a, b)` | |
| 70 | | -| `const x` | reads the caller's variable in place, without a copy, and doesn't change it | nothing | `Opt.at(p)` | |
| 60 | +| `const x` | reads the caller's variable in place, without a copy, and doesn't change it | nothing | `Opt.number(p, 1, 9)` | |
| 71 | 61 | | `var x` | may change the caller's variable | `var x` | `Buf.add(var b, c)` | |
| 72 | 62 | | `keep x` | may store it where it outlives the call | `keep x` | `Names.put(var table, keep name, keep 1)` | |
| 73 | 63 | | `ret x` | its results may point into it | nothing | `s := Str.trim(line[0..n])` | |
| | @@ -79,8 +69,8 @@ |
| 79 | 69 | `COPY(d, s)` fills `d`. A slice is a view of the caller's array, and |
| 80 | 70 | lending it is what it is for; the table says so in a note under it. |
| 81 | 71 | |
| 82 | | -`var` is in the language now; `keep` and `ret` come with part 3, `const` |
| 83 | | -with part 4. The table, and the note, go into the report (8), raz(7) |
| 72 | +`var` and `const` are in the language now (report 2026-10.33); `keep` |
| 73 | +and `ret` would come with part 3. The table, and the note, go into the report (8), raz(7) |
| 84 | 74 | and the tutorial as they are here. |
| 85 | 75 | |
| 86 | 76 | ### The rules |
| | @@ -125,7 +115,7 @@ |
| 125 | 115 | 8. **`const`** is never written at the call: the procedure neither |
| 126 | 116 | changes nor keeps what it is given. Its argument is any expression |
| 127 | 117 | of the parameter's type; a variable is passed in place, and anything |
| 128 | | - else in a temporary of the statement (part 4). |
| 118 | + else in a temporary of the statement (report section 8). |
| 129 | 119 | |
| 130 | 120 | ``` |
| 131 | 121 | Arguments = "(" [ Argument { "," Argument } ] ")" . |
| | @@ -134,7 +124,7 @@ |
| 134 | 124 | |
| 135 | 125 | Each rule looks at the call and the heading only, so a one-pass |
| 136 | 126 | compiler makes them as it reads the call: perhaps 40 lines, beside the |
| 137 | | -250 to 400 of part 3, the 30 to 60 of part 4 and the 20 of part 5. |
| 127 | +250 to 400 of part 3 (400 to 600, by the second review). |
| 138 | 128 | |
| 139 | 129 | ### Examples |
| 140 | 130 | |
| | @@ -253,7 +243,7 @@ |
| 253 | 243 | end; |
| 254 | 244 | ``` |
| 255 | 245 | |
| 256 | | -**A table a procedure keeps**, a constant (part 5), as `Sh`'s becomes: |
| 246 | +**A table a procedure keeps**, a constant (report section 4), as `Sh`'s is now: |
| 257 | 247 | |
| 258 | 248 | ``` |
| 259 | 249 | const Rows: []Opt.Row = [ |
| | @@ -262,14 +252,14 @@ |
| 262 | 252 | ... |
| 263 | 253 | Opt.init(var p, keep "Sh", keep Rows); |
| 264 | 254 | while Opt.next(var p) do ... end; |
| 265 | | -if Opt.at(p) > 1 then ... end; (* at only reads: const, no mark *) |
| 255 | +secs := Opt.number(p, 1, 600); (* number only reads: const, no mark *) |
| 266 | 256 | ``` |
| 267 | 257 | |
| 268 | 258 | Today's `Opt.init(ADR(p), "Sh", [...])`, with the literal in the call, |
| 269 | 259 | is an error once `init` is `keep table`: the literal lives in the |
| 270 | 260 | frame, and `keep` can't say "as long as `p`" (part 3, "False alarms"). |
| 271 | 261 | |
| 272 | | -**A large record only read**, by `const` (part 4), from `tools/Pretty.raz`: |
| 262 | +**A large record only read**, by `const` (report section 8), as `tools/Pretty.raz` has it now: |
| 273 | 263 | |
| 274 | 264 | ``` |
| 275 | 265 | proc is(const sc: Scanner; s: []U8): BOOL; (* Scan's *) |
| | @@ -278,8 +268,8 @@ |
| 278 | 268 | if Scan.among(Scan.text(sc), binaryWords) then ... end; |
| 279 | 269 | ``` |
| 280 | 270 | |
| 281 | | -Today each of these is `ADR(sc)`; by `var` each would say `var sc`, |
| 282 | | -and none changes it. |
| 271 | +Before 2026-10.33 each of these was `ADR(sc)`; by `var` each would say |
| 272 | +`var sc`, and none changes it. |
| 283 | 273 | |
| 284 | 274 | **A list of names a procedure keeps, passed on.** The parameter is |
| 285 | 275 | `keep` in turn, so the promise travels up: |
| | @@ -354,21 +344,19 @@ |
| 354 | 344 | Count.raz:9:27: key[0..4]: kept by Names.put, but it points into this procedure's frame |
| 355 | 345 | Sh.raz:60:28: [...]: kept by Opt.init, but an array literal lives in this procedure's frame: make it a constant |
| 356 | 346 | Pretty.raz:123:19: sc: Scan.is only reads it (const): no `var` |
| 357 | | -Scan.raz:41:5: sc: a const parameter can't be changed |
| 358 | | -Sh.raz:88:14: ADR(b): Buf.init takes `var b`, not a pointer |
| 359 | | -Sh.raz:151:14: p: Buf.add takes `var p^`, not a pointer |
| 360 | 347 | ``` |
| 361 | 348 | |
| 362 | | -The last two are part 2's mending, `ADR(x)` to `var x` and `p` to |
| 363 | | -`var p^`. |
| 349 | +The compiler already says, since 2026-10.33, that a `const` parameter |
| 350 | +can't be changed, and what to write for `ADR(b)` or `p` given to a |
| 351 | +`var` or `const` parameter. |
| 364 | 352 | |
| 365 | 353 | ### How much noise |
| 366 | 354 | |
| 367 | 355 | Measured by a search of `src/`, `lib/`, `tools/` and `examples/`, about |
| 368 | 356 | 23,300 lines of code (rough: a search, not the compiler): |
| 369 | 357 | |
| 370 | | -- about 630 `ADR`s; most are at calls to the library that part 2 turns |
| 371 | | - into `var x`: the same count, shorter, and true; |
| 358 | +- about 630 `ADR`s, before 2026-10.33; most were at calls to the |
| 359 | + library, which now take `x` itself, and would take `var x`; |
| 372 | 360 | - about 580 calls of our own procedures with `var` parameters, unmarked |
| 373 | 361 | today: each gains `var`, about one line in 40; |
| 374 | 362 | - `keep`: a few dozen calls (`Map.put`, `List.push`, `Vec.push`, |
| | @@ -376,9 +364,7 @@ |
| 376 | 364 | Since it follows the heading, it stands also before values that can't |
| 377 | 365 | end, `keep 1` in `Names.put(var table, keep name, keep 1)`: a word |
| 378 | 366 | each, the price of one rule for every instance; |
| 379 | | -- `const`: none at the call, and some 40 `var`s and `ADR`s fewer, where |
| 380 | | - a large record is only read (`Opt`, `Scan` in the tools, `Item` in |
| 381 | | - `src/`). |
| 367 | +- `const`: none at the call. |
| 382 | 368 | |
| 383 | 369 | So most of the marks stand where an `ADR` stands today. What is new is |
| 384 | 370 | the 580, and those are the calls, like `utf8(cur.pos)`, that change a |
| | @@ -399,10 +385,8 @@ |
| 399 | 385 | |
| 400 | 386 | - **The report, `doc/raz.md`.** 8: the grammar above; "Parameters" |
| 401 | 387 | becomes "Parameters and arguments", with the table and its note on |
| 402 | | - slices, rules 1 to 8, and the swap, map and `const` examples; `keep` |
| 403 | | - and `ret` from part 3, `const` from part 4. 4: a constant may hold a |
| 404 | | - variant (part 5), with `Opt`'s table as the example. 5.9: procedure |
| 405 | | - types with marks. 7.3: `ret`. 10: the promise, whose |
| 388 | + slices, rules 1 to 8, and the swap and map examples; `keep` and |
| 389 | + `ret` from part 3. 5.9: procedure types with marks. 7.3: `ret`. 10: the promise, whose |
| 406 | 390 | exceptions shrink to `ADR`, C, code procedures and `check off`. |
| 407 | 391 | 1, "A first look": its example marks its calls. Every example in the |
| 408 | 392 | report is marked. About two pages; the report stays under 40 (31 |
| | @@ -419,21 +403,16 @@ |
| 419 | 403 | ARGUMENTS": the table; a whole program, with its output, that counts |
| 420 | 404 | the words of its input in a `Map([]U8, INT)` with a `Buf`, using |
| 421 | 405 | `var`, `keep`, `ret` and `const`, each said in a sentence where it |
| 422 | | - stands, and taking its options from a constant table of `Opt`; |
| 406 | + stands; |
| 423 | 407 | then "What the compiler stops", the four mistakes of the messages |
| 424 | 408 | above, each with its message. Section 16, "FROM PASCAL AND C TO RAZ", |
| 425 | 409 | gains: Pascal's `var` is unmarked at the call, raz's is marked, as C#'s |
| 426 | 410 | `ref` is; C's `&x` becomes `var x` when the callee only changes it, |
| 427 | 411 | and stays `ADR(x)` when it keeps it. Every other example in the |
| 428 | 412 | tutorial is marked. Each runs under `make check`, as now. |
| 429 | | -- **Volume 2, `doc/raz-lib.md`, and raz-lib(3)**: every signature of |
| 430 | | - part 2, each module's example marked, and a note in each changed |
| 431 | | - module of what changed. |
| 432 | | -- **`STANDARDS.md`**: "Parameters: a value, `var`, or a pointer" becomes |
| 433 | | - "a value, `const`, `var`, or a pointer": a large record or array only |
| 434 | | - read is `const`, not `var`, so that `var` at a call always means a |
| 435 | | - change; `ADR` no longer marks what is kept, `keep` does; "The library |
| 436 | | - until a thaw" goes. |
| 413 | +- **Volume 2, `doc/raz-lib.md`, and raz-lib(3)**: each module's |
| 414 | + example marked, and `keep` and `ret` where the library has them. |
| 415 | +- **`STANDARDS.md`**: `ADR` no longer marks what is kept, `keep` does. |
| 437 | 416 | - **`doc/compiler.md`**: where the marks are read and checked, the |
| 438 | 417 | checks of part 3 and the set each value carries, with the code |
| 439 | 418 | before and after, and the table of lines. |
| | @@ -447,8 +426,7 @@ |
| 447 | 426 | |
| 448 | 427 | ### What it breaks, and the order of the work |
| 449 | 428 | |
| 450 | | -Every call to a procedure with a `var` or `keep` parameter, and every |
| 451 | | -call to the library's procedures of part 2: in `src/`, `lib/`, the |
| 429 | +Every call to a procedure with a `var` or `keep` parameter: in `src/`, `lib/`, the |
| 452 | 430 | tools, the examples, the tests, and rmacs, ravite, rat, rlX11, rloc, |
| 453 | 431 | rpg and rsqlite, each when it moves its pin. The mending is mechanical, |
| 454 | 432 | and the compiler names it at each place. |
| | @@ -462,19 +440,14 @@ |
| 462 | 440 | Then, one commit each: |
| 463 | 441 | |
| 464 | 442 | 1. The report, `report-history.md`, raz(7): for review. |
| 465 | | -2. The compiler reads the marks and checks rules 1 to 7. |
| 466 | | -3. The library's signatures (part 2), and every caller in this |
| 467 | | - repository mended. |
| 468 | | -4. `ret` and `keep` in headings and their checks (part 3), and the |
| 443 | +2. The compiler reads the marks and checks rules 1 to 8, and every |
| 444 | + caller in this repository is marked. |
| 445 | +3. `ret` and `keep` in headings and their checks (part 3), and the |
| 469 | 446 | library marked (`Str.trim`, `Map.put`, `List.push`, `Vec.push`, |
| 470 | 447 | `Opt.init`, `Opt.scope`, ...). |
| 471 | | -5. `const` parameters (part 4), and the library's and `src/`'s large |
| 472 | | - records only read moved to it. |
| 473 | | -6. Constants holding variants (part 5), and `Sh`'s and `Opt`'s tables |
| 474 | | - made constants. |
| 475 | | -7. The tutorial, volume 2, raz-lib(3), `STANDARDS.md`, |
| 448 | +4. The tutorial, volume 2, raz-lib(3), `STANDARDS.md`, |
| 476 | 449 | `doc/compiler.md`, `README.md`. |
| 477 | | -8. The tests: `conform/`, `test/err`, `test/msg`, `test/pretty`, the |
| 450 | +5. The tests: `conform/`, `test/err`, `test/msg`, `test/pretty`, the |
| 478 | 451 | editors. |
| 479 | 452 | |
| 480 | 453 | The examples of parts 2 and 3 are written as the whole thaw makes |
| | @@ -492,13 +465,9 @@ |
| 492 | 465 | either, so "the seed first" can't work as written: it takes two |
| 493 | 466 | releases, one that accepts every new form without requiring it, |
| 494 | 467 | made the seed, then one that marks `src/` and requires the marks. |
| 495 | | -2. **Errors here.** `Opt.at` and `operand` move the `Parser` (`at` |
| 496 | | - runs `next` to the end), so they are `var`, not `const`; the table |
| 497 | | - row and part 1's `Opt.at(p)` are wrong. `Sys.entryKind` reads a |
| 498 | | - `Dir` of 8 KB on Linux: `const` or `var`, not a value. Part 3's |
| 499 | | - `Names.put(var table, keep buf[0..n], 1)` lacks `keep 1`. Part 5's |
| 500 | | - table has a row part 1's lacks. Report 4 must let a variant's case |
| 501 | | - stand in a constant expression. |
| 468 | +2. **An error here.** Part 3's `Names.put(var table, keep buf[0..n], 1)` |
| 469 | + lacks `keep 1`. (The others the review found were in parts 2, 4 |
| 470 | + and 5, mended when they went into the report.) |
| 502 | 471 | 3. **A hole in part 3's exception for `var`.** `proc fill(var r: R); |
| 503 | 472 | begin r.s := r.buf[0..4]; end;` passes, since `r` points where it |
| 504 | 473 | pointed; a caller's local `r` copied to a module variable then |
| | @@ -522,19 +491,15 @@ |
| 522 | 491 | 7. **A mark that lends nothing in a plain heading**, `keep n: INT`, |
| 523 | 492 | costs every call a word. Proposed: a warning, but on a module |
| 524 | 493 | parameter's type or a procedure with a body for each target. |
| 525 | | -8. **`const`'s rules.** Check 4 must cover `match`'s names and views; |
| 526 | | - whether a slice's elements count as "a part of it" (they shouldn't); |
| 527 | | - a constant argument passed in place, not copied; `ret const` given a |
| 528 | | - temporary that holds an array, an error. The heading's grammar, |
| 529 | | - `Params = ["ret"] ["keep"] ["var" | "const"] ident ...`, and the |
| 530 | | - call's, a designator after `var`. |
| 494 | +8. **`ret` with `const`.** `ret const` given a temporary that holds an |
| 495 | + array would return a slice of the temporary: an error. The heading's |
| 496 | + grammar, `Params = ["ret"] ["keep"] ["var" | "const"] ident ...`, |
| 497 | + and the call's, a designator after `var`. (The rest of `const`'s |
| 498 | + rules are report 2026-10.33's, section 8.) |
| 531 | 499 | 9. **Procedure types** with fewer marks are assignable, not the same: |
| 532 | 500 | 5.10 must say so, for `=`, generic instances and `forward`. |
| 533 | 501 | `Map`'s `eq` can't take a `const` equality. |
| 534 | | -10. **Constants holding variants.** `match`'s names on one are read |
| 535 | | - only; a pointer field takes only `nil`; an untyped `const D = dot`; |
| 536 | | - padding zero; 30 to 40 lines, not 20. |
| 537 | | -11. **False alarms to document.** A local container over a local |
| 502 | +10. **False alarms to document.** A local container over a local |
| 538 | 503 | buffer, `Scan.init(var s, keep line[0..n])`, is refused though both |
| 539 | 504 | end together (a module variable, a `Buf` or the heap is the way |
| 540 | 505 | out); so is a store through `ADR` of a local. |
| | @@ -742,8 +707,6 @@ |
| 742 | 707 | for the exception above. `COPY` into such a place is no such store: |
| 743 | 708 | it copies bytes, not where they point. |
| 744 | 709 | 3. An argument for a call's `keep` parameter, as 2. |
| 745 | | -4. A `const` parameter, or a part of it, is never assigned, given to |
| 746 | | - a `var` parameter, nor to `ADR` (part 4). |
| 747 | 710 | |
| 748 | 711 | Checks 1 to 3 on a local variable's value wait for the procedure's |
| 749 | 712 | `end`, when everything assigned to it is known. |
| | @@ -789,8 +752,8 @@ |
| 789 | 752 | the array literal is frame-bound: an error, though `p` is a local |
| 790 | 753 | and dies with the literal. `keep` can't say "as long as `p`"; |
| 791 | 754 | saying that needs lifetimes on records, Rust's whole apparatus, which |
| 792 | | - is not proposed. The way out: the table a constant, which part 5 |
| 793 | | - allows, as part 1's example shows. |
| 755 | + is not proposed. The way out: the table a constant, which report |
| 756 | + 2026-10.33 allows, as part 1's example shows. |
| 794 | 757 | - **A local variable used twice.** One slice variable that holds a |
| 795 | 758 | slice of a local buffer early on and a result to return later is |
| 796 | 759 | frame-bound throughout. Two variables cure it. |
| | @@ -1089,3 +1052,69 @@ |
| 1089 | 1052 | |
| 1090 | 1053 | Met in mosaico's `Mconfig`, where `MenuAction.run` and a status block's |
| 1091 | 1054 | kind `run` met; the block's kind was renamed `command`. |
| 1055 | + |
| 1056 | +## A slice that can't be written: `[]const T` |
| 1057 | + |
| 1058 | +raz has no slice whose elements can't be written. A `const` parameter |
| 1059 | +(report 2026-10.33, section 8) is shallow: the procedure can't change |
| 1060 | +the record, but it can write through a slice in it, and through a |
| 1061 | +slice it makes of an array in it. A constant's slices, and every |
| 1062 | +string literal, point at bytes whose writing "isn't defined" (5.10, |
| 1063 | +10): the compiler doesn't refuse it, and on a target with read-only |
| 1064 | +memory the program stops. Nothing in a heading says that `Str.eq` |
| 1065 | +only reads its slices and `Str.lower` writes them. |
| 1066 | + |
| 1067 | +``` |
| 1068 | +type Rule = record class: []U8; tag: INT; end; |
| 1069 | +const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv"}]; |
| 1070 | + |
| 1071 | +proc shout(const r: Rule); |
| 1072 | +begin |
| 1073 | + r.class[0] := 'F'; (* allowed today: writes the constant's bytes, undefined *) |
| 1074 | +end; |
| 1075 | +``` |
| 1076 | + |
| 1077 | +The proposal: a slice type may say its elements are read only, |
| 1078 | +`[]const T`, as a pointer type says `^VOLATILE T`. |
| 1079 | + |
| 1080 | +- Its elements can be read and sliced, and not written: no `s[i] :=`, |
| 1081 | + no `COPY` into it, no `var` argument or `ADR` of an element, no |
| 1082 | + `INC` of one. A slice of it is `[]const T` too. |
| 1083 | +- A `[]T` goes where a `[]const T` is wanted, as `U8` widens to `INT`; |
| 1084 | + never the other way. A procedure that only reads a slice takes |
| 1085 | + `[]const T`, and every caller's `[]T` still fits it: `Str.eq(a, b: |
| 1086 | + []const U8)`, `Sys.write(fd: INT; s: []const U8)`, `Out.str`. Those |
| 1087 | + changes break no program. |
| 1088 | +- A record field may be `[]const U8`, so a record, a constant's above |
| 1089 | + all, can hold slices that can't be written: `type Rule = record |
| 1090 | + class: []const U8; ... end`, and `shout` above is refused. |
| 1091 | + |
| 1092 | +What a procedure returns of its argument is the hard part. `Str.trim(s: |
| 1093 | +[]const U8): []const U8` would hand a caller with a `[]U8` back a |
| 1094 | +slice it can't write, and break the caller that does. Either such |
| 1095 | +procedures keep `[]U8` until `ret` (above) can say "of the same kind |
| 1096 | +as the argument", or they come in pairs. This is where D's `inout` and |
| 1097 | +C++'s `const` overloads went; neither is small. |
| 1098 | + |
| 1099 | +A second step, for a thaw: a string literal and a constant's slices |
| 1100 | +are `[]const U8` and `[]const T`, so that writing them is an error, |
| 1101 | +not undefined, and section 10 loses a case. It breaks every program |
| 1102 | +that keeps a literal in a `[]U8` variable or field, which is most of |
| 1103 | +them, `Opt`'s rows included; each is mended by writing `[]const U8` |
| 1104 | +where nothing writes the bytes. |
| 1105 | + |
| 1106 | +Precedent: C's `const char *`; D's `const(T)[]`; Rust's `&[T]` and |
| 1107 | +`&mut [T]`; ulam, the other language here, makes `[]T` read only and |
| 1108 | +writes `[]var T` for one that may be written, which is the safer |
| 1109 | +default but breaks every raz program. |
| 1110 | + |
| 1111 | +Costs: the report, 5.3, 5.10 and 10, and 8 for `const` parameters, |
| 1112 | +which could then read their slices as `[]const`, making `const` deep |
| 1113 | +for slices; the compiler, a flag on a slice type, as `vol` is on a |
| 1114 | +pointer, checked where an element is written, about 60 to 100 lines; |
| 1115 | +the library, its read-only slice parameters, a long list but each |
| 1116 | +change one word. |
| 1117 | + |
| 1118 | +Met in the discussion of `const` parameters (2026-10-17): "If a const |
| 1119 | +can still be written, what's the point?", and "Can records have |
| 1120 | +constant slices?" |