arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2604.02852cs.SE
收藏

依赖引导的仓库级C到Rust翻译与强化对齐

Dependency-Guided Repository-Level C-to-Rust Translation with Reinforcement Alignment

Southeast University(东南大学);The Chinese University of Hong Kong(香港中文大学);Zhejiang University(浙江大学);Peking University(北京大学);Huawei(华为)

Jia Feng, Wenjie Gan, Cuiyun Gao, Chaozheng Wang, Feng Luo, Xin Xia, Ge Li, Kui Liu

AI总结:

提出DepTrans框架,通过强化对齐语法训练和依赖引导迭代精炼,实现仓库级C到Rust的高效翻译,编译成功率和计算准确性分别提升22.8和17.3个百分点。

摘要:

自动化C到Rust的迁移对于在不牺牲性能的情况下提高软件安全性至关重要。传统的基于规则的方法难以处理多样化的C语言惯用法,通常生成僵化且不符合Rust风格的代码。基于大规模代码语料库训练的大型语言模型(LLMs)通过利用跨语言泛化能力生成更地道、更易维护的Rust代码,提供了一种有前景的替代方案。然而,仍存在若干挑战。首先,现有的基于LLM的方法未能有效处理跨文件依赖,要么忽略它们,要么将整个文件作为上下文,这限制了准确的依赖建模。其次,复杂的依赖以及结构化的输入和输出使得在仓库级别验证语法正确性和功能等价性变得困难。第三,缺乏大规模C-Rust并行数据限制了模型性能。我们提出DepTrans,一个结合模型能力增强与结构化推理的框架。DepTrans引入强化对齐语法训练,通过多任务微调和反馈驱动的强化学习提高生成质量。它进一步应用依赖引导的迭代精炼来捕获细粒度的跨文件依赖,并迭代精炼生成的Rust代码。我们构建了一个包含85k训练样本的数据集和一个包含145个仓库级实例的基准测试。实验表明,DepTrans实现了60.7%的编译成功率和43.5%的计算准确性,分别比最强基线高出22.8和17.3个百分点。它还成功构建了15个工业C项目中的7个,展示了其实用潜力。

英文摘要:

Automating C-to-Rust migration is critical for improving software security without sacrificing performance. Traditional rule-based methods struggle with diverse C idioms, often producing rigid and unidiomatic Rust code. Large Language Models (LLMs), trained on massive code corpora, offer a promising alternative by leveraging cross-language generalization to generate more idiomatic and maintainable Rust code. However, several challenges remain. First, existing LLM-based approaches fail to handle cross-file dependencies effectively, either ignoring them or including entire files as context, which limits accurate dependency modeling. Second, complex dependencies and structured inputs and outputs make it difficult to verify syntactic correctness and functional equivalence at the repository level. Third, the lack of large-scale C-Rust parallel data constrains model performance. We propose DepTrans, a framework that combines model capability enhancement with structured inference. DepTrans introduces Reinforcement-Aligned Syntax Training to improve generation quality through multi-task fine-tuning and feedback-driven reinforcement learning. It further applies Dependency-Guided Iterative Refinement to capture fine-grained cross-file dependencies and iteratively refine generated Rust code. We construct a dataset of 85k training samples and a benchmark of 145 repository-level instances. Experiments show that DepTrans achieves a 60.7 percent compilation success rate and 43.5 percent computational accuracy, outperforming the strongest baseline by 22.8 and 17.3 percentage points. It also successfully builds 7 of 15 industrial C projects, demonstrating its practical potential.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑