Large language models (LLMs) have shown promising results for C-to-Rust translation, yet existing approaches primarily rely on source code as input, leaving natural-language specifications of program behavior underexplored as an alternative or complementary representation. We hypothesize that direct code translation encourages LLMs to preserve C-specific implementation choices, producing Rust that may be functionally correct but unnecessarily verbose, reliant on unsafe constructs, and less idiomatic. We investigate this hypothesis by comparing three translation settings: code-only, specification-only, and code-and-specification. Using 300 C programs from the IBM CodeNet dataset, we evaluate GPT-5.2 and GPT-4o-mini on functional correctness, maintainability, complexity, idiomaticity, unsafe construct usage, and cost. Code-only translation achieves the highest test pass rate (98.6%) but often mirrors C's implementation patterns. In contrast, specification-only translation produces the most idiomatic and compact Rust, reducing unsafe blocks by approximately 6x and Clippy style warnings by 2.4x. However, using specifications without validation yields test pass rates as low as 86% with our best performing model. Adding an iterative test-based validation and refinement step for specifications raises this to a 95.3% test pass rate. Overall, specification-based translation consistently improves code quality relative to code-only translation, while code-and-specification offers the best balance between correctness (98.3% test pass rate) and maintainability. Our study systematically compares these translation settings, highlighting the trade-offs among specification quality, translation correctness, code quality, and computational cost.


翻译:暂无翻译

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
大型语言模型(LLM)赋能的知识图谱构建:综述
专知会员服务
56+阅读 · 2025年10月24日
LLM4SR:关于大规模语言模型在科学研究中的应用综述
专知会员服务
42+阅读 · 2025年1月9日
大型语言模型(LLMs),附Slides与视频
专知会员服务
71+阅读 · 2024年6月30日
WSDM 2024| LLMs助力图学习?基于大模型的图数据增强
专知会员服务
27+阅读 · 2023年11月19日
中文自然语言处理数据集:ChineseNLPCorpus
AINLP
35+阅读 · 2019年6月21日
中文NLP福利!大规模中文自然语言处理语料
新智元
37+阅读 · 2019年2月13日
论文浅尝 | 基于知识图谱子图匹配以回答自然语言问题
开放知识图谱
26+阅读 · 2018年6月26日
语料库构建——自然语言理解的基础
计算机研究与发展
11+阅读 · 2017年8月21日
自然语言处理 (三) 之 word embedding
DeepLearning中文论坛
19+阅读 · 2015年8月3日
自然语言处理(二)机器翻译 篇 (NLP: machine translation)
DeepLearning中文论坛
12+阅读 · 2015年7月1日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
《美空军2026条令文件:对海压制作战》
专知会员服务
25+阅读 · 11月9日
人工智能与战争的未来
专知会员服务
10+阅读 · 11月8日
《Agent Mosaic:识别智能体LLM系统中的机密泄露》
专知会员服务
12+阅读 · 11月8日
人工智能在军事教育中的应用:若干视角与经验
专知会员服务
12+阅读 · 11月6日
“星链”减速与不断适应的乌克兰
专知会员服务
10+阅读 · 11月6日
美国中期选举之后:帕兰提尔面临不确定性?
专知会员服务
7+阅读 · 11月6日
相关资讯
相关基金
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员