Clean up hir map - #4878
Merged
Merged
Clean up hir map#4878
Conversation
P-E-P
force-pushed
the
hir_map_refactor
branch
5 times, most recently
from
September 16, 2026 15:35
8bf2536 to
a752f39
Compare
P-E-P
marked this pull request as ready for review
September 16, 2026 18:28
P-E-P
force-pushed
the
hir_map_refactor
branch
2 times, most recently
from
September 22, 2026 15:36
e640c97 to
cf21163
Compare
P-E-P
force-pushed
the
hir_map_refactor
branch
4 times, most recently
from
September 22, 2026 16:19
bf9fa05 to
a0b38e2
Compare
CohenArthur
reviewed
Sep 22, 2026
P-E-P
force-pushed
the
hir_map_refactor
branch
2 times, most recently
from
September 24, 2026 06:45
2d4fd5c to
4926415
Compare
HIR mappings are getting bigger, this commit attempts to regroup crate related mappings within a single class. gcc/rust/ChangeLog: * ast/rust-collect-lang-items.cc (CollectLangItems::visit): Use sub category. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): Likewise. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Likewise. * expand/rust-macro-substitute-ctx.cc: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Likewise. (ASTLoweringBase::lower_loop_label): Likewise. (ASTLoweringBase::lower_path_expr_seg): Likewise. (ASTLoweringBase::lower_self): Likewise. (ASTLoweringBase::lower_extern_block): Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-enumitem.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. (ASTLoweringSimplePath::lower): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Likewise. (ASTLowerQualifiedPathInType::visit): Likewise. (ASTLoweringType::visit): Likewise. (ASTLowerGenericParam::visit): Likewise. (ASTLoweringTypeBounds::visit): Likewise. (ASTLowerWhereClauseItem::visit): Likewise. * hir/rust-ast-lower.cc (ASTLowering::go): Likewise. (ASTLoweringBlock::visit): Likewise. (ASTLoweringIfBlock::visit): Likewise. (ASTLoweringIfLetBlock::desugar_iflet): Likewise. (ASTLoweringIfLetBlock::visit): Likewise. (ASTLowerStructExprField::visit): Likewise. (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. (ASTLoweringBase::lower_qual_path_type): Likewise. (ASTLowerQualPathInExpression::visit): Likewise. * metadata/rust-export-metadata.cc (PublicInterface::gather_export_data): Likewise. (PublicInterface::write_to_object_file): Likewise. (PublicInterface::write_to_path): Likewise. (PublicInterface::expected_metadata_filename): Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-forever-stack.h: Likewise. * resolve/rust-name-resolution-context.h: Likewise. * rust-session-manager.cc (Session::handle_crate_name): Likewise. (Session::compile_crate): Likewise. (Session::load_extern_crate): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::resolve_function_signature): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * typecheck/rust-tyty-bounds.cc: Likewise. * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::override_context): Likewise. * typecheck/rust-tyty-util.cc (TyVar::monomorphized_clone): Likewise. * typecheck/rust-tyty.cc (InferType::clone): Likewise. (ConstInferType::clone): Likewise. * util/rust-hir-map.cc (CrateMappings::CrateMappings): Add a new specialized class to keep all crate related mappings. (Mappings::Mappings): Move some member functions to CrateMappings. (Mappings::get_next_crate_num): Likewise. (CrateMappings::get_next_crate_num): Likewise. (Mappings::set_current_crate): Likewise. (CrateMappings::set_current_crate): Likewise. (Mappings::get_current_crate): Likewise. (CrateMappings::get_current_crate): Likewise. (Mappings::get_crate_name): Likewise. (CrateMappings::get_crate_name): Likewise. (Mappings::lookup_crate_num): Likewise. (CrateMappings::lookup_crate_num): Likewise. (Mappings::set_crate_name): Likewise. (CrateMappings::set_crate_name): Likewise. (Mappings::get_current_crate_name): Likewise. (CrateMappings::get_current_crate_name): Likewise. (Mappings::lookup_crate_name): Likewise. (CrateMappings::lookup_crate_name): Likewise. (Mappings::crate_num_to_nodeid): Likewise. (CrateMappings::crate_num_to_nodeid): Likewise. (Mappings::node_is_crate): Likewise. (CrateMappings::node_is_crate): Likewise. (Mappings::get_ast_crate): Likewise. (CrateMappings::get_ast_crate): Likewise. (Mappings::get_ast_crate_by_node_id): Likewise. (Mappings::get_ast_crate_by_node_id_raw): Likewise. (CrateMappings::get_ast_crate_by_node_id_raw): Likewise. (Mappings::insert_ast_crate): Likewise. (CrateMappings::insert_ast_crate): Likewise. (Mappings::insert_macro_def): Likewise. (Mappings::insert_glob_container): Likewise. * util/rust-hir-map.h (class Mappings): Move some declarations from here... (class CrateMappings): ...to here. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
HIR map is getting bigger and harder to use. This commit regroup all proc macro related operations under one subclass. gcc/rust/ChangeLog: * expand/rust-macro-expand.h (struct MacroExpander): Use new macro category. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_derive_attribute): Likewise. (Early::visit_non_builtin_attribute): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit_extern_crate): Likewise. * rust-session-manager.cc (Session::load_extern_crate): Likewise. * util/rust-hir-map.cc (Mappings::insert_derive_proc_macros): Move to specialized macro class declartion. (Mappings::insert_bang_proc_macros): Move from here... (ProcMacroMappings::insert_bang_proc_macros): ... to here. (Mappings::insert_attribute_proc_macros): Likewise. (Mappings::lookup_derive_proc_macros): Likewise. (ProcMacroMappings::lookup_derive_proc_macros): Likewise. (Mappings::lookup_bang_proc_macros): Likewise. (ProcMacroMappings::lookup_bang_proc_macros): Likewise. (Mappings::lookup_attribute_proc_macros): Likewise. (ProcMacroMappings::lookup_attribute_proc_macros): Likewise. (Mappings::insert_derive_proc_macro_def): Likewise. (ProcMacroMappings::insert_derive_proc_macro_def): Likewise. (Mappings::insert_bang_proc_macro_def): Likewise. (ProcMacroMappings::insert_bang_proc_macro_def): Likewise. (Mappings::insert_attribute_proc_macro_def): Likewise. (ProcMacroMappings::insert_attribute_proc_macro_def): Likewise. (Mappings::lookup_derive_proc_macro_def): Likewise. (ProcMacroMappings::lookup_derive_proc_macro_def): Likewise. (Mappings::lookup_bang_proc_macro_def): Likewise. (ProcMacroMappings::lookup_bang_proc_macro_def): Likewise. (Mappings::lookup_attribute_proc_macro_def): Likewise. (ProcMacroMappings::lookup_attribute_proc_macro_def): Likewise. (Mappings::insert_derive_proc_macro_invocation): Likewise. (Mappings::lookup_derive_proc_macro_invocation): Likewise. (ProcMacroMappings::lookup_derive_proc_macro_invocation): Likewise. (Mappings::insert_bang_proc_macro_invocation): Likewise. (Mappings::lookup_bang_proc_macro_invocation): Likewise. (Mappings::insert_attribute_proc_macro_invocation): Likewise. (Mappings::lookup_attribute_proc_macro_invocation): Likewise. * util/rust-hir-map.h (class ProcMacroMappings): Add specialized class for macro mappings. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
Those functions are part of a proc macro context and no longer require an explicit long name about their context. gcc/rust/ChangeLog: * expand/rust-macro-expand.h (struct MacroExpander): Apply new name. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_derive_attribute): Likewise. (Early::visit_non_builtin_attribute): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit_extern_crate): Likewise. * util/rust-hir-map.cc (ProcMacroMappings::insert_bang_proc_macros): Use new member name. (ProcMacroMappings::lookup_derive_proc_macros): Likewise. (ProcMacroMappings::lookup_bang_proc_macros): Likewise. (ProcMacroMappings::lookup_attribute_proc_macros): Likewise. (ProcMacroMappings::insert_derive_proc_macro_def): Likewise. (ProcMacroMappings::insert_derive_def): Likewise. (ProcMacroMappings::insert_bang_proc_macro_def): Likewise. (ProcMacroMappings::insert_bang_def): Likewise. (ProcMacroMappings::insert_attribute_proc_macro_def): Likewise. (ProcMacroMappings::insert_attribute_def): Likewise. (ProcMacroMappings::lookup_derive_proc_macro_def): Likewise. (ProcMacroMappings::lookup_derive_def): Likewise. (ProcMacroMappings::lookup_bang_proc_macro_def): Likewise. (ProcMacroMappings::lookup_bang_def): Likewise. (ProcMacroMappings::lookup_attribute_proc_macro_def): Likewise. (ProcMacroMappings::lookup_attribute_def): Likewise. (ProcMacroMappings::insert_derive_invocation): Likewise. (ProcMacroMappings::lookup_derive_proc_macro_invocation): Likewise. (ProcMacroMappings::lookup_derive_invocation): Likewise. (ProcMacroMappings::insert_bang_invocation): Likewise. (ProcMacroMappings::lookup_bang_invocation): Likewise. (ProcMacroMappings::insert_attribute_invocation): Likewise. (ProcMacroMappings::lookup_attribute_invocation): Likewise. * util/rust-hir-map.h (class ProcMacroMappings): Rename member maps as well as some functions to remove the proc macro mention. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
Rust hir map is too big, regroup some of ast item mappings within a specialized class. gcc/rust/ChangeLog: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_violation_inner): Use ast category. * checks/errors/privacy/rust-pub-restricted-visitor.cc (PubRestrictedVisitor::is_restriction_valid): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::go): Likewise. (VisibilityResolver::resolve_and_update): Likewise. (VisibilityResolver::visit): Likewise. * util/rust-hir-map.cc (Mappings::insert_visibility): Move to ASTMappings. (Mappings::lookup_visibility): Likewise. * util/rust-hir-map.h (class ASTMappings): Add a mapping class dedicated to mapping an id to an Item. Add a specialized ASTMappings class to hold all ast related mappings. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
HIR map is getting bigger and most lookup/insert functions are similar, this commit regroup all simple HIR related mappings under one field. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Use new hir category. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::check_function_call): Likewise. * checks/errors/rust-readonly-check.cc (ReadonlyChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static): Likewise. (UnsafeChecker::check_function_call): Likewise. (UnsafeChecker::check_function_attr): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_extern_block): Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::translate): Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::translate): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::translate): Likewise. (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::translate): Likewise. * hir/rust-ast-lower-struct-field-expr.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Likewise. (ASTLowerGenericParam::translate): Likewise. * hir/rust-ast-lower.cc (ASTLowerPathInExpression::visit): Likewise. (ASTLowerQualPathInExpression::visit): Likewise. * hir/tree/rust-hir-pattern-abstract.cc (PathPattern::is_refutable): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_root_path): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_item): Move to dedicated mappings within the hir category. (Mappings::lookup_hir_item): Likewise. (Mappings::insert_hir_trait_item): Likewise. (Mappings::lookup_hir_trait_item): Likewise. (Mappings::insert_hir_extern_block): Likewise. (Mappings::lookup_hir_extern_block): Likewise. (Mappings::insert_module): Likewise. (Mappings::lookup_module): Likewise. (Mappings::insert_hir_expr): Likewise. (Mappings::lookup_hir_expr): Likewise. (Mappings::insert_hir_path_expr_seg): Likewise. (Mappings::lookup_hir_path_expr_seg): Likewise. (Mappings::insert_hir_generic_param): Likewise. (Mappings::lookup_hir_generic_param): Likewise. (Mappings::insert_hir_type): Likewise. (Mappings::lookup_hir_type): Likewise. (Mappings::insert_hir_stmt): Likewise. (Mappings::lookup_hir_stmt): Likewise. (Mappings::insert_hir_param): Likewise. (Mappings::lookup_hir_param): Likewise. (Mappings::insert_hir_self_param): Likewise. (Mappings::lookup_hir_self_param): Likewise. (Mappings::insert_hir_struct_field): Likewise. (Mappings::lookup_hir_struct_field): Likewise. (Mappings::insert_hir_pattern): Likewise. (Mappings::lookup_hir_pattern): Likewise. (Mappings::resolve_nodeid_to_stmt): Likewise. (Mappings::build_impl_indexes): Likewise. (Mappings::insert_trait_item_mapping): Likewise. * util/rust-hir-map.h (class HIRMappings): Add new class for all hir related mappings. * util/rust-hir-map.hxx: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
Rename pmacro_mappings and crate_mappings to pmacro and crate respectively to stay consistent with the other members name. gcc/rust/ChangeLog: * ast/rust-collect-lang-items.cc (CollectLangItems::visit): Adapt name at call site. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): Likewise. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Likewise. * expand/rust-macro-substitute-ctx.cc: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Likewise. (ASTLoweringBase::lower_loop_label): Likewise. (ASTLoweringBase::lower_path_expr_seg): Likewise. (ASTLoweringBase::lower_self): Likewise. (ASTLoweringBase::lower_extern_block): Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-enumitem.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. (ASTLoweringSimplePath::lower): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Likewise. (ASTLowerQualifiedPathInType::visit): Likewise. (ASTLoweringType::visit): Likewise. (ASTLowerGenericParam::visit): Likewise. (ASTLoweringTypeBounds::visit): Likewise. (ASTLowerWhereClauseItem::visit): Likewise. * hir/rust-ast-lower.cc (ASTLowering::go): Likewise. (ASTLoweringBlock::visit): Likewise. (ASTLoweringIfBlock::visit): Likewise. (ASTLoweringIfLetBlock::desugar_iflet): Likewise. (ASTLoweringIfLetBlock::visit): Likewise. (ASTLowerStructExprField::visit): Likewise. (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. (ASTLoweringBase::lower_qual_path_type): Likewise. (ASTLowerQualPathInExpression::visit): Likewise. * metadata/rust-export-metadata.cc (PublicInterface::gather_export_data): Likewise. (PublicInterface::write_to_object_file): Likewise. (PublicInterface::write_to_path): Likewise. (PublicInterface::expected_metadata_filename): Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_derive_attribute): Likewise. (Early::visit_non_builtin_attribute): Likewise. * resolve/rust-forever-stack.h: Likewise. * resolve/rust-name-resolution-context.h: Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit_extern_crate): Likewise. * rust-session-manager.cc (Session::handle_crate_name): Likewise. (Session::compile_crate): Likewise. (Session::load_extern_crate): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::resolve_function_signature): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * typecheck/rust-tyty-bounds.cc: Likewise. * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::override_context): Likewise. * typecheck/rust-tyty-util.cc (TyVar::monomorphized_clone): Likewise. * typecheck/rust-tyty.cc (InferType::clone): Likewise. (VariantDef::clone): Likewise. (VariantDef::monomorphized_clone): Likewise. (ConstInferType::clone): Likewise. * util/rust-hir-map.cc (Mappings::get_ast_crate_by_node_id): Likewise. (Mappings::insert_macro_def): Likewise. (Mappings::insert_glob_container): Likewise. * util/rust-hir-map.h: Rename pmacro_mappings to pmacro and crate_mappings to crate. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
When using those mappings, the singular name feels weird and may deceive a developper. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Adapt call name. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_module_path): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::check_function_call): Likewise. * checks/errors/rust-readonly-check.cc (ReadonlyChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static): Likewise. (UnsafeChecker::check_function_call): Likewise. (UnsafeChecker::check_function_attr): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_extern_block): Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::translate): Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::translate): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::translate): Likewise. (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::translate): Likewise. * hir/rust-ast-lower-struct-field-expr.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Likewise. (ASTLowerGenericParam::translate): Likewise. * hir/rust-ast-lower.cc (ASTLowerPathInExpression::visit): Likewise. (ASTLowerQualPathInExpression::visit): Likewise. * hir/tree/rust-hir-pattern-abstract.cc (PathPattern::is_refutable): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_root_path): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::resolve_nodeid_to_stmt): Likewise. (Mappings::build_impl_indexes): Likewise. (Mappings::insert_trait_item_mapping): Likewise. * util/rust-hir-map.h: Change HIR mapping name to their plural counterpart. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
Some mapping getters were using the crate num for their key, just like any other mapping within the CrateMappings. Move them over there for consistency. Also modifies the crate mapping name to make use of the Mapping class instead of relying on separate insert/lookup function implementation. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Update function call name. * expand/rust-macro-substitute-ctx.cc: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit_extern_crate): Likewise. * rust-session-manager.cc (Session::load_extern_crate): Likewise. * util/rust-hir-map.cc (CrateMappings::get_next_crate_num): Likewise. (CrateMappings::get_crate_name): Remove. (CrateMappings::set_crate_name): Remove. (CrateMappings::get_current_crate_name): Update with new lookup function. (CrateMappings::lookup_crate_name): Use internal storage getter. (ProcMacroMappings::insert_bang_proc_macros): Remove. (ProcMacroMappings::lookup_derive_proc_macros): Remove. (ProcMacroMappings::lookup_bang_proc_macros): Remove. (ProcMacroMappings::lookup_attribute_proc_macros): Remove. * util/rust-hir-map.h (enum class): Move enum. (class Mapping): Add a getter to const storage in order to allow iteration on existing mappings. Also add a const getter. (class CrateMappings): Add proc macro crate mappings. Convert crate_name getter/setter to Mapping. (class ProcMacroMappings): Remove crate related mappings. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
Put macro invocations and definitions in their own container and reuse the Mapping infrastructure. gcc/rust/ChangeLog: * expand/rust-macro-expand.h (struct MacroExpander): Update call name. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_derive_attribute): Likewise. (Early::visit_non_builtin_attribute): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit_extern_crate): Likewise. * util/rust-hir-map.cc (ProcMacroMappings::insert_derive_def): Remove. (ProcMacroMappings::insert_bang_def): Remove. (ProcMacroMappings::insert_attribute_def): Remove. (ProcMacroMappings::lookup_derive_def): Remove. (ProcMacroMappings::lookup_bang_def): Remove. (ProcMacroMappings::lookup_attribute_def): Remove. (ProcMacroMappings::insert_derive_invocation): Remove. (ProcMacroMappings::lookup_derive_invocation): Remove. (ProcMacroMappings::insert_bang_invocation): Remove. (ProcMacroMappings::lookup_bang_invocation): Remove. (ProcMacroMappings::insert_attribute_invocation): Remove. (ProcMacroMappings::lookup_attribute_invocation): Remove. * util/rust-hir-map.h (class ProcMacroMappings): Convert to struct. (struct ProcMacroDefinitionMappings): Add definition mappings. (struct ProcMacroInvocationsMappings): Add invocation mappings. (struct ProcMacroMappings): Use two new separate fields for definitions and invocations. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
P-E-P
force-pushed
the
hir_map_refactor
branch
from
September 24, 2026 08:34
4926415 to
c5d1c77
Compare
Most variables in the rust front end use snake case instead of camel case. Also rename the ast_crate_mapping variable given we already are in a mapping context. gcc/rust/ChangeLog: * util/rust-hir-map.cc (CrateMappings::CrateMappings): Update variable name at call site. (CrateMappings::get_next_crate_num): Likewise. (CrateMappings::set_current_crate): Likewise. (CrateMappings::get_current_crate): Likewise. (CrateMappings::get_ast_crate): Likewise. (CrateMappings::get_ast_crate_by_node_id_raw): Likewise. (CrateMappings::insert_ast_crate): Likewise. * util/rust-hir-map.h (class CrateMappings): Rename variables. Signed-off-by: Pierre-Emmanuel Patry <pierre.emmanuel.patry@opensrcsec.com>
P-E-P
force-pushed
the
hir_map_refactor
branch
from
September 24, 2026 09:22
c5d1c77 to
d61c928
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Mapping class within rust-hir-map is slowly growing. A full clean up might be required in the future but in the meantime we may regroup related fields within specific classes.