Skip to content

A cache key names what produces the output (not who ran the build); a stale signature says which part changed - #1225

Merged
ehartford merged 1 commit into
mainfrom
cache-key-names-the-producer
Sep 20, 2026
Merged

ehartford merged 1 commit into
mainfrom
cache-key-names-the-producer

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Second item of the build-redo survey.

The redo. Every action's cache signature carried the fingerprint of the binary orchestrating the build (:WITH:, src/BuildGraphCache.w). Our workflow alternates orchestrators all day: the iterate tier uses the installed compiler, the battery the pinned seed, corpus promotion the release compiler. With the seed held fixed (WITH=src/main) and only the orchestrator changed, --explain reported stage1, stage2, link-compiler, the runtime objects and the bundle builds all stale: action signature changed: a full compiler rebuild, about 4.5 minutes, per switch. (:zlib-promote spent 270 s rebuilding all three right after a build had produced them.)

What the others do (checked in .reference/): Go's action ID hashes the ID of the tool that produces the output (exec.go:366, buildid.go:115), Zig hashes the compiler version and backend, Rust's clear_if_dirty takes the producing rustc. None keys on the build driver.

The change. The orchestrator produces a target's output only when it compiles it itself: the compile kinds, and an action with no compiler= (a workspace compile runs in the driver's own compiler). An action that names its compiler is produced by that compiler; a tree compiler is already hashed by the stage-target block, and compiler=seed is the seed WITH names. Such an action now keys on the seed (build_cache_producer_fingerprint). With WITH=src/main driven by src/main the signature text is unchanged, so seed-driven batteries stay warm.

A tool that could not answer. The state held the signature as one hash, so "signature changed" could not say what changed (I could not tell either, until this). The state now records each component's hash (target, producer, action-code or build-graph, compiler-source, compiler), the stale reason names the ones that differ, and WITH_BUILD_CACHE_TRACE=<target> prints them.

Evidence (pinned seed, head 6ab62ab):

build rc=0   fixpoint rc=0   test rc=0   test-green rc=0   last-green rc=0

Two binaries with different sha256 (release 32543048…, stage2 0dbd11f3…) over one seed, after a build orchestrated by the first:

orchestrator 1: stage1 stage2 link-compiler rt-core-object zlib-wo-build  -> fresh
orchestrator 2: stage1 stage2 link-compiler rt-core-object zlib-wo-build  -> fresh
libc-surface-check (no compiler=: the driver is its producer)
   orchestrator 1 -> fresh
   orchestrator 2 -> stale: action signature changed (producer)

Until the next seed. The pinned seed (v0.15.2.0) and a current compiler still disagree on these targets: the seed predates #1151/#1185/#1191's changes to this code and records no component hashes, so which component differs cannot be read from its states. Between current compilers (installed, release, stage2) the rebuilds are gone now.

…s which part changed

Every action's signature carried the fingerprint of the binary orchestrating
the build (:WITH:). Our workflow alternates orchestrators all day: the
iterate tier uses the installed compiler, the battery the pinned seed, corpus
promotion the release compiler. With the seed held fixed (WITH=src/main) and
only the orchestrator changed, --explain reported stage1, stage2,
link-compiler, the runtime objects and the bundle builds all "stale: action
signature changed": a full compiler rebuild, about 4.5 minutes, per switch.
(:zlib-promote spent 270 s rebuilding stage1, stage2 and link-compiler right
after a build had produced them.)

The orchestrator produces a target's output only when it compiles it itself:
the compile kinds, and an action with no `compiler=` (a workspace compile
runs in the driver's compiler). An action that names its compiler is produced
by that compiler; a tree compiler is already hashed by the stage-target block
and `compiler=seed` is the seed WITH names. Such an action now keys on the
seed (build_cache_producer_fingerprint). Go, Zig and Rust all key on the
producing tool, never on the build driver. With WITH=src/main driven by
src/main the signature text is unchanged, so seed-driven batteries stay warm.

The state file held the signature as one hash, so "signature changed" could
not say what changed. It now records each component's hash (target, producer,
action-code or build-graph, compiler-source, compiler) and the stale reason
names the ones that differ; WITH_BUILD_CACHE_TRACE=<target> prints them.

Evidence, two binaries with different sha256 (release 32543048…, stage2
0dbd11f3…) over one seed, after a build orchestrated by the first: stage1,
stage2, link-compiler, rt-core-object and zlib-wo-build are fresh under both.
libc-surface-check (no compiler=, so the driver is its producer) is fresh
under the first and "stale: action signature changed (producer)" under the
second. The pinned seed (v0.15.2.0) still disagrees with a current compiler:
it predates #1151/#1185/#1191's changes to this code and records no component
hashes; that ends at the next seed.
@ehartford
ehartford merged commit ebf2950 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 cache-key-names-the-producer branch September 24, 2026 16:53
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