Skip to content

:fixpoint compares every unit of the compiler, using the two compiles the build already did (was: main.w only, and 100 s of recompiling) - #1224

Merged
ehartford merged 1 commit into
mainfrom
fixpoint-compares-existing-objects
Sep 20, 2026
Merged

ehartford merged 1 commit into
mainfrom
fixpoint-compares-existing-objects

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

First item of the build-redo survey, and it turned up a hole in the core invariant.

The redo. :fixpoint recompiled the compiler twice with --emit-obj (stage2-fixpoint-object by stage1, stage3-fixpoint-object by stage2: 48.5 s and 48.9 s) and compared the two objects. Both compiles duplicated work build had just done: stage2 is stage1 compiling out/gen/main.w at -O1, and link-compiler is stage2 compiling the same source with the same flags, which is a stage3.

The hole. --emit-obj is module-object mode: the object holds the root module's declarations and leaves every other module's functions undefined. nm on with-stage2-fixpoint.o finds run_cli and not MirBuilder.lower_call, Codegen.gen_module, Sema.types_compatible, lower_module or process_c_import_with_defines: 498 With symbols against the binary's 7311. So stage2 == stage3 was only ever checked for main.w's own functions. A two-module test program shows the same at every emit width.

The change.

  • A binary build, given WITH_UNIT_DIGESTS=<file>, records the sha256 of every object it links (unit 0 and each <obj>.u<k>.o) before deleting them. WITH_KEEP_UNIT_OBJECTS=1 keeps the objects for diffing.
  • stage2 and link-compiler each write one (out/stage/bin/with-stage2.units, out/release/bin/with.units).
  • fixpoint-compare is an action that requires the two lists to agree and names every unit that does not. fixpoint-evidence hashes the two lists.
  • stage2-fixpoint-object and stage3-fixpoint-object remain for fixpoint-diff only; :fixpoint no longer builds them.

What the others do (checked in .reference/): Rust's bootstrap "uplifts" a later stage from artifacts an earlier stage already built rather than recompiling (compile.rs:1089); Zig is the only one with a byte-for-byte self-check, and runs it in CI release scripts; Go's is a staleness check. We keep the invariant on every battery and it now costs a comparison.

Evidence (pinned seed, head 3477fc5):

build rc=0   fixpoint rc=0   test rc=0   test-green rc=0   last-green rc=0
[fixpoint] stage2 == stage3 over all 16 units of the compiler
:fixpoint wall 7.8s   (was 107s)

The comparator goes red: a tampered digest names u7 with both hashes; a truncated list names u14 and u15 as "(no such unit)". Editing a digest file in place does not fool it: it is a declared output of link-compiler, which the build re-ran (72.7 s) before comparing.

…the build already did

:fixpoint recompiled the compiler twice with `--emit-obj` (stage2-fixpoint-
object by stage1, stage3-fixpoint-object by stage2: 48.5 s and 48.9 s) and
compared the two objects. Both compiles duplicated work `build` had just
done: `stage2` is stage1 compiling out/gen/main.w at -O1, and link-compiler
is stage2 compiling the same source with the same flags, which is a stage3.

And the comparison covered main.w alone. `--emit-obj` is module-object mode
(emit_object_to_path passes module_object_mode; the flag dates from
372629b, 2026-04-10, before the fixpoint targets were ported in be81792):
the object holds the root module's declarations and leaves every other
module's functions undefined. nm on with-stage2-fixpoint.o finds run_cli and
not MirBuilder.lower_call, Codegen.gen_module, Sema.types_compatible,
lower_module or process_c_import_with_defines: 498 With symbols against the
binary's 7311. stage2 == stage3 was never checked for MirLower, Codegen,
Sema or CImport.

Now a binary build, given WITH_UNIT_DIGESTS=<file>, records the sha256 of
every object it links (unit 0 and each <obj>.u<k>.o) before deleting them;
`stage2` and link-compiler each write one, and fixpoint-compare is an action
that requires the two lists to agree and names every unit that does not.
WITH_KEEP_UNIT_OBJECTS=1 keeps the objects for diffing. stage2-fixpoint-
object and stage3-fixpoint-object remain for `fixpoint-diff` only.

Evidence: "[fixpoint] stage2 == stage3 over all 16 units of the compiler",
:fixpoint wall 7.8 s (was 107 s). The comparator goes red: a tampered digest
names u7 with both hashes; a truncated list names u14 and u15 as "(no such
unit)". Editing the digest file in place does not fool it: it is a declared
output of link-compiler, which the build re-runs.
@ehartford
ehartford merged commit bdce761 into main Sep 20, 2026
5 checks passed
ehartford added a commit that referenced this pull request Sep 20, 2026
…(D50) (#1226)

* One tree, one compiler binary, in any worktree: WITH_FILE_PREFIX_MAP (D50)

The compiler named its checkout in three places, so the same commit built in
two worktrees gave two different compilers and nothing built in one could be
shared with another (test verdicts, artifacts, a warm start for a new
worktree):

- the DWARF compile unit: /Users/eric/with/rt (16x) and .../out/gen (2x);
- module link names: `__with_mod_<hash>__name` hashed the module's absolute
  path, so rt_core's alloc_* and channel_runtime's chan_* had a different
  name per checkout (176 bytes of __const, shifting 36 MB of the binary);
- the linker's debug map: 23 N_OSO stabs naming each linked object by
  absolute path (48 bytes of the string table between `path-free` and
  `path-free-b`).

WITH_FILE_PREFIX_MAP=<from>=<to>, after clang's -ffile-prefix-map and Rust's
remap-debuginfo, beside #949's canonical stdlib paths: the mapped root is what
codegen_canonical_module_path returns (so both the link-name hash and the
compile unit use it), the darwin lld link passes -oso_prefix <from>/, and
dsymutil gets -oso-prepend-path <from> to find the objects again. The build
passes <project root>=/with-src to the compiler's own compiles.

Evidence, one commit built at the same time in two worktrees
(path-free, path-free-b): out/release/bin/with.unstamped 56f47bd93c2ab7bc in
both, out/release/bin/with 7de3cf4dad34c38e in both, both unit-digest lists
identical. The .dSYM is whole (22 MB, 8496 subprograms). lldb with
`settings set target.source-map /with-src $PWD` sets rt_core.w:1500 and lists
the source; without the map it lists nothing, so CLAUDE.md's LLDB recipe
carries it. with-stage2 still differs between worktrees (136 symbols, all
rt_core's alloc_*): it links the bootstrap runtime objects, which the pinned
seed compiles and the seed does not know the option; that ends at the next
seed.

behav_file_prefix_map_objects_match: a two-module program compiled in two
directories gives identical objects under the map and different ones
without it.

D50 records the survey, what Go, Zig, Rust, Scala 3, Bazel and Vale do, the
three decisions landed so far (#1224, #1225, this) and what remains.

* Re-record the ABI source hash: FnAbi.w gained the file prefix map, the convention is unchanged

abi-hash-check asks for a conscious decision when an ABI-defining source
changes. src/FnAbi.w changed (fn_abi_file_prefix_mapped, and
codegen_canonical_module_path applying it); the calling convention did not.
The mapping changes a module's link-name hash only when WITH_FILE_PREFIX_MAP
is set and only for a module outside the stdlib tree; a .wo bundle's modules
are named <embedded-std>/..., which the mapping never sees. No
WITH_ABI_VERSION bump; every .wo rebuilds once, as the gate says.

---------

Co-authored-by: Eric Hartford <[email protected]>
@ehartford
ehartford deleted the fixpoint-compares-existing-objects branch September 24, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant