In Rust We Trust - A Transpiler from Unsafe C to Safer Rust

被引:0
|
作者
Ling, Michael [1 ]
Yu, Yijun [1 ,2 ]
Wu, Haitao [1 ]
Wang, Yuan [1 ]
Cordy, James R. [3 ]
Hassan, Ahmed E. [3 ]
机构
[1] Huawei Technol, Toronto, ON, Canada
[2] Open Univ, Milton Keynes, Bucks, England
[3] Queens Univ, Kingston, ON, Canada
关键词
transpiler; safety; measurement; refactoring; code transformation;
D O I
10.1145/3510454.3528640
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Rust is a type-safe system programming language with a compiler checking memory and concurrency safety. For a smooth transition from existing C projects, a source-to-source transpiler can auto-transform C programs into Rust using program transformation. However, existing C-to-Rust transformation tools (e.g. the open-source C2Rust transpiler(1) project) have the drawback of preserving the unsafe semantics of C, while rewriting them in Rust's syntax. The work by Emre et el. [2] acknowledged these drawbacks, and used rustc compiler feedback to refactor one certain type of raw pointers to Rust references to improve overall safety and idiomaticness of C2Rust output. Focusing on improving API-safeness (i.e. lowering unsafe keyword usage in function signatures), we apply source-to-source transformation technique to auto-refactor C2Rust output using code structure pattern matching and transformation, which does not rely on rustc compiler feedback. And by relaxing the semantics-preserving constraints of transformations, we present CRustS(2) a fully-automated source-to-source transformation approach that increases the ratio of the transformed code passing the safety checks of the rustc compiler. Our method uses 220 new TXL [1] source-to-source transformation rules, of which 198 are strictly semantics-preserving and 22 are semantics-approximating, thus reducing the scope of unsafe expressions and exposing more opportunities for safe Rust refactoring. Our method has been evaluated on both open-source and commercial C projects, and demonstrates significantly higher safe code ratios after the transformations, with function-level safe code ratios comparable to the average level of idiomatic Rust projects.
引用
收藏
页码:354 / 355
页数:2
相关论文
共 50 条
  • [41] rust-code-analysis: A Rust library to analyze and extract maintainability information from source codes
    Ardito, Luca
    Barbato, Luca
    Castelluccio, Marco
    Coppola, Riccardo
    Denizet, Calixte
    Ledru, Sylvestre
    Valsesia, Michele
    [J]. SOFTWAREX, 2020, 12
  • [42] Foundations for a Rust-Like Borrow Checker for C
    Silva, Tiago
    Bispo, Joao
    Carvalho, Tiago
    [J]. PROCEEDINGS OF THE 25TH ACM SIGPLAN/SIGBED INTERNATIONAL CONFERENCE ON LANGUAGES, COMPILERS, AND TOOLS FOR EMBEDDED SYSTEMS, LCTES 2024, 2024, : 155 - 165
  • [43] Shotgun identification of proteins from rust spores
    Cooper, B.
    [J]. PHYTOPATHOLOGY, 2005, 95 (06) : S144 - S144
  • [44] Regarding the germination of urediospores from wheat rust
    Beauverie, J
    [J]. COMPTES RENDUS HEBDOMADAIRES DES SEANCES DE L ACADEMIE DES SCIENCES, 1924, 179 : 993 - 996
  • [45] New graminicolous rust fungi from Pakistan
    Afshan, N. S.
    Berndt, R.
    Khalid, A. N.
    Niazi, A. R.
    [J]. MYCOTAXON, 2008, 104 : 123 - 130
  • [46] NEW RECORD OF GROUNDNUT RUST FROM HARYANA
    TRIPATHI, NN
    KAUSHIK, CD
    [J]. INDIAN JOURNAL OF AGRICULTURAL RESEARCH, 1978, 12 (04) : 273 - 273
  • [47] IDENTITY AND NOMENCLATURE OF SOYBEAN RUST FROM INDIA
    SATHE, AV
    [J]. CURRENT SCIENCE, 1972, 41 (07): : 264 - &
  • [48] Lessons from the Incursion of Myrtle Rust in Australia
    Carnegie, Angus J.
    Pegg, Geoff S.
    [J]. ANNUAL REVIEW OF PHYTOPATHOLOGY, VOL 56, 2018, 56 : 457 - 478
  • [49] RUST REMOVAL FROM SURGICAL-INSTRUMENTS
    KASDAN, A
    KASDAN, ML
    [J]. PLASTIC AND RECONSTRUCTIVE SURGERY, 1984, 73 (05) : 856 - 856
  • [50] A new rust on Tragopogon from Rhodes, Greece
    Gjaerum, Halvor B.
    Lye, Kare A.
    [J]. MYCOTAXON, 2014, 127 : 47 - 49