gccrs: Generalize prelude import handling
gccrs: Replaces ad-hoc prelude imports with a generalized glob import.
This commit refactors gccrs’ handling of prelude imports by replacing specific, ad-hoc import logic with a generalized glob import in every module and crate. This change simplifies the name resolution process and ensures consistent handling of the prelude across the compiler. A new virtual member function maybe_prelude_import is introduced to facilitate this generalization.
In Details
The rust-default-resolver.cc and related files in gccrs manage how names are resolved within Rust code. Previously, prelude imports (like std::prelude::*) were handled through scattered, specialized logic within different visitor methods. This commit introduces a unified approach by always performing a glob import of the prelude in every module and crate. This is achieved by adding a maybe_prelude_import method to the DefaultResolver and Early name resolver stages, ensuring that the prelude's contents are consistently brought into scope.
- prelude
- A set of Rust items (macros, traits, types) that are automatically imported into every Rust module by default. It provides convenient access to commonly used functionalities without requiring explicit imports.
- 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::*). - name resolution
- The process by which a compiler determines which declaration a particular use of an identifier refers to. This involves matching names against scopes, imports, and visibility rules.
- crate
- The fundamental compilation unit in Rust. A crate can be a binary (an executable program) or a library. It is compiled independently, and its public API is available to other crates.