arXiv:2412.17744cs.SEcs.AI2024-12被引 30

构建首个真实世界多语言仓库级代码翻译基准,评估大模型跨语言重构能力。

RepoTransBench: A Real-World Multilingual Benchmark for Repository-Level Code Translation

  • 提出覆盖13种语言对的仓库级代码翻译基准RepoTransBench,含1897个真实项目。
  • 最佳方法仅32.8%成功率,动态到静态语言翻译难度低于10%。
  • 揭示大模型在复杂代码结构迁移中的系统性缺陷,适合工具开发者参考。

仓库级代码翻译指将整个代码仓库从一种编程语言完整转换为另一种语言,同时保持源仓库功能一致。现有基准多聚焦于代码片段、函数或文件级别的翻译,难以反映真实场景中长代码量和复杂功能的需求。为此,我们提出了一个名为RepoTransBench的新基准,它是首个面向真实世界的多语言仓库级代码翻译评测集,包含1,897个真实仓库样本,覆盖13种语言对,并配备可自动执行的测试套件。同时,我们引入RepoTransAgent——一个通用代理框架,用于实现仓库级代码翻译。通过多种方法与骨干大模型评估,结果表明仓库级翻译仍具挑战性,最佳方法成功率仅为32.8%。分析显示,翻译难度随语言对方向显著变化:动态语言转静态语言成功率低于10%,而反向(静态转动态)可达45%-63%。最后,我们进行了详细错误分析,揭示当前大模型在处理仓库级代码时的结构性不足,为后续改进提供依据。代码与数据已开源至https://github.com/DeepSoftwareAnalytics/RepoTransBench。

原文摘要 · Abstract (English)

Repository-level code translation refers to translating an entire code repository from one programming language to another while preserving the functionality of the source repository. Many benchmarks have been proposed to evaluate the performance of such code translators. However, previous benchmarks mostly provide fine-grained samples, focusing at either code snippet, function, or file-level code translation. Such benchmarks do not accurately reflect real-world demands, where entire repositories often need to be translated, involving longer code length and more complex functionalities. To address this gap, we propose a new benchmark, named RepoTransBench, which is a real-world multilingual repository-level code translation benchmark featuring 1,897 real-world repository samples across 13 language pairs with automatically executable test suites. Besides, we introduce RepoTransAgent, a general agent framework to perform repository-level code translation. We evaluate both our benchmark's challenges and agent's effectiveness using several methods and backbone LLMs, revealing that repository-level translation remains challenging, where the best-performing method achieves only a 32.8% success rate. Furthermore, our analysis reveals that translation difficulty varies significantly by language pair direction, with dynamic-to-static language translation being much more challenging than the reverse direction (achieving below 10% vs. static-to-dynamic at 45-63%). Finally, we conduct a detailed error analysis and highlight current LLMs' deficiencies in repository-level code translation, which could provide a reference for further improvements. We provide the code and data at https://github.com/DeepSoftwareAnalytics/RepoTransBench.

代码翻译大模型多语言基准测试

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。