一句话:提出声明式多语言代码转换 DSL,通过组合、排序和流扩展轻量匹配替换,支持相互依赖的跨语言重构。
在大型多语言代码库中,API 迁移、死代码清理等维护任务缺乏兼具表达力和通用性的自动化工具:语言专用重写工具造成碎片化,通用匹配替换工具表达力有限。本文提出一种声明式 DSL,用组合、排序与流来控制相互依赖的跨语言代码变换,将轻量匹配替换扩展到多语言场景。作者实现开源工具 Polyglot Piranha 并在工业环境部署。三个案例研究删除 21 万行死代码、迁移 2 万行代码,覆盖 1611 个 pull request;与先进替代方案相比,所开发工具更快、更简洁且更易维护。
In today’s software industry, large-scale, multi-language codebases are the norm. This brings substantial challenges in developing automated tools for code maintenance tasks such as API migration or dead code cleanup. Tool builders often find themselves caught between two less-than-ideal tooling options: (1) languagespecific code rewriting tools or (2) generic, lightweight match-replace transformation tools with limited expressiveness. The former leads to tool fragmentation and a steep learning curve for each language, while the latter forces developers to create ad-hoc, throwaway scripts to handle realistic tasks. To fill this gap, we introduce a new declarative domain-specific language (DSL) for expressing interdependent multi-language code transformations. Our key insight is that we can increase the expressiveness and applicability of lightweight match-replace tools by extending them to support for composition, ordering, and flow. We implemented an open-source tool for our language, called P olyglot P iranha , and deployed it in an industrial setting. We demonstrate its effectiveness through three case studies, where it deleted 210K lines of dead code and migrated 20K lines, across 1611 pull requests. We compare our DSL against state-of-the-art alternatives, and show that the tools we developed are faster, more concise, and easier to maintain.
@article{paperbot2518,
title = {A Lightweight Polyglot Code Transformation Language},
author = {Ameya Ketkar and Daniel Ramos and Lazaro Clapp and Raj Barik and Murali Krishna Ramanathan},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {PLDI},
year = {2024},
doi = {10.1145/3656429}
}