raz / commit 37e8670e

commit
37e8670e0db4341cb602a2cdb35f39d41af7c547
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
c5a9376e
Report 2026-10.28: an array a call returns lives to its statement's end

A defect mended, met writing libro: f()[0..4] kept in a variable read
what the next statement put in the temporary, though the report gave
the array no end. By the owner's choice the report now says what the
compiler does (section 8): the array lives to the end of the statement
the call is in, and a slice of it kept past that is undefined, among
section 10's exceptions. No code changes; raz says it follows
2026-10.28. The history tells Sys's gains since 10.27.

patch · log

6 files changed, +29 -45

CLAUDE.md modified +3 -0

@@ -219,6 +219,9 @@
219219 local slice variable or a record, stored, or come back from a call,
220220 isn't, and is left undefined (10). `ret` and `keep`, in
221221 PROPOSALS.md, would close it; the owner keeps it open for now.
222+- An array a call returns is a temporary of the statement (report
223+ 2026-10.28, 8): a slice of it kept past the statement is undefined
224+ (10), and isn't caught.
222225 - `Buf.add`, `str` and `spare`, and `Vec`'s growing, stop the program
223226 when the allocator has no room; `room` asks first.
224227 - An `extern` module variable is read-only for an importer, as the

PROPOSALS.md modified +0 -41

@@ -514,47 +514,6 @@
514514 that breaks no program; about ten lines, with a test in `Map`'s
515515 `main`.
516516
517-## A slice of an array a call returns, kept
518-
519-A defect, of the report or the compiler, not a wish. `f()[0..4]`, a
520-slice of the array a call returns, is a slice of a temporary of the
521-caller's: the compiler takes the array's place from `allocTemp`, and
522-`releaseTemps` gives it back at the end of the statement. Kept in a
523-variable, the slice outlives it, and reads what the next statement
524-puts there:
525-
526-```
527-proc f(c: U8): [8]U8;
528-var a: [8]U8; i: INT;
529-begin
530- for i := 0 to 7 do a[i] := c; end;
531- return a;
532-end;
533-
534-proc main*;
535-var s, t: []U8; i: INT;
536-begin
537- s := f('a')[0..4];
538- for i := 1 to 3 do t := f('b')[0..4]; end;
539- Out.str(s); Out.str(" "); Out.str(t); Out.ln; (* "bbbb" and four blanks *)
540-end;
541-```
542-
543-The report doesn't say how long a returned array lives. 7.3 makes
544-returning a slice of one an error, as it is the frame's; section 10
545-leaves undefined only "a slice kept after the call whose frame holds
546-what it points at", and `main`'s call hasn't ended. So by the report
547-`s` is good until `main` returns, and by the compiler it isn't.
548-
549-Either mend closes it: the report says the array lives to the end of
550-the statement, a slice kept past it undefined, with section 10's
551-list; or slicing an array a call returns, anywhere but as an argument
552-or in the expression it is used in, is an error, as 7.3's return of
553-one is. The second is what 7.3 already checks (`Item.frame`), at more
554-places; the first changes nothing but the report.
555-
556-Met writing libro, trying what the report allows; libro doesn't do it.
557-
558517 ## Enumerations' names, each its own
559518
560519 An enumeration's names are declared in the scope around its type

doc/compiler.md (history) modified +3 -0

@@ -1183,6 +1183,9 @@
11831183 the epilogue and patches the frame's size in. Within a statement,
11841184 scratch space comes from `allocTemp` and is given back by
11851185 `releaseTemps`; `allocPerm` reserves space for the whole procedure.
1186+An array a call returns is such a temporary, so it lives to the end of
1187+its statement, as the report says (section 8), and a slice of it kept
1188+past that reads what the next statement puts there.
11861189
11871190 Register variables: the parser chooses them (`chooseRegs`, in
11881191 Parse.raz), then gives the locals left in memory their slots

doc/raz.md (history) modified +16 -3

@@ -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.27 of the report; section 11 says where each
16+This is version 2026-10.28 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
@@ -28,7 +28,9 @@
2828 reads and writes the bytes of a variable as a `T` (section 6.9); it
2929 breaks no program. 2026-10.27 mends a defect: returning a slice of the
3030 procedure's own frame is an error (section 7.3), which breaks only a
31-program that read memory already gone.
31+program that read memory already gone. 2026-10.28 mends another: an
32+array a call returns lives to the end of its statement, and a slice of
33+it kept past that is undefined (sections 8 and 10).
3234
3335 The language is frozen, softly, from this version on: it changes only
3436 to mend a defect, and its library grows only by what breaks no program
@@ -1329,7 +1331,17 @@
13291331 procedure that can fail has an `ERROR` as its last result (section
13301332 5.8), which `try` passes on (section 7.8).
13311333
1334+An array a call returns lives to the end of the statement the call is
1335+in. A slice of it may be used there, indexed, passed or compared; one
1336+kept past the statement, in a variable or anywhere else, points at
1337+what is gone, and is the exception of section 10:
1338+
13321339 ```
1340+s := f('a')[0..4]; (* f returns a [8]U8: s is undefined after this *)
1341+Out.str(f('a')[0..4]); (* used in its statement: defined *)
1342+```
1343+
1344+```
13331345 module Divide;
13341346 import Out;
13351347
@@ -1483,7 +1495,8 @@
14831495 defined by this report, with one exception: memory reached other than
14841496 through a checked variable. Dereferencing a stale or made-up pointer,
14851497 indexing through a pointer, a slice kept after the call whose frame
1486-holds what it points at (section 7.3), an index out of range in a
1498+holds what it points at (section 7.3), a slice of an array a call
1499+returned kept past its statement (section 8), an index out of range in a
14871500 module that says `check off;`, writing a string's bytes, a code procedure that
14881501 breaks its rules, and C code can read or write any memory, and what
14891502 follows isn't defined. Dereferencing `nil`, dividing

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

@@ -160,3 +160,9 @@
160160 `Buf` gains `spare`, and its `add` and `str` stop the program when
161161 memory runs out rather than dropping bytes; the standard library
162162 gains `Vec`, a growable array (volume 2).
163+- **2026-10.28.** A defect mended: an array a call returns lives to the
164+ end of the statement the call is in, and a slice of it kept past
165+ that is undefined, among the exceptions of section 10 (section 8).
166+ `Sys` gains `entryKind` and `Info.dev`; `spawn` finds a name without
167+ a `/` along `PATH`; over the C library, `syncAll` of a file that
168+ isn't open is -9 (EBADF), as on Linux (volume 2).

src/Raz.raz (history) modified +1 -1

@@ -29,7 +29,7 @@
2929 import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf;
3030
3131 const
32- Report = "2026-10.27"; (* the version of doc/raz.md it follows *)
32+ Report = "2026-10.28"; (* the version of doc/raz.md it follows *)
3333 MemfdCreate = 319; (* the system call *)
3434 MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *)
3535 Execve = 59;