Introduction
The rapid advancement of Large Language Models (LLMs) in code generation has led to impressive performance on benchmarks like HumanEval. However, these evaluations are primarily "black-box," focusing only on whether the final output matches the expected result. This approach fails to determine if a model truly understands the underlying logic or is simply performing sophisticated pattern matching. To address this, we introduce $\mathcal{R}$Eval, a framework designed to evaluate the "white-box" reasoning capabilities of LLMs by testing their ability to predict intermediate runtime behaviors.
The $\mathcal{R}$Eval Framework
$\mathcal{R}$Eval shifts the focus from final output to the execution process. It decomposes program execution into four hierarchical reasoning tasks:
- Code Coverage Prediction (CCP): Determining if a specific statement is reached during execution.
- Program State Prediction (PSP): Predicting the value and type of a variable after a specific statement.
- Execution Path Prediction (EPP): Identifying the next line of code to be executed.
- Output Prediction (OP): Generating the final program output.
By requiring models to perform these tasks, $\mathcal{R}$Eval exposes the "lucky guess" phenomenon, where a model correctly predicts the final output despite failing to understand the intermediate steps.
Methodology and Consistency
The framework is built by "upcycling" existing benchmarks like HumanEval and ClassEval. Using a custom program tracer, we extract ground-truth execution traces to create a dataset of over 3,000 reasoning problems.
A core innovation of $\mathcal{R}$Eval is the Incremental Consistency (IC) Score. This metric evaluates whether a model's reasoning follows a logical flow. A model only receives credit for a "harder" task (like Output Prediction) if it also correctly predicted all prerequisite "easier" tasks (CCP, PSP, and EPP). This ensures that the model's success is grounded in a consistent mental simulation of the code.
Key Findings
Our evaluation of various LLMs, including GPT-4 and open-source alternatives, revealed several critical insights:
- Path Prediction is the Primary Bottleneck: Execution Path Prediction (EPP) proved to be the most difficult task. Models often struggle to determine the next branch even when they have correctly tracked variable states.
- The Consistency Gap: While GPT-4-Turbo leads with an average accuracy of 75%, its IC score drops to 42.5%. This indicates that even the most advanced models fail to maintain logical consistency in more than half of the execution traces.
- Open-Source Struggles: Open-source models show a significant performance gap, with an average IC score of only 10.3. This suggests that current training paradigms do not sufficiently teach models the mechanics of program execution.
- Instruction Tuning and CoT: While instruction tuning generally helps, Chain-of-Thought (CoT) prompting is a double-edged sword. It can improve intermediate reasoning but may lead to cascading errors that ruin the final output prediction.
Conclusion
$\mathcal{R}$Eval highlights a fundamental weakness in current code LLMs: a lack of robust runtime reasoning. Moving forward, improving model performance will likely require "execution-aware" training, where models are explicitly taught to simulate program behavior. Expanding the framework to include complex dynamic behaviors like exception handling and multi-threading will further push the boundaries of LLM code understanding.
Summary updated