Repository navigation
Closed
Description
Repro
with build :emit-c-roundtrip
# or directly, after the roundtrip has produced out/emit-c-roundtrip/main.c (~48 MB):
out/release/bin/with migrate out/emit-c-roundtrip/main.c -o /tmp/main_roundtrip.w \
-I runtime -include out/gen/wl_decls.h --no-c-exportActual
error: with: memory limit exceeded: committed=68719426576 requested=65536 limit=68719476736 bytes
The CLI's default build memory cap is 64 GiB (CLI_DEFAULT_BUILD_MEMORY_LIMIT_BYTES,
overridable via the documented env var; 0 disables). Committed bytes on a 48 MB C
input exceed it — ~1300x the input size.
Evidence so far
- Observed RSS: ~44 GB at 4.5 min into the run; ceiling (64 GiB committed) hit at ~9-10 min.
- After d39fd50 (large-range ownership checks binary-search; previously ~90% of CPU),
the CPU profile during the climb is dominated byci_str_matches_at/
ci_find_strviaci_lookup_macro_value/ci_lookup_known— migrator text
scanning, i.e. real work, so this is retention, not scan overhead. - Cursor/children cache tables in
src/compiler/ClangBridge.w(store_cursor,
ensure_children_cached) are linear in TU size — estimated ~1 GB for this input,
so they cannot account for the bulk. Prime suspects: per-expression clang string
copies (session_make_str/session_strdup— session-arena strings retained
until session end), tokenization buffers, and CiIR pools retained TU-wide instead
of per-decl.
Expected
Migration of the emitted compiler C completes within the default cap. Peak memory
should be roughly proportional to the largest declaration being lowered plus
TU-level indexes, not to the whole TU's expression count.
Impact
Blocks with build :emit-c-roundtrip at the migrate-compiler-c step (its other
known blockers were fixed in 1d4fa51 / 29a369b / abf1e2e / d39fd50; migration
now reaches ~11 min of real work before dying at the ceiling).
Notes
- Do not raise the cap or the step timeout to make the target green; the retention
is the defect (mission: leaks must take deliberate effort). - First step is attribution: an allocation-site histogram at ceiling-exceeded (or a
debug-allocator mode that dumps live-bytes-by-site) would settle where the bytes
live before any redesign.
Metadata
Metadata
Assignees
Labels
No labels
Activity
ehartford commentedon Jul 31, 2026
Investigation complete — primary cause is the pending #691 str flip; two migrator amplifiers fixed in 22d0950
Method
WITH_ALLOC_SYSTEM=1 MallocStackLogging=literun sampled withmalloc_history -allBySizeat ~13 GB footprint, plus lldb breakpointsampling on
session_strdup/rt_alloc_unlocked(the malloc_historyunwinder cannot walk pure-With frames; lldb can), plus a debug-alloc leak
probe on a reduction.
Findings
Primary: transient str drops do not free. A 1000-iteration loop
binding one f-string per iteration reports 2002 debug-alloc leaks — str
buffers are pending the Campaign: the wide flip — containers own their buffers (POD-element drop elaboration) #691 wide-flip stage (
docs/decisions.md: 'theCampaign: the wide flip — containers own their buffers (POD-element drop elaboration) #691 str flip must decide what Copy means for str-bearing structs'; the
Vec-buffer half landed). Migrating 48 MB of C creates hundreds of millions
of transient strings (type spellings, cursor source text, rendered
fragments); with no frees, committed bytes reach total-ever-allocated.
Measured peak with the cap disabled: 68.4 GB, with a sharp drop at
session dispose — i.e., the classic leak-until-arena-teardown curve. Any
comparably string-heavy workload dies the same way until the str flip
lands; the migrator is just the first one this big.
Amplifier A (fixed): per-probe session retention in decl lookups.
ci_lookup_c_function_decl_idx/ci_lookup_c_function_return_typerescanned all decls per call and every probe session-retained a fresh
with_cimport_decl_namecopy — 82M+ live strings at ~1/4 progress;5/5 lldb-sampled allocations went through this path. Now one-pass
owned-copy indexes, keyed by session + a new parse generation.
Amplifier B (fixed): duplicate cursor stores.
with_cimport_decl_cursorre-stored the cursor per call; each freshindex rebuilt whole subtree children caches (4 GB / ~125M cursors at the
same sample). Now memoized per decl.
Sibling rescan loops remain in
ci_type_field_count/name/type(CImport.w:14634+) — same shape, not observed dominating; worth the same
index treatment when touched.
Behavior preservation: the fixed migrator's output is byte-identical
to the pre-fix compiler's on a prelude-scale input (5 MB fixture C).
Measurements
Environment caveat that blocked final verification
This dev box (macOS 26.5) SIGKILLs long CPU-pegged processes at ~10–11
minutes regardless of nohup/disown or launchd hosting — 66 launchd-looped
roundtrip attempts all died at
migrate-compiler-cwith rc=137 and empty(buffer-lost) captures, with no jetsam/memorystatus log entries. The full
migrate needs one uninterrupted ~11-minute run; from an interactive terminal:
(Once migration completes, the next known fallout item is #746 —
positional struct literals from the goto-CFG memcpy path.)
Where this leaves the fix
live set). Until then the migrate step cannot fit 64 GiB by construction.
raised/disabled cap documented as tied to the str flip, or keep the
roundtrip red until the flip lands. Maintainer's call.
ehartford commentedon Jul 31, 2026
D28 ruled (both predictions confirmed by Eric): the fix is the #691 str flip, now filed as #747 with the de-Copy conformance list; ephemeral view-structs (the view-token mechanism's new shape) filed as #748. Interim: the roundtrip's migrate step disables its memory cap per D28 ruling 3 (bdcb9b3), revert condition named in the code — the #608/#693 pin doctrine. This issue stays open to track the un-pin: it closes when #747 lands and the migrate step fits the default cap again.
ehartford commentedon Aug 2, 2026
Roundtrip update: the migrate step's i32 session-string-counter overflow is fixed (record/typedef lookups indexed per the fn-index pattern; counters widened to i64 — commit on main). With that fixed, the step now dies at max RSS 94.4 GiB (OS kill, no jetsam log): the D28-acknowledged transient-str retention has outgrown this machine — the pre-#749 baseline peaked 68.4 GB and survived; the #749 payload-enum/access-hop translation plus #750-era work added enough transient string churn to cross physical limits. The step is memory-infeasible until #747 (the str flip) lands, which is already next in the D29 sequence. The RSS trace and repro command are in docs/handoff.md.
c-migrate: index decl-name lookups; memoize decl cursors (#744)
docs: record #744 root-cause chain and roundtrip state in handoff
build: pin migrate-compiler-c memory cap off until the str flip; reco…
c-migrate: index record/typedef name lookups; widen session string co…
WIP withlang-dev#747: un-pin the D28 migrate memory cap
ehartford commentedon Aug 31, 2026
Triage 2026-08-31: CLOSE (overcome by events). The cap failure is dead: retention root-caused and fixed (22d0950, d39fd50, 7af076d) plus the #747 flip removing the transient class; the full 47.6MB compiler-C migration has since completed (~2GB peak) and been censused. Remaining roundtrip redness is downstream compile errors, tracked elsewhere.
c_import is linear in a header's declarations: emitted names are a ha…
c_import is linear in a header's declarations: emitted names are a ha…
c_import: a DEFINE_GUID var no longer feeds winnt.h to the C expressi…