From 4402a6820a5a40f7d98b7abe9478b792dd1a2f38 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:34:49 +0000 Subject: [PATCH] Report 2026-10.37 is the rule: the old forms are errors, -strict and RAZ_STRICT gone What SYSTEM fences is refused outside a module that imports it, and extern, link, check off and code procedures are said and read on, so a missing import is one error; the bare ADR, PTR, SYSCALL and ARGV, an atomic given a pointer, a string or a constant's slice into a []U8, and MSG into one are refused with help. The old branches are gone from Item and Parse. conform/err gains a test of each. --- diff --git a/CLAUDE.md b/CLAUDE.md index d971929..bbb3a3a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -95,8 +95,9 @@ mode. Every old form is still taken: a literal into a `[]U8`, the bare built-ins, what `SYSTEM` fences without it, an atomic given `ADR(x)`. `BOOT` names v0.23.0 (2026-10-26), so `src/` and the library it imports -may use all of 10.37; v0.24.0 makes the old forms errors and mends -`~/r`. CI couldn't run for it either; `make dist` made its tarball here. +may use all of 10.37. On main since 2026-10-26, for v0.24.0, the old +forms are errors, and `lib/`, `src/`, the tools and the tests are +mended; the programs in `~/r` come next. CI couldn't run for it either; `make dist` made its tarball here. v0.22.0, report 2026-10.36, before it, is the twelfth thaw, what `PROPOSALS.md` collated: `MIN`, `MAX`, `ABS`, `CLZ`, `CTZ`, `POPCOUNT`, `INT(b)`, `OFFSET`, `SIZE(T.f)`, `BYTES` and `FILL`; a qualified case in an arm, @@ -386,18 +387,15 @@ - `CAS(v, old, new)`, `XCHG(v, x)` and `XADD(v, x)` (report 2026-10.37) take a variable, whose address is pushed as `ADR`'s is (`atomic`); a local named in one is kept out of a register, as for `ADR` - (`chooseRegs`). A pointer that isn't a variable, `ADR(x)`, is still - taken as the old form until v0.24.0; a pointer variable is the new - form, so `XADD(p, 1)` is an error whose help says `p^`. -- `raz -strict` (temporary, until v0.24.0 makes it the default) refuses - every old form of report 2026-10.37: see `doc/compiler.md`. The - library and every program are mended against it first. + (`chooseRegs`). A pointer that isn't a variable, `ADR(x)`, is refused + with help, and so is a pointer variable, `XADD(p, 1)`, whose help says + `p^`. - `import SYSTEM` (report 2026-10.37) binds to `Sym.system`, no file, whose scope holds `ADR`, `PTR`, `SYSCALL` and `ARGV`; it is never - warned of as unused, and an alias is refused. In v0.23.0 nothing is - fenced yet: the bare built-ins, pointer arithmetic and conversions, - views, `extern`, `link`, code procedures and `check off;` are taken - in any module, until v0.24.0. + warned of as unused, and an alias is refused. What it fences + (`Item.needSystem`, `doc/compiler.md`) is refused elsewhere: `extern`, + `link`, code procedures and `check off;` are said and read on, so one + missing import is one error. - `[]const T` (report 2026-10.37) is a slice type with `rdonly` set: not the same as `[]T`, which goes into it with no code (`coerce`), never back (help says why). An element read through one has the item's @@ -406,9 +404,10 @@ and `FILL` refuse one as their destination (`destSlice`); a slice of one, or of an array read through one or of another module's array, is one (`slice`); `BYTES` of one is a `[]const U8`; `match` on an - element gives names only read. Until v0.24.0 a string literal, a - constant's slice, `MSG` and a `const` parameter's array keep their - old types, `[]U8` and `[]T`. + element gives names only read. A string literal (`tConstBytes` where + indexed), a constant's slice (`ofConst`), `MSG` and a slice of a + `const` parameter's array are `[]const`; a constant's slice part must + be declared `[]const`. - `ROL(x, n)` and `ROR(x, n)` (report 2026-10.35) are done at `x`'s own width, `rol al, cl` for a `U8`, with no mask of the count: x86 takes it modulo 32 or 64, and a byte's or a word's rotation goes diff --git a/PLAN.md b/PLAN.md index bafda7a..f20b148 100644 --- a/PLAN.md +++ b/PLAN.md @@ -92,7 +92,9 @@ and v0.23.0; 35 pages. No rewriting tool, by the owner's word: v0.24.0's errors point at each place to mend. 3. `BOOT` moved to v0.23.0, a step of its own. **Done** 2026-10-26. -4. **v0.24.0, which enforces it.** `lib/`, `src/`, `tools/`, +4. **v0.24.0, which enforces it.** Steps 1 to 3 done 2026-10-26: `raz -strict` + first, `lib/`, `src/`, the tools and tests mended against it by + agents, then the old forms made errors and the option gone. `lib/`, `src/`, `tools/`, `examples/` and the tests mended where the old forms, made errors, are found (`ADR` at a parameter only dereferenced becomes `var` or `const`; `SYSTEM.` where an address is kept); the programs in `~/r` diff --git a/conform/err/AtomicPointer.raz b/conform/err/AtomicPointer.raz new file mode 100644 index 0000000..9129354 --- /dev/null +++ b/conform/err/AtomicPointer.raz @@ -0,0 +1,12 @@ +(* An atomic takes the variable, not a pointer to it (report 6.8). *) +module AtomicPointer; +import SYSTEM; + +var n: INT; + +proc main*; +begin + _ := XADD(SYSTEM.ADR(n), 1); +end; + +end AtomicPointer. diff --git a/conform/err/ConstArrayToSlice.raz b/conform/err/ConstArrayToSlice.raz new file mode 100644 index 0000000..6541f75 --- /dev/null +++ b/conform/err/ConstArrayToSlice.raz @@ -0,0 +1,13 @@ +(* A slice of an array constant is a []const T (report 4). *) +module ConstArrayToSlice; + +const Primes: [3]INT = [2, 3, 5]; + +proc main*; +var s: []INT; +begin + s := Primes; + s[0] := 0; +end; + +end ConstArrayToSlice. diff --git a/conform/err/MsgToSlice.raz b/conform/err/MsgToSlice.raz new file mode 100644 index 0000000..b661138 --- /dev/null +++ b/conform/err/MsgToSlice.raz @@ -0,0 +1,13 @@ +(* An error's message is a []const U8 (report 6.8). *) +module MsgToSlice; + +const Oops: ERROR = "oops"; + +proc main*; +var s: []U8; +begin + s := MSG(Oops); + s[0] := 0; +end; + +end MsgToSlice. diff --git a/conform/err/StringToSlice.raz b/conform/err/StringToSlice.raz new file mode 100644 index 0000000..4091a4e --- /dev/null +++ b/conform/err/StringToSlice.raz @@ -0,0 +1,12 @@ +(* A string is a []const U8, and doesn't go into a []U8, which could + write its constant bytes (report 5.10). *) +module StringToSlice; + +proc main*; +var s: []U8; +begin + s := "abc"; + s[0] := 0; +end; + +end StringToSlice. diff --git a/conform/err/SystemArith.raz b/conform/err/SystemArith.raz new file mode 100644 index 0000000..9be2a4a --- /dev/null +++ b/conform/err/SystemArith.raz @@ -0,0 +1,14 @@ +(* A pointer moved by arithmetic needs import SYSTEM (report 3, 6.4). *) +module SystemArith; + +proc next(p: ^INT): ^INT; +begin + return p + 1; +end; + +proc main*; +begin + _ := next(nil); +end; + +end SystemArith. diff --git a/conform/err/SystemBareAdr.raz b/conform/err/SystemBareAdr.raz new file mode 100644 index 0000000..e1c7ab1 --- /dev/null +++ b/conform/err/SystemBareAdr.raz @@ -0,0 +1,13 @@ +(* ADR is SYSTEM.ADR, in a module that imports SYSTEM (report 3, 6.8). *) +module SystemBareAdr; + +var n: INT; + +proc main*; +var p: ^INT; +begin + p := ADR(n); + p^ := 1; +end; + +end SystemBareAdr. diff --git a/conform/err/SystemCheckOff.raz b/conform/err/SystemCheckOff.raz new file mode 100644 index 0000000..f1a3d71 --- /dev/null +++ b/conform/err/SystemCheckOff.raz @@ -0,0 +1,9 @@ +(* check off; needs import SYSTEM (report 3). *) +module SystemCheckOff; +check off; + +proc main*; +begin +end; + +end SystemCheckOff. diff --git a/conform/err/SystemConvert.raz b/conform/err/SystemConvert.raz new file mode 100644 index 0000000..d574860 --- /dev/null +++ b/conform/err/SystemConvert.raz @@ -0,0 +1,11 @@ +(* An integer made a pointer needs import SYSTEM (report 3, 6.7). *) +module SystemConvert; + +proc main*; +var p: ^INT; +begin + p := ^INT(4096); + p^ := 0; +end; + +end SystemConvert. diff --git a/conform/err/SystemExtern.raz b/conform/err/SystemExtern.raz new file mode 100644 index 0000000..bfbf66e --- /dev/null +++ b/conform/err/SystemExtern.raz @@ -0,0 +1,11 @@ +(* A procedure of C needs import SYSTEM (report 3, 9). *) +module SystemExtern; + +extern proc getpid(): I32; + +proc main*; +begin + _ := getpid(); +end; + +end SystemExtern. diff --git a/doc/compiler.md b/doc/compiler.md index 8d6f893..2607fc0 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -1,6 +1,6 @@ # Reading the raz compiler -The compiler is eleven files of raz, about 12,600 lines of code (the +The compiler is eleven files of raz, about 12,700 lines of code (the budget is 14,000). It is its own compiler: a release of it, the one `BOOT` names, builds `src/`, and `make fixpoint` checks that what it makes makes itself again, byte for byte. Each release was built by the @@ -16,17 +16,17 @@ | File | Lines | Code | What | |---|---|---|---| -| `src/Diag.raz` | 422 | 324 | Messages: positions, source excerpts, colour, counts | -| `src/Scan.raz` | 1,169 | 965 | Symbols, literals, comments, positions | -| `src/Sym.raz` | 792 | 633 | Types, objects, scopes, layout | -| `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes | -| `src/X64.raz` | 1,620 | 1,329 | The instruction encoder, jumps within a procedure, the assembler | -| `src/Gen.raz` | 2,840 | 1,986 | The stack machine, for x86-64: values, operations, checks, calls, frames | -| `src/Item.raz` | 2,501 | 2,006 | Items: types, constants, variables, operators, conversions, calls | -| `src/Parse.raz` | 4,797 | 4,084 | Declarations, statements, expressions, built-ins, recovery, warnings | -| `src/Link.raz` | 407 | 315 | Tree shaking, layout, patching, the places | -| `src/Elf.raz` | 449 | 355 | Static and dynamic ELF, symbol table, line numbers | -| `src/Raz.raz` | 418 | 333 | The command line | +| `src/Diag.raz` | 423 | 325 | Messages: positions, source excerpts, colour, counts | +| `src/Scan.raz` | 1,170 | 966 | Symbols, literals, comments, positions | +| `src/Sym.raz` | 815 | 652 | Types, objects, scopes, layout | +| `src/Chunk.raz` | 364 | 280 | The compiled program: chunks, fixups, line notes | +| `src/X64.raz` | 1,621 | 1,330 | The instruction encoder, jumps within a procedure, the assembler | +| `src/Gen.raz` | 2,841 | 1,987 | The stack machine, for x86-64: values, operations, checks, calls, frames | +| `src/Item.raz` | 2,553 | 2,051 | Items: types, constants, variables, operators, conversions, calls | +| `src/Parse.raz` | 4,806 | 4,093 | Declarations, statements, expressions, built-ins, recovery, warnings | +| `src/Link.raz` | 408 | 316 | Tree shaking, layout, patching, the places | +| `src/Elf.raz` | 450 | 356 | Static and dynamic ELF, symbol table, line numbers | +| `src/Raz.raz` | 419 | 334 | The command line | Every file opens with a comment that says what it is, what it depends on and what it leaves out. Read those first; they are the map. @@ -1885,17 +1885,18 @@ which its type's fingerprint has. Last, modules, at the end of the file. `compileFile` reads one module. -`raz -strict`, until v0.24.0 makes it the rule, holds report 2026-10.37 -whole (`Item.strict`): `needSystem` refuses, in a module whose -`Sym.Module.system` isn't set, a pointer's arithmetic, indexing and +What report 2026-10.37 fences behind `import SYSTEM` is refused by +`needSystem` in a module whose `Sym.Module.system` isn't set: a pointer's arithmetic, indexing and slicing, pointer and procedure conversions, views and `BYTES` that make or change an address (`Sym.isPlain`, the item's `viewOver`, checked in `notReadOnly`), a string as a `^U8`, `extern`, `link`, `check off` and -code procedures; `builtin` refuses `ADR`, `PTR`, `SYSCALL` and `ARGV` -not reached through `SYSTEM` (their objects' `home` tells them apart); -a string, a slice of a constant, `MSG` and a slice of a `const` -parameter's array are `[]const`; and an atomic given a pointer is -refused. +code procedures (the last four reported and the declaration read on, +so that one missing import is one error). `builtin` refuses `ADR`, +`PTR`, `SYSCALL` and `ARGV` not reached through `SYSTEM` (their +objects' `home` tells them apart). A string, a slice of a constant, +`MSG` and a slice of a `const` parameter's array are `[]const`. raz +0.23 took all of it, under an option `-strict` to refuse it while the +library and the programs were mended; 0.24 has no other way. `import SYSTEM` (report 2026-10.37) finds no file: the import binds the name to `Sym.system`, a module made once in `Sym`'s body whose scope @@ -1904,8 +1905,7 @@ export and `builtin` compiles it as `ADR`. It is marked used at the import, since a module may import it only for `extern` or `link`. An alias, `import S := SYSTEM`, is refused, so a grep finds every such -module. Until v0.24.0 nothing needs it: the bare built-ins and the rest -it fences are still taken anywhere. +module. `importModule` finds a module's file, trying the target's names first, and compiles it if it isn't yet. A module found in an `-I` or @@ -1990,7 +1990,7 @@ does: `atomic` pushes its address, as `ADR` would, and `Gen.atomic` works through it as before, so the code is the same as for `XADD(ADR(n), 1)`. A first argument that is a pointer but no variable, -`ADR(n)`, is the form before 10.37, kept until v0.24.0. Since the +`ADR(n)`, the form before 10.37, is refused with help. Since the address is taken, `chooseRegs` keeps a local named in one in memory, as it does one named in `ADR`. diff --git a/doc/raz.md b/doc/raz.md index 7291b6b..050b2d9 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -76,7 +76,7 @@ 10 says what is left undefined outside such modules. It breaks a program that gives an atomic a pointer, writes through a string or a constant, or does what `SYSTEM` holds without importing it; raz 0.23 -still takes all of these as before, until 0.24. +still took them, as before; raz 0.24 doesn't. The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program diff --git a/doc/report-history.md b/doc/report-history.md index d031c26..04a342e 100644 --- a/doc/report-history.md +++ b/doc/report-history.md @@ -268,15 +268,15 @@ And `CAS`, `XCHG` and `XADD` take the variable they work on, as `INC` does, not a pointer to it (section 6.8): `XADD(count, 1)`, `XADD(p^, 1)`. It breaks a program that gives them a pointer; raz - 0.23 still takes one that isn't a variable, `ADR(x)`, until 0.24. + 0.23 still took one that isn't a variable, `ADR(x)`; 0.24 doesn't. And `[]const T`, a slice whose elements can't be written through it (section 5.3): a `[]T` or an array goes where one is wanted, never the other way. A string literal and a slice of a constant are `[]const`, as `MSG` and a slice of a `const` parameter's array are, so writing them is an error, not undefined; another module's exported array may be read as one (sections 3, 4, 5.10, 6.8 and 8). It breaks - a program that writes through these; raz 0.23 still gives them their - old types until 0.24. + a program that writes through these; raz 0.23 still gave them their + old types; 0.24 doesn't. And `import SYSTEM` (section 3): a module the language gives, with no file, that a module imports, by that name only, to reach memory other than through its variables: `SYSTEM.ADR`, `SYSTEM.PTR`, @@ -287,4 +287,4 @@ and 9). Section 10 says what is left undefined outside such modules, and 7.6 that a race on a pointer, a slice or a variant is undefined. It breaks every module that does these without it; raz 0.23 still - takes them, and the built-ins unprefixed, until 0.24. + took them, and the built-ins unprefixed; 0.24 doesn't. diff --git a/src/Item.raz b/src/Item.raz index 8530c82..94917a7 100644 --- a/src/Item.raz +++ b/src/Item.raz @@ -84,8 +84,6 @@ procedure is compiled again, the variable in memory *) checks*: BOOL; (* the module's index and slice checks are made: it doesn't say check off *) - strict*: BOOL; (* raz -strict: report 2026-10.37 held whole, as v0.24.0 - will hold it; until then, its old forms are taken *) result: ^Sym.Type; (* the result of the procedure being compiled, or nil *) passing: ^Sym.Obj; (* the parameter the argument at passingAt goes to *) passingAt: Diag.Pos; @@ -100,11 +98,6 @@ checks := yes; end; -proc setStrict*(yes: BOOL); -begin - strict := yes; -end; - (* The comparison that holds when op doesn't *) proc negated(op: Scan.Sym): Scan.Sym; begin @@ -138,12 +131,11 @@ return Diag.say(f, [Fmt.str(a)]); end; -(* Under -strict, what reaches memory other than through a variable, - what, is refused at pos in a module that doesn't import SYSTEM - (report 3) *) +(* What reaches memory other than through a variable, what, is refused + at pos in a module that doesn't import SYSTEM (report 3) *) proc needSystem*(pos: Diag.Pos; what: []const U8): ERROR; begin - if strict and not Sym.curModule^.system then + if not Sym.curModule^.system then return Scan.markHelp(pos, say1("{} needs import SYSTEM", what), "it reaches memory other than through a variable: say import SYSTEM after the module's imports"); end; @@ -641,7 +633,7 @@ if x.mode = mCond then try value(x); end; s := x.typ; if x.mode = mStr then - if strict and (t^.form = Sym.fSlice) and (t^.base = Sym.tU8) and not t^.rdonly then + if (t^.form = Sym.fSlice) and (t^.base = Sym.tU8) and not t^.rdonly then return mismatchHelp(x, say1("a string is a []const U8, not {}", Sym.typeName(t)), "its bytes are constant: take a []const U8 where they are only read, or copy them"); end; @@ -683,10 +675,10 @@ return mismatchHelp(x, say2("can't use {} as {}", Sym.typeName(s), Sym.typeName(t)), "its elements are only read, and a []T could write them"); elsif (s^.form = Sym.fArray) and (t^.form = Sym.fSlice) and Sym.same(s^.base, t^.base) then - (* a slice of what is only read may be made, to read, as of a - constant; another module's array, or one read through a - []const, only as a []const *) - if strict and (onlyRead(x) or ofConst(x)) and not t^.rdonly then + (* a slice of what is only read, a constant or a const parameter, + another module's array, or one read through a []const, is made + only as a []const *) + if (onlyRead(x) or ofConst(x)) and not t^.rdonly then return mismatchHelp(x, say2("can't use {} as {}", Sym.typeName(s), Sym.typeName(t)), say1("{} is only read: a slice of it is a []const", Diag.source(x.pos))); end; @@ -695,7 +687,7 @@ [Fmt.str(Diag.source(x.pos)), Fmt.str(Scan.nameOf(x.obj^.home^.name))]), say1("it may be read as a {}", Sym.typeName(constOf(t)))); end; - if not onlyRead(x) and not t^.rdonly then try notReadOnly(x); end; + if not t^.rdonly then try notReadOnly(x); end; if x.vol then return Scan.markAt(x.pos, "can't make a slice through a volatile pointer"); end; if x.odd then return Scan.markAt(x.pos, "can't make a slice of a field of a packed record"); end; if x.view then return noAddress(x, "can't make a slice of a view"); end; @@ -805,7 +797,7 @@ begin nilTest(x); if x.mode = mStr then - if strict then try coerce(x, Sym.tConstBytes); else try coerce(x, Sym.tBytes); end; + try coerce(x, Sym.tConstBytes); end; if (x.typ^.form = Sym.fPtr) and (x.typ^.base^.form = Sym.fArray) then return Scan.markAt(x.pos, "a pointer to an array is indexed as p^[i]"); @@ -891,7 +883,7 @@ []const, is a []const; of a const parameter's, a slice to read *) roSlice := (t^.form = Sym.fSlice) and t^.rdonly; if t^.form = Sym.fArray then - roSlice := (x.ro and not onlyRead(x)) or x.elemRo or (strict and (onlyRead(x) or ofConst(x))); + roSlice := x.ro or x.elemRo or ofConst(x); (* x.ro: another module's, or a const parameter's *) end; if t^.form = Sym.fPtr then try needSystem(x.pos, "a slice of a pointer"); end; try value(hi); @@ -2554,7 +2546,7 @@ try value(x); s := Gen.allocTemp(16, 8); Gen.errorText(s); - if strict then tempItem(x, Sym.tConstBytes, s); else tempItem(x, Sym.tBytes, s); end; (* the message is constant *) + tempItem(x, Sym.tConstBytes, s); (* the message is constant *) return nil; end; diff --git a/src/Parse.raz b/src/Parse.raz index 0e2d5b7..eeaf29a 100644 --- a/src/Parse.raz +++ b/src/Parse.raz @@ -1103,45 +1103,34 @@ end; (* CAS(v, old, new), XCHG(v, x) or XADD(v, x) (report 6.8): v is a - variable, whose address goes on the stack, as ADR's would. A pointer - that isn't a variable, ADR(v) say, is the form before report - 2026-10.37, still taken: what it points at is the variable. *) + variable, whose address goes on the stack, as ADR's would. Before + report 2026-10.37 they took a pointer to it, ADR(v): the error says + so. *) proc atomic(var x: TItem; which: INT): ERROR; var p, a: TItem; t: PType; i, n: INT; begin try expression(p, nil); - if (p.mode = Item.mVar) and p.isVar then - t := p.typ; - if not atomicType(t, which) then - if (t^.form = Sym.fPtr) and atomicType(t^.base, which) then - return Scan.markHelp(p.pos, say1("{} works on an INT or a UINT variable, not a pointer", atomicName(which)), - say1("for what the pointer points at, write {}^", Diag.source(p.pos))); - elsif which = Sym.bXadd then - return Scan.markAt(p.pos, say1("expected an INT or a UINT variable, found {}", Item.what(p))); - end; - return Scan.markAt(p.pos, say1("expected an INT, a UINT or a pointer variable, found {}", Item.what(p))); - end; - try Item.notReadOnly(p); - if p.odd then return Scan.markAt(p.pos, "a field of a packed record has no address"); end; - if p.view then return Item.noAddress(p, "an atomic can't take a view"); end; - try Item.address(p); - else - if p.typ^.form # Sym.fPtr then - return Scan.markAt(p.pos, say1("expected a variable, found {}", Item.what(p))); - end; - if Item.strict then + if (p.mode # Item.mVar) or not p.isVar then + if p.typ^.form = Sym.fPtr then return Scan.markHelp(p.pos, say1("{} takes a variable, not a pointer to it", atomicName(which)), "give it the variable itself: XADD(n, 1), or XADD(p^, 1) through a pointer"); end; - t := p.typ^.base; - if not atomicType(t, which) then - if which = Sym.bXadd then - return Scan.markAt(p.pos, say1("expected a pointer to an INT or a UINT, found {}", Sym.typeName(p.typ))); - end; - return Scan.markAt(p.pos, say1("expected a pointer to an INT, a UINT or a pointer, found {}", Sym.typeName(p.typ))); + return Scan.markAt(p.pos, say1("expected a variable, found {}", Item.what(p))); + end; + t := p.typ; + if not atomicType(t, which) then + if (t^.form = Sym.fPtr) and atomicType(t^.base, which) then + return Scan.markHelp(p.pos, say1("{} works on an INT or a UINT variable, not a pointer", atomicName(which)), + say1("for what the pointer points at, write {}^", Diag.source(p.pos))); + elsif which = Sym.bXadd then + return Scan.markAt(p.pos, say1("expected an INT or a UINT variable, found {}", Item.what(p))); end; - try Item.value(p); + return Scan.markAt(p.pos, say1("expected an INT, a UINT or a pointer variable, found {}", Item.what(p))); end; + try Item.notReadOnly(p); + if p.odd then return Scan.markAt(p.pos, "a field of a packed record has no address"); end; + if p.view then return Item.noAddress(p, "an atomic can't take a view"); end; + try Item.address(p); if which = Sym.bCas then n := 2; else n := 1; end; for i := 1 to n do try expect(Scan.sComma); @@ -1265,7 +1254,7 @@ var which, n, start: INT; y: TItem; t: PType; f: PObj; at: Diag.Pos; begin which := INT(x.obj^.val); - if Item.strict and (x.obj^.home # Sym.system) + if (x.obj^.home # Sym.system) and ((which = Sym.bAdr) or (which = Sym.bPtr) or (which = Sym.bSyscall) or (which = Sym.bArgv)) then return Scan.markHelp(x.pos, say2("{} is SYSTEM's, and written SYSTEM.{}", nameOf(x.obj^.name), nameOf(x.obj^.name)), "say import SYSTEM after the module's imports, and write the name after SYSTEM."); @@ -3551,7 +3540,7 @@ end; p^.fwd := false; if Scan.tok = Scan.sCode then - try Item.needSystem(Scan.tokPos(), "a code procedure"); + _ := Item.needSystem(Scan.tokPos(), "a code procedure"); (* said, and the declaration read on *) Scan.next; p^.isCode := true; try codeBody(p, sig, at); @@ -3576,7 +3565,7 @@ proc externDecl: ERROR; var n: INT; exp: BOOL; o, q: PObj; t: PType; at: Diag.Pos; begin - try Item.needSystem(Scan.tokPos(), "extern"); + _ := Item.needSystem(Scan.tokPos(), "extern"); (* said, and the declaration read on *) Scan.next; Sym.curModule^.usesC := true; if Scan.tok = Scan.sProc then @@ -3789,7 +3778,7 @@ return Scan.mark(say1("expected {}, found an array literal", Sym.typeName(t))); end; try expression(e, t); - if Item.strict and (t^.form = Sym.fSlice) and not t^.rdonly then + if (t^.form = Sym.fSlice) and not t^.rdonly then return Scan.markHelp(e.pos, say1("a constant's slice is a []const, not {}", Sym.typeName(t)), "a constant can't be changed: declare the slice []const"); end; @@ -4444,7 +4433,7 @@ if (Scan.tok = Scan.sIdent) and (Scan.id = nameStatic) then m^.linkStatic := true; elsif Scan.tok = Scan.sString then - try Item.needSystem(Scan.tokPos(), "a link of a library"); + _ := Item.needSystem(Scan.tokPos(), "a link of a library"); (* said, and the declaration read on *) NEW(lib, Heap.heap); lib^.name := internName(Scan.strBytes()); lib^.next := m^.libs; @@ -4459,7 +4448,7 @@ (* check off;: the module's index and slice checks left out; neither word is reserved *) if (Scan.tok = Scan.sIdent) and (Scan.id = nameCheck) then - try Item.needSystem(Scan.tokPos(), "check off"); + _ := Item.needSystem(Scan.tokPos(), "check off"); (* said, and the declaration read on *) Scan.next; if (Scan.tok # Scan.sIdent) or (Scan.id # nameOff) then return nil, expected("\"off\""); end; Scan.next; diff --git a/src/Raz.raz b/src/Raz.raz index 6f22dae..11b9b3c 100644 --- a/src/Raz.raz +++ b/src/Raz.raz @@ -29,7 +29,7 @@ Leaves out: the work itself; the other units compile, link and write, and this only reads the command line and runs them in order. *) module Raz; -import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Item, Parse, Link, Elf; +import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf; import SYSTEM; const @@ -259,9 +259,6 @@ bare := false; listing := false; libcSaid := false; - (* until v0.24.0, RAZ_STRICT=1 is -strict for every compile, so that a - whole test run can be made strict *) - if Sys.env("RAZ_STRICT") = "1" then Item.setStrict(true); end; run := (ARGC() >= 2) and (Files.arg(1) = "run"); if run then i := 2; else i := 1; end; while i < ARGC() do @@ -275,9 +272,6 @@ outPath := Files.arg(i); elsif s = "-Werror" then Diag.setWerror(true); - elsif s = "-strict" then - (* until v0.24.0: report 2026-10.37 held whole, its old forms refused *) - Item.setStrict(true); elsif s = "-S" then listing := true; X64.setListing(true); diff --git a/test/msg/AtomicPointer.err b/test/msg/AtomicPointer.err new file mode 100644 index 0000000..c7315cf --- /dev/null +++ b/test/msg/AtomicPointer.err @@ -0,0 +1,5 @@ +conform/err/AtomicPointer.raz:9:15: error: XADD takes a variable, not a pointer to it + 9 | _ := XADD(SYSTEM.ADR(n), 1); + | ^^^^^^^^^^^^^ +help: give it the variable itself: XADD(n, 1), or XADD(p^, 1) through a pointer +raz: 1 error diff --git a/test/msg/ConstArrayToSlice.err b/test/msg/ConstArrayToSlice.err new file mode 100644 index 0000000..2ca331e --- /dev/null +++ b/test/msg/ConstArrayToSlice.err @@ -0,0 +1,5 @@ +conform/err/ConstArrayToSlice.raz:9:10: error: can't use [3]INT as []INT + 9 | s := Primes; + | ^^^^^^ +help: Primes is only read: a slice of it is a []const +raz: 1 error diff --git a/test/msg/MsgToSlice.err b/test/msg/MsgToSlice.err new file mode 100644 index 0000000..fa7ba52 --- /dev/null +++ b/test/msg/MsgToSlice.err @@ -0,0 +1,5 @@ +conform/err/MsgToSlice.raz:9:10: error: can't use []const U8 as []U8 + 9 | s := MSG(Oops); + | ^^^^^^^^^ +help: its elements are only read, and a []T could write them +raz: 1 error diff --git a/test/msg/StringToSlice.err b/test/msg/StringToSlice.err new file mode 100644 index 0000000..bdfa503 --- /dev/null +++ b/test/msg/StringToSlice.err @@ -0,0 +1,5 @@ +conform/err/StringToSlice.raz:8:10: error: a string is a []const U8, not []U8 + 8 | s := "abc"; + | ^^^^^ +help: its bytes are constant: take a []const U8 where they are only read, or copy them +raz: 1 error diff --git a/test/msg/SystemArith.err b/test/msg/SystemArith.err new file mode 100644 index 0000000..8d8a5e7 --- /dev/null +++ b/test/msg/SystemArith.err @@ -0,0 +1,5 @@ +conform/err/SystemArith.raz:6:12: error: a pointer's arithmetic needs import SYSTEM + 6 | return p + 1; + | ^^^^^ +help: it reaches memory other than through a variable: say import SYSTEM after the module's imports +raz: 1 error diff --git a/test/msg/SystemBareAdr.err b/test/msg/SystemBareAdr.err new file mode 100644 index 0000000..dcbf1e4 --- /dev/null +++ b/test/msg/SystemBareAdr.err @@ -0,0 +1,5 @@ +conform/err/SystemBareAdr.raz:9:10: error: ADR is SYSTEM's, and written SYSTEM.ADR + 9 | p := ADR(n); + | ^^^ +help: say import SYSTEM after the module's imports, and write the name after SYSTEM. +raz: 1 error diff --git a/test/msg/SystemCheckOff.err b/test/msg/SystemCheckOff.err new file mode 100644 index 0000000..b4a37d6 --- /dev/null +++ b/test/msg/SystemCheckOff.err @@ -0,0 +1,5 @@ +conform/err/SystemCheckOff.raz:3:1: error: check off needs import SYSTEM + 3 | check off; + | ^^^^^ +help: it reaches memory other than through a variable: say import SYSTEM after the module's imports +raz: 1 error diff --git a/test/msg/SystemConvert.err b/test/msg/SystemConvert.err new file mode 100644 index 0000000..b160d28 --- /dev/null +++ b/test/msg/SystemConvert.err @@ -0,0 +1,5 @@ +conform/err/SystemConvert.raz:7:15: error: a conversion to ^INT needs import SYSTEM + 7 | p := ^INT(4096); + | ^^^^ +help: it reaches memory other than through a variable: say import SYSTEM after the module's imports +raz: 1 error diff --git a/test/msg/SystemExtern.err b/test/msg/SystemExtern.err new file mode 100644 index 0000000..b4b0230 --- /dev/null +++ b/test/msg/SystemExtern.err @@ -0,0 +1,5 @@ +conform/err/SystemExtern.raz:4:1: error: extern needs import SYSTEM + 4 | extern proc getpid(): I32; + | ^^^^^^ +help: it reaches memory other than through a variable: say import SYSTEM after the module's imports +raz: 1 error