Skip to content

[Perf] compiler: eliminate the --no-opt self-compilation memory floor & stack-unsafety (#40) - #41

Merged
katsujukou merged 16 commits into
mainfrom
bugfix/repair-exex
Jun 16, 2026
Merged

katsujukou merged 16 commits into
mainfrom
bugfix/repair-exex

Conversation

@katsujukou

@katsujukou katsujukou commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

This PR partially resolves #40 by addressing all currently identified scalability problems
except those originating in the optimization passes. With these fixes, purs-wasm can now
compile itself to Wasm under --no-opt (running the self-compiled output is still gated on
ST support — see follow-ups).

Changes

  • Stop retaining CoreFn, MIR, and ANF IR in memory through code generation.

    • CoreFn is dropped once translated to MIR (translate + lambda-lift fused per module).
    • MIR is dropped once lowered to ANF.
    • ANF is dropped once code generation to Binaryen completes.

    Previously, keeping all intermediate representations alive imposed a linear memory floor
    proportional to compilation progress — the front-half OOM that blocked self-compilation.

  • Convert Effect impurification into a trampolined execution model (stack-safe on deep ASTs).

  • Fix several secondary issues uncovered by --no-opt builds:

    • stripNewtype did not traverse as patterns (name@pat).
    • Eta-expansion for recursive let bindings failed to recognize functions built via
      mkFnN / mkEffectFnN (and let-wrapped / saturated point-free forms) as functions.
    • Multiple sources of stack-unsafety in code generation (genBody spine, genSwitch /
      genLitSwitch, addInternStr).
    • Stack-unsafety from traversing Array in raw Effect (whole-program emission loops).

    These interacted and collectively caused OOMs, hangs, and Maximum call stack size exceeded
    failures in --no-opt builds.

Fix uncovered while running the self-compiled compiler

  • Externs.Decoder imported PureScript ADT constructors from within a foreign module, relying on
    the JS runtime representation of PS values. Reworked to pass the constructors in from the PS side
    (the ADR-0014 foreign-provider idiom). In general, foreign modules must not depend on the JS
    representation of PureScript values.

Follow-ups (not in this PR)

  • ulib/arrays fromFoldable and the broader ST mutable-array support on wasm — tracked on a
    separate branch; the self-compiled compiler currently traps at the marshalling boundary for the
    Data.Array.ST / Control.Monad.ST foreign layer.
  • The optimizer-pass scalability gate (the NbE reducer is exponential without sharing) — ADR 0035 / 0036.

Checklist

  • Docs updated — docs/ + ADRs reflect the changes (frontiers, supported-features, ADR 0020 / 0035 / 0036).
  • Tests — regression guards added for the lowering fixes (as-pattern, recursive-let) in the
    unit lane; the codegen / serialize stack-safety fixes are currently validated only by the
    self-compile, not by a routine-lane guard.
  • Design changes have an ADR — ADR 0035 / 0036 added (forward-looking design for the
    optimizer gate); the changes in this PR are bug/perf fixes within the existing ADR 0009 model.
  • No perf regression — bench bundles byte-identical; node bench/run.mjs <dir> all within
    noise; bench/snapshots/baseline.json not overwritten.
  • [ ] N/A Runtime GC-type / ABI — no value-substrate / host-ABI change.

@katsujukou katsujukou changed the title Bugfix/repair exex [Perf] compiler: eliminate the --no-opt self-compilation memory floor & stack-unsafety (#40) Jun 16, 2026
@katsujukou katsujukou added bug Something isn't working performance labels Jun 16, 2026
@katsujukou katsujukou self-assigned this Jun 16, 2026
@katsujukou
katsujukou merged commit 710f921 into main Jun 16, 2026
14 checks passed
@katsujukou
katsujukou deleted the bugfix/repair-exex branch June 16, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exponential explosion during building large-scale application

1 participant