Files
LithosAnanke/docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md
T
Claude 4d64e677f5
Build / Image RASPI (push) Successful in 4m13s
Build / Image PC (push) Successful in 3m51s
Build / Image MILKV (push) Successful in 4m30s
Build / v4 tests (32- and 64-bit cells) (push) Successful in 17m32s
v4 text.c: the address record (ADR step 3, task 1)
Every cell laid down that holds an address of the assembly is recorded,
with its branch slot or 7 for the whole cell, as ARTIFACT.md's
relocations need. Test first: test_text 13 checks failed before.
test_host_rom_nucleus runs with the record on: 1825 branches, 664 whole
cells, the ROM still equal word for word. v4 test, test-32 and
ASan+UBSan pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-19 17:51:54 +00:00

11 KiB
Raw Blame History

Artifacts in the build -- design, for ruling

Written 2026-11-19. Step 3 of ADR-2026-11-19-F18-ARTIFACTS.md §7, "Integrate artifact production into the existing build system". It builds on:

  • ABI.md, ABI v0 as ruled, in particular choice 1, "A host tool";
  • ARTIFACT.md, the layout as ruled.

Nothing here is built. The questions in §6 are ruled (2026-11-19).

1. What is there already

  • The host assembler exists. v4/src/text.c assembles .f18 text onto a node. v4/tools/mkrom.c uses it on the build machine to build the ROM, "as a bitstream is built". The tests use it to build the system.

  • The ROM and text.c are proved to agree. test_host_rom_nucleus assembles the system's source twice:

    • once off the node with text.c, the oracle;
    • once on the machine, by the ROM fed through the console.

    Every word of RAM must be the same, apart from the ROM's own state. This is ABI choice 1's cell-for-cell check already, for the one train that has .f18 today.

  • Only one train has .f18 today: the nucleus. Its source is capsules/v4/sys. The map comes first, then the fourteen files in sys_files.h's order, then end.f18. The boot feeds them to the ROM as the blobs v4:sys:*.f18 (boot.c).

  • The nucleus is not relocatable. It is assembled at a fixed origin against the map's fixed addresses. end.f18 stores addresses into the map's variables, and its dictionary holds absolute links. Ruling 1 keeps it as it is: the ROM still assembles the system at boot (ABI.md §8).

2. The tool: v4/tools/mkf18a.c

A C tool beside mkrom.c, built the same way, one per cell width:

mkf18a OUT.f18a MAP.f18 DIR
  1. It assembles every .f18 in DIR with text.c, at origin 0, in name order (ruled §6.3), after MAP.
  2. It writes the artifact, laid out as ARTIFACT.md gives:
    • the header;
    • the provenance, with its four SHA-512 hashes;
    • the exports, the imports and the relocations;
    • an empty verification record;
    • the string pool and the code, low byte first.
  3. It fails the build if anything cannot be written as the ABI requires:
    • a relocation whose patched address is beyond its slot's reach;
    • a capability it cannot derive.

The relocations come from text.c. text.c gains a record of each cell it lays down that holds an address: every branch it resolves to a word or a label, and every &NAME. That is one hook, and test-first: test_text checks the record against the cells.

The stack effects come from a new analysis, v4/src/effect.c. It walks each word's instruction words from its entry to every ; and counts what each opcode takes and leaves on both stacks:

  • the opcode table is iword.h's;
  • a call takes the effect of the word it calls, derived first;
  • a branch that joins two paths with different depths is "no fixed effect";
  • so are a loop whose count is data, EXECUTE and a DEFERred word.

It is a module of its own, so the proofs can state it on its own (ADR step 5).

3. Where it runs

  • v4/Makefile: make -C v4 artifacts builds the artifacts of each width into v4/build/. make -C v4 test runs it, so a .f18 the tool refuses fails the test gate.
  • The check against the ROM: the nucleus is not an artifact (ruled §6.2a), so no file is written for it. test_host_rom_nucleus assembles it with the tool's assembler, the address record turned on, and the ROM must still lay down every word the same. That proves the record changes no cell. The records themselves are proved by the small train (§4, test 5).
  • The kernel build: nothing changes in step 3. The boot still feeds the ROM the source. Carrying the artifact in the capsule, and placing it, is steps 4 and 6.
  • CI: build.yml's v4-tests job runs make -C v4 test already, so it gains the gate with no change.

4. Test first, seen to fail

  1. test_text: the address record for a branch, a forward branch, a label, and an &NAME.
  2. test_effect, new: words of known effect, written in test_text's notation:
    • dup (1 → 2);
    • drop (1 → 0);
    • a call;
    • a for/next loop of fixed count;
    • two branches that agree;
    • two branches that disagree (no fixed effect).
  3. test_mkf18a, new: a small text's artifact read back unit by unit against ARTIFACT.md. It checks the magic, the counts, each record, every reserved unit 0, and the code low byte first.
  4. test_host_rom_nucleus, with the address record on: the ROM's assembly equal to the tool's, word for word (ruled §6.2a: no artifact file for the nucleus).
  5. Then a small train, a few words of .f18 with one import from the nucleus, is placed from its artifact at a base other than 0. Its words run, and its calls into the nucleus reach the nucleus (ruled §6.2).

POST, the protocol and the dictionary gate are unchanged, since the boot is unchanged.

5. Cost

The build gains one assembly of the nucleus per width, which takes a second or less on the host (test_host_rom_nucleus reports its time today), plus the analysis. That is measured when it is built, as ADR step 8 asks. The boot gains nothing.

6. For ruling, one at a time

  1. Address literals Ruled 2026-11-19: "Slot 7 = whole cell", recorded in ARTIFACT.md §5 and §7. As asked: ARTIFACT.md §5's relocation covers branch fields only (a slot, 0–3). The system's source also holds addresses in whole cells: the &NAME literals (31 in capsules/v4/sys), and the dictionary's links. One fix is a slot value of 7 meaning "the whole cell". The top 3 bits allow 0–7, so the record keeps its size.

  2. Which train first Ruled 2026-11-19: "Both, nucleus first". The nucleus is built and checked against the ROM; then a small train is placed at a base other than 0, to prove the relocations (§4, test 5). As asked: The nucleus is the only .f18 train, but it is not relocatable, and the ROM keeps assembling it (§1). Its artifact can be built and checked (§3), but it is never placed by the loader.

    2a, ruled 2026-11-19: "Nucleus not an artifact". Asked how an artifact would say it is fixed at an origin, since ABI.md §4 has its code "as if placed at address 0": only relocatable trains are artifacts. The nucleus is checked as the tool's assembly against the ROM's, and no artifact file is written for it. ABI.md §4 stands. Is the nucleus the first artifact, or is a small relocatable train written first?

  3. The order of the sources Ruled 2026-11-19: "All it finds, name order". The tool takes every .f18 in a train's directory, sorted by name, so the file names set the order (00-core.f18, ...) and there is no list to keep. As asked: Captain Bob's image is "the .f18 assembler assembles all .f18 files it finds", but the order matters: the map first, sys_files.h's list, end.f18 last. Does each train name its order in a list, as sys_files.h does, or does the tool take the files in name order? 3a, ruled 2026-11-19: "Nucleus too: rename". Asked whether name order applies to the nucleus, which is read in sys_files.h's order: it does. capsules/v4/sys is renamed so that its name order is today's order, the map first and end.f18 last (00-map, 01-core, ... 99-end), and sys_files.h goes. The boot, the tests and the ROM's feed read the directory in name order. The blob names and the capsule hashes change, so the protocol runs again. This is a task of its own, designed and tested first. One point for its design: the directory holds both widths' maps, map-32.f18 and map-64.f18, and name order would take both.

  4. Which words are exports Ruled 2026-11-19: "Every fixed-effect word". Every word the tool derives a fixed effect for is exported; the rest stay internal, and the build does not fail for them. As asked: The nucleus defines hundreds of words, and some have no fixed effect, which 2c refuses as exports. Is every word with a fixed effect exported, or only those a list names? With a list, the words outside it stay internal.

  5. The tool's identity Ruled 2026-11-19: "Its source". The provenance's tool hash is the SHA-512 of the tool's source: mkf18a.c, text.c, effect.c and the v4 headers they include, in a fixed order. The same source gives the same hash on every host. As asked: The provenance holds "the host tool's hash". The hash of the binary differs with the host's compiler. Should it be the hash of the tool's source (mkf18a.c, text.c, effect.c and their headers), or of the binary?

  6. The name Ruled 2026-11-19: "mkf18a / .f18a", after the magic: v4/tools/mkf18a.c, and each train's artifact <train>.f18a. As asked: mkf18a and .f18a, after the magic, or something else?

7. Status, and the order of the work

All six questions are ruled, plus 2a and 3a. Each task below is built test-first, seen to fail, and accepted before the next:

  1. text.c's address record (§4, test 1), with test_host_rom_nucleus unchanged (test 4).
  2. effect.c, the stack-effect analysis (test 2).
  3. mkf18a and make -C v4 artifacts (test 3).
  4. The small train, placed at a base other than 0 (test 5).
  5. The nucleus renamed to name order (3a), designed first: it changes the boot, so the protocol runs.

8. Task 1 built (2026-11-19): text.c's address record

What changed:

  • text.h and text.c: v4_text_record(t, buf, cap) turns the record on, and v4_text_addresses(t) says how many were recorded. Each entry is a cell and its slot, 0–3 for a branch field or 7 (V4_TEXT_WHOLE_CELL) for the whole cell. What is recorded:

    • every branch, to a word or a label, back or forward, including NEXT's;
    • an &NAME literal in code, and #, &NAME;
    • here, and a set variable that holds an address, wherever it is laid down (code, #,, store);
    • a header's name cell, and its link when there is an entry before it.

    The map's constants and plain numbers are not recorded. A full record is an error. With the record off, nothing changes.

  • Found while building: the nucleus lays its headers down with set HDR-NFA here ... #, HDR-LINK, not with header. So a set variable carries whether it holds an address, or those links would be missed.

Test first (logs/20261119-text-record/):

  • test_text: 15 new checks. Before the change, 13 failed: every one that expects an address recorded. The two that expect nothing passed, as they should. Two errors in the tests themselves were fixed before the change: source needs its N-1 constant, and the notation is FOR ... NEXT, upper case.
  • test_host_rom_nucleus, with the record on (test 4). On the system's source it records 1825 branches and 664 whole cells. Every whole cell holds an address of the assembly, and the ROM's assembly is still equal to it word for word, at both widths. This check could not be seen to fail before: the record did not exist. It guards that the record changes no cell.

Verified:

  • make -C v4 test passes: all tests at both widths, and the three mesh boots with POST 990/990.
  • make -C v4 test-32 passes.
  • ASan+UBSan passes for every test at both widths, and for the mesh boot (POST 990/990). The run hit my one-hour background limit at the 64-bit test_host_mesh, so the rest was run again from there. v4-gates.txt and v4-sanitize-rest.txt hold the two parts.
  • The boot does not use the record, so the kernel and the protocol are unchanged.