raz / commit cd2f687b

commit
cd2f687b52eb16a89093224401206379d95b75de
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
80996a6b
Report 2026-10.27: a slice of the frame returned is an error

A defect mended (section 7.3): returning as a slice a local array, a
value parameter that is an array, an array literal, or a slice, field
or element of one. What the narrow rule doesn't catch is named among
section 10's exceptions; ret and keep, in PROPOSALS.md, would close
it at a thaw. The history also tells Sys's and Buf's gains, and Vec,
for volume 2.

patch · log

3 files changed, +37 -38

PROPOSALS.md modified +0 -33

@@ -95,39 +95,6 @@
9595 new files `sauce commit` takes 1.2 s against the Pascal sauce's 0.7,
9696 and `verify` 0.95 s against 0.48: the hashing.
9797
98-## A slice that outlives what it points at
99-
100-```
101-proc short(h: Hex): []U8; (* Hex = [64]U8 *)
102-begin
103- return h[0..8];
104-end;
105-
106-proc word: []U8;
107-var a: [4]U8;
108-begin
109- ...
110- return a; (* the array, silently a slice *)
111-end;
112-```
113-
114-Both compile without a word, under `-Werror`, and return a slice of
115-the procedure's own frame, which the next call overwrites. Section 10
116-says a program that reaches memory only through checked variables is
117-defined; a slice is checked, so this is a hole in that promise, a
118-defect rather than a wish, and it can be mended without a thaw.
119-
120-The narrow mend, which needs no analysis of where values go: it is an
121-error to return, as a slice, a slice of a local array or of a value
122-parameter that is an array or holds one, the silent conversion of
123-such an array included. It doesn't catch a slice stored in a module
124-variable or through a pointer, which is the rarer mistake, nor one of
125-an `ADR`, which section 10 already gives no promise for. The report
126-says it in section 7.3, Return; the compiler checks it where it
127-checks the type of `return`'s expression.
128-
129-Met in sauce's `Ssha.short`, which takes `var h: Hex` now.
130-
13198 ## Marking what a procedure does with what it is given: `ret` and `keep`
13299
133100 ### The hole

doc/raz.md (history) modified +28 -5

@@ -13,7 +13,7 @@
1313 This report defines the language. It is short on purpose. Whatever it
1414 doesn't allow, raz doesn't have.
1515
16-This is version 2026-10.26 of the report; section 11 says where each
16+This is version 2026-10.27 of the report; section 11 says where each
1717 version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
1818 for a language anyone can build again. They break programs written
1919 for 2026-10.10 and before: for 2026-10.9, say, the report of compiler
@@ -26,7 +26,9 @@
2626 is a fifth: an `INT` widens to an `I64` wherever it goes to one, in
2727 an expression too (sections 5.10 and 6.1); and a view, `v.(T)`,
2828 reads and writes the bytes of a variable as a `T` (section 6.9); it
29-breaks no program.
29+breaks no program. 2026-10.27 mends a defect: returning a slice of the
30+procedure's own frame is an error (section 7.3), which breaks only a
31+program that read memory already gone.
3032
3133 The language is frozen, softly, from this version on: it changes only
3234 to mend a defect, and its library grows only by what breaks no program
@@ -1034,6 +1036,26 @@
10341036 procedure with results that runs off its end returns zeros, each result
10351037 as a variable of its type starts (section 4).
10361038
1039+A slice returned must not point into the procedure's own frame, which
1040+is gone once it returns. It is an error to return, as a slice, a local
1041+array, a value parameter that is an array, or an array literal, or a
1042+slice of one, a field or an element of one included:
1043+
1044+```
1045+proc short(h: Hex): []U8; (* Hex = [64]U8 *)
1046+begin
1047+ return h[0..8]; (* an error: h is the procedure's copy *)
1048+end;
1049+```
1050+
1051+A slice of a `var` parameter, of a module variable, or of what a
1052+pointer points at may be returned: none of them is this procedure's
1053+frame. A slice of a frame that leaves it some other way isn't caught,
1054+and is the exception of section 10: one held in a local slice
1055+variable, or in a record, that is returned; one stored in a module
1056+variable or through a pointer; and one that came back from a call, as
1057+the slice of a `var` parameter does to the caller whose local it is.
1058+
10371059 ### 7.4 Match
10381060
10391061 ```
@@ -1459,8 +1481,9 @@
14591481 and indexing arrays and slices is checked, so a program's behaviour is
14601482 defined by this report, with one exception: memory reached other than
14611483 through a checked variable. Dereferencing a stale or made-up pointer,
1462-indexing through a pointer, an index out of range in a module that
1463-says `check off;`, writing a string's bytes, a code procedure that
1484+indexing through a pointer, a slice kept after the call whose frame
1485+holds what it points at (section 7.3), an index out of range in a
1486+module that says `check off;`, writing a string's bytes, a code procedure that
14641487 breaks its rules, and C code can read or write any memory, and what
14651488 follows isn't defined. Dereferencing `nil`, dividing
14661489 by zero, calling a `nil` procedure and running out of stack stop the
@@ -1565,7 +1588,7 @@
15651588 language, reals aside, is the core of the library: `Rt`, `Out`, `Mem`,
15661589 `Arena`, `Lock`, `Str` and `Buf`, and of `Sys` what they need. A program
15671590 that keeps to the core runs on every target. The rest of the library
1568-(`Heap`, `Fmt`, `List`, `Map`, `Sort`, `Math`, `Files`, `Opt` and the
1591+(`Heap`, `Fmt`, `List`, `Map`, `Vec`, `Sort`, `Math`, `Files`, `Opt` and the
15691592 rest of `Sys`) is the standard library: a target may leave a module
15701593 out, and one that has it gives what `doc/raz-lib.md` says. `conform/` tests
15711594 the core only.

doc/report-history.md (history) modified +9 -0

@@ -151,3 +151,12 @@
151151 appendix B). It breaks no program. `Sys` gains `position`,
152152 `truncate`, `sync` and `infoOf`; `Opt` gains `at`, where the
153153 operands are (volume 2).
154+- **2026-10.27.** A defect mended: returning, as a slice, a local
155+ array, a value parameter that is an array, an array literal, or a
156+ slice, field or element of one, is an error, since the frame it
157+ points into is gone once the procedure returns (section 7.3); what
158+ isn't caught is named among the exceptions of section 10. `Sys`
159+ gains `openMode`, `syncAll`, `lock`, `linkInfo` and `Info.ino`;
160+ `Buf` gains `spare`, and its `add` and `str` stop the program when
161+ memory runs out rather than dropping bytes; the standard library
162+ gains `Vec`, a growable array (volume 2).