arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2603.02617cs.SE
收藏

基于构建意识的增量C到Rust迁移:通过骨架优先翻译和历史知识重用

His2Trans: A Knowledge-Guided Agentic Framework for Project-Level C-to-Rust Migration

Sun Yat-sen University(中山大学)

Shengbo Wang, Mingwei Liu, Guangsheng Ou, Yuwen Chen, Zike Li, Yanlin Wang

AI总结:

本文提出His2Trans框架,通过构建意识的骨架构建和历史知识重用,实现C到Rust的增量迁移,提升构建可行性并减少警告数量。

摘要:

自动化工业软件的C到Rust迁移仍具挑战性,因为构建关键上下文分散在编译配置、宏、外部符号和跨模块依赖中,而可重用的迁移知识常隐匿于先前的C/Rust演变中。为此,我们提出了His2Trans框架,用于在构建复杂的生态系统中进行增量C到Rust迁移。His2Trans首先从构建跟踪重建可编译的项目级Rust骨架,恢复模块、类型定义、签名、全局变量和依赖关系,然后检索从历史编译接受的C/Rust对中挖掘的Rust侧接口和本地编码模式,以指导翻译和编译器反馈修复。我们评估了His2Trans在五个OpenHarmony子模块和九个通用C基准上的表现。在OpenHarmony模块上,His2Trans实现了97.51%的增量编译通过率,并在复现基线之上显著提升了构建可行性;生成的产物也支持混合C/Rust构建,未观察到接口不匹配。在通用基准上,它保持了高编译可行性,将不安全比例降低了24.02个百分点,且与Claude-Opus-4.5相比降低了编译输出的警告数量。此外,自我进化知识库将未见过的模块的平均修复轮次减少了约60%。这些结果表明,结合构建意识的骨架构建与历史知识重用是实际渐进C到Rust迁移的有效策略。

英文摘要:

C remains a major implementation language for operating systems, embedded platforms, and infrastructure software, but manual memory management continues to create security and maintenance costs. Rust is a practical migration target because it retains low-level control while enforcing stronger memory-safety checks. At project scale, especially under gradual C/Rust coexistence, migration is not a sequence of syntax-preserving function rewrites. A translator must preserve project interfaces, observable behavior, system interaction protocols, and low-level interoperability boundaries while staying consistent with migration choices already made in the codebase. We introduce His2Trans, a knowledge-guided agentic framework for project-level C-to-Rust migration. His2Trans reuses interface-level and fragment-level knowledge mined from historical C/Rust migrations to guide new translations toward Rust interfaces, wrapper choices, and local idioms already accepted in the evolving project. It then refines the assembled crate with project-level agentic feedback. On ten OpenHarmony modules, His2Trans reaches a 100.00\% incremental compilation pass rate, a 94.92\% Test Pass Rate, and a 16.35\% Unsafe Ratio. On eight open-source C projects, it reaches 100.00\% for both incremental compilation and Test Pass Rate, reducing Unsafe Ratio from 42.88\% under C2Rust to 8.59\%. These results support knowledge-guided migration and project-level agentic refinement as practical mechanisms for preserving observable behavior while reducing the unsafe burden of rule-based transpilation.

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

↑