[Paper Review] Better Together: Unifying Datalog and Equality Saturation
This paper introduces egglog, a unified fixpoint reasoning system that combines Datalog's efficient, incremental execution with equality saturation's powerful equational reasoning. By integrating built-in equality, extensible functions with merge expressions, and lattice-based analyses, egglog enables faster, simpler, and more correct program analyses and optimizations than prior Datalog or EqSat systems alone.
We present egglog, a fixpoint reasoning system that unifies Datalog and equality saturation (EqSat). Like Datalog, it supports efficient incremental execution, cooperating analyses, and lattice-based reasoning. Like EqSat, it supports term rewriting, efficient congruence closure, and extraction of optimized terms. We identify two recent applications--a unification-based pointer analysis in Datalog and an EqSat-based floating-point term rewriter--that have been hampered by features missing from Datalog but found in EqSat or vice-versa. We evaluate egglog by reimplementing those projects in egglog. The resulting systems in egglog are faster, simpler, and fix bugs found in the original systems.
Motivation & Objective
- To address the limitations of Datalog and equality saturation (EqSat) when used in isolation for complex program analyses.
- To unify the strengths of Datalog—such as efficient incremental evaluation and composability—with EqSat’s capabilities in term rewriting and congruence closure.
- To eliminate the need for ad-hoc, error-prone implementations (e.g., union-find in Datalog) and unsound rewrites (e.g., in EqSat) by providing a unified, type-safe framework.
- To enable scalable, composable, and formally correct program optimizations and static analyses through a single, extensible system.
- To close the gap between Datalog and EqSat by introducing novel mechanisms like merge expressions for functional dependency repair in user-defined functions.
Proposed method
- egglog is built as a Datalog engine with two core extensions: native support for user-defined equality and extensible uninterpreted functions.
- Equality is enforced via a built-in, extensible congruence closure mechanism that maintains equivalence classes across terms.
- Functions in egglog are relations with functional dependencies, and conflicts from equivalent inputs are resolved via user-defined merge expressions.
- Merge expressions allow flexible resolution of functional dependency violations—e.g., by asserting equality of outputs or taking a lattice supremum—enabling safe, composable rewriting.
- The system uses bottom-up evaluation with semi-naive optimization and supports incremental e-matching by reducing it to relational queries, enabling efficient pattern matching modulo equality.
- egglog integrates lattice-based reasoning and supports conditional rewriting through relational pattern matching and rule scheduling, enhancing expressiveness over traditional EqSat or Datalog alone.
Experimental results
Research questions
- RQ1How can Datalog and equality saturation be unified to overcome their respective limitations in program analysis and optimization?
- RQ2Can a single system efficiently support both incremental, lattice-based reasoning (from Datalog) and equational reasoning with congruence closure (from EqSat)?
- RQ3What mechanisms are needed to safely reconcile functional dependencies when user-defined functions are applied to equivalent inputs?
- RQ4To what extent can efficient e-matching and incremental reasoning be natively supported in a Datalog-first system with built-in equality?
- RQ5Can the integration of Datalog and EqSat features lead to simpler, faster, and more correct implementations of real-world program analyses and optimizers?
Key findings
- egglog successfully reimplemented two complex systems—Herbie (floating-point term rewriter) and cclyzer++ (pointer analysis)—and achieved better performance and correctness than the original implementations.
- The egglog version of Herbie eliminated unsound rewrites by integrating conditional reasoning and lattice-based checks, removing the need for post-hoc validation.
- The egglog version of cclyzer++ replaced an ad-hoc union-find implementation with native equality support, fixing previously undetected bugs and improving performance.
- egglog’s e-matching is more efficient than in traditional EqSat systems because it reduces e-matching to relational queries, enabling incremental and optimized pattern matching.
- The use of merge expressions in egglog enables safe, composable functional dependency resolution, surpassing the expressiveness of both pure Datalog and EqSat in handling complex rewrites.
- egglog’s Datalog-first design with built-in equality and lattice support allows for natural, high-level encoding of complex analyses without performance penalties or low-level complexity.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.