Skip to content

Build speed: parallel lanes, no self-hash, drop-audit/tools/emit-c in parallel; prepare-bootstrap-link-root re-runs before a runner recompile (#1899 #1908) - #1909

Merged
ehartford merged 14 commits into
mainfrom
speed-main
Sep 29, 2026
Merged

ehartford merged 14 commits into
mainfrom
speed-main

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Battery 43 min → ~17 min on the measured stack tree (this branch is the same work on main, minus stage2-as-release, which needs #1815 from stack #1898). No check is skipped; every lane still runs.

Immediate (build.w / build/ / tools — take effect under the pinned seed):

At the next seed (driver code):

Filed on the way: #1907 (u8 hex format), #1908 (fixed here). Draft until the battery is green.

Eric Hartford added 14 commits September 29, 2026 10:07
The lane built its 31 tools one after another. build/par.w runs
independent child processes in a sliding window of spawn_capture/wait,
std.sys.cpu_count() wide, reaps every child before returning and hands
back every exit code in job order, so the lane reports every failing
tool after all of them finish. Every non-build.w tool is still built
(a link catches the missing symbol a check cannot).

Measured on this Mac (18 cores, other agents building), driver = the
pinned seed, `src/main build :tools-tests` (runner path):
tools-tests 523.3 s -> 259.2 s.

The floor is the work, not the scheduling: six tools compile the
compiler's own modules (130 MB binaries); one of them alone is 420 CPU-s
and 91 s wall (tools/migrate_receivers.w), so the lane is ~2,700 CPU-s.
The 13 cases (hello without prelude, the prelude runtime, a panicking
expect, three named programs, the seven test/emit_c fixtures) ran
emit -> cc -> run one case at a time. Each case is now a row (EcCase):
every case's emit (and each fixture's `with test`) runs in one window,
then every compile, then the runs; within a case emit precedes compile
precedes run. Every assertion is kept: exit codes, exact or trimmed
stdout, stderr needles, the generic-intrinsics placeholder refusal, the
hello cc line without -lm. Every failing case is reported after every
child is reaped (planted: a mismatched and a non-compiling fixture both
reported, rc=1). The cc argument list has one builder,
bs_emit_c_cc_args, shared with the edge lane's emit-c cases.

Measured, `src/main build :emit-c-smoke` under the pinned seed:
emit-c-smoke 336.6 s -> 62.8 s.
… after the pooled wave

The pool overlaps only consecutive allow_parallel targets; an unflagged
one drains it first. In the 2026-09-29 battery (checks 1864 s) serial
lanes sat inside the wave: cli-selfhost-edge-tests 54.7 s,
cli-selfhost-parallel-tests 35.2 s, c-migrator-core-tests 25.1 s,
emit-c-smoke 423.9 s, stdlib-complexity and the wo-drift/corpus lanes,
each forcing a drain (the drain before stdlib-complexity waited on
behavior-tests; the one before cli-selfhost-edge-tests waited on
tools-tests' 564 s).

allow_parallel now: cli-selfhost-edge-tests, c-migrator-basic-tests,
c-migrator-core-tests, emit-c-smoke. Each writes only its own output
directory (every case under it) and reads the release compiler and
out/lib, like the cli-selfhost lanes already pooled.

Still serial, moved after emit-c-smoke so the wave never drains for
them: cli-selfhost-parallel-tests (32 concurrent compiles, each under a
120 s budget: the lane measures concurrency and must not share the
machine with the wave), stdlib-complexity (runtime measurements need a
quiet machine), wo-drift and the corpus test lanes (each under 13 s).
The set of checks is unchanged; only their order in :test moved.
#1899)

The per-file PASS key was the compiler's content, the test file's content
and project-relative path, the target's args and WITH_MEMORY_LIMIT_BYTES.
It missed what a test reads besides itself: sibling modules and headers
(use shadow_helper, c_import("behav_*.h"), embed_file data),
test/behavior/lib, and src/ and lib/ modules a test imports
(use MirValidationTests, use facades.sqlite3) that are not all compiled
into the compiler. Editing one left a stale PASS. The key now adds the
test's directory tree and the .w sources under src/ and lib/, each by
project-relative path and content (never the absolute path the existing
directory fingerprint embeds), the harness argv, and the SDKROOT,
DEVELOPER_DIR, CC and WITH_CLANG_RESOURCE_DIR the compile and link read.

With no path or mtime left in it, the store moves beside the .wo store:
$WITH_TEST_VERDICT_DIR, else ~/.local/with-test-verdicts, one file per
compiler fingerprint and target, written to a sibling and renamed. Only
passes are stored.

Verified with the fresh release binary as driver on a scratch project
(two tests and a data file): first run 2 ran; second 2 cached; a copy of
the project at another path 2 cached; after editing the sibling data
file 2 ran. Takes effect after the next reseed (the driver is the seed).
docs/spec/toolchain/with-build.md names the directory.
…tires

The pool admitted a new worker only after retiring the oldest, so a slow
lane at the head held every slot its finished siblings had freed. In the
2026-09-29 battery behavior-tests (555 s) ran from t=1402 to t=1957 of
the checks run; its five sibling Test lanes were done by t=1515, and for
the remaining 442 s the head lane ran alone on an inner window of 2
(18 cores / pool width 9) while the rest of the wave waited.

Admission now counts running children (PoolState.running_len; a sweep
reaps exits), and finished lanes at the head retire in order as before,
so output replay and failure handling are unchanged and the number of
concurrent children never exceeds the pool width. A child waiting for a
slot is not being retired, so its budget runs from spawn there
(wait_for_slot kills one past its timeout; it reads as a timeout at
retire).

Scratch project, WITH_BUILD_JOBS=2, one 20 s and five 3 s pooled
actions: seed driver 27.2 s, this driver 22.4 s. Takes effect after the
next reseed.
…n in the comptime evaluator, which cannot read cpu_count

std.sys.cpu_count() caches in a mutable global, which the evaluator refuses
("mutable global access is not allowed in comptime"), so tools-tests and
emit-c-smoke failed under --no-deps. Measured on an idle 18-core host:
tools-tests 564 s (battery, serial) -> 184 s, bounded by five tools that
use the compiler's own modules and so recompile most of the compiler each.
A pooled Test lane gets cores / pool width children (2 of 18), so the lane
left last in a wave ran 2 wide on an idle machine: behavior-tests 243 s
pooled against 45 s at full width (1486 files, idle 18-core host, after
the Developer Tools exemption removed macOS's serialized first-launch
scan). behavior, compile-error, spec, phase and codegen now run alone,
one after another, each with the full window; children are 57-300 MB.
…etires

Retiring only the oldest held the window behind one slow file: a 43 s test
near the front of the alphabet let the other slots drain. The 300 s
per-test budget is kept, counted from each child's spawn. Takes effect at
the next seed (the battery's driver runs this code).
…; the build cache reads it instead of hashing the binary

Every `with build`, no-op included, sha256-hashed the running 136 MB
compiler to key its graph cache: 1.0 s of a 1.0 s no-op (sampled: the
whole no-op is sha256). The stamp step (comp_patch_version_binary) now
patches a WITHSELFIDSTAMPv1 slot with the digest it computes once; the
running compiler reads its own slot, another compiler binary (the seed,
a test lane's compiler) is asked with `version --self-id`, and a binary
without the slot is hashed as before. One identity per binary on every
path, so cross-driver cache agreement holds.
…built per call

sha256_k built its 64-entry local array on every call, 64 calls per block
(57% of samples hashing a binary). 64 MB: 326 ms -> 224 ms; abc digest
unchanged (ba7816bf...15ad).
…-wide window

213 cells x 2 sides ran one after another: 263 s in the battery. Each run
is an independent `with run --debug-alloc`; they now share a window as
wide as the host's cores, refilled when any child exits, with each run's
60 s budget counted from spawn. The table still prints in cell order.
…built (Eric, 2026-09-29)

Each such build recompiled most of the compiler (~360 CPU-s; five tools,
1,800 CPU-s). Every module they link is linked by every stage build; only
their own code's codegen goes unexercised. tools-tests: 183 s -> 30 s.
…nner will be recompiled (#1908)

The driver compiles its action runner once this target has completed in
the run, executed or fresh, and links it against out/lib whenever out/lib
holds the probe objects. Cached across a build/ edit, the target left the
tree's own out/lib in place, and the seed linked its runner against another
generation's runtime. On the ABI v8 stack that crashed every action at the
runner's first statement (lldb: rt_compat_setenv_str copied with an address
as its length); on main it is the same mixed link, silent because both
sides pass &str alike. The target now keys on the runner's own inputs
(build.w, build/, lib/std/build.w). Evidence: the crashing runner's debug
map lists out/lib/*.o, the fixed one out/bootstrap-lib/*.o; seed-driven
tools-tests on the stack tree passes.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 0a8cc5f8 (pinned seed nightly-20260927 cffa4a40…, SDKROOT CLT 15.4): gate rc=0, battery-checks rc=0, every target green.

Wall time in this run is not a speed measurement: the Mac entered clamshell sleep at 10:22:28, one second into the check phase, and slept (with maintenance dark wakes) until 11:11 (pmset -g log). A fully cached re-run of the check phase takes 45 s. Measured speed numbers (idle machine, same changes) are in the PR description.

@ehartford
ehartford marked this pull request as ready for review September 29, 2026 15:14
@ehartford
ehartford merged commit 2fa54a7 into main Sep 29, 2026
@ehartford
ehartford deleted the speed-main branch September 29, 2026 16:51
ehartford added a commit that referenced this pull request Sep 29, 2026
#1909) (#1910)

The battery's driver is the pinned seed, so #1909's driver-side build-speed
work (test lanes refill on any exit, the compiler self-id, the machine-wide
test verdict cache) and the #1908 runner link-root fix reach batteries only
through a seed cut from main. Verified: the published binary builds main
from a fresh checkout to a stage2 == stage3 fixpoint. Workflow pins moved
with tools/bump_seed_pins.w; other platforms stay on their current seeds.

Co-authored-by: Eric Hartford <[email protected]>
ehartford pushed a commit that referenced this pull request Oct 3, 2026
…ves compiler-producing actions across worktrees (#1899)

A green belongs to the sources, not to the worktree (D49/D50); so does a
built artifact. Once an action that names its compiler (stage compiles,
runtime and bridge objects, .wo bundles, producer stamps) has run, its
declared outputs, state record and effect log are published under
$WITH_BUILD_CACHE_DIR (default ~/.local/with-build-cache; "none"
disables it), keyed on the local signature (the producing seed or stage
compiler, the action code, the compiler sources, with.toml), the content
of every declared input, the compiler= binary's identity and the driver's
own digest, so nothing is served across seeds or drivers. A worktree whose
freshness check misses restores the entry into its own out/ and
re-verifies it with the same check: a hit is exactly a fresh target, or
it is discarded and the target runs. The store keeps the 96
least-recently-used entries (WITH_BUILD_CACHE_KEEP).

What made a key worktree-specific, each found by a second worktree that
missed: directory fingerprints and the compiler-source hash named files
absolutely, and so did the action-code hash (the module closure's paths),
now all root-relative; records and effect logs are stored with <root> and
the restore re-pins the record's effects hash to the localized log; and
stage1 declared the seed-built out/bin/with-sha256 binary as an input,
whose bytes differ per worktree (its debug map names the worktree in
N_SO/N_OSO, so LC_UUID and the code signature differ) — stage1 now keys
on tools/with-sha256.w, what that binary is made from (the dep still
orders the build).

Proof (two fresh worktrees on one commit, a stage1 of this tree driving,
one store): the second `:dev` restored 25 entries, stage1 included, none
failed verification; with one byte changed in src/Lexer.w, stage1 was not
restored and rebuilt. Not yet seconds: 39 targets outside the store's
scope still run per worktree (SDK and sysroot packing, the empty
placeholder objects), and the pinned seed carries none of this until the
next seed, so seed-driven batteries see it then. The test verdicts and
build runners were already machine-wide (#1909, #1929).
ehartford pushed a commit that referenced this pull request Oct 3, 2026
…ves compiler-producing actions across worktrees (#1899)

A green belongs to the sources, not to the worktree (D49/D50); so does a
built artifact. Once an action that names its compiler (stage compiles,
runtime and bridge objects, .wo bundles, producer stamps) has run, its
declared outputs, state record and effect log are published under
$WITH_BUILD_CACHE_DIR (default ~/.local/with-build-cache; "none"
disables it), keyed on the local signature (the producing seed or stage
compiler, the action code, the compiler sources, with.toml), the content
of every declared input, the compiler= binary's identity and the driver's
own digest, so nothing is served across seeds or drivers. A worktree whose
freshness check misses restores the entry into its own out/ and
re-verifies it with the same check: a hit is exactly a fresh target, or
it is discarded and the target runs. The store keeps the 96
least-recently-used entries (WITH_BUILD_CACHE_KEEP).

What made a key worktree-specific, each found by a second worktree that
missed: directory fingerprints and the compiler-source hash named files
absolutely, and so did the action-code hash (the module closure's paths),
now all root-relative; records and effect logs are stored with <root> and
the restore re-pins the record's effects hash to the localized log; and
stage1 declared the seed-built out/bin/with-sha256 binary as an input,
whose bytes differ per worktree (its debug map names the worktree in
N_SO/N_OSO, so LC_UUID and the code signature differ) — stage1 now keys
on tools/with-sha256.w, what that binary is made from (the dep still
orders the build).

Proof (two fresh worktrees on one commit, a stage1 of this tree driving,
one store): the second `:dev` restored 25 entries, stage1 included, none
failed verification; with one byte changed in src/Lexer.w, stage1 was not
restored and rebuilt. Not yet seconds: 39 targets outside the store's
scope still run per worktree (SDK and sysroot packing, the empty
placeholder objects), and the pinned seed carries none of this until the
next seed, so seed-driven batteries see it then. The test verdicts and
build runners were already machine-wide (#1909, #1929).
ehartford pushed a commit that referenced this pull request Oct 3, 2026
…ves compiler-producing actions across worktrees (#1899)

A green belongs to the sources, not to the worktree (D49/D50); so does a
built artifact. Once an action that names its compiler (stage compiles,
runtime and bridge objects, .wo bundles, producer stamps) has run, its
declared outputs, state record and effect log are published under
$WITH_BUILD_CACHE_DIR (default ~/.local/with-build-cache; "none"
disables it), keyed on the local signature (the producing seed or stage
compiler, the action code, the compiler sources, with.toml), the content
of every declared input, the compiler= binary's identity and the driver's
own digest, so nothing is served across seeds or drivers. A worktree whose
freshness check misses restores the entry into its own out/ and
re-verifies it with the same check: a hit is exactly a fresh target, or
it is discarded and the target runs. The store keeps the 96
least-recently-used entries (WITH_BUILD_CACHE_KEEP).

What made a key worktree-specific, each found by a second worktree that
missed: directory fingerprints and the compiler-source hash named files
absolutely, and so did the action-code hash (the module closure's paths),
now all root-relative; records and effect logs are stored with <root> and
the restore re-pins the record's effects hash to the localized log; and
stage1 declared the seed-built out/bin/with-sha256 binary as an input,
whose bytes differ per worktree (its debug map names the worktree in
N_SO/N_OSO, so LC_UUID and the code signature differ) — stage1 now keys
on tools/with-sha256.w, what that binary is made from (the dep still
orders the build).

Proof (two fresh worktrees on one commit, a stage1 of this tree driving,
one store): the second `:dev` restored 25 entries, stage1 included, none
failed verification; with one byte changed in src/Lexer.w, stage1 was not
restored and rebuilt. Not yet seconds: 39 targets outside the store's
scope still run per worktree (SDK and sysroot packing, the empty
placeholder objects), and the pinned seed carries none of this until the
next seed, so seed-driven batteries see it then. The test verdicts and
build runners were already machine-wide (#1909, #1929).
ehartford added a commit that referenced this pull request Oct 3, 2026
…ty (#1899 #1906 #1905 #1865 #1835 #1888 #1900 #1998 #2000) (#2008)

* Build: a machine-wide build store under ~/.local/with-build-cache serves compiler-producing actions across worktrees (#1899)

A green belongs to the sources, not to the worktree (D49/D50); so does a
built artifact. Once an action that names its compiler (stage compiles,
runtime and bridge objects, .wo bundles, producer stamps) has run, its
declared outputs, state record and effect log are published under
$WITH_BUILD_CACHE_DIR (default ~/.local/with-build-cache; "none"
disables it), keyed on the local signature (the producing seed or stage
compiler, the action code, the compiler sources, with.toml), the content
of every declared input, the compiler= binary's identity and the driver's
own digest, so nothing is served across seeds or drivers. A worktree whose
freshness check misses restores the entry into its own out/ and
re-verifies it with the same check: a hit is exactly a fresh target, or
it is discarded and the target runs. The store keeps the 96
least-recently-used entries (WITH_BUILD_CACHE_KEEP).

What made a key worktree-specific, each found by a second worktree that
missed: directory fingerprints and the compiler-source hash named files
absolutely, and so did the action-code hash (the module closure's paths),
now all root-relative; records and effect logs are stored with <root> and
the restore re-pins the record's effects hash to the localized log; and
stage1 declared the seed-built out/bin/with-sha256 binary as an input,
whose bytes differ per worktree (its debug map names the worktree in
N_SO/N_OSO, so LC_UUID and the code signature differ) — stage1 now keys
on tools/with-sha256.w, what that binary is made from (the dep still
orders the build).

Proof (two fresh worktrees on one commit, a stage1 of this tree driving,
one store): the second `:dev` restored 25 entries, stage1 included, none
failed verification; with one byte changed in src/Lexer.w, stage1 was not
restored and rebuilt. Not yet seconds: 39 targets outside the store's
scope still run per worktree (SDK and sysroot packing, the empty
placeholder objects), and the pinned seed carries none of this until the
next seed, so seed-driven batteries see it then. The test verdicts and
build runners were already machine-wide (#1909, #1929).

* Build: the action runner links against a runtime root the driver names, of the driver's own generation (#1906)

Cause: the scheduler compiled the runner as soon as
prepare-bootstrap-link-root had completed in the run, executed or fresh,
and linked it under WITH_OUT_DIR, so the link probed out/lib first. The
prepare's freshness says nothing about out/lib: the stage chain re-creates
it (tree generation) after the prepare last ran, and a seed whose Link.w
lacked the per-candidate generation check (nightly-20260927, before
030293c) linked the tree's runtime into its runner: rt_compat_setenv_str
read an address as a length.

Reproduced on the pinned seed (c95ae12, which carries 030293c) in a
fresh worktree: out/lib a stage1 runtime set (.producer 91b9f004...),
out/bootstrap-lib the seed's (22a6c48c...), prepare fresh, runner store
empty: the runner compiled and ran. That seed's link skips the foreign
candidate, so the crash does not recur under it; the safety lived only in
the link's probe, and the driver still decided on the prepare's
freshness. The tool that should have refused stayed silent.

Fix: build_runner_link_root picks the first complete runtime directory of
the driver's generation (out/bootstrap-lib for the seed, out/lib for a
tree compiler) and the runner compile names it as WITH_RUNTIME_ROOT,
which Link.w refuses outright when its .producer is another generation
and never trades for a probed directory. The runner is compiled when such
a root exists, or when the prepare is done and the project has no runtime
directory at all (it links from the embedded runtime, as before); a
project whose only runtime is foreign says so instead of linking.

* Build: `--no-deps` runs an action in the native runner when a link root of the driver's generation exists, and refuses naming the dep when none does (#1835)

Cause: with --no-deps, prepare-bootstrap-link-root is not in the graph,
so the scheduler fell back to "no runtime directory belongs to another
generation". After a full build out/lib is the tree's generation, so
under the pinned seed that was false, the runner was never compiled, and
the action evaluated in the seed's comptime evaluator, which predates
7aed70f (generic calls without type arguments read Sema's
specialization) and failed after the smoke itself passed.

Failing first, pinned seed, fresh worktree, out/lib foreign, out/bootstrap-lib
the seed's own (.producer 22a6c48c...): `:embedded-clang-resource-source`
linked the runner and ran in 0.1 s; the same target with --no-deps
compiled no runner and ran 25.8 s in the comptime evaluator.

Fix: the runner decision is build_runner_link_root's (#1906): --no-deps
uses the seed's out/bootstrap-lib like any other run. When no root of the
driver's generation exists, --no-deps refuses, naming
prepare-bootstrap-link-root as the dependency it skipped, instead of
silently changing evaluators; a full run says once that actions evaluate
at comptime until the prepare builds the root.

* deps/seed: release discovery searches every page and says why it found nothing (#1888)

Cause: seed_release_from_api read one page of
`/releases?per_page=10` and returned "" for a miss. Every nightly
seed and SDK publish adds a release on top, so a platform's newest SDK
falls off that page within days: when #1888 was filed the darwin-aarch64
SDK (nightly-sdk-20260928-3ae5c9ec0b31) sat under more than ten newer
releases; today it is 9th, and the windows-aarch64 SDK is 17th, so
unpinned `:deps` on that host fails now. The miss said nothing about
whether the request failed, the response was malformed, or no release
carried the asset, and the response file was deleted.

Fix: the lookup walks the pages (100 releases each, at most 10 pages),
newest first, and reads the body as one text (each release's assets
follow its tag_name; an asset matches only as an exact quoted name, so
the .sha256 sidecar and a release body never do). It returns the tag or
the reason, keeps each response at out/tmp/seed-download/releases-<n>.json,
and both callers' errors name that reason.

Evidence (the real function through a temporary probe target, pinned
seed, reverted): windows-aarch64 -> nightly-20260907-34132069721-1-8a729db8d01f
(17th, beyond the old page); darwin-aarch64 -> nightly-sdk-20260928-3ae5c9ec0b31;
an absent asset -> "none of the 89 newest releases of withlang-dev/with
carries it (responses kept under out/tmp/seed-download)".

* test: the D acceptance corpus runs as the std fallback tier will resolve it (`:d-acceptance-tests`), import-free as D29 keeps it; the debug-alloc lane checks expect-stdout exactly (#1865)

test/d_acceptance (D29, #750): the import-free originals of the behavior
tests the §18.1 scaffolding gave explicit `use` lines, forked "not
overwriting" into a suite quarantined until D activation (#752)
un-quarantines it as the activation test. No lane compiled it, so it rotted
silently, and #1970 then inserted 183 explicit std imports into 166 of its
files (a mechanical §18.1 sweep that did not know the corpus's purpose),
which would make the activation test vacuous.

- The 183 `use` lines #1970 inserted are removed (exactly those lines; the
  eight files whose originals carried a `use std.` keep it). #1970's D71
  `xs[i]` respellings stay: a ruling moved that spelling.
- Respellings later rulings gave the behavior originals, mirrored into the
  forks: D32 field moves (behav_drop_tuple_field_extract,
  behav_mut_self_vec_owner_receiver: explicit `move` from a `var` base;
  behav_rc_arc_basic: `.clone()`), §4.2.6 narrowing (duck_method_ok:
  `-> i64`). Each now equals its behavior original minus imports.
- Deleted: behav_byvalue_view_escape_{nested,tail}. They pin the retired
  D5 share-place reading (a consuming T as the caller's place, escaping
  views valid); 2fdfbb9 (#718) turned their behavior originals into the
  negative fixtures err_consuming_param_{,nested_}view_escape.w.
- `:d-acceptance-tests` (in `:test`; build/acceptance.w): a copy under
  out/d-acceptance/corpus gains exactly the `use` lines the compiler's
  unique-match fix-it names, applied by tools/insert_std_uses.w (the tool
  the scaffolding used) to a fixpoint, and every file then runs under the
  exact-stdout runner. The tree's corpus stays import-free; at activation
  the fix-it step goes.

Census before (installed compiler, `check` per file): 14 of 181 red — 4
needing only `write`'s import (the fix-it's job), 3 D32, 2 retired D5,
1 §4.2.6, 4 issue59/61 fixtures whose helper modules live in
test/behavior/lib (the lane copies it beside the corpus).

tools/debug_drop.w `check` now also compares the program's stdout, from
the run under the debug allocator, with the fixture's `//! expect-stdout:`
lines: every line, in order, once each (#1855's runner rule). Failing
first: with one expected line changed, and with one dropped, the old
tool passes both (`debug-alloc lane: ok`); the new one fails each naming
the first difference. All 145 fixtures pass it. The tool also drops the
internal with_exec_*/with_fs_* externs (#901) for std.process
run_to_files and std.fs; its per-process capture paths are #2004's (PR #2005).

The lane's first run then named 11 more forks #1855 (c4a2863) had left
stale: it rewrote their behavior originals' expectation headers for the
exact-stdout rule (`expect-run-output:` -> `expect-stdout:` lines, subset
lists completed, a stray "\n" that printed a blank line dropped), and the
forks still pinned the old text. Each is re-derived as its behavior
original minus the scaffolding's `use` lines (a `use` the fork carried is
kept). `:d-acceptance-tests`: 179 files ok.

* Corpora are their migrator's output again, and `:corpus-drift-check` (in the gate) fails when they are not (#1905)

Cause: the checked-in corpora are generated (build/corpora.w: promotion
copies the migration; never hand-edited), but nothing compared them with
what this tree's migrator produces: the battery compiles the checked-in
output, and `<stem>-check-generated` runs only on a deliberate
re-migration. Two migrator changes landed without a re-promotion and the
drift was silent:
- D75 (173d8aa): a variadic definition spells `va_start()`; pcre2test.w
  and zl/gzwrite.w still called the retired with_va_start/with_va_end.
- #1933 (bfa0201): the migrator's own helpers take `__with_`-prefixed
  parameters, so a C global named `c` no longer makes them a refused
  shadow; every corpus's defs.w still had `c`.
(c_algorithms/binary_heap.w no longer differs.)

`<stem>-drift-check` (one per corpus, grouped as `corpus-drift-check` and
added to the gate's fixed list) runs the corpus's own stage, migrate and
finish hooks and writes its bundle root into a scratch tree — the migrate
action's steps, now shared as corpus_generate — with this tree's release
compiler as the migrator: an action carrying `migrator=<path>` runs
`<path> migrate` with exactly the workspace's option set
(corpus_migrate_argv), so the CLI and the workspace call
migrate_c_directory over the same settings. It then compares every
module byte for byte and fails naming each one that differs, is missing
or is extra, with the re-promotion command.

Failing first (`src/main build :corpus-drift-check` before the
re-promotion): pcre2 2 modules (defs.w, pcre2test.w), zlib 2 (defs.w,
gzwrite.w), c_algorithms 1 (defs.w), tommyds 1 (defs.w). Every hunk was
read: all are the two rules above, none changes behavior.

Re-promoted from the migrator's fresh output (exactly the six modules;
every corpus keeps its module count). After: corpus-drift-check green
("pcre2: 35 modules are the migrator's output", zlib 22, c_algorithms
24, tommyds 16); wo-drift, pcre2-wo-test, c-algorithms-test and
tommyds-test green over the re-promoted corpora.

* with get: a source build gets a CMake package config for every requirement, written from its recorded metadata as Conan's CMakeDeps would (#1900)

Cause: conan_install_from_source passes the installed requirements to
CMake only through CMAKE_PREFIX_PATH. A Conan Center binary package
carries no `<name>Config.cmake` (glfw/3.4's lib/cmake holds only
conan-official-glfw-targets.cmake): Conan's CMakeDeps generator writes it
at install time, and `with get` did not. So raylib/6.0, configured with
USE_EXTERNAL_GLFW=ON, failed at find_package(glfw3 3.4) whenever raylib
built from source while glfw came as a binary; every recipe that finds a
requirement by find_package(<Config>) has the same failure. (Under
`--from-source` the requirement is itself built from source and installs
its own config, which is why that path worked.)

Failing first (installed `with`, macOS arm64, fresh spiral project):
`WITH_GET_CMAKE_RAYLIB=SUPPORT_MODULE_RAUDIO=ON with get c.raylib` ->
glfw binary 71dfbca4fd16, then "Could not find a package configuration
file provided by "glfw3" (requested version 3.4)", rc 1.

Fix: for each resolved requirement without a config of its own,
`<file>Config.cmake` declares the recipe's target (cmake_file_name /
cmake_target_name read from the requirement's recipe, else CMakeDeps'
defaults: the package name, <name>::<name>) as an INTERFACE IMPORTED
target over the libraries, include directories, defines and link options
recorded in metadata.json, its requirements folded in; two-token Apple
flags stay one SHELL: option. `<file>ConfigVersion.cmake` answers the
version request (SameMajorVersion, CMakeDeps' default; a non-numeric
version such as "system" answers none). CMake finds it by -D<file>_DIR.
One metadata reader: ProjectConfig's, now public. No per-package table.

After (stage1 of this tree, same command): "-- Using external GLFW",
raylib/6.0 configures, builds and installs libraylib.a against the glfw
binary; the bundled rglfw is not compiled.

* stdlib-complexity times CPU, not the wall: std.libc cpu_time_ns over a with_libc seam, one body per backend; a quadratic control keeps the 6x bound honest (#1998)

Cause: test/complexity/stdlib.w timed each row with now_ns(), wall time.
On a loaded machine contention reads as super-linear growth, so a linear
row failed its 6x bound (#1998: trie 6.4x at load 36) and blocked a
battery for reasons unrelated to the change.

Failing first (the pre-change harness, ambient load ~50 from other
builds): 3 of 5 runs red, two on linear rows far outside the bound —
binary-heap 23x (0.43 ms -> 10.1 ms), trie 12x.

Fix: the harness times CPU — user + system of this process and of every
child it has reaped, so the stdin rows (whose work is a child process)
still count their work and nothing else on the machine does.
- std.libc cpu_time_ns(): a With function over the with_libc_cpu_time_ns
  seam in rt/rt_core.w (the category std.libc's rule names; POSIX
  getrusage itself may not be exported, and C's clock() leaves children
  out and on the UCRT counts wall time). rt_cpu_time_ns, one body per
  backend: getrusage(RUSAGE_SELF) + getrusage(RUSAGE_CHILDREN) on darwin
  and linux (each with its timeval layout); GetProcessTimes on Windows,
  each child's kernel + user time summed at every reap site as
  RUSAGE_CHILDREN does (GetProcessTimes gets its win32 facade row); 0 on
  wasm, which the harness's positive-duration assertion refuses.
- The harness declares the seam itself for now: importing std.libc into
  this file trips a Sema internal error in std/collections/sorted_vec.w
  (#2000, filed with the repro); it switches to `use std.libc.cpu_time_ns`
  when that is fixed.
- The 6x bound is kept. A `quadratic-control` row (each step scans all
  prior pushes) must miss it, or the run fails: the clock still sees
  super-linear growth on every run, not only in this commit's evidence.

After: `:stdlib-complexity` green; under 36 CPU hogs (load 49-60) the
harness passed 5 of 5 runs, every linear row inside the bound
(binary-heap ~4.6x, trie ~4x), the five XFAIL rows unchanged, and
quadratic-control outside it every time (16.5x in the lane run).
Every backend type-checks (`with check --no-prelude rt/<backend>.w`);
only darwin is run here.

* Sema: a generic instance is found by identity, never by the memo's absence; a comptime evaluation no longer duplicates Option[V] (#2000)

Cause (lldb + WITH_TRACE_INST on the reduced harness): the first check of
SortedVec[i32].index_of joined its `if` at Option[i32] (tid 1079). A
comptime evaluation (a `[x; N]` count; std.libc's import was only what
put one in the harness's order) runs on prepare_comptime_eval_copy, which
empties generic_inst_cache and writes the Sema back. preregister_mir_types
then read the memo's absence as "no Option[V] for HashMap[i32, i32] yet"
(Sema.w, `if not self.generic_inst_cache.contains(opt_key)`) and added a
second Option[i32] (tid 2225) under the same key. The re-check before MIR
lowering resolved `Option[i32]` through the memo to 2225 and met the
decision recorded at 1079: "conflicting contextual join decisions for one
expression". The same raw-memo read sat in SemaCheck's index-expression
instance lookup and MirLower.resolve_index_generic_inst, which also
trusted a bare hash hit as a type.

Fix: instance identity has one owner, find_generic_inst_type /
ensure_generic_inst_type (verify the memo hit, else scan); every
VecIter[T] / Option[V] / Vec[str] / VecIter[str] preregistration, the
index-expression lookup and the MirLower lookup go through it. The
internal error now names both decisions (sig, expected and final types
with their ids), so the next one says which types disagree.

Failing first: test/behavior/behav_2000_generic_inst_identity_after_comptime_eval.w
(a generic method joining at Option[i32], a `[0; 4]`, a HashMap[i32, i32])
reported the internal error on the unfixed stage1; it passes now, as do
the reduced harness and test/complexity/stdlib.w, which drops its #1998
workaround and imports std.libc.cpu_time_ns (harness run: all rows pass,
quadratic control outside the bound, rc 0).

* Build: the build store serves every cacheable target whose outputs are the same in every worktree; a second worktree's :dev is 9.7s, not 269s (#1899)

c558ec8 restored the 25 actions that name a compiler; a second worktree on
the same commit still ran 39 targets (268.7s :dev, release driver). Measured
in two fresh worktrees on one commit (driver = WITH = this tree's release
binary, as the next seed will be), what re-ran and why:

- Every runner action in a fresh worktree fell back to comptime evaluation
  (3.4s per empty placeholder, 38s compiler-no-c-export): the driver named
  out/bootstrap-lib as the runner's root because its rt_core.o matched the
  embedded one byte for byte, before bootstrap-runtime-producer had written
  its .producer, and Link.w then refused that named root for lacking one.
  One question, two answers: build_runner_link_root now asks the link's own
  test for a named root (link_stage_named_runtime_root_is_this_generation),
  and a runner already built for the key, here or in the machine-wide
  runner store, is used without any root (it links nothing).
- The store took only actions naming `compiler=`. It now takes every
  cacheable target (the local freshness contract: compiles, actions,
  generated sources, packs, placeholder objects) whose outputs and write
  scopes lie under out/, minus the always-run targets. The key hashes the
  signature with the worktree's root spelled <root> (an `llvm-prefix=<root>/
  .deps/...` arg is one argument everywhere); a restore re-pins the record's
  sig lines to this worktree's spelling, then verifies as before.
- An output that names its worktree is never stored, and the build says so
  ("[cache] X: not stored: ... names this worktree"): publishing it would
  hand another worktree this one's paths.
- darwin-sysroot depended on sysroot-zig-source, which extracts 279MB into
  .deps/src (outside out/, so no restore brings it) on every fresh worktree.
  It now fetches the pinned Zig source and libc++ ABI list into its own
  scratch and declares the tree every darwin link reads
  (out/gen/darwin-sysroot) as an output; pack and tree are byte-identical
  to the .deps-built ones.
- An embed target's assembly named its blobs by absolute path; it names
  them from the root (`.incbin "out/bootstrap-lib/rt_core.o"`) and the
  assembler reads a copy whose operands are resolved against the root.
- A restore forgets only the restored outputs' fingerprints, not the memo
  (src/ was re-hashed per stage-target restore).
- The store keeps 512 entries (a :dev publishes ~60, mostly small).

Numbers (same commit, fresh worktrees A then B, one store):
  before: A 342.2s, B 268.7s (39 ran), no-op 1.6s
  after:  A 334.5s, B 9.7s (59 restored, 4 ran), no-op 1.8s
B's 9.7s: ~4s evaluating build.w in a worktree with no graph cache (a
cached-graph run with every output deleted is 5.6s), ~1s hashing ~250MB of
restored outputs to verify them, the rest the four targets below.
Changed input (C: B's commit + one line in src/Lexer.w): 63.1s; ran stage1,
compiler-no-c-export and the two runtime-producer stamps (the targets whose
signature covers src/), restored the other 55.

Not storable, each named by the build when it runs:
- bootstrap-/stage1-llvm-link-metadata: llvm_link.rsp is an lld response
  file listing the SDK archives by absolute path (0.0s each; nothing stored
  keys on it);
- with-sha256: an Executable the driver compiles in-process, whose debug
  map names the worktree (no file-prefix map outside the stage actions);
- sdk-clang-main: adds clang's driver archive to the SDK in .deps, outside
  out/ (0.0s when present).

Failing first: test/behavior/behav_1899_build_store_serves_any_target.w
(an action naming no compiler is served to a second root; a changed input
misses; a root-naming output is not stored; a rooted arg is portable; an
embed's assembly carries no root) fails on the previous tree at the first
restore, passes now.

* Corpora: re-promote pcre2, zlib, c_algorithms and tommyds from this tree's migrator (#1905)

The drift check this stack adds found all four checked-in corpora stale
against the migrator on main: #1838 stopped emitting `-> Unit` on void C
functions and lowers a pure `(void)x` discard to nothing, and the D39
write contracts now print each function's `writes` clause. Nothing
re-promoted after those landed. Regenerated with
`WITH=out/release/bin/with out/release/bin/with build :<stem>-promote`,
each gated on the corpus's own tests (all four rc=0).

* Build: --no-deps refuses for a missing runner root only when it skipped the prepare that builds it (#1835)

The selfhost case build-w-evaluator-seed (`build :seed --no-deps` over a
foreign-generation out/lib) failed in the battery on c78e242 with
"--no-deps: ... `prepare-bootstrap-link-root` (a dependency of 'seed')
builds them and --no-deps skipped it". `seed` has no dependencies: the
refusal (src/main.w build_runner_explain_no_root, reached from the runner
check in run_build_graph) keyed on the --no-deps flag alone, so it named a
dependency that does not exist and refused a run that skipped nothing. The
same build without --no-deps evaluates at comptime and says so. It passed
on runs where the machine-wide runner store already held a runner for the
graph's key (build_runner_built), which links nothing and so never reached
the refusal.

run_build_command now computes what --no-deps skipped: the selected
target's full closure (build_graph_filter_target) containing
prepare-bootstrap-link-root. Only then does the run refuse; otherwise the
driver says actions evaluate in its comptime evaluator, as a full run does.

Verified with stage1 on a project with a foreign out/lib marker and an
empty runner store: `:x --no-deps` (x depends on the prepare) refuses
naming it; `:y --no-deps` (no dependency) evaluates at comptime; this
tree's `:seed --no-deps` prints "is the pinned seed" under the evaluator.

* Build: the build store never serves an action made from other reads; an entry is checked before it touches the outputs; WITH_BUILD_NO_EARLY_CUTOFF holds for the store (#1899)

The battery on c78e242 failed the four binary-read fixtures and
behav_build_early_cutoff, and cli-selfhost-build-w-tests on a second run.

Root cause (src/BuildGraphCache.w build_cache_store_key): the store key
hashes the signature, the driver, the compiler and the content of the
DECLARED inputs. An action's reads through ToolFs were recorded nowhere,
so the key and the record were the same for every project whose build.w
was the same, whatever the action read. binary_read_cases' action declares
no input and copies `input.bin`; its four kinds (missing, directory,
empty, binary) share one key. With an empty store, in one run: the empty
case published, and the binary case was served the empty output (fails at
binary_read_cases.w:39). Across runs the directory case was served a
success ("rc=0, expected a failure mentioning copy_file", store entry
9e5316c668ea, whose state has no in:/dep: line at all). The same gap holds
for the local state, which only hid behind each case's fresh root.

Fix: what an action reads through ToolFs is an input of its result.
- lib/std/build.w ToolFs.record_read (native runner) and
  ComptimeEvaluator.record_read_effect (evaluator, --strict-effects and the
  fallback) record every path an action reads, probes and listings
  included, outside its own write scope; build(ctx)'s reads (no write scope,
  or graph reconstruction with writes suppressed) are not the action's. The
  runner keeps one file per path beside its effect log (constant time per
  read); the driver reads them back (main.w build_runner_read_effects) and
  clears them before each run.
- build_cache_record turns `read` effects into `dep:` lines, fingerprinted
  like a compile's tracked inputs, so the local freshness check and a
  restored record both go stale when a read path's bytes, kind or absence
  differ.
- build_cache_store_restore checks the stored record's in:/dep:/env: lines
  against this worktree (build_cache_store_record_mismatch) BEFORE it
  replaces any output; an entry made from other reads is refused ("does not
  apply") and the target runs. It used to copy the outputs first and verify
  after, so a refused entry had already overwritten what was on disk.
- Failed actions were never stored (build_cache_record is reached only on
  success, in the runner, pool and evaluator paths), and still are not.

behav_build_early_cutoff:67: with WITH_BUILD_NO_EARLY_CUTOFF=1 `gen` ran,
and `use` (dependency rebuilt) was restored from the store entry step 3 had
published for the same input bytes. The escape hatch means "a dependency
ran, so rebuild"; main.w build_graph_early_cutoff_enabled now gates the
store restore of a target whose dependency ran, as it gates the cutoff.

Tests assert what their builds ran, and the machine-wide store serves a
target another run built from the same inputs (an action that prints,
served, prints nothing: the selfhost evaluator_print case failed that way
on a second run with the same compiler). The p7 harness gives each test
process a store of its own, emptied on first use; the selfhost cwd helpers
give each case one under the action's output; a test or case that names
WITH_BUILD_CACHE_DIR keeps it. These stores still serve within a test, so
the binary-read fixtures keep exercising the refusal. The selfhost
evaluator cases also get an empty runner store: a runner built for the same
graph links nothing and so ran `:seed` natively despite the foreign out/lib
marker, while the test's only check was the absence of "runner compiled";
they now also require the driver to say actions evaluate at comptime.

Failing first: test/behavior/behav_1899_build_store_undeclared_read.w (two
projects, one shared store, the same build.w reading different undeclared
bytes; a directory there must fail without its output being replaced; the
same bytes must be served; runner and evaluator) fails on c78e242's
release ("served another project's output: alpha"), passes on stage1. The
four binary-read fixtures, behav_build_early_cutoff and
behav_1899_build_store_serves_any_target pass on stage1.

---------

Co-authored-by: Eric Hartford <[email protected]>
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