GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Use DefId indexes for trait and impl resolution.

Replaces AST node IDs with DefIds for indexing, improving trait and impl resolution.

This commit refactors gccrs to use DefId (Definition IDs) instead of AST (Abstract Syntax Tree) node IDs for indexing, which is crucial for resolving trait implementations and other associated items. By introducing a new indexing pass after HIR lowering, the compiler can map AST nodes to DefIds, enabling more robust and efficient resolution in components like the method resolver and path probe expressions.

In Details

The rust-hir-map.cc implementation now includes a new indexer (Mappings::Mappings, build_impl_indexes) that translates AST node IDs to DefIds. This change affects various lookup functions such as MethodResolver::try_select_predicate_candidates and PathProbeImplTrait::process_trait_impl_items_for_candidates, which now use these DefId indexes instead of direct node ID lookups, improving the accuracy and efficiency of mapping AST constructs to their definitions.

For Context
DefId (Definition ID)
A unique identifier assigned to each definition (like functions, structs, traits, impls) within a Rust crate. It provides a stable way to refer to items across different compilation stages and modules.
AST (Abstract Syntax Tree)
A tree representation of the abstract syntactic structure of source code. It's an intermediate representation used by compilers after parsing but before semantic analysis and code generation.
HIR (High-Level Intermediate Representation)
An intermediate representation used in Rust compilers that is closer to the source code's structure than lower-level IRs, but more processed than the AST. It facilitates semantic analysis and optimizations.
trait impls
Implementations of Rust traits for specific types. For example, impl Display for MyStruct provides the Display trait's functionality for the MyStruct type.
Filed Under: gccrsrustccompiler internals