paperbot · PL 论文追踪

全部论文 待读 收藏

P1 Scalable, Validated Code Translation of Entire Projects using Large Language Models

使用大语言模型对整个项目进行可扩展、经校验的代码翻译
PLDI 9(PLDI)2025匹配度 5/10 · 论文将 LLM 用于代码翻译,并结合模块化切分、类型兼容性检查与 I/O 等价验证,属于 LLM 与程序语言/软件工程的交叉,带有轻量静态检查与验证思路;但其目标不是改进静态分析或形式化验证,也未涉及 Agentic 程序、浮点程序分析或贝叶斯程序分析,因此与画像核心方向中等相关。引用 13 inbox
Hanliang Zhang, Cristina David, Meng Wang, Brandon Paulsen, Daniel Kroening
crossref: 2026-09-10

AI 速览

一句话:提出模块化、特征映射与类型兼容性检查的 LLM 代码翻译方法,可将万行级 Go 项目可靠翻译为 Rust。

现有基于大语言模型(LLM)的代码翻译在代码规模超过约 100 行时成功率显著下降。本文提出一种模块化翻译方法:将项目切分为可独立翻译并做 I/O 等价语义校验的小代码片段。针对朴素方法中 LLM 难以处理源语言与目标语言无直接对应特性、且易陷入修复循环的问题,作者引入两个关键机制:(1)feature mapping,将预定义翻译规则与 LLM 翻译结合,引导模型处理细微语言差异并生成语义准确的代码;(2)type-compatibility,在函数签名级别进行局部检查以尽早发现错误,从而缩小潜在修复范围。作者将该方法应用于真实 Go 代码库到 Rust 的翻译,在最大 9700 行、780 个函数的项目上持续生成可靠的 Rust 翻译,平均 73% 的函数通过 I/O 等价验证,显著高于已有工作。

问题
LLM 在代码翻译中虽有生成地道代码的能力,但可扩展性差:当代码超过约 100 行时翻译成功率明显下降,且对无直接映射的语言特性不可靠、修复时容易陷入循环。
方法
采用模块化翻译,将代码切分为可独立翻译并做 I/O 等价校验的小片段;结合预定义规则的 feature mapping 引导 LLM 处理语言差异;并用函数签名级的 type-compatibility 局部检查提前发现错误、缩小修复范围。
评估
在真实 Go 代码库到 Rust 的翻译任务上评估,项目规模达 9700 行、780 个函数,平均 73% 的函数通过 I/O 等价验证,并与已有工作比较成功率。
原文摘要(Abstract)

Large language models (LLMs) show promise in code translation due to their ability to generate idiomatic code. However, a significant limitation when using LLMs for code translation is scalability: existing works have shown a drop in translation success rates for code exceeding around 100 lines. We overcome this limitation by developing a modular approach to translation, where we partition the code into small code fragments which can be translated independently and semantically validated (that is, by checking I/O equivalence). When this approach is applied naively, we discover that LLMs are unreliable when translating features of the source language that do not have a direct mapping to the target language, and that the LLM often gets stuck in repair loops when attempting to fix errors. To address these issues, we introduce two key concepts: (1) feature mapping , which integrates predefined translation rules with LLM-based translation to guide the LLM in navigating subtle language differences and producing semantically accurate code; and (2) type-compatibility , which facilitates localized checks at the function signature level to detect errors early, thereby narrowing the scope of potential repairs. We apply our approach to translating real-world Go codebases to Rust, demonstrating that we can consistently generate reliable Rust translations for projects up to 9,700 lines of code and 780 functions, with an average of 73% of functions successfully validated for I/O equivalence, considerably higher than any existing work.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot3112,
  title = {Scalable, Validated Code Translation of Entire Projects using Large Language Models},
  author = {Hanliang Zhang and Cristina David and Meng Wang and Brandon Paulsen and Daniel Kroening},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {9},
  number = {PLDI},
  year = {2025},
  doi = {10.1145/3729315}
}