Skip to content

[clang][NFC] Remove CXXRecordDecl::lookupDependentName() and its helpers #128392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2025

Conversation

HighCommander4
Copy link
Collaborator

This function has been superseded by HeuristicResolver::lookupDependentName(), which implements the same heuristics and more.

Porting note for any out-of-tree callers:

RD->lookupDependentName(Name, Filter);

can be replaced with:

HeuristicResolver(RD->getASTContext())->lookupDependentName(Name, Filter);

… use it in StandaloneEmptyCheck

The use replaces CXXRecordDecl::lookupDependentName() which
HeuristicResolver aims to supersede.
This function has been superseded by HeuristicResolver::lookupDependentName(),
which implements the same heuristics and more.

Porting note for any out-of-tree callers:

```
RD->lookupDependentName(Name, Filter);
```

can be replaced with:

```
HeuristicResolver(RD->getASTContext())->lookupDependentName(Name, Filter);
```
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2025

@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)

Changes

This function has been superseded by HeuristicResolver::lookupDependentName(), which implements the same heuristics and more.

Porting note for any out-of-tree callers:

RD->lookupDependentName(Name, Filter);

can be replaced with:

HeuristicResolver(RD->getASTContext())->lookupDependentName(Name, Filter);

Full diff: https://github.com/llvm/llvm-project/pull/128392.diff

2 Files Affected:

  • (modified) clang/include/clang/AST/DeclCXX.h (-8)
  • (modified) clang/lib/AST/CXXInheritance.cpp (-53)
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 266b93a64a390..dbd02ef7f8011 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1720,14 +1720,6 @@ class CXXRecordDecl : public RecordDecl {
   /// static analysis, or similar.
   bool hasMemberName(DeclarationName N) const;
 
-  /// Performs an imprecise lookup of a dependent name in this class.
-  ///
-  /// This function does not follow strict semantic rules and should be used
-  /// only when lookup rules can be relaxed, e.g. indexing.
-  std::vector<const NamedDecl *>
-  lookupDependentName(DeclarationName Name,
-                      llvm::function_ref<bool(const NamedDecl *ND)> Filter);
-
   /// Renders and displays an inheritance diagram
   /// for this C++ class and all of its base classes (transitively) using
   /// GraphViz.
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index ee5775837d535..ab862d57eae89 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -411,59 +411,6 @@ bool CXXRecordDecl::hasMemberName(DeclarationName Name) const {
       Paths);
 }
 
-static bool
-findOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
-                                     CXXBasePath &Path, DeclarationName Name) {
-  const TemplateSpecializationType *TST =
-      Specifier->getType()->getAs<TemplateSpecializationType>();
-  if (!TST) {
-    auto *RT = Specifier->getType()->getAs<RecordType>();
-    if (!RT)
-      return false;
-    return findOrdinaryMember(cast<CXXRecordDecl>(RT->getDecl()), Path, Name);
-  }
-  TemplateName TN = TST->getTemplateName();
-  const auto *TD = dyn_cast_or_null<ClassTemplateDecl>(TN.getAsTemplateDecl());
-  if (!TD)
-    return false;
-  CXXRecordDecl *RD = TD->getTemplatedDecl();
-  if (!RD)
-    return false;
-  return findOrdinaryMember(RD, Path, Name);
-}
-
-std::vector<const NamedDecl *> CXXRecordDecl::lookupDependentName(
-    DeclarationName Name,
-    llvm::function_ref<bool(const NamedDecl *ND)> Filter) {
-  std::vector<const NamedDecl *> Results;
-  // Lookup in the class.
-  bool AnyOrdinaryMembers = false;
-  for (const NamedDecl *ND : lookup(Name)) {
-    if (isOrdinaryMember(ND))
-      AnyOrdinaryMembers = true;
-    if (Filter(ND))
-      Results.push_back(ND);
-  }
-  if (AnyOrdinaryMembers)
-    return Results;
-
-  // Perform lookup into our base classes.
-  CXXBasePaths Paths;
-  Paths.setOrigin(this);
-  if (!lookupInBases(
-          [&](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
-            return findOrdinaryMemberInDependentClasses(Specifier, Path, Name);
-          },
-          Paths, /*LookupInDependent=*/true))
-    return Results;
-  for (DeclContext::lookup_iterator I = Paths.front().Decls, E = I.end();
-       I != E; ++I) {
-    if (isOrdinaryMember(*I) && Filter(*I))
-      Results.push_back(*I);
-  }
-  return Results;
-}
-
 void OverridingMethods::add(unsigned OverriddenSubobject,
                             UniqueVirtualMethod Overriding) {
   SmallVectorImpl<UniqueVirtualMethod> &SubobjectOverrides

@HighCommander4
Copy link
Collaborator Author

For reference, the callers of CXXRecordDecl::lookupDependentName() have been ported over to HeuristicResolver over the following series of patches:

#124888
#125153
#128106
#128391

Copy link
Contributor

@zyn0217 zyn0217 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, but my concern would be that we're less clear about the number of uses of this function out-of-tree (and how hard it could be to migrate them to HeuristicResolver), so as an alternative, can we turn the implementation to use HeuristicResolver and explicitly deprecate it for a while before eventually removing it?

@HighCommander4
Copy link
Collaborator Author

LGTM in general, but my concern would be that we're less clear about the number of uses of this function out-of-tree (and how hard it could be to migrate them to HeuristicResolver), so as an alternative, can we turn the implementation to use HeuristicResolver and explicitly deprecate it for a while before eventually removing it?

I tried this, but this would require linking clangSema into clang/lib/AST which creates a circular dependency.

FWIW I did a Github code search and could only find one out-of-tree use in public code available on Github, and it looks straightforward to port to HeuristicResolver.

@cor3ntin
Copy link
Contributor

LGTM in general, but my concern would be that we're less clear about the number of uses of this function out-of-tree (and how hard it could be to migrate them to HeuristicResolver), so as an alternative, can we turn the implementation to use HeuristicResolver and explicitly deprecate it for a while before eventually removing it?

We make no stability guarantees whatsoever for the C++ interfaces (except we don't change in in abi breaking ways in point releases).
The only stable interfaces we offer are the C interfaces

Base automatically changed from users/HighCommander4/lookupdependentname-clangtidy to main February 24, 2025 16:31
@HighCommander4 HighCommander4 merged commit 8ce17c1 into main Feb 24, 2025
14 checks passed
@HighCommander4 HighCommander4 deleted the users/HighCommander4/lookupdependentname-remove branch February 24, 2025 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants