gccrs: Handle ambiguous glob imports
gccrs: Improves handling of ambiguous glob imports.
This commit enhances gccrs’ ability to handle ambiguous glob imports by offloading the details of globbing definitions to a new Rib::insert_globbed function. This change simplifies the GlobbingVisitor and ensures that ambiguities arising from glob imports are managed more robustly. A new test case, glob-import-ambiguous.rs, is added to verify this functionality.
In Details
In gccrs, rust-finalize-imports-2.0.cc and rust-rib.cc are involved in resolving imports, particularly handling complex cases like glob imports. This patch refactors the GlobbingVisitor::glob_definitions to delegate the insertion logic for globbed items to a new Rib::insert_globbed method. This separation of concerns improves the clarity and maintainability of the import resolution process, specifically addressing scenarios where a glob import might lead to ambiguous references or name collisions within the Resolved Import Bank (Rib).
- glob import
- A Rust import statement that brings all public items from a module or crate into the current scope using the
*wildcard (e.g.,use std::prelude::*). - ambiguous reference
- A situation where an identifier could refer to multiple different declarations, making it unclear to the compiler which one is intended. This typically needs to be resolved through more specific imports or qualified paths.
- Resolved Import Bank (Rib)
- A data structure used in Rust compilers (like gccrs) to manage and resolve imported names during the compilation process. It helps track available items and their associated scopes.
- compiler internals
- The internal data structures, algorithms, and phases that constitute the operation of a compiler. This includes how the compiler parses code, performs optimizations, and generates machine code.