A modern compiler framework for datalog
Abstract
Datalog is a declarative logic programming language with fixpoint semantics that originated in database theory. Since its emergence in the 1970s, Datalog has experienced multiple renaissances. The most recent resurgence, in the 2010s, has been driven by its suitability for domains such as program analysis, network verification, and smart contract validation. This renewed interest has led to the proliferation of numerous Datalog dialects, each tailored to specific application domains. Frustratingly, this has also resulted in a fragmented ecosystem, with systems that are incompatible at both the surface language (dialect) level and the underlying evaluation engines. One might assume that this fragmentation is unavoidable, due to the specialization of each system for a specific use case. However, we argue that the true root cause is the lack of a shared compiler infrastructure. Drawing inspiration from LLVM and its multi-level intermediate representation (MLIR) infrastructure, we identify four essential characteristics to mitigate this fragmentation: (i) modularity, the ability to cleanly add frontends and backends to a compiler, (ii) extensibility, which allows new language features to be systematically incorporated into a compiler, (iii) reusability, enabling transformations and optimizations to be shared across frontends, and (iv) interoperability, which facilitates code sharing between frontends. Such a system is what we call a compiler framework, as opposed to conventional single- or multi-pass compilers. In this thesis, we propose MLDL (Multi-Level Datalog), a novel compiler framework specifically designed for Datalog. At its core, MLDL introduces a declarative, typed, multi-level IR that preserves Datalog’s logical structure while enabling domain-specific extensions and progressive lowerings. This IR serves as a common target for multiple frontend dialects and diverse backend engines, decoupling language design from optimization and execution. To highlight the modularity and extensibility of our approach, we design the first object-oriented Datalog dialect with side-effects, OODL, and integrate it into MLDL. Next, to ensure reusability, we develop an extensible analysis framework built atop the IR, enabling inter-relational analyses. We implement a well-studied constant propagation optimization and also introduce a novel termination checking analysis for our IR. These analyses can be adapted easily to new language extensions without requiring global redesign. Finally, to enable true interoperability, we introduce a module system for the Datalog IR that supports separate compilation, partial linking, and cross-dialect reuse. To demonstrate this, we compose a Soufflé-based points-to analysis for Java within a Functional IncA program to create an escape analysis. Through implementation and evaluation, we show that MLDL fulfills the four pillars of a modern compiler framework: modularity, extensibility, reusability, and interoperability. Our work lays the foundation for a unified, collaborative Datalog ecosystem, reducing duplication, lowering barriers to entry, and accelerating innovation across domains.
Community
0 commentsNo discussion yet
Be the first to share a question or observation.