Fix ICE with deep recursion in Rust const fn
GCC Rust compiler resolves an ICE (Internal Compiler Error) in `const fn` evaluation by properly managing call cache insertions for deep recursion.
An internal compiler error in GCC’s Rust frontend when evaluating deeply recursive const fn calls has been fixed. The issue stemmed from the compiler reserving space in the call cache even when recursion depth exceeded caching limits, leading to a hash table check failure. The fix ensures that cache insertions are only requested when a call will actually be cached, mirroring the behavior of the C++ frontend.
In Details
The rust-constexpr.cc function eval_call_expression is modified to conditionally request an insertion into the call cache (call_cache.insert). Previously, it unconditionally reserved a slot. The fix introduces a check to only attempt insertion if the call is within the caching depth limits, preventing an ICE when deep recursion exhausts the cache. This aligns the behavior with cp/constexpr-eval.cc.
- ICE
- Internal Compiler Error. A severe error indicating a bug within the compiler itself, usually halting compilation.
- const fn
- A Rust function that is allowed to be evaluated at compile time, enabling compile-time computation.
- call cache
- A mechanism used during compile-time evaluation (like
const fn) to store and reuse results of function calls, improving performance. - hash table check
- A verification step within a hash table data structure, which failed in this case due to incorrect cache management.