Type Checking Semantically Lifted Programs via Query Containment under Entailment Regimes

Eduard Kamburjan, Egor V. Kostylev

Introduction

Modern software development increasingly requires a synergy between imperative logic and declarative knowledge. While imperative programming excels at defining "how" a system should behave, ontologies and the Semantic Web provide a robust framework for defining "what" entities and relationships exist within a domain. This paper explores the intersection of these paradigms, specifically focusing on semantic lifting—a technique where a program's internal state is projected into a Knowledge Base (KB) to facilitate complex semantic queries.

Semantic Lifting and the Type Safety Problem

In a semantically lifted environment, a program (such as one written in the SMOL language) takes its current runtime state and views it as an OWL ontology. This allows developers to use SPARQL to perform sophisticated reasoning that would be cumbersome in standard imperative code. For instance, a cloud management system might query its own state to identify "overloaded platforms" based on complex domain rules defined in an external ontology.

The workflow of semantic lifting where program state is mapped to a knowledge graph and queried.

However, this integration introduces a significant challenge: type safety. In traditional languages, type errors are caught at compile-time. In semantically lifted programs, the results of a query depend on an external ontology that the compiler typically does not analyze. If a query returns data that does not match the program's expected data structures, the application may crash at runtime. Previously, the SMOL language relied on dynamic checking, which is insufficient for mission-critical systems. This research proposes a framework to move these checks to the compilation phase.

Methodology: From Queries to Subsumption

The authors bridge the gap between programming language theory and description logics (DL) through a two-step reduction process:

  1. Reduction to Query Containment: The authors define type safety as a query containment problem. To verify if a query $Q$ is safe for a specific program type $T$, the system asks: "Is every possible answer to $Q$ also an answer to the query $Q_T$ that defines type $T$?" If $Q \subseteq Q_T$ holds across all valid program states, the operation is guaranteed to be type-safe.
  2. Approximation via Concept Subsumption: Direct query containment under expressive OWL 2 regimes is often computationally prohibitive. To provide a practical solution, the authors approximate the check by "unraveling" queries into tree-shaped structures known as DL Concepts. They then utilize optimized DL reasoners, such as HermiT, to determine if the query-concept is a "sub-concept" (subclass) of the required program type.

Implementation and Formal Results

The primary contribution of this work is the formalization and implementation of a static type-checker for the SMOL language. The authors provide a "Progress and Preservation" theorem (Theorem 1), proving that programs passing the static check will not encounter type mismatches during semantic access operations.

The implementation leverages a modern stack: ANTLR for parsing, Kotlin for the compiler backend, and the Jena framework to bridge the gap to the HermiT reasoner. While the authors focus on the theoretical framework rather than large-scale empirical datasets, they demonstrate the system's utility through illustrative examples like cloud scheduling systems. Currently, the system can automatically verify any query that can be translated into a tree-shaped DL concept, which encompasses the vast majority of common data retrieval patterns.

Limitations and Future Outlook

While the framework is a significant step forward, certain limitations remain. The current approximation method is optimized for tree-shaped queries; "cyclic" queries (e.g., those involving circular relationships) may trigger false-positive warnings even if the code is safe. Furthermore, the performance of the type-checker is tied to the efficiency of the underlying DL reasoner, which can vary with the complexity of the OWL 2 axioms used.

Future work aims to develop specialized containment algorithms that offer higher precision for non-tree queries and to explore how object-oriented encapsulation (e.g., private vs. public modifiers) should interact with the globally visible lifted ontology.

Summary updated

BibTeX
@inproceedings{kamburjan2021type,
  author = {Eduard Kamburjan and Egor V. Kostylev},
  title = {{Type Checking Semantically Lifted Programs via Query Containment under Entailment Regimes}},
  booktitle = {Description Logics},
  year = {2021},
}
Figure