raz / commit 1d0597c6

commit
1d0597c6d2d1397fead67b87138ecacebd02af04
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
b88a1710
Report 2026-10.11: separate compilation is the implementation's

The report keeps what binds: an importer depends only on a module's
interface, and two instances with the same arguments are one (sec 3).
Object files, their currency and instance naming move to doc/ir.md;
an anonymous record may now be a type argument, named there by line
and column. PLAN's done-when says so.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

patch · log

3 files changed, +53 -43

PLAN.md (history) modified +4 -4

@@ -76,10 +76,10 @@
7676
7777 **Done when:** the report alone is enough to rebuild raz, with a
7878 conformance suite to say when a rebuild is done; the report has a
79-system integer, optional reals and object files; the compiler goes
80-through an IR, which is what an object file holds, and keeps its
81-values in registers as Wirth's compilers do; `make bench` still
82-passes; a new code budget is written down; `v0.6.0` is tagged.
79+system integer and optional reals, and leaves separate compilation to
80+the implementation; the compiler goes through an IR, which is what its
81+object files hold, and keeps its values in registers as Wirth's
82+compilers do; `make bench` still passes; a new code budget is written down; `v0.6.0` is tagged.
8383
8484 **Kept out:** a second back end (aarch64 is the milestone after, to
8585 measure a port); an optimiser; the wishes below.

doc/ir.md modified +29 -6

@@ -270,9 +270,11 @@
270270 1. **A header**: the module's name, the target, the version of this
271271 form, and the fingerprint of the module's interface.
272272 2. **Its imports**: each module it read the interface of, with that
273- interface's fingerprint when it was compiled. The object file is
274- current while each of those is still the one there, and its source
275- hasn't changed (report, section 10).
273+ interface's fingerprint when it was compiled, and each generic
274+ module it made an instance of, with the fingerprint of its whole
275+ source. The object file is current while each of those is still the
276+ one there, and its own source hasn't changed; when it isn't, the
277+ compiler compiles the module again from its source.
276278 3. **Its interface**: what it exports, as an importer needs it: its
277279 constants with their values, its types with their layouts, its
278280 variables, and its procedures' signatures. An importer reads this,
@@ -281,9 +283,8 @@
281283 as a size and an alignment; each string and `ERROR` as its bytes.
282284 A chunk is named, so that the linker finds it from other object
283285 files.
284-5. **Its instances**: each instance of a generic module it made, its
285- chunks named by the generic module, its arguments and the
286- fingerprints they were built from (report, section 10). The linker
286+5. **Its instances**: each instance of a generic module it made, from
287+ the generic module's source, its chunks named as below. The linker
287288 keeps one of each name.
288289 6. **Its places**: the lines of its statements and the places of its
289290 checks, for messages, the trap report and the debugger.
@@ -293,6 +294,28 @@
293294 is linked from object files alone: the linker reads them, marks what
294295 the entry point reaches (tree shaking, as today), hands each live
295296 procedure to the back end, and writes the executable.
297+
298+## Naming an instance
299+
300+The report makes two instances with the same arguments one instance
301+(section 3), and leaves to the compiler how it finds them so. An
302+instance is named by the generic module, the fingerprint of its whole
303+source, and its arguments, so that two arguments that are the same
304+type (report, section 5.10) give one name:
305+
306+- A type is named as it is built, down to its records, variants and
307+ enumerations. An alias, or a named pointer, array, slice, set or
308+ procedure type, is named as what it stands for; a procedure type
309+ without its parameters' names.
310+- A record, variant or enumeration is named by where it is declared,
311+ with the fingerprint of its declaration: its module, its procedure if
312+ it is local to one, or the instance's name if an instance declares
313+ it, and its name; an anonymous one by its line and column in place
314+ of a name.
315+- A procedure is named by its module and its name.
316+
317+Two object files that hold an instance of the same name hold the same
318+code.
296319
297320 ## The interpreter
298321

doc/raz.md (history) modified +20 -33

@@ -166,7 +166,10 @@
166166 An import gives the arguments: `import Ints := List(I64);`. Each
167167 distinct list of arguments makes one *instance*: the module compiled
168168 with `T` standing for `I64`. Two imports of `List(I64)`, in any modules,
169-share one instance. Since every instance is checked on its own, an
169+share one instance, its variables and its `ERROR`s with it: two lists
170+of arguments are the same when their types are the same (section
171+5.10), an alias as what it stands for, and their procedures are the
172+same procedures. Since every instance is checked on its own, an
170173 operation the argument type doesn't support (adding two records, say)
171174 is reported as an error in that instance.
172175
@@ -1098,34 +1101,14 @@
10981101 the compiled code checks for them is the implementation's choice
10991102 (appendix A); that they stop the program isn't.
11001103
1101-**Object files.** A module can be compiled on its own, into an object
1102-file: its interface, what it exports as an importer sees it, and its
1103-code, in an intermediate form that a back end turns into any target's
1104-machine code. A program is made from the object files of its modules.
1105-An object file records the fingerprint of every interface it was
1106-compiled against, and of the whole source of every generic module it
1107-made an instance of, and stays current while its source and those
1108-don't change; when it isn't current, the compiler compiles
1109-the module again from its source. A program comes out the same
1110-whether its modules were compiled one at a time or all at once.
1104+**Separate compilation.** An importer depends only on a module's
1105+interface: what it exports, as an importer sees it, never its source
1106+or its code. So a module can be compiled on its own, and a program
1107+made from modules compiled at different times. Whether an
1108+implementation does so, and into what, is its own choice (appendix
1109+A); one that does makes the same program as if every module were
1110+compiled together, and keeps one copy of each instance.
11111111
1112-An instance is made from the generic module's source, and goes into
1113-the object file of the module that made it, named by the generic
1114-module, the fingerprint of its whole source, and its arguments. A
1115-type argument is named as it is built, down to its records, variants
1116-and enumerations, so that two arguments that are the same type
1117-(section 5.10) give one name: an alias, or a named pointer, array,
1118-slice, set or procedure type, is named as what it stands for, and a
1119-procedure type without its parameters' names. A record, variant or
1120-enumeration is named by where it is declared, with the fingerprint of
1121-its declaration: its module, its procedure if it is local to one, or
1122-the instance's name if an instance declares it, and its name. One
1123-given as a type argument must therefore be named, since each written
1124-anonymously is a type of its own. A procedure given as an argument is
1125-named by its module and its name. Two object files that hold an
1126-instance of the same name hold the same code, and the program keeps
1127-one.
1128-
11291112 **Messages.** The compiler reports an error with its file, line and
11301113 column, the line of source with the offending part underlined, and,
11311114 where they help, notes pointing at other places, such as where a name
@@ -1693,9 +1676,10 @@
16931676 every signed type divided by -1 stops the program (6.1). Writing a
16941677 string's bytes isn't defined (5.10). The atomic built-ins work on
16951678 `INT`, `UINT` and pointers (6.8). An integer constant past an
1696- extern's parameters goes as an `INT` (9). Modules compile on their
1697- own, into object files, and instances are named so that one type
1698- gives one name (section 10; appendix A). The library takes and gives
1679+ extern's parameters goes as an `INT` (9). An importer depends only
1680+ on a module's interface, so a module can be compiled on its own;
1681+ whether it is, and into what, is the implementation's (sections 3
1682+ and 10; appendix A). The library takes and gives
16991683 `INT` for lengths, counts, descriptors, process ids and statuses,
17001684 `main`'s and `Rt.exit`'s among them, and `I32` for a character;
17011685 `I64` stays for what may pass an `INT` on a small target: a file's
@@ -1711,8 +1695,11 @@
17111695 - **The target.** Which machines and systems it compiles for, and the
17121696 names of their files (`linux-x86_64`, section 3); for each, the size
17131697 of an address, and so of `INT`, and whether it has reals.
1714-- **Object files.** Their format, and the intermediate form of the
1715- code in them (section 10); this compiler's is in `doc/ir.md`.
1698+- **Separate compilation.** Whether modules are compiled on their own,
1699+ and if so into what: the object file, its format, the form of the
1700+ code in it, when one is out of date, and how an instance is named so
1701+ that the program keeps one (section 10). This compiler's are in
1702+ `doc/ir.md`.
17161703 - **Atomics.** How `CAS`, `XCHG` and `XADD` are made sequentially
17171704 consistent on a machine without atomic instructions (section 6.8):
17181705 on one with a single processor, by holding off interrupts while