RUSTY: Effective C to Rust Conversion via Unstructured Control Specialization
Xiangjun Han, Baojian Hua, Yan Wang, Ziyao Zhang · 2022
Rust is an emerging programming language designed for both performance and security, and thus many research efforts have been conducted recently to migrate legacy code bases in C/C++ to Rust to exploit Rust's safety benefits. Unfortunately, prior studies on C to Rust conversion still have three limitations: 1) complex structure; 2) code explosion; and 3) poor performance. These limitations greatly affect the effectiveness and usefulness of such conversions. This paper presents Rusty, the first system for effective C to Rust code conversion via unstructured control specialization. The key technical insight of Rusty is to implement C-style syntactic sugars on top of Rust, thus eliminating the discrepancies between the two languages. We have implemented a software prototype for Rusty and conducted experiments to evaluate the effectiveness and testify the usefulness of it by applying Rusty to micro-benchmarks, as well as 3 real-world C projects: 1) Vim; 2) cURL; and 3) the silver searcher. And experimental results demonstrated that Rusty is effective in eliminating unstructured controls, reducing the code size by 16% on average with acceptable overhead (less than 61 microseconds per line of C code).