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

Use AST for metadata export instead of HIR.

Switches metadata export in gccrs from HIR to AST for better accuracy and code reuse.

This commit changes gccrs’ metadata export mechanism to use the Abstract Syntax Tree (AST) instead of the High-Level Intermediate Representation (HIR). The HIR lacked UseDeclaration nodes, which are crucial for resolving some metadata. By using the AST, which already accurately represents these declarations and is used by other systems like proc macro expansion, the compiler deduplicates dumper code and improves the accuracy of exported metadata.

In Details

GCC's Rust frontend now uses the AST, rather than HIR, for metadata export. This change was driven by the HIR's lack of UseDeclaration nodes, which are necessary for complete metadata resolution. The AST's existing use by systems like proc macro expansion provides a stable and accurate source, simplifying the metadata dumper implementation and reducing code duplication.

For Context
AST
Abstract Syntax Tree. A tree representation of the abstract syntactic structure of source code, used internally by compilers.
HIR
High-level Intermediate Representation. An intermediate representation of code used in Rust compilation, situated between the AST and lower-level representations.
UseDeclaration
A Rust syntax construct that imports items from other modules or crates into the current scope.
metadata export
The process of generating metadata about a Rust crate that can be used by other tools or crates, such as for linking or reflection.
proc macro expansion
The process of expanding Rust procedural macros, which are macros that run at compile time and can generate or transform code.
Filed Under: gccrsrustcompiler internalsmetadata