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

从C到Rust的代码质量分析

Code Quality Analysis of Translations from C to Rust

North Carolina State University(北卡罗来纳州立大学);Columbia University(哥伦比亚大学)

Biruk Tadesse, Vikram Nitin, Mazin Salah, Baishakhi Ray, Marcelo d'Amorim, Wesley Assunção

AI总结:

本文研究了三种C到Rust翻译器的代码质量,发现尽管新技术减少了部分问题,但引入了新的问题,揭示了翻译质量的多维挑战。

摘要:

C/C++是一种广泛使用的编程语言。然而,它却存在显著的内存安全和线程安全问题。最近的研究探讨了将C/C++自动翻译成更安全的语言,如Rust。然而,这些研究主要集中在翻译代码的正确性和安全性上,虽然这些确实至关重要,但它们忽略了其他重要的质量问题(例如性能、鲁棒性和可维护性)。本研究调查了三种C到Rust翻译器的优缺点,即C2Rust(一种转译器)、C2SaferRust(一种由LLM引导的转译器)和TranslationGym(一种基于LLM的直接翻译)。我们对流行的GNU coreutils的翻译Rust代码的重要质量属性进行了深入的定量和定性分析,使用人工翻译作为基准。为了评估Rust代码的内部和外部质量,我们:(i)应用Clippy,一种基于规则的当前最佳实践Rust静态分析工具;(ii)研究LLM(GPT-4o)识别可能被Clippy遗漏的问题的能力;(iii)对Clippy和GPT-4o报告的问题进行人工分析。我们的结果表明,虽然新技术减少了某些不安全和非idiomatic模式,但它们经常引入新的问题,揭示了现有评估实践下不可见的系统性权衡。值得注意的是,没有任何自动技术在所有质量维度上都能一致地匹配或超过人工编写翻译。然而,即使人工编写的Rust代码也表现出持续的内部质量问题,如可读性和非idiomatic模式。这些发现表明,翻译质量仍然是一个多维的挑战,需要系统性的评估和有针对性的工具支持,超越了单纯的自动化和手动重写。

英文摘要:

C/C++ is a prevalent programming language. Yet, it suffers from significant memory and thread-safety issues. Recent studies have explored automated translation of C/C++ to safer languages, such as Rust. However, these studies focused mostly on the correctness and safety of the translated code, which are indeed critical, but they left other important quality concerns (e.g., performance, robustness, and maintainability) largely unexplored. This work investigates strengths and weaknesses of three C-to-Rust translators, namely C2Rust (a transpiler), C2SaferRust (an LLM-guided transpiler), and TranslationGym (an LLM-based direct translation). We perform an in-depth quantitative and qualitative analysis of several important quality attributes for the translated Rust code of the popular GNU coreutils, using human-based translation as a baseline. To assess the internal and external quality of the Rust code, we: (i) apply Clippy, a rule-based state-of-the-practice Rust static analysis tool; (ii) investigate the capability of an LLM (GPT-4o) to identify issues potentially overlooked by Clippy; and (iii) perform a manual analysis of the issues reported by Clippy and GPT-4o. Our results show that while newer techniques reduce some unsafe and non-idiomatic patterns, they frequently introduce new issues, revealing systematic trade-offs that are not visible under existing evaluation practices. Notably, none of the automated techniques consistently match or exceed human-written translations across all quality dimensions, yet even human-written Rust code exhibits persistent internal quality issues such as readability and non-idiomatic patterns. Together, these findings show that translation quality remains a multi-dimensional challenge, requiring systematic evaluation and targeted tool support beyond both naive automation and manual rewriting.

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

↑