Unlocking a New Rust Programming Experience: Fast and Slow Thinking with LLMs to Conquer Undefined Behaviors

📅 2025-03-04
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Unsafe Rust code frequently induces undefined behavior (UB), compromising memory safety; conventional UB repair relies heavily on manual analysis and domain expertise, resulting in low efficiency and poor scalability. This paper proposes RustBrain, a dual-modal large language model framework inspired by cognitive science’s “fast–slow thinking” theory: the fast modality generates candidate patches, while the slow modality performs feature extraction, formal verification via Miri, and abstraction-based generalization—orchestrated through feedback-driven chain-of-thought iteration for dynamic synergy. To our knowledge, RustBrain is the first LLM framework integrating dual-process cognition into UB repair and the first to establish a closed-loop, adaptive mechanism unifying semantic understanding, program verification, and generalized patching. Evaluated on the Miri dataset, RustBrain achieves a 94.3% test pass rate and an 80.4% executable patch rate, significantly enhancing both security assurance and development productivity in Rust projects.

Technology Category

Application Category

📝 Abstract
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.
Problem

Research questions and friction points this paper is trying to address.

Addressing undefined behaviors in Rust using LLMs
Enhancing Rust project safety with adaptive LLM frameworks
Improving code analysis efficiency with dual-process theory
Innovation

Methods, ideas, or system contributions that make the work stand out.

LLM-based framework for Rust UB minimization
Fast and Slow Thinking for dynamic adjustments
Feedback mechanism integrates verification and generalization
Renshuang Jiang
Renshuang Jiang
National University of Defense Technology
P
Pan Dong
National University of Defense Technology, Changsha, China
Z
Zhenling Duan
National University of Defense Technology, Changsha, China
Y
Yu Shi
National University of Defense Technology, Changsha, China
X
Xiaoxiang Fang
National University of Defense Technology, Changsha, China
Y
Yan Ding
National University of Defense Technology, Changsha, China
J
Jun Ma
National University of Defense Technology, Changsha, China
S
Shuai Zhao
Sun Yat-sen University, Guangzhou, China
Z
Zhe Jiang
Southeast University, Nanjing, China