gccrs: Optimizes trait probing by only adding requested auto traits
gccrs optimizes trait probing to avoid exponential complexity.
The gccrs compiler has been optimized to only add the specifically requested auto trait when probing for traits. Previously, the TypeBoundsProbe::scan function incorrectly added all auto traits to every probe. This led to redundant checks, causing exponential increases in type-checking time and memory usage, particularly with nested data structures, and preventing libcore from type-checking. This change resolves an issue where checking a trait on a nested struct would re-probe fields excessively.
In Details
This commit refactors TypeBoundsProbe::scan in gccrs (typecheck/rust-tyty-bounds.cc) to only probe for the auto trait that was explicitly requested. The previous implementation added all known auto traits to every probe, leading to combinatorial explosion in complexity for nested types. Since auto traits do not have supertraits, checking only the requested one is sufficient and avoids redundant work, fixing issues like libcore failing to type-check and resolving Rust-GCC/gccrs#4971.
- gccrs
- The GCC backend for the Rust programming language, enabling Rust code to be compiled by GCC.
- auto trait
- A special trait in Rust (like
Send,Sync,Unpin) whose implementation is automatically determined by the compiler based on the structure of a type, rather than being explicitly implemented by the user. - trait probing
- The process by which the compiler checks if a type satisfies certain trait bounds, often involving recursive checks on associated types or fields.
- ADT
- Algebraic Data Type. A composite type that can be one of several variants, such as enums or structs in Rust.
- libcore
- A minimal, no-std library in Rust that provides fundamental types and traits, forming the core of the Rust standard library.