[Feature] Reduction-aware inlining - #43
Merged
Merged
Conversation
…String, surpress genericShow code-size explosion
… pmo as lowerd ANF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Makes the NbE reducer (
Semantics, ADR 0020) share work instead of recomputing it, and bounds the one case sharing can't help (genuine code-size blow-up). Together these let the optimized (opt-ON) self-compile ofPursWasm.CLI.Maincomplete — it previously hung indefinitely atOptimize.Specialize.The hang had two independent causes, both fixed here:
evalre-evaluated each inline-set binding per use site (M1), andquotere-evaluated shared values per path (M2) — Θ(2^d) on a diamond-shaped inline DAG.Specialize(module 276). Two sub-causes: the specialization dedup key was theshow-serialized lambda body (multi-KB strings built + retained asMapkeys), and NbE fully inlined the derivedgenericShowdictionary of the large IR ADTs into multi-million-node normal forms.What's included
ADR 0035 — sharing the NbE reducer:
b12f633) — memoize each inline-set binding'seval(Data.Lazykeyed by binding name). Kills the M1 re-eval. Byte-identical output.d1d26f8) —SSharedconstructor:evalVartags inline unfolds;unSharedstrips it at every consumption site so it never blocks a redex;quoteCSEs shared values into a hoistedlet. Kills the M2 re-quote. Diamond DAGs now normalize in O(d).cc11c18) —DictElim.normalFormSizeCap: when a declaration's reduced form exceeds the cap, re-reduce with the inline context emptied (the binding stays an ordinary call — the--no-opt-correct shape). Bounds thegenericShow-into-showblow-up. PlusSpecialize.canonicalKeynow hashes the canonical form (Serialize.Hash.hashString) and abstracts free vars in a singlesubstManypass instead ofshow-ing it per free var — removing the giant-stringMapkeys.Tests:
Test.NbeStress— a synthetic diamond-DAG guard (depth-20 normalizes to linear size, fails loudly if the exponential returns) + two Layer-C cap guards (fallback above the cap; still inlines below it). Wired intoTest.Unit.Compiler.Docs:
.pmi/.pmo-as-ANF,wasm-mergelink). Included here as the recorded rationale; no code change behind it.Verification
PursWasm.CLI.Maincompletes — writes a valid 8 MBindex.wasm(previously hung atOptimize.Specialize).showShadow/intGenericShadow/examplesRun— thegenericShowpath).examples/metatheorycompiles and runs.Byte-equality is not required (the current compiler isn't a verified reference); the gate is test-suite + bench + examples no-regression.
Checklist
CI passing is enforced by the required
ci-gatestatus check, not by a box here.The items below are the human-judgment gates:
docs/and relevant ADR(s).test:binscript.Statusset (ADR-first).node bench/run.mjs <dir>; do not overwritebench/snapshots/baseline.json). N/A otherwise.- [ ] Runtime GC-type / ABI / canonicalization — changes to the value-type substrate or the host/runtime ABI keep cross-module type canonicalization intact. N/A otherwise.