From 1d0597c6d2d1397fead67b87138ecacebd02af04 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 11 Oct 2026 22:56:02 +0100 Subject: [PATCH] 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) --- diff --git a/PLAN.md b/PLAN.md index bb3d274..c9c6107 100644 --- a/PLAN.md +++ b/PLAN.md @@ -76,10 +76,10 @@ **Done when:** the report alone is enough to rebuild raz, with a conformance suite to say when a rebuild is done; the report has a -system integer, optional reals and object files; the compiler goes -through an IR, which is what an object file holds, and keeps its -values in registers as Wirth's compilers do; `make bench` still -passes; a new code budget is written down; `v0.6.0` is tagged. +system integer and optional reals, and leaves separate compilation to +the implementation; the compiler goes through an IR, which is what its +object files hold, and keeps its values in registers as Wirth's +compilers do; `make bench` still passes; a new code budget is written down; `v0.6.0` is tagged. **Kept out:** a second back end (aarch64 is the milestone after, to measure a port); an optimiser; the wishes below. diff --git a/doc/ir.md b/doc/ir.md index a21cb05..962977d 100644 --- a/doc/ir.md +++ b/doc/ir.md @@ -270,9 +270,11 @@ 1. **A header**: the module's name, the target, the version of this form, and the fingerprint of the module's interface. 2. **Its imports**: each module it read the interface of, with that - interface's fingerprint when it was compiled. The object file is - current while each of those is still the one there, and its source - hasn't changed (report, section 10). + interface's fingerprint when it was compiled, and each generic + module it made an instance of, with the fingerprint of its whole + source. The object file is current while each of those is still the + one there, and its own source hasn't changed; when it isn't, the + compiler compiles the module again from its source. 3. **Its interface**: what it exports, as an importer needs it: its constants with their values, its types with their layouts, its variables, and its procedures' signatures. An importer reads this, @@ -281,9 +283,8 @@ as a size and an alignment; each string and `ERROR` as its bytes. A chunk is named, so that the linker finds it from other object files. -5. **Its instances**: each instance of a generic module it made, its - chunks named by the generic module, its arguments and the - fingerprints they were built from (report, section 10). The linker +5. **Its instances**: each instance of a generic module it made, from + the generic module's source, its chunks named as below. The linker keeps one of each name. 6. **Its places**: the lines of its statements and the places of its checks, for messages, the trap report and the debugger. @@ -293,6 +294,28 @@ is linked from object files alone: the linker reads them, marks what the entry point reaches (tree shaking, as today), hands each live procedure to the back end, and writes the executable. + +## Naming an instance + +The report makes two instances with the same arguments one instance +(section 3), and leaves to the compiler how it finds them so. An +instance is named by the generic module, the fingerprint of its whole +source, and its arguments, so that two arguments that are the same +type (report, section 5.10) give one name: + +- A type is named as it is built, down to its records, variants and + enumerations. An alias, or a named pointer, array, slice, set or + procedure type, is named as what it stands for; a procedure type + without its parameters' names. +- A record, variant or enumeration is named by where it is declared, + with the fingerprint of its declaration: its module, its procedure if + it is local to one, or the instance's name if an instance declares + it, and its name; an anonymous one by its line and column in place + of a name. +- A procedure is named by its module and its name. + +Two object files that hold an instance of the same name hold the same +code. ## The interpreter diff --git a/doc/raz.md b/doc/raz.md index 22c9ca7..dd0d8cb 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -166,7 +166,10 @@ An import gives the arguments: `import Ints := List(I64);`. Each distinct list of arguments makes one *instance*: the module compiled with `T` standing for `I64`. Two imports of `List(I64)`, in any modules, -share one instance. Since every instance is checked on its own, an +share one instance, its variables and its `ERROR`s with it: two lists +of arguments are the same when their types are the same (section +5.10), an alias as what it stands for, and their procedures are the +same procedures. Since every instance is checked on its own, an operation the argument type doesn't support (adding two records, say) is reported as an error in that instance. @@ -1098,34 +1101,14 @@ the compiled code checks for them is the implementation's choice (appendix A); that they stop the program isn't. -**Object files.** A module can be compiled on its own, into an object -file: its interface, what it exports as an importer sees it, and its -code, in an intermediate form that a back end turns into any target's -machine code. A program is made from the object files of its modules. -An object file records the fingerprint of every interface it was -compiled against, and of the whole source of every generic module it -made an instance of, and stays current while its source and those -don't change; when it isn't current, the compiler compiles -the module again from its source. A program comes out the same -whether its modules were compiled one at a time or all at once. +**Separate compilation.** An importer depends only on a module's +interface: what it exports, as an importer sees it, never its source +or its code. So a module can be compiled on its own, and a program +made from modules compiled at different times. Whether an +implementation does so, and into what, is its own choice (appendix +A); one that does makes the same program as if every module were +compiled together, and keeps one copy of each instance. -An instance is made from the generic module's source, and goes into -the object file of the module that made it, named by the generic -module, the fingerprint of its whole source, and its arguments. A -type argument is named as it is built, down to its records, variants -and enumerations, so that two arguments that are the same type -(section 5.10) give one name: an alias, or a named pointer, array, -slice, set or procedure type, is named as what it stands for, and a -procedure type without its parameters' names. A record, variant or -enumeration is named by where it is declared, with the fingerprint of -its declaration: its module, its procedure if it is local to one, or -the instance's name if an instance declares it, and its name. One -given as a type argument must therefore be named, since each written -anonymously is a type of its own. A procedure given as an argument is -named by its module and its name. Two object files that hold an -instance of the same name hold the same code, and the program keeps -one. - **Messages.** The compiler reports an error with its file, line and column, the line of source with the offending part underlined, and, where they help, notes pointing at other places, such as where a name @@ -1693,9 +1676,10 @@ every signed type divided by -1 stops the program (6.1). Writing a string's bytes isn't defined (5.10). The atomic built-ins work on `INT`, `UINT` and pointers (6.8). An integer constant past an - extern's parameters goes as an `INT` (9). Modules compile on their - own, into object files, and instances are named so that one type - gives one name (section 10; appendix A). The library takes and gives + extern's parameters goes as an `INT` (9). An importer depends only + on a module's interface, so a module can be compiled on its own; + whether it is, and into what, is the implementation's (sections 3 + and 10; appendix A). The library takes and gives `INT` for lengths, counts, descriptors, process ids and statuses, `main`'s and `Rt.exit`'s among them, and `I32` for a character; `I64` stays for what may pass an `INT` on a small target: a file's @@ -1711,8 +1695,11 @@ - **The target.** Which machines and systems it compiles for, and the names of their files (`linux-x86_64`, section 3); for each, the size of an address, and so of `INT`, and whether it has reals. -- **Object files.** Their format, and the intermediate form of the - code in them (section 10); this compiler's is in `doc/ir.md`. +- **Separate compilation.** Whether modules are compiled on their own, + and if so into what: the object file, its format, the form of the + code in it, when one is out of date, and how an instance is named so + that the program keeps one (section 10). This compiler's are in + `doc/ir.md`. - **Atomics.** How `CAS`, `XCHG` and `XADD` are made sequentially consistent on a machine without atomic instructions (section 6.8): on one with a single processor, by holding off interrupts while