raz / commit ea111be3

commit
ea111be36218b9f464b829daffec145206626e8c
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
cfff918d
Proposal for report 2026-10.22: INT is I64, and no exported variables

patch · log

1 file changed, +126 -0

doc/proposal-10.22.md added +126 -0

@@ -0,0 +1,126 @@
1+# Proposal: report 2026-10.22
2+
3+Two changes that take rules out of the language. Neither adds a feature.
4+Nothing in `doc/raz.md` or the code changes until the owner approves
5+this; it is a thaw of the freeze (CLAUDE.md), so it needs the owner's
6+word.
7+
8+## 1. `INT` and `UINT` are names for `I64` and `U64`
9+
10+**Now.** `INT` and `I64` are two types of one size. An `INT` goes
11+silently into an `I64`, and the two never mix in an expression
12+(5.1, 5.10, 6.1). The widening applies to assignment, arguments and
13+`return n, m`, and not to `a, b := f(x)`, `return f(x)`, `for` or
14+`INC`/`DEC`. A program that holds an `I64` from a library next to a
15+length gets `I64 and INT are different types` (`conform/err/IntMix`).
16+
17+**Proposed.** `INT` is another name for `I64`, and `UINT` for `U64`,
18+as `type Count = I64;` already is (5.10). A target has 64-bit
19+addresses (appendix A no longer lets the target choose their size);
20+no target of this compiler has had any other.
21+
22+**Report text.**
23+
24+- 5.1: the table rows become `INT` = `I64` and `UINT` = `U64`. The
25+ paragraph after the table reads: "`INT` is the everyday integer:
26+ lengths, indexes and sizes are `INT`s. It is the integer a pointer
27+ converts to (6.7), and a word the atomic built-ins work on (6.8).
28+ `INT` is `I64`, `UINT` is `U64`." Drop "`INT` and `I64` are two
29+ types … which may drop bits on a smaller target" and "A type bigger
30+ than the largest `INT` in bytes is an error".
31+- 5.10: drop the last bullet (`INT` to `I64`), and the paragraph's
32+ "Results passed on whole need the same types exactly … an `INT`
33+ widens as above".
34+- 6.1: drop "whatever their sizes", and the example `i < LEN(s)`;
35+ "Two integer types of different names are one type if one is
36+ another name for the other" is already 5.10's rule. Drop "On a
37+ target whose `INT` is narrower, a pointer's offset is cut".
38+- Appendix A, "The target": drop "the size of an address, and so of
39+ `INT`".
40+
41+**What it costs.**
42+
43+- Every valid program stays valid and means the same. A program
44+ that had two procedures' types, or two generic instances, told
45+ apart by `INT` against `I64` now has one type (no such program is
46+ in `lib/`, `src/`, `examples/` or `tools/`).
47+- A target with 32-bit addresses is no longer expressible. None is
48+ planned.
49+- Messages say `I64` where they said `INT`; `test/msg` changes with
50+ them.
51+- `conform/err/IntMix` stops being an error and goes; `test/` gets
52+ the same for `UINT`. No new tests.
53+
54+**What it saves.** The compiler's `coerce` and its exact twin, the
55+list of places that widen and the list that don't, the `INT`/`UINT`
56+cases in constant folding and the `Results passed on whole` rule: an
57+estimated 150–250 lines in this compiler, and one rule fewer for
58+every reader.
59+
60+## 2. A variable is not exported
61+
62+**Now.** `var x*: T;` exports `x` read-only: other modules read it but
63+can't assign it, pass it by `var`, `INC` it, take its `ADR`, slice an
64+array in it or `match` it in place (3, "Exports"). The rule is one
65+paragraph and a handful of conditions in every place that names a
66+variable.
67+
68+**Proposed.** Only constants, types, procedures and the fields of
69+records are exported. `*` after a variable's name is an error: "a
70+variable isn't exported; export a procedure that returns its value".
71+A module shares state through procedures (`Heap.heap()` for
72+`Heap.heap`), or a pointer to the data.
73+
74+**Report text.**
75+
76+- 3, "Exports": replace the paragraph from "An exported variable can
77+ be read" to "…or a procedure that returns a slice of it." with "A
78+ variable can't be exported; a module shares its state by exporting
79+ procedures that read and change it."
80+- 5.x and appendix B: `*` is not part of the grammar of a variable's
81+ name.
82+- 12: drop "An exported variable can't be changed, passed by `var`
83+ or …" from 2026-10.x's entry; it describes a rule that is gone.
84+
85+**What it costs.** This one is real work in what is already written:
86+
87+- `lib/` has one exported variable, `Heap.heap`. It becomes
88+ `Heap.allocator()`.
89+- `src/` has some sixty, most of them the compiler's own state:
90+ `Scan.tok`, `Scan.ival`, `Chunk.pc`, `Gen.depth`, `Link.textOff`,
91+ `Diag.errors`, `Sym.tInt` and the like. Each becomes a procedure
92+ or, for a group, one record the module owns and exports a pointer
93+ to. The compiler reads `Scan.tok` in its inner loops; each read
94+ becomes a call (the compiler has no inliner; PLAN.md, "Next"),
95+ and the compiler's 650,000 lines a second would drop by an amount
96+ I haven't measured. That is the reason to weigh this change.
97+- A program that exports a variable no longer compiles. The fix is
98+ mechanical and the error says it.
99+- `conform/err/Export{Adr,AsSlice,Assign,Elem,Inc,Slice,VarParam}`,
100+ `NoteExport` and their `test/msg` twins become one test: that `*`
101+ on a variable is an error.
102+
103+**What it saves.** The read-only flag and its checks in `ADR`,
104+slicing, `var` arguments, `INC`, `NEW`, assignment and `match`, and
105+the message for each, in every implementation: an estimated 120–200
106+lines in this compiler, and eight of the 235 error tests.
107+
108+**An alternative that keeps most of the saving.** Keep exported
109+variables read-only, as now, and drop only the cases that need a
110+special rule: no array or record is exported by value (a module
111+exports a pointer to it, as the report already advises), so
112+"slice an array in it" and "`match` on a copy" can't arise. That
113+keeps `Scan.tok` and the compiler's speed, and removes the odd cases,
114+for about half the saving.
115+
116+## Order, if approved
117+
118+1. Report: `doc/raz.md` (the sections above and an entry in 12), the
119+ grammar in appendix B, `doc/compiler.md` where it names the rules.
120+2. `conform/` and `test/`: the tests named above.
121+3. The compiler: `src/`, one commit per step as CLAUDE.md says; then
122+ `make check`, `make fixpoint`, `make bench`.
123+4. Library and `src/` rewrites for change 2.
124+
125+Change 1 can go alone; change 2 should wait for a measurement of what
126+the accessors cost the compiler.