https://gcc.gnu.org/g:2b13311fad4b249624e207118b4b4b1f7a93445b
commit r17-5160-g2b13311fad4b249624e207118b4b4b1f7a93445b Author: Pierre-Emmanuel Patry <[email protected]> Date: Thu Sep 10 20:38:55 2026 +0200 gccrs: Rename functions and members within mappings 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 <[email protected]> Diff: --- gcc/rust/expand/rust-macro-expand.h | 6 +-- gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 12 ++--- .../resolve/rust-toplevel-name-resolver-2.0.cc | 6 +-- gcc/rust/util/rust-hir-map.cc | 62 +++++++++++----------- gcc/rust/util/rust-hir-map.h | 39 ++++++-------- 5 files changed, 59 insertions(+), 66 deletions(-) diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index ddd433c39369..02de84220d12 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -412,7 +412,7 @@ struct MacroExpander AST::Fragment expand_derive_proc_macro (T &item, AST::SimplePath &path) { tl::optional<CustomDeriveProcMacro &> macro - = mappings.pmacro_mappings.lookup_derive_proc_macro_invocation (path); + = mappings.pmacro_mappings.lookup_derive_invocation (path); if (!macro.has_value ()) { rust_error_at (path.get_locus (), "macro not found"); @@ -435,7 +435,7 @@ struct MacroExpander AST::MacroInvocation &invocation) { tl::optional<BangProcMacro &> macro - = mappings.pmacro_mappings.lookup_bang_proc_macro_invocation (invocation); + = mappings.pmacro_mappings.lookup_bang_invocation (invocation); if (!macro.has_value ()) { rust_error_at (invocation.get_locus (), "macro not found"); @@ -457,7 +457,7 @@ struct MacroExpander AST::Fragment expand_attribute_proc_macro (T &item, AST::SimplePath &path) { tl::optional<AttributeProcMacro &> macro - = mappings.pmacro_mappings.lookup_attribute_proc_macro_invocation (path); + = mappings.pmacro_mappings.lookup_attribute_invocation (path); if (!macro.has_value ()) { rust_error_at (path.get_locus (), "macro not found"); diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc index d4d0cb8e1ec8..d45536717a73 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -402,12 +402,12 @@ Early::visit_derive_attribute (AST::Attribute &attr, continue; } - auto pm_def = mappings.pmacro_mappings.lookup_derive_proc_macro_def ( + auto pm_def = mappings.pmacro_mappings.lookup_derive_def ( ns_def->definition.get_node_id ()); if (pm_def.has_value ()) - mappings.pmacro_mappings.insert_derive_proc_macro_invocation ( - trait, pm_def.value ()); + mappings.pmacro_mappings.insert_derive_invocation (trait, + pm_def.value ()); } } @@ -425,14 +425,14 @@ Early::visit_non_builtin_attribute (AST::Attribute &attr, name.c_str ())); return; } - auto pm_def = mappings.pmacro_mappings.lookup_attribute_proc_macro_def ( + auto pm_def = mappings.pmacro_mappings.lookup_attribute_def ( ns_def->definition.get_node_id ()); if (!pm_def.has_value ()) return; - mappings.pmacro_mappings.insert_attribute_proc_macro_invocation ( - attr.get_path (), pm_def.value ()); + mappings.pmacro_mappings.insert_attribute_invocation (attr.get_path (), + pm_def.value ()); } void diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 88b946649f4b..4b2fae0ddb89 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -199,19 +199,19 @@ TopLevel::visit_extern_crate (AST::ExternCrate &extern_crate, AST::Crate &crate, { insert_macros (derive_macros.value (), ctx); for (auto ¯o : derive_macros.value ()) - mappings.pmacro_mappings.insert_derive_proc_macro_def (macro); + mappings.pmacro_mappings.insert_derive_def (macro); } if (attribute_macros.has_value ()) { insert_macros (attribute_macros.value (), ctx); for (auto ¯o : attribute_macros.value ()) - mappings.pmacro_mappings.insert_attribute_proc_macro_def (macro); + mappings.pmacro_mappings.insert_attribute_def (macro); } if (bang_macros.has_value ()) { insert_macros (bang_macros.value (), ctx); for (auto ¯o : bang_macros.value ()) - mappings.pmacro_mappings.insert_bang_proc_macro_def (macro); + mappings.pmacro_mappings.insert_bang_def (macro); } // We do *NOT* visit the crate because loaded crates are resolved diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index af3d6f222319..a5eefa9e8673 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1137,37 +1137,37 @@ void ProcMacroMappings::insert_derive_proc_macros ( CrateNum num, std::vector<CustomDeriveProcMacro> macros) { - auto it = procmacrosDeriveMappings.find (num); - rust_assert (it == procmacrosDeriveMappings.end ()); + auto it = deriveMappings.find (num); + rust_assert (it == deriveMappings.end ()); - procmacrosDeriveMappings[num] = macros; + deriveMappings[num] = macros; } void ProcMacroMappings::insert_bang_proc_macros (CrateNum num, std::vector<BangProcMacro> macros) { - auto it = procmacrosBangMappings.find (num); - rust_assert (it == procmacrosBangMappings.end ()); + auto it = bangMappings.find (num); + rust_assert (it == bangMappings.end ()); - procmacrosBangMappings[num] = macros; + bangMappings[num] = macros; } void ProcMacroMappings::insert_attribute_proc_macros ( CrateNum num, std::vector<AttributeProcMacro> macros) { - auto it = procmacrosAttributeMappings.find (num); - rust_assert (it == procmacrosAttributeMappings.end ()); + auto it = attributeMappings.find (num); + rust_assert (it == attributeMappings.end ()); - procmacrosAttributeMappings[num] = macros; + attributeMappings[num] = macros; } tl::optional<std::vector<CustomDeriveProcMacro> &> ProcMacroMappings::lookup_derive_proc_macros (CrateNum num) { - auto it = procmacrosDeriveMappings.find (num); - if (it == procmacrosDeriveMappings.end ()) + auto it = deriveMappings.find (num); + if (it == deriveMappings.end ()) return tl::nullopt; return it->second; @@ -1176,8 +1176,8 @@ ProcMacroMappings::lookup_derive_proc_macros (CrateNum num) tl::optional<std::vector<BangProcMacro> &> ProcMacroMappings::lookup_bang_proc_macros (CrateNum num) { - auto it = procmacrosBangMappings.find (num); - if (it == procmacrosBangMappings.end ()) + auto it = bangMappings.find (num); + if (it == bangMappings.end ()) return tl::nullopt; return it->second; @@ -1186,15 +1186,15 @@ ProcMacroMappings::lookup_bang_proc_macros (CrateNum num) tl::optional<std::vector<AttributeProcMacro> &> ProcMacroMappings::lookup_attribute_proc_macros (CrateNum num) { - auto it = procmacrosAttributeMappings.find (num); - if (it == procmacrosAttributeMappings.end ()) + auto it = attributeMappings.find (num); + if (it == attributeMappings.end ()) return tl::nullopt; return it->second; } void -ProcMacroMappings::insert_derive_proc_macro_def (CustomDeriveProcMacro macro) +ProcMacroMappings::insert_derive_def (CustomDeriveProcMacro macro) { auto it = procmacroDeriveMappings.find (macro.get_node_id ()); rust_assert (it == procmacroDeriveMappings.end ()); @@ -1203,7 +1203,7 @@ ProcMacroMappings::insert_derive_proc_macro_def (CustomDeriveProcMacro macro) } void -ProcMacroMappings::insert_bang_proc_macro_def (BangProcMacro macro) +ProcMacroMappings::insert_bang_def (BangProcMacro macro) { auto it = procmacroBangMappings.find (macro.get_node_id ()); rust_assert (it == procmacroBangMappings.end ()); @@ -1212,7 +1212,7 @@ ProcMacroMappings::insert_bang_proc_macro_def (BangProcMacro macro) } void -ProcMacroMappings::insert_attribute_proc_macro_def (AttributeProcMacro macro) +ProcMacroMappings::insert_attribute_def (AttributeProcMacro macro) { auto it = procmacroAttributeMappings.find (macro.get_node_id ()); rust_assert (it == procmacroAttributeMappings.end ()); @@ -1221,7 +1221,7 @@ ProcMacroMappings::insert_attribute_proc_macro_def (AttributeProcMacro macro) } tl::optional<CustomDeriveProcMacro &> -ProcMacroMappings::lookup_derive_proc_macro_def (NodeId id) +ProcMacroMappings::lookup_derive_def (NodeId id) { auto it = procmacroDeriveMappings.find (id); if (it == procmacroDeriveMappings.end ()) @@ -1231,7 +1231,7 @@ ProcMacroMappings::lookup_derive_proc_macro_def (NodeId id) } tl::optional<BangProcMacro &> -ProcMacroMappings::lookup_bang_proc_macro_def (NodeId id) +ProcMacroMappings::lookup_bang_def (NodeId id) { auto it = procmacroBangMappings.find (id); if (it == procmacroBangMappings.end ()) @@ -1241,7 +1241,7 @@ ProcMacroMappings::lookup_bang_proc_macro_def (NodeId id) } tl::optional<AttributeProcMacro &> -ProcMacroMappings::lookup_attribute_proc_macro_def (NodeId id) +ProcMacroMappings::lookup_attribute_def (NodeId id) { auto it = procmacroAttributeMappings.find (id); if (it == procmacroAttributeMappings.end ()) @@ -1251,8 +1251,8 @@ ProcMacroMappings::lookup_attribute_proc_macro_def (NodeId id) } void -ProcMacroMappings::insert_derive_proc_macro_invocation ( - AST::SimplePath &invoc, CustomDeriveProcMacro def) +ProcMacroMappings::insert_derive_invocation (AST::SimplePath &invoc, + CustomDeriveProcMacro def) { auto it = procmacroDeriveInvocations.find (invoc.get_node_id ()); rust_assert (it == procmacroDeriveInvocations.end ()); @@ -1261,7 +1261,7 @@ ProcMacroMappings::insert_derive_proc_macro_invocation ( } tl::optional<CustomDeriveProcMacro &> -ProcMacroMappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc) +ProcMacroMappings::lookup_derive_invocation (AST::SimplePath &invoc) { auto it = procmacroDeriveInvocations.find (invoc.get_node_id ()); if (it == procmacroDeriveInvocations.end ()) @@ -1271,8 +1271,8 @@ ProcMacroMappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc) } void -ProcMacroMappings::insert_bang_proc_macro_invocation ( - AST::MacroInvocation &invoc, BangProcMacro def) +ProcMacroMappings::insert_bang_invocation (AST::MacroInvocation &invoc, + BangProcMacro def) { auto it = procmacroBangInvocations.find (invoc.get_node_id ()); rust_assert (it == procmacroBangInvocations.end ()); @@ -1281,8 +1281,7 @@ ProcMacroMappings::insert_bang_proc_macro_invocation ( } tl::optional<BangProcMacro &> -ProcMacroMappings::lookup_bang_proc_macro_invocation ( - AST::MacroInvocation &invoc) +ProcMacroMappings::lookup_bang_invocation (AST::MacroInvocation &invoc) { auto it = procmacroBangInvocations.find (invoc.get_node_id ()); if (it == procmacroBangInvocations.end ()) @@ -1292,8 +1291,8 @@ ProcMacroMappings::lookup_bang_proc_macro_invocation ( } void -ProcMacroMappings::insert_attribute_proc_macro_invocation ( - AST::SimplePath &invoc, AttributeProcMacro def) +ProcMacroMappings::insert_attribute_invocation (AST::SimplePath &invoc, + AttributeProcMacro def) { auto it = procmacroAttributeInvocations.find (invoc.get_node_id ()); rust_assert (it == procmacroAttributeInvocations.end ()); @@ -1302,8 +1301,7 @@ ProcMacroMappings::insert_attribute_proc_macro_invocation ( } tl::optional<AttributeProcMacro &> -ProcMacroMappings::lookup_attribute_proc_macro_invocation ( - AST::SimplePath &invoc) +ProcMacroMappings::lookup_attribute_invocation (AST::SimplePath &invoc) { auto it = procmacroAttributeInvocations.find (invoc.get_node_id ()); if (it == procmacroAttributeInvocations.end ()) diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index a7f631608eb3..c0041399fc65 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -110,11 +110,9 @@ public: class ProcMacroMappings { - std::map<CrateNum, std::vector<CustomDeriveProcMacro>> - procmacrosDeriveMappings; - std::map<CrateNum, std::vector<BangProcMacro>> procmacrosBangMappings; - std::map<CrateNum, std::vector<AttributeProcMacro>> - procmacrosAttributeMappings; + std::map<CrateNum, std::vector<CustomDeriveProcMacro>> deriveMappings; + std::map<CrateNum, std::vector<BangProcMacro>> bangMappings; + std::map<CrateNum, std::vector<AttributeProcMacro>> attributeMappings; std::map<NodeId, CustomDeriveProcMacro> procmacroDeriveMappings; std::map<NodeId, BangProcMacro> procmacroBangMappings; @@ -138,28 +136,25 @@ public: tl::optional<std::vector<AttributeProcMacro> &> lookup_attribute_proc_macros (CrateNum num); - void insert_derive_proc_macro_def (CustomDeriveProcMacro macro); - void insert_bang_proc_macro_def (BangProcMacro macro); - void insert_attribute_proc_macro_def (AttributeProcMacro macro); + void insert_derive_def (CustomDeriveProcMacro macro); + void insert_bang_def (BangProcMacro macro); + void insert_attribute_def (AttributeProcMacro macro); - tl::optional<CustomDeriveProcMacro &> - lookup_derive_proc_macro_def (NodeId id); - tl::optional<BangProcMacro &> lookup_bang_proc_macro_def (NodeId id); - tl::optional<AttributeProcMacro &> - lookup_attribute_proc_macro_def (NodeId id); + tl::optional<CustomDeriveProcMacro &> lookup_derive_def (NodeId id); + tl::optional<BangProcMacro &> lookup_bang_def (NodeId id); + tl::optional<AttributeProcMacro &> lookup_attribute_def (NodeId id); tl::optional<CustomDeriveProcMacro &> - lookup_derive_proc_macro_invocation (AST::SimplePath &invoc); + lookup_derive_invocation (AST::SimplePath &invoc); tl::optional<BangProcMacro &> - lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc_id); + lookup_bang_invocation (AST::MacroInvocation &invoc_id); tl::optional<AttributeProcMacro &> - lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc); - void insert_derive_proc_macro_invocation (AST::SimplePath &invoc, - CustomDeriveProcMacro def); - void insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc, - BangProcMacro def); - void insert_attribute_proc_macro_invocation (AST::SimplePath &invoc, - AttributeProcMacro def); + lookup_attribute_invocation (AST::SimplePath &invoc); + void insert_derive_invocation (AST::SimplePath &invoc, + CustomDeriveProcMacro def); + void insert_bang_invocation (AST::MacroInvocation &invoc, BangProcMacro def); + void insert_attribute_invocation (AST::SimplePath &invoc, + AttributeProcMacro def); }; class Mappings
