Skip to content

Build: fix compiler-main-source comptime budget overflow on Windows (CRLF normalize) - #910

Merged
ehartford merged 1 commit into
withlang-dev:mainfrom
ropoctl:fix-compiler-main-source-budget
Sep 1, 2026
Merged

ehartford merged 1 commit into
withlang-dev:mainfrom
ropoctl:fix-compiler-main-source-budget

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Problem

with build fails before stage1 on GitHub's Windows runners (both windows x86_64 and windows aarch64), and now also reds main itself:

error: action target 'compiler-main-source' failed during comptime evaluation:
comptime string construction budget exceeded (1073873897 bytes > 1073741824 bytes);
repeated `++` in a loop copies prior content, use StringBuilder or collect pieces

Every downstream error (missing out/stage/bin/with-stage2.exe for the bridge,
cimport-stubs, runtime, regex-IR objects, etc.) is a cascade from stage1 never
being produced.

Root cause

comp_normalize_line_endings (build/compiler.w) built its result with
out = out ++ slice in a loop over the whole input. src/main.w is the
amalgamated compiler source (~220 KB), and GitHub's Windows runners check out
with CRLF (core.autocrlf=true by default). That trips the CR-rewrite path,
which recopies the growing buffer on every line — O(n²) in bytes copied. As
the compiler source grew it crossed the 1 GiB comptime string-construction
budget (over by ~129 KB), so the compiler-main-source action now fails.

Linux/macOS check out with LF, so has_cr is false and the function returns
early — which is why only the Windows lanes fail.

Fix

Build the result with a StringBuilder, matching the sibling normalizers that
already do this for exactly this reason (br_normalize_embedded_source in
build/runtime.w, plus the pcre2 / package / sdk source generators). The LF
path is byte-for-byte unchanged (early return before the loop).

Verification

  • with build :compiler-main-source runs green; out/gen/main.w is
    byte-identical to src/main.w on the LF path (unchanged behavior).
  • The CRLF→LF rewrite is verbatim from the shipping br_normalize_embedded_source,
    which normalizes embedded sources on every build.
  • Windows CI on this branch is the CRLF gate.

build/*.w is interpreted by the seed at build time, so this takes effect with
no reseed; the seed already supports these StringBuilder calls (the twin in
build/runtime.w uses them on every build).

…g budget

comp_normalize_line_endings built its result with `out = out ++ slice` in a
loop over the whole input. src/main.w is the amalgamated compiler source
(~220KB), and on GitHub's Windows runners the checkout is CRLF
(core.autocrlf=true by default), so the compiler-main-source action took the
CR-rewrite path and recopied the growing buffer on every line. That is
O(n^2) in bytes copied and now exceeds the 1 GiB comptime string-construction
budget (1073873897 > 1073741824), failing the build before stage1 on both
windows x86_64 and windows aarch64.

Build the result with a StringBuilder, matching the sibling normalizers that
already do this for the same reason (br_normalize_embedded_source in
build/runtime.w, and the pcre2/package/sdk source generators). The Linux/mac
LF path is unchanged: no CR means an early return, exactly as before.
@ropoctl
ropoctl requested a review from ehartford August 31, 2026 18:52
@ehartford
ehartford merged commit 35300a0 into withlang-dev:main Sep 1, 2026
5 checks passed
ehartford pushed a commit that referenced this pull request Sep 1, 2026
Measured peak is ~0.5 GB; any target crossing 1 GB is a memory
regression and fails the build loudly, naming the target and its peak.
Raising the limit is a deliberate visible edit at the tripwire — never
a silent creep. Coverage note: pooled children carry exact wait4
rusage; in-process actions are independently capped at the same 1 GB
by the comptime evaluator's string budget (#910), so the two guards
agree on the number.
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.

2 participants