[clang] [clang] Unique NamespaceAndPrefixStorages with a UniquingSet (NFC) (PR #224221)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 00:49:31 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch migrates NamespaceAndPrefixStorages in ASTContext from
llvm::FoldingSet to llvm::UniquingSet.
NamespaceAndPrefixStorage keys on a pair of const NamespaceBaseDecl *
and NestedNameSpecifier. Switching to UniquingSet allows us to look
up storages with a typed key, eliminating FoldingSetNodeID
serialization at lookup sites and removing
NamespaceAndPrefixStorage::Profile.
Assisted-by: Antigravity
---
Full diff: https://github.com/llvm/llvm-project/pull/224221.diff
3 Files Affected:
- (modified) clang/include/clang/AST/ASTContext.h (+1-1)
- (modified) clang/include/clang/AST/NestedNameSpecifierBase.h (+2-6)
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (+1-4)
``````````diff
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 2f7d39599c477..d01712c58c04e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -345,7 +345,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// Internal storage for NestedNameSpecifiers.
///
/// This set is managed by the NestedNameSpecifier class.
- mutable llvm::FoldingSet<NamespaceAndPrefixStorage>
+ mutable llvm::UniquingSet<NamespaceAndPrefixStorage>
NamespaceAndPrefixStorages;
/// A cache mapping from RecordDecls to ASTRecordLayouts.
diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h
index 5d883246252a1..f5d11e589a0b1 100644
--- a/clang/include/clang/AST/NestedNameSpecifierBase.h
+++ b/clang/include/clang/AST/NestedNameSpecifierBase.h
@@ -265,12 +265,8 @@ struct alignas(8) NamespaceAndPrefixStorage : NamespaceAndPrefix,
NamespaceAndPrefixStorage(const NamespaceBaseDecl *Namespace,
NestedNameSpecifier Prefix)
: NamespaceAndPrefix{Namespace, Prefix} {}
- void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Namespace, Prefix); }
- static void Profile(llvm::FoldingSetNodeID &ID,
- const NamespaceBaseDecl *Namespace,
- NestedNameSpecifier Prefix) {
- ID.AddPointer(Namespace);
- Prefix.Profile(ID);
+ std::pair<const NamespaceBaseDecl *, NestedNameSpecifier> getKey() const {
+ return {Namespace, Prefix};
}
};
diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp
index b668a61021800..1eca017a81e24 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -38,12 +38,9 @@ const NamespaceAndPrefixStorage *
NestedNameSpecifier::MakeNamespaceAndPrefixStorage(
const ASTContext &Ctx, const NamespaceBaseDecl *Namespace,
NestedNameSpecifier Prefix) {
- llvm::FoldingSetNodeID ID;
- NamespaceAndPrefixStorage::Profile(ID, Namespace, Prefix);
-
llvm::FoldingSetInsertToken Token;
NamespaceAndPrefixStorage *S =
- Ctx.NamespaceAndPrefixStorages.lookup(ID, Token);
+ Ctx.NamespaceAndPrefixStorages.lookup({Namespace, Prefix}, Token);
if (!S) {
S = new (Ctx, alignof(NamespaceAndPrefixStorage))
NamespaceAndPrefixStorage(Namespace, Prefix);
``````````
</details>
https://github.com/llvm/llvm-project/pull/224221
More information about the cfe-commits
mailing list