Rewrite Rule Inference Using Equality Saturation

OOPSLA 2021, August 2021
BibTeX
@misc{2021-ruler,
  title={Rewrite Rule Inference Using Equality Saturation},
  author = {
    Chandrakana Nandi and
    Max Willsey and
    Amy Zhu and
    Yisu Remy Wang and
    Brett Saiki and
    Adam Anderson and
    Adriana Schulz and
    Dan Grossman and
    Zachary Tatlock
  },
  year={2021},
  eprint={2108.10436},
  archivePrefix={arXiv},
  primaryClass={cs.PL},
  url = {https://arxiv.org/abs/2108.10436},
}
Given a grammar and interpreter for a target domain, Ruler uses e-graphs and equality saturation to efficiently enumerate potential rewrite rules and iteratively select a small set of general, orthogonal rules. Ruler supports various validation strategies to ensure soundness and speed up synthesis, including constraint solving (e.g., SMT), model checking, and fuzzing.

Abstract

Many compilers, synthesizers, and theorem provers rely on rewrite rules to simplify expressions or prove equivalences. Developing rewrite rules can be difficult: rules may be subtly incorrect, profitable rules are easy to miss, and rulesets must be rechecked or extended whenever semantics are tweaked. Large rulesets can also be challenging to apply: redundant rules slow down rule-based search and frustrate debugging. This paper explores how equality saturation, a promising technique that uses e-graphs to apply rewrite rules, can also be used to infer rewrite rules. E-graphs can compactly represent the exponentially large sets of enumerated terms and potential rewrite rules. We show that equality saturation efficiently shrinks both sets, leading to faster synthesis of smaller, more general rulesets.

We prototyped these strategies in a tool dubbed Ruler. Compared to a similar tool built on CVC4, ruler synthesizes 5.8x smaller rulesets 25x faster without compromising on proving power. In an end-to-end case study, we show ruler-synthesized rules which perform as well as those crafted by domain experts, and addressed a longstanding issue in a popular open source tool.