Abstract
Unstructured line-based merge tools are widely used in practice but often fail to handle semantic changes accurately. While structured AST-based merge tools offer improved accuracy, their language-specific nature makes them costly to develop and maintain. This paper introduces LastMerge, a generic structured merge tool that leverages the Tree Sitter framework to provide language-agnostic integration. By using a thin configuration interface, LastMerge significantly reduces the effort required to support new languages. Our evaluation against state-of-the-art Java-specific tools (jDime and Spork) demonstrates that LastMerge achieves comparable accuracy and superior performance, reporting 15% fewer false positives than jDime. These results suggest that generic structured merge tools can effectively replace language-specific implementations, facilitating broader industry adoption.
What Problem Does This Paper Address?
Standard version control systems rely on line-based merge tools like diff3. These tools treat source code as raw text, which leads to frequent "false positive" conflicts—situations where the tool flags a conflict even though the changes are semantically compatible. For example, if two developers add different modifiers to the same method, a line-based tool may struggle to reconcile the changes because it lacks understanding of the code's structure.
Structured merge tools address this by parsing code into Abstract Syntax Trees (ASTs) and merging the trees rather than the text. However, the high cost of building custom parsers and merge engines for every language has prevented their widespread use. The authors propose a way to break this bottleneck by creating a generic tool that works across many languages with minimal configuration.
Methods: The LASTMERGE Approach
The authors developed LASTMERGE (Language Agnostic Structured Tool for Code Merging). Its core innovation is the use of Tree Sitter, a high-performance parsing framework that generates Concrete Syntax Trees (CSTs) for hundreds of languages.
Instead of hard-coded merge logic for each language, LASTMERGE uses a "thin configuration interface." Developers provide high-level rules defining which nodes can be reordered (such as modifiers) and how to uniquely identify specific elements (like method signatures). The tool then applies sophisticated matching and merging algorithms—originally developed for the Java-specific tool jDime—to these generic trees.
To validate this approach, the researchers compared LASTMERGE and another generic tool, Mergiraf, against their language-specific counterparts (jDime and Spork). They replayed 5,229 real-world Java merge scenarios from 1,116 open-source projects to measure accuracy and speed.
Key Results and Insights
The study yielded several critical findings regarding the viability of generic structured merging:
- Accuracy Parity: Operating on generic trees does not sacrifice quality. The generic tools disagreed with language-specific ones in only about 10% of cases, and manual analysis showed these differences were often due to minor configuration choices rather than architectural flaws.
- Improved Conflict Detection: LASTMERGE reported 15% fewer false positives than jDime. Meanwhile, Mergiraf missed 42% fewer real conflicts (false negatives) than Spork.
- Performance Gains: Because the generic tools were implemented in Rust, they significantly outperformed the Java-based specific tools. LASTMERGE completed over 80% of merges in under 3 seconds, making it suitable for real-time developer workflows.
Conclusion
The success of LASTMERGE demonstrates that the "one tool per language" paradigm for structured merging is no longer necessary. By leveraging robust parsing frameworks like Tree Sitter and a lightweight configuration layer, developers can achieve state-of-the-art merge accuracy across a vast array of programming languages. This paves the way for structured merge tools to finally move from academic research into mainstream industrial practice.
Summary updated