Type-migrating C-to-Rust translation using a large language model
Empirical Software Engineering · 2025-01 · 30 (1)
DOI: 10.1007/s10664-024-10573-2 ↗Kurz gefasst
Fachartikel in der Zeitschrift Empirical Software Engineering, online erschienen am 17.10.2024. Verfasst von Jaemin Hong und 1 weiteren Autor:innen. Die Arbeit wurde bisher 36-mal zitiert (Crossref) und nennt 50 Literaturangaben. Der Volltext ist frei zugänglich (Open Access, CC BY 4.0). Gefördert von: National Research Foundation of Korea, Institute for Information and Communications Technology Promotion, Samsung Electronics Co., Ltd.
Abstract (Originalsprache)
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ï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ïve LLM-based translation) with modest performance overhead.
Förderung
- National Research Foundation of Korea
- Institute for Information and Communications Technology Promotion
- Samsung Electronics Co., Ltd
- Korea Advanced Institute of Science and Technology
Zitieren
APA
Hong, J., & Ryu, S. (2025). Type-migrating C-to-Rust translation using a large language model. Empirical Software Engineering, 30(1). https://doi.org/10.1007/s10664-024-10573-2
Vancouver
Hong J, Ryu S. Type-migrating C-to-Rust translation using a large language model. Empirical Software Engineering. 2025;30(1). doi:10.1007/s10664-024-10573-2
BibTeX
@article{Hong2025,
author = {Hong, Jaemin and Ryu, Sukyoung},
title = {Type-migrating C-to-Rust translation using a large language model},
journal = {Empirical Software Engineering},
year = {2025},
volume = {30},
number = {1},
doi = {10.1007/s10664-024-10573-2}
}
EUVIMED