Abstract
Fault localization is a popular research topic and many techniques have been proposed to locate faults in imperative code, e.g. C and Java. In this paper, we focus on the problem of fault localization for declarative models in Alloy -- a first order relational logic with transitive closure. We introduce AlloyFL, the first set of fault localization techniques for faulty Alloy models which leverages multiple test formulas. AlloyFL is also the first set of fault localization techniques at the AST node granularity. We implement in AlloyFL both spectrum-based and mutation-based fault localization techniques, as well as techniques that are based on Alloy's built-in unsat core. We introduce new metrics to measure the accuracy of AlloyFL and systematically evaluate AlloyFL on 38 real faulty models and 9000 mutant models. The results show that the mutation-based fault localization techniques are significantly more accurate than other types of techniques.
Introduction
Debugging imperative code (like Java or C++) is a well-worn path, but what happens when your "code" is actually a set of mathematical constraints? Alloy is a powerful language used to model complex systems using first-order relational logic. However, writing these models is notoriously error-prone. Unlike traditional programming, Alloy models have no control flow; they are collections of constraints that are either satisfied or not.
Currently, when an Alloy model fails a test, users often rely on the "unsat core" feature, which highlights a chunk of the model that is logically inconsistent. This is often a "needle in a haystack" problem, as the unsat core might point to a broad paragraph rather than the specific faulty expression. This paper introduces AlloyFL, the first comprehensive framework for automatically locating faults in declarative models at the fine-grained Abstract Syntax Tree (AST) node level.
Methodology
AlloyFL implements five distinct fault localization (FL) techniques:
- AlloyFL$_{co}$ (Spectrum-based): Ranks nodes based on their appearance in failing vs. passing tests using static analysis to determine transitive usage.
- AlloyFL$_{un}$ (SAT-based): Aggregates Alloy’s built-in "unsat core" across multiple failing tests.
- AlloyFL$_{su}$ (Hybrid): Combines static analysis for satisfiable failing tests and unsat cores for unsatisfiable ones.
- AlloyFL$_{mu}$ (Mutation-based): Creates "mutants" by changing operators. If a mutation fixes a failing test without breaking passing ones, the node is highly suspicious.
- AlloyFL$_{hy}$ (Hybrid): Averages scores from spectrum-based and mutation-based approaches.
Measuring Accuracy on Trees
Traditional "line of code" metrics are insufficient for hierarchical logic models. The authors adapted the Nearest Neighbor (NN) distance metric to the AST, measuring how many tree-traversal steps a developer would need to take from a suggested node to find the actual bug.
Evaluation and Key Results
The researchers evaluated AlloyFL using 38 real-world faults and 9,000 second-order mutants. They used MuAlloy to generate robust test suites for evaluation.
- Mutation is King: Mutation-based FL ($AlloyFL_{mu}$) and its hybrid counterpart ($AlloyFL_{hy}$) significantly outperformed traditional SAT-based methods. While mutation is computationally more expensive (averaging ~33.7s for real faults), it provides the most precise localization.
- Top-K Performance: For real faults, mutation-based techniques placed the actual bug in the "Top 1" spot 14-16 times, whereas the spectrum-based approach only managed it 3 times. This demonstrates that multi-test mutation analysis is far more effective than relying on a single unsat core.
Conclusion
AlloyFL demonstrates that fault localization techniques from the imperative world can be successfully adapted to declarative logic. By operating at the AST node granularity and leveraging mutation testing, AlloyFL provides a much more accurate roadmap for developers to fix their models than existing unsat core features. Future work will focus on improving the handling of omission errors and further integrating automated test generation into the debugging loop.
Summary updated