Automatic Test-Case Reduction in Proof Assistants: A Case Study in Coq

Jason Gross, Théo Zimmermann, Rajashree Agrawal, Adam Chlipala

TL;DR

The authors present the Coq Bug Minimizer, an automated tool integrated into Coq’s continuous integration (CI) pipeline that automatically reduces massive, broken external codebases into tiny, standalone test cases. By leveraging Coq's unique language constraints, the tool successfully minimizes bugs 75% of the time, shrinking test cases to a third of their original size and reducing compilation times to mere seconds.

What Problem Does This Paper Address?

Proof assistants like Coq are evolving rapidly. To ensure that updates to the core language don't accidentally break user code, Coq developers use a strategy called reverse continuous integration (reverse CI). Instead of just running internal tests, they test new versions of Coq against a massive, crowdsourced suite of external, real-world Coq projects.

While reverse CI is great for catching regressions, debugging these failures is a nightmare. When a new Coq feature breaks an external library, core developers must download, configure, and compile a massive, unfamiliar codebase just to locate the bug. Traditional test-case reduction tools (like classic delta debugging) fail here because proof assistants feature heavy automation, long compilation times, global state, and dependently typed systems where compile-time and runtime are tightly coupled.

Methods

The authors developed the Coq Bug Minimizer to automate this tedious debugging process. Rather than relying on generic reduction algorithms, it exploits specific properties of the Coq language:

  • Linear, Backward Elimination: Unlike languages like Java or Haskell where functions can be mutually recursive throughout a file, Coq forbids forward references. The minimizer finds the line that threw the error, deletes everything after it, and then tests deleting preceding syntactic units one-by-one, moving backwards.
  • Proof Admitting: Proof scripts are notoriously slow to compile. The tool speeds up its own search loop by aggressively replacing proof blocks with commands like Admitted or admit, which instruct Coq to "trust" the proof without checking it, drastically lowering compilation overhead.
  • Dependency Inlining and Module Wrapping: To make the final file completely standalone, the tool linearizes the project's dependency tree and inlines external files. To prevent name shadowing and resolution errors, it wraps inlined files in nested modules and uses Coq's .glob files to track down identifier origins.
  • Relaxed Error Matching: If a modification changes a trivial detail in an error message (like a variable number or a filename), a strict reduction tool would reject the change. The minimizer uses relaxed semantic matching—for example, treating any "universe inconsistency" error as a match—to ensure it doesn't get stuck on incidental text changes.

Datasets

Because no standard benchmark exists for proof assistant bug reduction, the authors evaluated their tool on a live dataset collected over nearly a year of Coq's production CI system. The dataset consists of 191 minimization runs spanning 51 different Pull Requests (PRs) triggered by real-world project failures.

Key Insights and Ideas

  • Simpler Can Be Better: While traditional compilers often require complex binary-search delta debugging, Coq’s strict lack of forward references means a simple linear, backward pass is highly performant and effective.
  • The Cost of Dependent Types: In simply typed languages, stripping out unused code is trivial. In dependently typed languages, types can compute and depend on terms, creating an incredibly tight coupling between files. This makes dependency inlining one of the hardest but most vital parts of the reduction process.
  • Speeding Up the Loop: The bottleneck of test-case reduction is the edit-compile-test loop. By realizing that proofs can be "admitted" during minimization without masking core compiler bugs, the authors unlocked massive speedups.

Key Results

  • High Success Rate: The tool successfully produced a reduced test case in 75% of the production CI failures it encountered.
  • Truly Standalone: On a recent tracked subset, 89% of the successful runs yielded a completely standalone file requiring no external dependencies outside of Coq's standard library.
  • Massive Code Compression: On average, the minimized files were one-third the size of the original test cases (including their dependencies). For cases where code reduction occurred, the file shrunk by a factor of 4 to 5.
  • Blazing Fast Compilation: The average reduced test case compiles in just 1.25 seconds, with 75% of them compiling in under half a second. This allows developers to instantly experiment with fixes.
  • Reasonable Automation Time: 50% of successful minimization runs finished in under 20 minutes, running entirely in the background via coqbot and GitHub Actions.

Limitations and Future Work

The authors note several areas for improvement:

  • Lack of a Proper Parser: The tool currently relies on regex and tool-output workarounds (like coqtop -emacs and .glob files) rather than a full Coq parser. This prevents it from doing fine-grained reductions, like removing individual fields from a record type.
  • Global State Aggravation: Coq relies heavily on global flags and notations. If an inlined file alters global state, it can break later code in ways the linearizer struggles to predict.
  • Future Directions: The authors propose integrating incremental compilation so the minimizer doesn't have to re-verify unchanged lines of code, as well as exploring parallel minimization of multiple files to maximize multi-core CPU usage.

Summary updated

BibTeX
@inproceedings{gross2022automatic,
  author = {Jason Gross and Théo Zimmermann and Rajashree Agrawal and Adam Chlipala},
  title = {{Automatic Test-Case Reduction in Proof Assistants: A Case Study in Coq}},
  booktitle = {ITP},
  year = {2022},
  url = {https://openreview.net/forum?id=S5qJJq0-IP},
}
Figure