raz / commit d704863b

commit
d704863b54349026b46c90ac72851e9b0c96fb98
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
51a90a63
PROPOSALS.md: what report 2026-10.33 did goes; a slice that can't be written

The call-site marks' proposal keeps only its two parts not approved,
the marks (part 1) and ret and keep (part 3): what it said of the
library by var, const parameters and variants in constants, now in the
report, goes, and so do the review's questions about them. The other
entries are none of them done, and stay.

New: []const T, a slice whose elements can't be written, as ^VOLATILE
marks a pointer. A []T fits where a []const T is wanted, so read-only
library parameters can take it without breaking a caller; a record's
field can hold one, so a constant's slices can't be written; a later
step would type literals so, closing a case of section 10.

patch · log

1 file changed, +112 -83

PROPOSALS.md modified +112 -83

@@ -10,30 +10,20 @@
1010 2026-10-17 (the second review's findings are under "Open questions",
1111 at the end of part 1). The owner judged the feature, and its use, not
1212 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:
1818
1919 1. **Marks at the call** (this section): an argument for a `var`
2020 parameter is written `var x`, and one for a `keep` parameter
2121 `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.
2522 3. **`ret` and `keep`** (below): a heading says what a procedure does
2623 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.
3324
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.
3727
3828 ### The problem: a call hides what it does
3929
@@ -67,7 +57,7 @@
6757 | Heading | The procedure | At the call | Example |
6858 |---|---|---|---|
6959 | 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)` |
7161 | `var x` | may change the caller's variable | `var x` | `Buf.add(var b, c)` |
7262 | `keep x` | may store it where it outlives the call | `keep x` | `Names.put(var table, keep name, keep 1)` |
7363 | `ret x` | its results may point into it | nothing | `s := Str.trim(line[0..n])` |
@@ -79,8 +69,8 @@
7969 `COPY(d, s)` fills `d`. A slice is a view of the caller's array, and
8070 lending it is what it is for; the table says so in a note under it.
8171
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)
8474 and the tutorial as they are here.
8575
8676 ### The rules
@@ -125,7 +115,7 @@
125115 8. **`const`** is never written at the call: the procedure neither
126116 changes nor keeps what it is given. Its argument is any expression
127117 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).
129119
130120 ```
131121 Arguments = "(" [ Argument { "," Argument } ] ")" .
@@ -134,7 +124,7 @@
134124
135125 Each rule looks at the call and the heading only, so a one-pass
136126 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).
138128
139129 ### Examples
140130
@@ -253,7 +243,7 @@
253243 end;
254244 ```
255245
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:
257247
258248 ```
259249 const Rows: []Opt.Row = [
@@ -262,14 +252,14 @@
262252 ...
263253 Opt.init(var p, keep "Sh", keep Rows);
264254 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 *)
266256 ```
267257
268258 Today's `Opt.init(ADR(p), "Sh", [...])`, with the literal in the call,
269259 is an error once `init` is `keep table`: the literal lives in the
270260 frame, and `keep` can't say "as long as `p`" (part 3, "False alarms").
271261
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:
273263
274264 ```
275265 proc is(const sc: Scanner; s: []U8): BOOL; (* Scan's *)
@@ -278,8 +268,8 @@
278268 if Scan.among(Scan.text(sc), binaryWords) then ... end;
279269 ```
280270
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.
283273
284274 **A list of names a procedure keeps, passed on.** The parameter is
285275 `keep` in turn, so the promise travels up:
@@ -354,21 +344,19 @@
354344 Count.raz:9:27: key[0..4]: kept by Names.put, but it points into this procedure's frame
355345 Sh.raz:60:28: [...]: kept by Opt.init, but an array literal lives in this procedure's frame: make it a constant
356346 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
360347 ```
361348
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.
364352
365353 ### How much noise
366354
367355 Measured by a search of `src/`, `lib/`, `tools/` and `examples/`, about
368356 23,300 lines of code (rough: a search, not the compiler):
369357
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`;
372360 - about 580 calls of our own procedures with `var` parameters, unmarked
373361 today: each gains `var`, about one line in 40;
374362 - `keep`: a few dozen calls (`Map.put`, `List.push`, `Vec.push`,
@@ -376,9 +364,7 @@
376364 Since it follows the heading, it stands also before values that can't
377365 end, `keep 1` in `Names.put(var table, keep name, keep 1)`: a word
378366 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.
382368
383369 So most of the marks stand where an `ADR` stands today. What is new is
384370 the 580, and those are the calls, like `utf8(cur.pos)`, that change a
@@ -399,10 +385,8 @@
399385
400386 - **The report, `doc/raz.md`.** 8: the grammar above; "Parameters"
401387 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
406390 exceptions shrink to `ADR`, C, code procedures and `check off`.
407391 1, "A first look": its example marks its calls. Every example in the
408392 report is marked. About two pages; the report stays under 40 (31
@@ -419,21 +403,16 @@
419403 ARGUMENTS": the table; a whole program, with its output, that counts
420404 the words of its input in a `Map([]U8, INT)` with a `Buf`, using
421405 `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;
423407 then "What the compiler stops", the four mistakes of the messages
424408 above, each with its message. Section 16, "FROM PASCAL AND C TO RAZ",
425409 gains: Pascal's `var` is unmarked at the call, raz's is marked, as C#'s
426410 `ref` is; C's `&x` becomes `var x` when the callee only changes it,
427411 and stays `ADR(x)` when it keeps it. Every other example in the
428412 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.
437416 - **`doc/compiler.md`**: where the marks are read and checked, the
438417 checks of part 3 and the set each value carries, with the code
439418 before and after, and the table of lines.
@@ -447,8 +426,7 @@
447426
448427 ### What it breaks, and the order of the work
449428
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
452430 tools, the examples, the tests, and rmacs, ravite, rat, rlX11, rloc,
453431 rpg and rsqlite, each when it moves its pin. The mending is mechanical,
454432 and the compiler names it at each place.
@@ -462,19 +440,14 @@
462440 Then, one commit each:
463441
464442 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
469446 library marked (`Str.trim`, `Map.put`, `List.push`, `Vec.push`,
470447 `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`,
476449 `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
478451 editors.
479452
480453 The examples of parts 2 and 3 are written as the whole thaw makes
@@ -492,13 +465,9 @@
492465 either, so "the seed first" can't work as written: it takes two
493466 releases, one that accepts every new form without requiring it,
494467 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.)
502471 3. **A hole in part 3's exception for `var`.** `proc fill(var r: R);
503472 begin r.s := r.buf[0..4]; end;` passes, since `r` points where it
504473 pointed; a caller's local `r` copied to a module variable then
@@ -522,19 +491,15 @@
522491 7. **A mark that lends nothing in a plain heading**, `keep n: INT`,
523492 costs every call a word. Proposed: a warning, but on a module
524493 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.)
531499 9. **Procedure types** with fewer marks are assignable, not the same:
532500 5.10 must say so, for `=`, generic instances and `forward`.
533501 `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
538503 buffer, `Scan.init(var s, keep line[0..n])`, is refused though both
539504 end together (a module variable, a `Buf` or the heap is the way
540505 out); so is a store through `ADR` of a local.
@@ -742,8 +707,6 @@
742707 for the exception above. `COPY` into such a place is no such store:
743708 it copies bytes, not where they point.
744709 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).
747710
748711 Checks 1 to 3 on a local variable's value wait for the procedure's
749712 `end`, when everything assigned to it is known.
@@ -789,8 +752,8 @@
789752 the array literal is frame-bound: an error, though `p` is a local
790753 and dies with the literal. `keep` can't say "as long as `p`";
791754 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.
794757 - **A local variable used twice.** One slice variable that holds a
795758 slice of a local buffer early on and a result to return later is
796759 frame-bound throughout. Two variables cure it.
@@ -1089,3 +1052,69 @@
10891052
10901053 Met in mosaico's `Mconfig`, where `MenuAction.run` and a status block's
10911054 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?"