Skip to content

feat(opt): cost-driven ægraph extraction (v1.1.0 Track B)#134

Merged
avrabe merged 1 commit into
mainfrom
release/v1.1.0-track-bd
May 19, 2026
Merged

feat(opt): cost-driven ægraph extraction (v1.1.0 Track B)#134
avrabe merged 1 commit into
mainfrom
release/v1.1.0-track-bd

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 19, 2026

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

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 avrabe merged commit 57745af into main May 19, 2026
@avrabe avrabe deleted the release/v1.1.0-track-bd branch May 19, 2026 18:28
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant