arrow
返回

Type-migrating C-to-Rust translation using a large language model

delete2024-10-17
delete1
delete
OA
AI
J
Jaemin Hong *
S
Sukyoung Ryu
DOI:10.1007/s10664-024-10573-2delete
delete原文链接
delete原文求助
delete分享
delete收藏
摘要

摘要

En 中文
Rust, a modern system programming language, introduces new types that prevent memory bugs and data races. This makes translating legacy system programs from C to Rust a promising approach to enhance their reliability. Since manual code translation is time-consuming, it is desirable to automate the translation. To yield satisfactory results, the translator should have the ability to perform type migration, i.e., removing C types and introducing Rust types in the code. In this work, we aim to automatically port an entire C program to Rust by translating each C function to a Rust function with a signature containing proper Rust types through type migration. This goal is challenging because (1) type migration cannot be achieved through syntactic mappings between type names, and (2) after type migration, function bodies should be correctly restructured based on the precise understanding of the functions' behavior. To address these difficulties, we leverage large language models (LLMs), which possess knowledge of program semantics and programming idioms. However, na & iuml;vely instructing LLMs to translate each function produces unsatisfactory Rust code, containing unmigrated or improperly migrated types and a huge number of type errors. To resolve these issues, we propose three techniques: (1) generating candidate signatures, (2) providing translated callees' signatures to LLMs, and (3) iteratively fixing type errors using compiler feedback. Our evaluation shows that the proposed approach yields a 63.5% increase in migrated types and a 71.5% decrease in type errors compared to the baseline (the na & iuml;ve LLM-based translation) with modest performance overhead.
Keyword:
Rust
Code translation
Type migration
Large language model

期刊

Empirical Software Engineering 封面图
Empirical Software Engineering
IF:
3.6
论文数:
2.0K
被引数:
5.3K

机构

暂无机构信息
引用论文

引用论文

Plasmonic porous ceramics based on zirconia-toughened alumina functionalized with silver nanoparticles for surface-enhanced Raman scattering
err2022-03-01
err0
errOAAI
errTongwei Guo; Md Nurul Karim; Kowsik Ghosh; M. Mangir Murshed; Kurosch Rezwan; Michael Maas
err分享
err收藏
Quantification of climatic niches in birds: adding the temporal dimension
err2017-09-13
err0
errOAAI
errAlison Eyres; Katrin Böhning‐Gaese; Susanne A. Fritz
err分享
err收藏
err分享
err收藏
err分享
err收藏
Recent Developments in SiC Device Research
err1999-01-01
err0
PREAI
errC. I. Harris; A. O. Konstantinov
err分享
err收藏
学者 查看更多内容