gccrs: Fix const evaluation for intrinsic calls.
Ensures const evaluation works correctly for intrinsic calls by managing a const context stack.
This commit addresses an issue in gccrs where constant evaluation could fail during type-checking. Previously, resolving function signatures separately from their bodies could lead to unresolved function calls within a const context. The fix introduces a const context stack, allowing the compiler to override normal behavior during const evaluation and ensure that necessary function definitions are available, resolving Rust-GCC/gccrs#4855.
In Details
The query_type function in rust-type-util.cc was modified to properly handle const evaluation contexts. By introducing a new const context stack managed in TypeCheckExpr::visit and related functions, this commit ensures that recursive calls or intrinsic function calls within a const evaluation do not fail due to unresolved types or signatures, particularly when those dependencies are not yet fully type-checked.
- const evaluation
- The process of evaluating expressions at compile time, typically when they are marked as constant. In Rust, this is important for compile-time known values and optimizations.
- intrinsic calls
- Special functions often provided by the compiler or hardware that perform low-level operations, such as bit manipulation or memory access, typically with optimized implementations.
- const context stack
- A mechanism used during compilation to manage the state of constant evaluation. It allows the compiler to track nested constant expressions and ensure that evaluation rules are consistently applied, even in complex scenarios.