feat(opt): cost-driven ægraph extraction (v1.1.0 Track B)#134
Merged
Conversation
Closes the v1.0.5 Track 1 substrate gap. The v1.0.4 ægraph substrate's extract() always emitted the node originally stored at the requested class id, ignoring union-find merging. v1.0.5 Track 1 worked around this in the pipeline pass by scanning all class ids in the same UF root for the smallest extraction. This PR moves that logic into egraph::extract() itself, with a proper byte-cost model: - New Op::encoded_byte_cost() returns 1 for opcodes, 1 + LEB128 width for Const/Const64/LocalGet. Mirrors the wasm-encoder behavior exactly. - extract() / extract_into() now scan all class ids whose UF root matches the requested class, pick the cheapest representative by TOTAL subtree cost (not just node-local cost), and emit that subtree. - subtree_cost() is memoized via HashMap to prevent combinatorial blowup on large merged classes (the v1.0.4-substrate equivalent recursion overflowed the stack on the v1.0.5 Track 1 test's recurse-into-blocks case). - The acyclic invariant (child id < parent id) is the termination guarantee. The v1.0.5 Track 1 pipeline workaround at lib.rs:7677 is removed — the call site is now just `egraph.extract(root_class)`. ## Tests All 14 v1.0.4 substrate tests pass. All 4 v1.0.5 Track 1 pipeline tests pass. 18 egraph-related tests green. ## Track D (Track-3 housekeeping) deferred The other v1.0.5 carry-forward — derive Eq/Hash on Instruction + pub(crate) AdapterInfo + surface FusedOptimizationStats + no-silent-swallow in optimize_fused_module — is deferred to v1.1.1. v1.1.0 is already a substantial surface (cost extract, Rocq Path A, i64/commutativity rule widening, meld-fixture deferral); adding the housekeeping touches every fused-optimizer call site and would expand the v1.1.0 review surface materially. Trace: REQ-3, REQ-14
avrabe
added a commit
that referenced
this pull request
May 19, 2026
…ers (v1.1.0 Track C, rebased) (#137) Track C's content rebased onto post-Track-B main. Track B's cost-driven extract is preserved (it's already merged on main as PR #134); this PR adds i64 op variants + 8 i64 identity rules + commutativity helpers on top. ## What lands 11 new Op variants: I64Add/Sub/Mul/And/Or/Xor/Shl/ShrS/ShrU/Eq/Eqz. 8 new identity rules (i64 add/or/and/mul/xor + 3 shift-by-zero). Op::is_commutative() + EGraph::canonicalize_commutative() helpers. ## Tests 25 egraph tests pass (was 18 after Track B). 1 ignored (commutativity end-to-end — needs insertion-time normalization, v1.1.1). Trace: REQ-3
6 tasks
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.
Closes v1.0.5 Track 1 substrate gap. extract() now scans UF root with memoized byte-cost DP. 18 egraph tests pass.
🤖 Generated with Claude Code