fix(elc): eliminate OOM in --emit-header; add memory guard #47
Reference in New Issue
Block a user
Delete Branch "fix/elc-oom-checkout"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root cause
--emit-headercalledparse()which builds the full program AST (all function bodies) before writing the.elh. Forcheckout.el(~491 lines with a large HTML template tree and deep BinOp string-concat chains), this exhausted memory. The streaming codegen path was irrelevant —--emit-headernever used it.Fix
Replace
parse()+emit_header()withscan_fn_sigs_el()+emit_header_from_sigs():scan_fn_sigs_el()— token-level pre-scan, skips all function bodies entirely. Peak memory is O(tokens), not O(whole-program AST).emit_header_from_sigs()— writes.elhdirectly from the scanned signatures.The
.elhonly needs function signatures — there was never a reason to parse bodies for header emission.Memory guard
Add
el_mem_check()toel_runtime.c: readsELC_MAX_MEM_MB(default 512MB), checks RSS viagetrusage(macOS bytes / Linux KB normalised to MB), prints a diagnostic to stderr andexit(1)if exceeded. Wired into:compiler.el: upfront check at--emit-headerentrycodegen.el: per-function check in the streaming loop after eachel_arena_popPrevents the process from taking the whole machine down on runaway growth.
Verification
checkout.el --emit-header→ all 3 function sigs in.elh(was 2/3 before)ELC_MAX_MEM_MB=1 elc --emit-header checkout.el→ exits 1 with clear diagnosticelc compiled with new elc, diff identical