用大模型双思模式自动修复Rust的未定义行为,提升安全性。
Unlocking a New Rust Programming Experience: Fast and Slow Thinking with LLMs to Conquer Undefined Behaviors
- 借鉴人类双思维模式,快思生成方案,慢思验证抽象。
- 在Miri数据集上通过率达94.3%,执行率达80.4%。
- 适合需要高安全性的系统级Rust开发人员使用。
为提供灵活性和底层交互能力,Rust中的unsafe标签在许多项目中不可或缺,但会破坏内存安全并引入未定义行为(UB),降低程序安全性。消除这些UB需深入理解Rust的安全规则与强类型机制。传统方法依赖代码深度分析,过程繁琐且高度依赖人工经验。大型语言模型(LLM)强大的语义理解能力为此类问题带来新机遇。尽管现有大模型调试框架在语义任务上表现优异,但受限于固定流程,缺乏自适应与动态调整能力。受决策双过程理论(快思考与慢思考)启发,本文提出基于LLM的RustBrain框架,可自动、灵活地最小化Rust项目的未定义行为。快思考提取特征并生成解决方案,慢思考则进行分解、验证与抽象泛化。通过反馈机制将验证与泛化结果反馈至解生成环节,实现动态调整与精准输出。在Miri数据集上的实验结果显示,该框架达到94.3%的通过率与80.4%的执行率,显著提升了灵活性与Rust项目安全性。
原文摘要 · Abstract (English)
To provide flexibility and low-level interaction capabilities, the unsafe tag in Rust is essential in many projects, but undermines memory safety and introduces Undefined Behaviors (UBs) that reduce safety. Eliminating these UBs requires a deep understanding of Rust's safety rules and strong typing. Traditional methods require depth analysis of code, which is laborious and depends on knowledge design. The powerful semantic understanding capabilities of LLM offer new opportunities to solve this problem. Although existing large model debugging frameworks excel in semantic tasks, limited by fixed processes and lack adaptive and dynamic adjustment capabilities. Inspired by the dual process theory of decision-making (Fast and Slow Thinking), we present a LLM-based framework called RustBrain that automatically and flexibly minimizes UBs in Rust projects. Fast thinking extracts features to generate solutions, while slow thinking decomposes, verifies, and generalizes them abstractly. To apply verification and generalization results to solution generation, enabling dynamic adjustments and precise outputs, RustBrain integrates two thinking through a feedback mechanism. Experimental results on Miri dataset show a 94.3% pass rate and 80.4% execution rate, improving flexibility and Rust projects safety.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。