Skip to content

Compiled build graph: build.w compiles to a cached native runner; the evaluator leaves the build path (#679 arc, promoted) #921

Open

Description

@ehartford

Ruled direction (Eric, 2026-09-02, after the reference pause): every reference build system executes build logic as NATIVE code evaluated at most once per build — Zig compiles build.zig into a cached build-runner binary; Go compiles the logic into the go tool; Cargo compiles build.rs once per package; SwiftPM compiles Package.swift once into a data manifest. None interprets build logic, and none re-executes it per step.

With today: build.w is comptime-INTERPRETED per invocation (~2.5s floor even for an error), and every worker child re-evaluates it in full — pooled lanes, serial action workers, all of them. Measured: the test-green worker spent its first ~35-70s in re-evaluation; each of #680's 19 pooled lane workers pays the same tax (why cli-selfhost-project went 28.6s->88.1s pooled and the lane-pooling win capped at 16%).

Tactical fixes banked first (e41bd55/0ce5b23c/e5e19578: decl-index memoization, same-file context skip, bulk push_str — test-green 79->35s); the remaining evaluator cost is intrinsic per-step interpretation (rt_payload_start_is_owned churn from per-step str traffic — sampled), which this campaign deletes wholesale.

Design (Zig's shape, With's advantage: build.w IS a With program)

  • with build compiles build.w + build/*.w + std.build into a native build-runner binary, cached by (compiler fingerprint, build-source hash) — the same keying discipline as the graph cache. Cache hit = zero build-logic cost; miss = one native compile (~seconds at -O1 for the build tree).
  • The runner constructs the graph and executes targets natively: actions run at native speed in-process or in cheap workers (a worker child of the RUNNER re-enters natively — no evaluator anywhere).
  • The comptime evaluator remains for comptime-in-user-code; it simply exits the build path.
  • Invariants: no cache-format changes beyond the new runner cache entry; -O1; fixpoint discipline (the runner is compiler output — determinism applies); no external deps.
  • Interaction: supersedes further Build: parallel build-graph executor with memory-claim admission (study delta 8) #680 tuning of worker cost; the worker re-eval tax and the 2.5s invocation floor both go to ~0.
  • Prereq check: build.w actions use ActionCtx/ToolFs capability machinery — the native runner must provide the same surface (std.build already defines it; today the evaluator implements the backing — inventory which ctx entry points have evaluator-only implementations and give them native ones).

Expected effect at the battery level: removes ~30-70s x N_workers from :test, the 2.5s per-invocation floor everywhere, and the whole class of evaluator budgets/step limits from build actions.

Activity

  1. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    Phase 0 + phase 1 are implemented and verified locally (batteries in flight):

    Remaining in this arc: Workspace-surface native design (subprocess compile + message-stream protocol) so the selfhost/LSP lanes leave the evaluator; then the endgame where the parent's own graph evaluation moves into the runner and the 2.5s invocation floor goes to ~0.2s cache-load + native dispatch.

  2. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    Phase 2 design brief: native Workspace surface

    What exists already (changes the cost of this phase substantially): D24/#729 made every workspace compile process-isolated — the evaluator serializes a ComptimeWorkspaceCompilePlan (sources incl. in-memory texts, options, migrate options, link libs) and spawns with __workspace-compile <plan> <result>. The compile itself already runs out of process; only the orchestration (plan construction, message interception, link-command staging) is evaluator-hosted.

    Usage census (build/*.w): ~21 plain create_workspace → add_file/add_string → set_options → compile() uses across sdk, seed, emit_c, zlib, pcre2, selfhost; the intercept surface (begin_intercept/wait_for_message/end_intercept) is concentrated in selfhost.w (38 uses) + pcre2.w (4) — i.e. exactly the cli-selfhost trio that is now the honest critical path (~90s×3, co-terminal).

    Design:

    1. Plain compiles (the easy 80%): native Workspace.compile in std.build builds the same plan and spawns the same with __workspace-compile child. Decision fork: (a) a std.build twin of the plan serializer (the effect-records parity precedent — second format duplication), or (b) a v2 std-authored plan format the child also reads. I lean (b): the child already owns deserialization; one reader with two versions beats two writers of one fragile format.
    2. Intercepts: messages appear observational (script asserts on compiler envelopes; set_link_command stages before the link step). If that holds — verify before building — the child streams envelopes to a file/pipe, wait_for_message reads sequentially, and the link command rides in the plan. No bidirectional control channel needed. If a suite genuinely steers mid-compile, that suite stays on the evaluator (97-fallback already handles it per-target).
    3. parallel() becomes native process fan-out over the same children — strictly simpler than the evaluator's version.

    Mission fit: completes the reference-language shape (build logic native, evaluated once); deletes the last evaluator dependency from the hot path; selfhost lanes get native orchestration glue around their (already-subprocess) compiles.

    Prediction: proceed as sketched, with (b) for the plan format — the runner is already the ruled direction and this is implementation architecture, not surface. Flagging it anyway because the intercept suites change execution model (no same-process Sema access); anything secretly relying on that breaks loudly under the 97-fallback rather than silently.

  3. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    C1 landed and reseeded (6cd878d): plain (non-migrate, non-intercept) Workspace flows run natively — file-backed state, plan format canonical in std.build, same D24 child via WITH_BUILD_COMPILER. sdk/seed/emit_c workspace actions now run native inside the battery (green). Found+filed #929 (silent unknown string escapes) en route. Next: post-reseed serializer-twin cleanup in ComptimeEval, then C2 (intercept surface — compile-to-prelink/execute-link child modes + envelope replay) for the selfhost trio.

  4. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still open. C1 runs Workspace flows natively, and the runner compiles in a ready tree ("[build] runner compiled 5.9s"), but the evaluator has not left the build path: in a fresh worktree the driver reports "build runner compile failed …; actions fall back to comptime evaluation by the driver" and runs actions in the evaluator (a doc-path-check took 48 s that way against 0.9 s compiled). C2 (the intercept surface) is the open step.

    post-release: build-system campaign.

  5. added this to the post-v0.16.0 milestone on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions