Invariant Diffs

Ashwin Kallingal Joshy, Wei LearXiv 2019

TL;DR

This paper introduces "invariant diffs" – a novel way to understand changes between software versions by focusing on program conditions (invariants) rather than just code lines. Their tool, H2, uses a demand-driven analysis on multiversion control flow graphs to automatically compute these invariant diffs, providing deeper insights into how code changes affect program behavior.

What Problem Does This Paper Address?

Modern software development, especially with agile methodologies, emphasizes rapid iteration and frequent releases. This means software is constantly evolving, with changes being made to existing codebases. Traditional tools like git diff show changes at the source code line level, which can be difficult for developers to interpret. It's hard to grasp what program conditions or properties have changed, or why they changed, especially when dealing with complex logic or multiple developers contributing to a project. Existing program analysis tools often struggle with this incremental nature, being slow and inflexible when analyzing multiple versions. This gap makes it challenging for developers to understand the impact of their changes, ensure correctness, and effectively debug evolving software.

Methods

The core innovation is the concept of "invariant diffs," which consist of two parts:

  • Version Invariants: These are program conditions (e.g., variable relationships, value ranges) that hold true across multiple versions of a program at "matched program points" (locations where code hasn't changed).
  • Invariant Churns: These describe the changes in program conditions between two specific versions, crucially linking these changes to the source code lines that caused them.

To compute these, the authors developed a static, demand-driven, path-sensitive analysis that operates on a Multiversion Control Flow Graph (MVICFG). The MVICFG represents common code across versions only once, enabling efficient analysis. The demand-driven approach means the analysis only explores paths relevant to the user's query (e.g., "does variable x always equal 5 at this point?"). This allows for efficient computation, especially in large or complex codebases. The analysis uses invariant templates (e.g., variable = ?) to generate queries, which are then propagated backward through the MVICFG. The system resolves these queries by checking for conflicts across different paths and versions, consolidating findings into version invariants or invariant churns.

Datasets

The experiments were conducted on 104 program versions from a benchmark dataset that solves mathematical problems. These programs were implemented by multiple students for the same tasks, providing both variations in implementation and pairs of buggy and fixed versions. This setup allowed the researchers to evaluate how their approach handles different implementations and to assess the effectiveness of invariant churns in capturing bug fixes.

Key Insights and Ideas

  • Beyond Code Lines: The fundamental insight is that understanding software evolution requires looking beyond just source code diffs. Program invariants offer a higher-level, semantic view of program behavior that is more robust to implementation variations.
  • Efficiency through MVICFG and Demand-Driven Analysis: By representing common code once in an MVICFG and using demand-driven queries, the analysis avoids redundant computations and focuses only on relevant parts of the code, making it efficient for analyzing multiple versions.
  • Invariant Churns as Semantic Explanations: Invariant churns provide a powerful way to explain why a change occurred. They link specific code modifications to changes in program properties, offering a more intuitive understanding than raw code diffs.
  • Version Invariants as Stable Specifications: Version invariants highlight what remains constant across different implementations of the same task, suggesting they represent core specifications or essential properties of the program's functionality.

Key Results

  • The H2 tool correctly computed version invariants and invariant churns within a reasonable amount of time.
  • Version invariants were found to capture common properties even across programs implemented by different individuals for the same task.
  • Invariant churns effectively specified the semantics of changes, such as how a bug fix corrected a faulty condition.
  • The number of invariant churns was found to be significantly more manageable than the total number of program invariants, making them more practical for analysis.
  • For bug fixes, invariant churns often clearly indicated the removal of buggy conditions and the introduction of correct ones.
  • The analysis demonstrated that invariant churns can help pinpoint source code lines responsible for property changes, with an average of 1.37 invariant churns per changed line.

Limitations and Future Work

  • Intra-procedural Analysis: The current implementation performs intra-procedural analysis and handles loops by unrolling them once. This limits its ability to analyze complex inter-procedural interactions or deeply nested loops.
  • Limited Instruction Support: The tool currently supports a specific set of instructions related to mathematical computations.
  • Equality Invariant Templates: The evaluation primarily used equality invariant templates. Applying more diverse templates could yield more invariant diffs but might also increase computation time.
  • Future Work: The authors suggest exploring the scalability and usability of invariant diffs for real-world software repositories, which may reveal additional application scenarios. They also aim to extend the analysis to handle more complex program constructs and inter-procedural analysis.

Summary updated

Abstract

Software development is inherently incremental. Nowadays, many software companies adopt an agile process and a shorter release cycle, where software needs to be delivered faster with quality assurances. On the other hand, the majority of existing program analysis tools still target single versions of programs and are slow and inflexible to handle changes. In the popular version control systems such as git, the program changes are still presented using source code diffs. It is hard to understand what program conditions are changed and which source code lines cause them. In this paper, we propose to compute "invariant diffs" to specify changes. Similar to source diffs that report common code and code churns, we define version invariants to represent program conditions that are common across versions, and invariant churns to show the changes of program conditions between versions. We designed a static demand-driven, path-sensitive analysis to compute and compare invariants for multiple versions of programs using multiversion control flow graphs. We report invariant diffs at the matched program points where comparing invariants are meaningful. Importantly, our analysis correlates source diffs with invariant diffs to explain what source code changes lead to the property changes. We implemented our algorithms in a tool called $H_2$ and performed experiments on 104 versions of programs. Our results show that we are able to compute invariant diffs correctly within reasonable amount of time. The version invariants can capture the common properties of program versions even constructed by different persons, and the invariant churns can specify the semantics of changes such as how a patch changed a buggy condition to a correct condition.
BibTeX
@misc{joshy2019invariant,
  author = {Ashwin Kallingal Joshy and Wei Le},
  title = {{Invariant Diffs}},
  year = {2019},
  eprint = {1911.07988},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1911.07988},
}

Loading related content...

Figure