NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Embracing a mechanized formalization gap

Antal Spector-Zabusky, Joachim Breitner, Yao Li, Stephanie WeiricharXiv 2019

TL;DR

This paper tackles the challenge of formally verifying large, industrial-strength software systems like the Haskell compiler (GHC). The authors demonstrate that by strategically creating a "formalization gap" – a simplified, mechanized model of the system – they can successfully verify critical properties of GHC's intermediate language, Core, even when full verification is intractable. This approach makes formal verification accessible for complex, real-world software.

What Problem Does This Paper Address?

Why don't we use proof assistants (like Coq) to formally verify large, production-ready software systems? The primary hurdle is scale and complexity. Systems like the Glasgow Haskell Compiler (GHC) are massive (hundreds of thousands of lines of code) and employ intricate optimizations. A complete, direct formalization and verification of such a system is often infeasible due to the sheer effort required and the semantic differences between the implementation language (Haskell) and the proof assistant's language (Gallina). This paper addresses the question of whether we can still gain significant benefits from formal verification by focusing on a manageable subset of the system and its critical properties, even if we can't prove everything.

Methods

The core of the paper's methodology lies in using the hs-to-coq tool to generate a Gallina (Coq) model of a subset of GHC's Core language. Crucially, they introduce and leverage a "formalization gap" managed through a sophisticated "edit language" for hs-to-coq. This gap allows them to:

  • Simplify the Model: They selectively translate only the parts of GHC relevant to their verification goals, abstracting away or axiomatizing other components (like type and coercion details). This is achieved through "skip" and "axiomatize" edits.
  • Reconcile Language Differences: Edits are used to bridge semantic gaps between Haskell and Gallina, for instance, by redefining how certain data structures are represented or by handling partial functions.
  • Focus Verification: By abstracting away irrelevant complexity, they can concentrate on proving specific invariants related to term variables, well-scopedness, and join points within the Core language.
  • Extend hs-to-coq: The authors developed new edit forms to manage the complexity of translating a large system like GHC, including constructor skipping, definition axiomatization, and data structure replacement.

Datasets

Not discussed in the paper. The focus is on verifying an existing software system (GHC), not on training or evaluating models on datasets.

Key Insights and Ideas

  • The "Formalization Gap" as an Enabler: Instead of viewing the differences between the source code and the formal model as a problem, the authors embrace them as a necessary tool to make verification tractable. This gap allows them to focus on what matters for their specific verification goals.
  • Partial Verification is Valuable: Even without verifying the entire GHC, the process of formalizing and verifying a subset yielded tangible benefits, including bug discovery (e.g., in the exitify optimization) and the correction of documentation errors.
  • hs-to-coq with Edits is Powerful: The hs-to-coq tool, augmented with a rich edit language, proves to be a flexible and effective way to generate manageable formal models from complex Haskell code, allowing for selective translation and simplification.
  • Industrial Compilers are Complex: The paper highlights the intricate details and optimizations within GHC, underscoring why direct formalization is challenging and why abstraction is crucial.

Key Results

The paper demonstrates the successful partial verification of GHC's Core language, focusing on two key invariants:

  • Well-scopedness: Proving that variable bindings are correctly managed within their scopes.
  • Join Points: Verifying invariants related to the use of "join points," an innovative feature for expressing non-trivial control flow.

They proved theorems demonstrating that:

  • The substExpr operation (for substitution) preserves well-scopedness.
  • The exitify optimization preserves both well-scopedness and join point validity.

The authors also found and helped fix a bug in the exitify optimization related to shadowing. Their Gallina model of Core, after simplifications, comprises over 5000 lines of code, derived from approximately 12% of GHC's source code.

Limitations and Future Work

Limitations: * Partial Verification: The work focuses on a subset of GHC and specific invariants, not a complete formalization. * Axiomatization: While necessary, the use of axioms introduces a potential for inconsistency if not carefully managed. The authors justify their axioms but acknowledge the inherent risk. * hs-to-coq Limitations: Certain Haskell features, like complex mutual recursion, still pose challenges for translation.

Future Work: * Verify More Passes: Extend the verification to other Core optimization passes already translated. * Handle More Complex Haskell Features: Develop extensions to hs-to-coq to better handle mutual recursion and coinductive data structures. * Reason About Core Type System: Verify that Core passes preserve the typing of Core terms. * Connect to CoreLint: Integrate their formal invariants with GHC's existing type-checking tool, CoreLint. * Prove Semantic Equivalence: Move beyond syntactic invariants to prove semantic preservation of Core operations.

Summary updated

BibTeX
@misc{spectorzabusky2019embracing,
  author = {Antal Spector-Zabusky and Joachim Breitner and Yao Li and Stephanie Weirich},
  title = {{Embracing a mechanized formalization gap}},
  year = {2019},
  eprint = {1910.11724},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.11724},
}

Loading related content...

Figure