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

Jason Gross, Théo Zimmermann, Miraya Poddar-Agrawal, Adam Chlipala

TL;DR

Maintaining backwards compatibility in evolving proof assistants is notoriously difficult because downstream formal developments are massive and tightly coupled. The authors present the Coq Bug Minimizer, an automated tool integrated into Coq’s continuous integration (CI) that shrinks large, failing external codebases into tiny, standalone test cases. In real-world deployment, it succeeds ~75% of the time, cutting test files to a third of their original size and reducing compilation times down to an average of just 1.25 seconds.

What Problem Does This Paper Address?

When core changes are made to the Coq proof assistant, they frequently break external developments. To safeguard against accidental breakage, Coq uses Reverse Dependency Compatibility Testing (RDCT), running CI against a large crowdsourced suite of real-world user projects.

However, diagnosing an RDCT failure is painful. Developers must clone complex external projects, configure idiosyncratic build systems, and decipher thousands of lines of domain-specific proofs just to isolate the regression. Standard delta-debugging tools designed for C or Java fail here because dependently typed proof assistants tightly interweave type checking, metaprogramming, and global state across files.

Methods

The authors built the Coq Bug Minimizer and wired it directly into coqbot (Coq’s GitHub automation bot). Key components include:

  • Backwards Linear Pruning: Because Coq forbids forward references, code after the failing line cannot affect the failure. The tool deletes everything after the failure and works backwards, removing statements one by one.
  • Fast Speedup Passes via Proof Admitting: Proof checking dominates Coq's runtime. The minimizer first replaces proof scripts with Admitted, Admit Obligations, or admit, testing both opaque and transparent variants to avoid breaking downstream tactic unfoldings.
  • Dependency Inlining: To create a standalone file without external dependencies, the tool computes the transitive closure of required modules, wraps them into synthesized nested modules to prevent naming collisions, and inlines them directly into the target file.
  • Heuristic Bug Equivalence: Instead of strict string equality, the tool considers two errors equivalent under relaxed rules tailored to Coq: ignoring file paths, line numbers, variable counter numbers, and variations in universe inconsistency graphs or constraint-solver messages.
  • Build System Agnosticism: Coq compiler wrappers intercept environment variables (COQPATH) and CLI flags during CI runs, eliminating the need to understand specific project build systems (e.g., Dune or custom Makefiles).

Datasets

The authors evaluated the tool directly on production CI runs in the main Coq repository:

  • 191 minimization runs across 51 pull requests, triggered on real regression failures in diverse external libraries (such as Flocq, VST, and MetaCoq).
  • Data collection scripts and the resulting dataset are publicly archived on Figshare.

Key Insights and Ideas

  • No need for binary search: Classic compiler delta debugging uses binary search over ASTs. For proof assistants, the strict top-to-bottom dependency order makes a simple backward linear scan sufficiently fast while avoiding syntax invalidation.
  • Proof omission is proof assistant "dead-code elimination": In standard compilers, removing a function body breaks linking. In interactive theorem provers, replacing an entire multi-minute tactic script with Admitted is logically sound enough for bug reproduction and speeds up subsequent minimization iterations exponentially.
  • Global state is the true enemy: Unlike C-style preprocessor #include directives, Coq's Require command introduces pervasive side effects (notations, implicit arguments, tactic databases, and universe constraints). Wrapping inlined dependencies in modules isolates most non-Global effects, though global flag leakage remains a tricky hurdle.

Key Results

  • Success Rate: Successfully produced a reduced test case in 75% of runs (144 / 191).
  • Standalone Quality: Among recent successful runs tracking inlining metadata, 89% (42 / 47) produced completely self-contained files with no external dependencies.
  • Speed & Size:
  • Reduced test cases take an average of 1.25 seconds to compile (with 75% finishing under 0.5 seconds), compared to minutes or hours for parent projects.
  • Test sizes shrank to an average of 31% (~one-third) of the relevant code footprint; median size of standalone files was 114 lines (25% were under 39 lines).
  • CI Turnaround: 50% of successful minimizations finished in under 20 minutes, and 80% finished in under 140 minutes.

Limitations and Future Work

  • Lack of a Full AST Parser: The tool relies on lexical parsing and Coq’s .glob metadata files. Integrating directly with Coq's internal parser would allow finer-grained simplifications (such as stripping individual record fields).
  • Nonlinearizable Global State: Build flags and global side effects from external files cannot always be faithfully reconstructed in a single module hierarchy.
  • Section Variables: Lemmas inside Coq Section blocks often depend subtly on section-local variables; replacing proofs with Admitted can inadvertently alter the lemma's external type signature. Future work plans to leverage Set Suggest Proof Using to preserve these dependencies.

Summary updated

BibTeX
@inproceedings{gross2022automatic,
  author = {Jason Gross and Théo Zimmermann and Miraya Poddar-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