Skip to content

[clang][Sema] Upstream HeuristicResolver from clangd #121314

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

Conversation

HighCommander4
Copy link
Collaborator

@HighCommander4 HighCommander4 commented Dec 30, 2024

@HighCommander4
Copy link
Collaborator Author

Depends on #121313

@HighCommander4 HighCommander4 force-pushed the users/HighCommander4/heuristic-resolver-test-suite branch 6 times, most recently from d5403c8 to c342743 Compare January 7, 2025 21:30
Base automatically changed from users/HighCommander4/heuristic-resolver-test-suite to main January 8, 2025 01:52
@HighCommander4 HighCommander4 force-pushed the users/HighCommander4/heuristic-resolver-upstreaming branch from 4a1f5a1 to 4f0e828 Compare January 10, 2025 05:05
@HighCommander4
Copy link
Collaborator Author

Rebased.

@HighCommander4 HighCommander4 marked this pull request as ready for review January 10, 2025 05:52
@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra clangd clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2025

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang-tools-extra

Author: Nathan Ridge (HighCommander4)

Changes

Fixes #121310

EDIT: See accompanying RFC at https://discourse.llvm.org/t/rfc-upstream-heuristicresolver-from-clangd-to-libsema/84004


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

14 Files Affected:

  • (modified) clang-tools-extra/clangd/CMakeLists.txt (-1)
  • (modified) clang-tools-extra/clangd/FindTarget.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/FindTarget.h (+3-1)
  • (modified) clang-tools-extra/clangd/InlayHints.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/ParsedAST.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/ParsedAST.h (+1-1)
  • (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/XRefs.cpp (+1-1)
  • (modified) clang-tools-extra/clangd/unittests/CMakeLists.txt (-1)
  • (renamed) clang/include/clang/Sema/HeuristicResolver.h (+2-5)
  • (modified) clang/lib/Sema/CMakeLists.txt (+1)
  • (renamed) clang/lib/Sema/HeuristicResolver.cpp (+1-3)
  • (modified) clang/unittests/Sema/CMakeLists.txt (+1)
  • (renamed) clang/unittests/Sema/HeuristicResolverTest.cpp (+1-2)
diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt
index d797ddce8c44d1..6f10afe4a5625f 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -91,7 +91,6 @@ add_clang_library(clangDaemon STATIC
   GlobalCompilationDatabase.cpp
   Headers.cpp
   HeaderSourceSwitch.cpp
-  HeuristicResolver.cpp
   Hover.cpp
   IncludeCleaner.cpp
   IncludeFixer.cpp
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index e702c6b3537a09..04fd6d437b7bdd 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -8,7 +8,6 @@
 
 #include "FindTarget.h"
 #include "AST.h"
-#include "HeuristicResolver.h"
 #include "support/Logger.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -35,6 +34,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
diff --git a/clang-tools-extra/clangd/FindTarget.h b/clang-tools-extra/clangd/FindTarget.h
index b41c5470951001..a7706804ce7ece 100644
--- a/clang-tools-extra/clangd/FindTarget.h
+++ b/clang-tools-extra/clangd/FindTarget.h
@@ -33,9 +33,11 @@
 #include <bitset>
 
 namespace clang {
-namespace clangd {
+
 class HeuristicResolver;
 
+namespace clangd {
+
 /// Describes the link between an AST node and a Decl it refers to.
 enum class DeclRelation : unsigned;
 /// A bitfield of DeclRelations.
diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..1b1bcf78c9855e 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -9,7 +9,6 @@
 #include "../clang-tidy/utils/DesignatedInitializers.h"
 #include "AST.h"
 #include "Config.h"
-#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -27,6 +26,7 @@
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index 725cbeb154cb84..89d6f26d0f150e 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -20,7 +20,6 @@
 #include "Feature.h"
 #include "FeatureModule.h"
 #include "Headers.h"
-#include "HeuristicResolver.h"
 #include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
@@ -53,6 +52,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Diagnostic.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.h b/clang-tools-extra/clangd/ParsedAST.h
index 8d9d1e64569267..82fac96360488e 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -38,9 +38,9 @@
 #include <vector>
 
 namespace clang {
+class HeuristicResolver;
 class Sema;
 namespace clangd {
-class HeuristicResolver;
 
 /// Stores and provides access to parsed AST.
 class ParsedAST {
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index e6d16af2495fec..86ca05644c7031 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -9,7 +9,6 @@
 #include "SemanticHighlighting.h"
 #include "Config.h"
 #include "FindTarget.h"
-#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -27,6 +26,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 8d5ab2e491a406..0a093108b752c3 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -10,7 +10,6 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "Headers.h"
-#include "HeuristicResolver.h"
 #include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
@@ -53,6 +52,7 @@
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index 8dba8088908d5e..dffdcd5d014ca9 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -64,7 +64,6 @@ add_unittest(ClangdUnitTests ClangdTests
   GlobalCompilationDatabaseTests.cpp
   HeadersTests.cpp
   HeaderSourceSwitchTests.cpp
-  HeuristicResolverTests.cpp
   HoverTests.cpp
   IncludeCleanerTests.cpp
   IndexActionTests.cpp
diff --git a/clang-tools-extra/clangd/HeuristicResolver.h b/clang/include/clang/Sema/HeuristicResolver.h
similarity index 95%
rename from clang-tools-extra/clangd/HeuristicResolver.h
rename to clang/include/clang/Sema/HeuristicResolver.h
index c130e0677e86dd..947de7a4e83ce0 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.h
+++ b/clang/include/clang/Sema/HeuristicResolver.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEURISTICRESOLVER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEURISTICRESOLVER_H
+#ifndef LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
+#define LLVM_CLANG_SEMA_HEURISTICRESOLVER_H
 
 #include "clang/AST/Decl.h"
 #include <vector>
@@ -24,8 +24,6 @@ class NamedDecl;
 class Type;
 class UnresolvedUsingValueDecl;
 
-namespace clangd {
-
 // This class handles heuristic resolution of declarations and types in template
 // code.
 //
@@ -80,7 +78,6 @@ class HeuristicResolver {
   ASTContext &Ctx;
 };
 
-} // namespace clangd
 } // namespace clang
 
 #endif
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 3241cb53f004ce..dbe4c1437897a7 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -19,6 +19,7 @@ add_clang_library(clangSema
   CodeCompleteConsumer.cpp
   DeclSpec.cpp
   DelayedDiagnostic.cpp
+  HeuristicResolver.cpp
   HLSLExternalSemaSource.cpp
   IdentifierResolver.cpp
   JumpDiagnostics.cpp
diff --git a/clang-tools-extra/clangd/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
similarity index 99%
rename from clang-tools-extra/clangd/HeuristicResolver.cpp
rename to clang/lib/Sema/HeuristicResolver.cpp
index 9eb892e8e4a8ea..7c1b8450b96330 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "HeuristicResolver.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclTemplate.h"
@@ -14,7 +14,6 @@
 #include "clang/AST/Type.h"
 
 namespace clang {
-namespace clangd {
 
 namespace {
 
@@ -466,5 +465,4 @@ const Type *HeuristicResolver::getPointeeType(const Type *T) const {
   return HeuristicResolverImpl(Ctx).getPointeeType(T);
 }
 
-} // namespace clangd
 } // namespace clang
diff --git a/clang/unittests/Sema/CMakeLists.txt b/clang/unittests/Sema/CMakeLists.txt
index 7ded562e8edfa5..17d39408000a47 100644
--- a/clang/unittests/Sema/CMakeLists.txt
+++ b/clang/unittests/Sema/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_unittest(SemaTests
   ExternalSemaSourceTest.cpp
   CodeCompleteTest.cpp
+  HeuristicResolverTest.cpp
   GslOwnerPointerInference.cpp
   SemaLookupTest.cpp
   SemaNoloadLookupTest.cpp
diff --git a/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp b/clang/unittests/Sema/HeuristicResolverTest.cpp
similarity index 99%
rename from clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
rename to clang/unittests/Sema/HeuristicResolverTest.cpp
index e4b3822fc7eb79..c4f054683ccdc9 100644
--- a/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -5,7 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-#include "HeuristicResolver.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Tooling.h"
@@ -13,7 +13,6 @@
 #include "gtest/gtest.h"
 
 using namespace clang::ast_matchers;
-using clang::clangd::HeuristicResolver;
 using testing::ElementsAre;
 
 namespace clang {

@HighCommander4
Copy link
Collaborator Author

Now that the dependent PR #121313 has merged, I've posted an RFC at https://discourse.llvm.org/t/rfc-upstream-heuristicresolver-from-clangd-to-libsema/84004, and I'm publishing this PR for review.

@HighCommander4
Copy link
Collaborator Author

Adding some reviewers. The RFC has been published for a week, and the responses have been favourable with no objections.

Copy link
Collaborator

@hokein hokein left a comment

Choose a reason for hiding this comment

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

The change looks good to me.

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.

Thanks

@HighCommander4 HighCommander4 merged commit ae932be into main Jan 17, 2025
14 checks passed
@HighCommander4 HighCommander4 deleted the users/HighCommander4/heuristic-resolver-upstreaming branch January 17, 2025 22:01
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 clang-tools-extra clangd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upstream HeuristicResolver from clangd to libSema
4 participants