Skip to content

emit-c self-compile OOMs (>32 GiB): single ~12.9 GB allocation during with --emit-c on the compiler #619

Closed

Description

@ehartford

Summary

The --emit-c self-compile of the compiler exceeds the 32 GiB memory tripwire. During with build :test, right after EMIT-C SMOKE OK, the emit-c-test phase aborts with:

with: memory limit exceeded: committed=33819029136 requested=12884901904 limit=34359738368 bytes

i.e. committed = 33.8 GB, a single 12.9 GB allocation request, against the 32 GiB (34359738368) default cap. with build :test still exits 0 because the harness tolerates this late-phase abort, but it exceeds the tripwire and is a real resource bug.

Repro

# the emit-c-test phase runs, effectively:
./out/release/bin/with build out/gen/main.w --emit-c -o /tmp/main.c
# (or: with build :emit-c-test)

out/gen/main.w is the combined compiler source; this emits the whole compiler through the C backend.

Analysis / where to look

  • The abort is a single 12.9 GB allocation (committed already 33.8 GB), i.e. one runaway Vec doubling (~6.4 GB → 12.9 GB) rather than diffuse accumulation. Look for an unbounded/duplicated buffer in the C backend (build/emit_c.w, the --emit-c codegen path), or a clone-style leak analogous to the comptime one below.
  • This is the --emit-c cross-compilation path only (spec §16, --emit-c C source backend). The normal LLVM backend path is unaffected — check src/main.w is now 2.51 GB after the fix in the sibling change (comptime prepare_comptime_eval_copy was deep-cloning the full ~8.5 MB source text on every comptime eval). A similar per-something deep-copy in the emit-c path is a plausible cause.

Notes

  • Pre-existing (documented previously as a cli-selfhost/high-RAM peak); not introduced by the comptime source-text fix (that only reduces memory).
  • Spec reference: §16 (CLI reference), --emit-c (C source backend / cross-compilation).
  • Target: memory for emitting the compiler should be well under 8 GB, not >32 GB.

Activity

  1. ehartford commented on Jul 17, 2026

    @ehartford
    ContributorAuthor

    Retested on a7efb23 while unblocking #668: the full-compiler --emit-c run no longer OOMs — emission completed under the default 32 GiB limit and produced the full 1.84M-line C artifact. The comptime memory-profiling fixes that landed since this was filed (source-text leak, 4.76→2.51 GB) appear to have resolved the single ~12.9 GB allocation this issue reported; I did not re-observe it.

    The cross-compilation story's current barrier has moved: the emitted compiler C fails cc with (a) lazy map-init assignments through const-qualified receiver pointers (18+ sites before the error limit) and (b) a missing with_str_split_vec extern declaration. Fixing those is the next step toward the emitted compiler actually building.

    Suggest either repurposing this issue to track 'emitted compiler C compiles and runs' or closing it as resolved-by-memory-work when the maintainer next triages — leaving that call open.

  2. ehartford commented on Jul 17, 2026

    @ehartford
    ContributorAuthor

    The cross-compilation loop is closed in 33b064e. Following up on my earlier retest comment: both remaining barrier classes are fixed, plus three more that surfaced behind them, and the pipeline's own gates now pass end-to-end with no environment overrides:

    • with build src/main.w --emit-c emits the full compiler (1.84M lines of C) — no OOM, under the default memory limit
    • The emitted C compiles clean with the stock host cc (61 errors → 0)
    • The resulting with-from-c reports its version, compiles and runs real With programs
    • :emit-c-fixpoint passes: with-from-c re-emits the compiler's C byte-identically

    Fix inventory (details in the commit): lazy map-init removed from MAP_INSERT (wrote through const receivers; LLVM has no such crutch), C99 compound literals for constant operands at pointer params, MAP_KEYS lowering implemented (VALUES/ITEMS fail loudly instead of leaking bare calls), VEC_PUSH result materialization guarded to vec-typed destinations, four missing with_runtime.h declarations, and an emitc_c_compiler existence-probe fallback (the static-LLVM SDK ships archives, not the clang driver — the old default was a dangling symlink, exit 127).

    One infrastructure note for triage: the SDK's clang/clang++ symlinks in .deps/llvm-22.1.6-darwin-arm64/bin dangle (clang-22 absent). The fallback makes the pipeline independent of that, but if the SDK is meant to ship the driver, that's a tools/build-static-llvm.sh packaging question.

    With the original OOM gone and the loop green, I believe this issue can close — leaving that to you since the issue title describes the OOM and the scope evolved.

  3. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-08-31: CLOSE (overcome by events). Fixed by 33b064e "emit-C: close the compiler cross-compilation loop (#619)" — the self-compile completes under the default memory cap with no override; out/gen/.emit-c-test-stamp records the full compiler emitting and rebuilding byte-identically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions