Table of Contents
Fetching ...

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

Renshuang Jiang, Pan Dong, Zhenling Duan, Yu Shi, Xiaoxiang Fang, Yan Ding, Jun Ma, Shuai Zhao, Zhe Jiang

TL;DR

The paper addresses Undefined Behaviors in Unsafe Rust and proposes RustBrain, a dual-process LLM framework that integrates fast, intuitive repair generation with slow, analytic verification. It uses Miri for UB detection and a multi-agent slow-thinking pipeline to decompose, verify, reason, and generalize repairs, tied together by a feedback mechanism. RustBrain achieves a 94.3% pass rate and 80.4% execution rate on the Miri dataset (with knowledge-base integration) and outperforms the state-of-the-art RustAssistant by about 30% in pass rate, with up to 18x speedups over human experts. The approach introduces novel components such as AST-based abstract reasoning, adaptive rollback, and dedicated repair agents, contributing to improved safety and generalization for similar errors in Rust programs.

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.

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

TL;DR

The paper addresses Undefined Behaviors in Unsafe Rust and proposes RustBrain, a dual-process LLM framework that integrates fast, intuitive repair generation with slow, analytic verification. It uses Miri for UB detection and a multi-agent slow-thinking pipeline to decompose, verify, reason, and generalize repairs, tied together by a feedback mechanism. RustBrain achieves a 94.3% pass rate and 80.4% execution rate on the Miri dataset (with knowledge-base integration) and outperforms the state-of-the-art RustAssistant by about 30% in pass rate, with up to 18x speedups over human experts. The approach introduces novel components such as AST-based abstract reasoning, adaptive rollback, and dedicated repair agents, contributing to improved safety and generalization for similar errors in Rust programs.

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.

Paper Structure

This paper contains 16 sections, 12 figures, 1 table, 1 algorithm.

Figures (12)

  • Figure 1: RustBrain: Fast and Slow thinking LLM processes.
  • Figure 2: RustBrain Overview: it leverages Miri for static analysis (F1). Extracts and combines features for solution generation (F2). Abstraction and decomposition into steps (S1), integrates multi-agent verification to reduce UBs. Evaluate and reason to fine-tune solution(S2). Generalization provides a solution for such UBs(S3).
  • Figure 3: The same API requires different substitution methods.
  • Figure 4: Three types of prompt strategies.
  • Figure 5: No Rollback Mechanism and Adaptive Rollback Mechanism.
  • ...and 7 more figures