Skip to content
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

[clang-query] Remove support for srcloc output #92442

Merged

Conversation

AaronBallman
Copy link
Collaborator

This functionality was added about three years ago, but has been in a significantly broken state since it was added. It has begun to cause a maintenance burden for work in Clang (largely due to the complexity of having two levels of code generation involved), and the original author is unable to help maintain it. Because it only worked under limited circumstances and because of the maintenance burden, it is being removed. If someone wishes to resurrect the functionality, they should hopefully be able to do so from this one commit.

Fixes #82591

This functionality was added about three years ago, but has been in a
significantly broken state since it was added. It has begun to cause a
maintenance burden for work in Clang (largely due to the complexity of
having two levels of code generation involved), and the original author
is unable to help maintain it. Because it only worked under limited
circumstances and because of the maintenance burden, it is being
removed. If someone wishes to resurrect the functionality, they
should hopefully be able to do so from this one commit.

Fixes llvm#82591
@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra labels May 16, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 16, 2024

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

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

This functionality was added about three years ago, but has been in a significantly broken state since it was added. It has begun to cause a maintenance burden for work in Clang (largely due to the complexity of having two levels of code generation involved), and the original author is unable to help maintain it. Because it only worked under limited circumstances and because of the maintenance burden, it is being removed. If someone wishes to resurrect the functionality, they should hopefully be able to do so from this one commit.

Fixes #82591


Patch is 142.09 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/92442.diff

24 Files Affected:

  • (modified) clang-tools-extra/clang-query/CMakeLists.txt (-1)
  • (modified) clang-tools-extra/clang-query/Query.cpp (+1-97)
  • (modified) clang-tools-extra/clang-query/Query.h (+1-2)
  • (modified) clang-tools-extra/clang-query/QueryParser.cpp (+1-9)
  • (modified) clang-tools-extra/clang-query/QuerySession.h (+2-3)
  • (modified) clang-tools-extra/unittests/clang-query/QueryParserTest.cpp (+7-25)
  • (modified) clang/docs/tools/clang-formatted-files.txt (-5)
  • (removed) clang/include/clang/Tooling/NodeIntrospection.h (-101)
  • (modified) clang/lib/Tooling/CMakeLists.txt (-90)
  • (removed) clang/lib/Tooling/DumpTool/APIData.h (-31)
  • (removed) clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp (-271)
  • (removed) clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h (-53)
  • (removed) clang/lib/Tooling/DumpTool/CMakeLists.txt (-16)
  • (removed) clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp (-155)
  • (removed) clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py (-452)
  • (removed) clang/lib/Tooling/EmptyNodeIntrospection.inc.in (-48)
  • (removed) clang/lib/Tooling/NodeIntrospection.cpp (-88)
  • (modified) clang/unittests/CMakeLists.txt (-1)
  • (removed) clang/unittests/Introspection/CMakeLists.txt (-22)
  • (removed) clang/unittests/Introspection/IntrospectionTest.cpp (-1679)
  • (modified) llvm/utils/gn/secondary/clang/lib/Tooling/BUILD.gn (-16)
  • (removed) llvm/utils/gn/secondary/clang/lib/Tooling/DumpTool/BUILD.gn (-20)
  • (modified) llvm/utils/gn/secondary/clang/unittests/BUILD.gn (-1)
  • (removed) llvm/utils/gn/secondary/clang/unittests/Introspection/BUILD.gn (-19)
diff --git a/clang-tools-extra/clang-query/CMakeLists.txt b/clang-tools-extra/clang-query/CMakeLists.txt
index 8a58d4224e049..34f018c4a03f3 100644
--- a/clang-tools-extra/clang-query/CMakeLists.txt
+++ b/clang-tools-extra/clang-query/CMakeLists.txt
@@ -20,7 +20,6 @@ clang_target_link_libraries(clangQuery
   clangBasic
   clangDynamicASTMatchers
   clangFrontend
-  clangTooling
   clangSerialization
   )
 
diff --git a/clang-tools-extra/clang-query/Query.cpp b/clang-tools-extra/clang-query/Query.cpp
index 9d5807a52fa8e..e80d98c8dfdbd 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -13,7 +13,6 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/TextDiagnostic.h"
-#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/Support/raw_ostream.h"
 #include <optional>
 
@@ -69,8 +68,6 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
         "Diagnostic location for bound nodes.\n"
         "  detailed-ast                      "
         "Detailed AST output for bound nodes.\n"
-        "  srcloc                            "
-        "Source locations and ranges for bound nodes.\n"
         "  dump                              "
         "Detailed AST output for bound nodes (alias of detailed-ast).\n\n";
   return true;
@@ -91,90 +88,6 @@ struct CollectBoundNodes : MatchFinder::MatchCallback {
   }
 };
 
-void dumpLocations(llvm::raw_ostream &OS, DynTypedNode Node, ASTContext &Ctx,
-                   const DiagnosticsEngine &Diags, SourceManager const &SM) {
-  auto Locs = clang::tooling::NodeIntrospection::GetLocations(Node);
-
-  auto PrintLocations = [](llvm::raw_ostream &OS, auto Iter, auto End) {
-    auto CommonEntry = Iter->first;
-    auto Scout = Iter;
-    SmallVector<std::string> LocationStrings;
-    while (Scout->first == CommonEntry) {
-      LocationStrings.push_back(
-          tooling::LocationCallFormatterCpp::format(*Iter->second));
-      if (Scout == End)
-        break;
-      ++Scout;
-      if (Scout->first == CommonEntry)
-        ++Iter;
-    }
-    llvm::sort(LocationStrings);
-    for (auto &LS : LocationStrings) {
-      OS << " * \"" << LS << "\"\n";
-    }
-    return Iter;
-  };
-
-  TextDiagnostic TD(OS, Ctx.getLangOpts(), &Diags.getDiagnosticOptions());
-
-  for (auto Iter = Locs.LocationAccessors.begin();
-       Iter != Locs.LocationAccessors.end(); ++Iter) {
-    if (!Iter->first.isValid())
-      continue;
-
-    TD.emitDiagnostic(FullSourceLoc(Iter->first, SM), DiagnosticsEngine::Note,
-                      "source locations here", std::nullopt, std::nullopt);
-
-    Iter = PrintLocations(OS, Iter, Locs.LocationAccessors.end());
-    OS << '\n';
-  }
-
-  for (auto Iter = Locs.RangeAccessors.begin();
-       Iter != Locs.RangeAccessors.end(); ++Iter) {
-
-    if (!Iter->first.getBegin().isValid())
-      continue;
-
-    if (SM.getPresumedLineNumber(Iter->first.getBegin()) !=
-        SM.getPresumedLineNumber(Iter->first.getEnd()))
-      continue;
-
-    TD.emitDiagnostic(
-        FullSourceLoc(Iter->first.getBegin(), SM), DiagnosticsEngine::Note,
-        "source ranges here " + Iter->first.printToString(SM),
-        CharSourceRange::getTokenRange(Iter->first), std::nullopt);
-
-    Iter = PrintLocations(OS, Iter, Locs.RangeAccessors.end());
-  }
-  for (auto Iter = Locs.RangeAccessors.begin();
-       Iter != Locs.RangeAccessors.end(); ++Iter) {
-
-    if (!Iter->first.getBegin().isValid())
-      continue;
-
-    if (SM.getPresumedLineNumber(Iter->first.getBegin()) ==
-        SM.getPresumedLineNumber(Iter->first.getEnd()))
-      continue;
-
-    TD.emitDiagnostic(
-        FullSourceLoc(Iter->first.getBegin(), SM), DiagnosticsEngine::Note,
-        "source range " + Iter->first.printToString(SM) + " starting here...",
-        CharSourceRange::getTokenRange(Iter->first), std::nullopt);
-
-    auto ColNum = SM.getPresumedColumnNumber(Iter->first.getEnd());
-    auto LastLineLoc = Iter->first.getEnd().getLocWithOffset(-(ColNum - 1));
-
-    TD.emitDiagnostic(FullSourceLoc(Iter->first.getEnd(), SM),
-                      DiagnosticsEngine::Note, "... ending here",
-                      CharSourceRange::getTokenRange(
-                          SourceRange(LastLineLoc, Iter->first.getEnd())),
-                      std::nullopt);
-
-    Iter = PrintLocations(OS, Iter, Locs.RangeAccessors.end());
-  }
-  OS << "\n";
-}
-
 } // namespace
 
 bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
@@ -195,8 +108,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
       return false;
     }
 
-    auto &Ctx = AST->getASTContext();
-    const auto &SM = Ctx.getSourceManager();
+    const ASTContext &Ctx = AST->getASTContext();
     Ctx.getParentMapContext().setTraversalKind(QS.TK);
     Finder.matchAST(Ctx);
 
@@ -244,19 +156,11 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
         }
         if (QS.DetailedASTOutput) {
           OS << "Binding for \"" << BI->first << "\":\n";
-          const ASTContext &Ctx = AST->getASTContext();
           ASTDumper Dumper(OS, Ctx, AST->getDiagnostics().getShowColors());
           Dumper.SetTraversalKind(QS.TK);
           Dumper.Visit(BI->second);
           OS << "\n";
         }
-        if (QS.SrcLocOutput) {
-          OS << "\n  \"" << BI->first << "\" Source locations\n";
-          OS << "  " << std::string(19 + BI->first.size(), '-') << '\n';
-
-          dumpLocations(OS, BI->second, Ctx, AST->getDiagnostics(), SM);
-          OS << "\n";
-        }
       }
 
       if (MI->getMap().empty())
diff --git a/clang-tools-extra/clang-query/Query.h b/clang-tools-extra/clang-query/Query.h
index 7242479633c24..af250fbe13ce3 100644
--- a/clang-tools-extra/clang-query/Query.h
+++ b/clang-tools-extra/clang-query/Query.h
@@ -17,7 +17,7 @@
 namespace clang {
 namespace query {
 
-enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST, OK_SrcLoc };
+enum OutputKind { OK_Diag, OK_Print, OK_DetailedAST };
 
 enum QueryKind {
   QK_Invalid,
@@ -149,7 +149,6 @@ struct SetExclusiveOutputQuery : Query {
     QS.DiagOutput = false;
     QS.DetailedASTOutput = false;
     QS.PrintOutput = false;
-    QS.SrcLocOutput = false;
     QS.*Var = true;
     return true;
   }
diff --git a/clang-tools-extra/clang-query/QueryParser.cpp b/clang-tools-extra/clang-query/QueryParser.cpp
index 85a442bdd7ded..15fb11ef1fa1f 100644
--- a/clang-tools-extra/clang-query/QueryParser.cpp
+++ b/clang-tools-extra/clang-query/QueryParser.cpp
@@ -11,7 +11,6 @@
 #include "QuerySession.h"
 #include "clang/ASTMatchers/Dynamic/Parser.h"
 #include "clang/Basic/CharInfo.h"
-#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include <optional>
@@ -104,18 +103,15 @@ QueryRef QueryParser::parseSetBool(bool QuerySession::*Var) {
 
 template <typename QueryType> QueryRef QueryParser::parseSetOutputKind() {
   StringRef ValStr;
-  bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
   unsigned OutKind =
       LexOrCompleteWord<unsigned>(this, ValStr)
           .Case("diag", OK_Diag)
           .Case("print", OK_Print)
           .Case("detailed-ast", OK_DetailedAST)
-          .Case("srcloc", OK_SrcLoc, /*IsCompletion=*/HasIntrospection)
           .Case("dump", OK_DetailedAST)
           .Default(~0u);
   if (OutKind == ~0u) {
-    return new InvalidQuery("expected 'diag', 'print', 'detailed-ast'" +
-                            StringRef(HasIntrospection ? ", 'srcloc'" : "") +
+    return new InvalidQuery("expected 'diag', 'print', 'detailed-ast'"
                             " or 'dump', got '" + ValStr + "'");
   }
 
@@ -126,10 +122,6 @@ template <typename QueryType> QueryRef QueryParser::parseSetOutputKind() {
     return new QueryType(&QuerySession::DiagOutput);
   case OK_Print:
     return new QueryType(&QuerySession::PrintOutput);
-  case OK_SrcLoc:
-    if (HasIntrospection)
-      return new QueryType(&QuerySession::SrcLocOutput);
-    return new InvalidQuery("'srcloc' output support is not available.");
   }
 
   llvm_unreachable("Invalid output kind");
diff --git a/clang-tools-extra/clang-query/QuerySession.h b/clang-tools-extra/clang-query/QuerySession.h
index 9a08289a25344..31a4900e26190 100644
--- a/clang-tools-extra/clang-query/QuerySession.h
+++ b/clang-tools-extra/clang-query/QuerySession.h
@@ -25,15 +25,14 @@ class QuerySession {
 public:
   QuerySession(llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs)
       : ASTs(ASTs), PrintOutput(false), DiagOutput(true),
-        DetailedASTOutput(false), SrcLocOutput(false), BindRoot(true),
-        PrintMatcher(false), Terminate(false), TK(TK_AsIs) {}
+        DetailedASTOutput(false), BindRoot(true), PrintMatcher(false),
+        Terminate(false), TK(TK_AsIs) {}
 
   llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs;
 
   bool PrintOutput;
   bool DiagOutput;
   bool DetailedASTOutput;
-  bool SrcLocOutput;
 
   bool BindRoot;
   bool PrintMatcher;
diff --git a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
index b561e2bb98332..e414587c568b7 100644
--- a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
+++ b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
@@ -9,7 +9,6 @@
 #include "QueryParser.h"
 #include "Query.h"
 #include "QuerySession.h"
-#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "gtest/gtest.h"
 
@@ -61,7 +60,6 @@ TEST_F(QueryParserTest, Quit) {
 
 TEST_F(QueryParserTest, Set) {
 
-  bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa<InvalidQuery>(Q));
   EXPECT_EQ("expected variable name", cast<InvalidQuery>(Q)->ErrStr);
@@ -72,13 +70,8 @@ TEST_F(QueryParserTest, Set) {
 
   Q = parse("set output");
   ASSERT_TRUE(isa<InvalidQuery>(Q));
-  if (HasIntrospection)
-    EXPECT_EQ(
-        "expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', got ''",
-        cast<InvalidQuery>(Q)->ErrStr);
-  else
-    EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''",
-              cast<InvalidQuery>(Q)->ErrStr);
+  EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''",
+            cast<InvalidQuery>(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa<InvalidQuery>(Q));
@@ -86,13 +79,8 @@ TEST_F(QueryParserTest, Set) {
 
   Q = parse("set output foo");
   ASSERT_TRUE(isa<InvalidQuery>(Q));
-  if (HasIntrospection)
-    EXPECT_EQ("expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', "
-              "got 'foo'",
-              cast<InvalidQuery>(Q)->ErrStr);
-  else
-    EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'",
-              cast<InvalidQuery>(Q)->ErrStr);
+  EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'",
+            cast<InvalidQuery>(Q)->ErrStr);
 
   Q = parse("set output dump");
   ASSERT_TRUE(isa<SetExclusiveOutputQuery >(Q));
@@ -232,10 +220,8 @@ TEST_F(QueryParserTest, Complete) {
   EXPECT_EQ("output ", Comps[0].TypedText);
   EXPECT_EQ("output", Comps[0].DisplayText);
 
-  bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
-
   Comps = QueryParser::complete("enable output ", 14, QS);
-  ASSERT_EQ(HasIntrospection ? 5u : 4u, Comps.size());
+  ASSERT_EQ(4u, Comps.size());
 
   EXPECT_EQ("diag ", Comps[0].TypedText);
   EXPECT_EQ("diag", Comps[0].DisplayText);
@@ -243,12 +229,8 @@ TEST_F(QueryParserTest, Complete) {
   EXPECT_EQ("print", Comps[1].DisplayText);
   EXPECT_EQ("detailed-ast ", Comps[2].TypedText);
   EXPECT_EQ("detailed-ast", Comps[2].DisplayText);
-  if (HasIntrospection) {
-    EXPECT_EQ("srcloc ", Comps[3].TypedText);
-    EXPECT_EQ("srcloc", Comps[3].DisplayText);
-  }
-  EXPECT_EQ("dump ", Comps[HasIntrospection ? 4 : 3].TypedText);
-  EXPECT_EQ("dump", Comps[HasIntrospection ? 4 : 3].DisplayText);
+  EXPECT_EQ("dump ", Comps[3].TypedText);
+  EXPECT_EQ("dump", Comps[3].DisplayText);
 
   Comps = QueryParser::complete("set traversal ", 14, QS);
   ASSERT_EQ(2u, Comps.size());
diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt
index eaeadf2656b0b..b747adfb6992e 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -252,7 +252,6 @@ clang/include/clang/Tooling/CompilationDatabasePluginRegistry.h
 clang/include/clang/Tooling/DiagnosticsYaml.h
 clang/include/clang/Tooling/Execution.h
 clang/include/clang/Tooling/JSONCompilationDatabase.h
-clang/include/clang/Tooling/NodeIntrospection.h
 clang/include/clang/Tooling/Refactoring.h
 clang/include/clang/Tooling/StandaloneExecution.h
 clang/include/clang/Tooling/ToolExecutorPluginRegistry.h
@@ -562,15 +561,11 @@ clang/lib/Tooling/Execution.cpp
 clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
 clang/lib/Tooling/FixIt.cpp
 clang/lib/Tooling/GuessTargetAndModeCompilationDatabase.cpp
-clang/lib/Tooling/NodeIntrospection.cpp
 clang/lib/Tooling/StandaloneExecution.cpp
 clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
 clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
 clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
 clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
-clang/lib/Tooling/DumpTool/APIData.h
-clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
-clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
 clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
 clang/lib/Tooling/Inclusions/IncludeStyle.cpp
 clang/lib/Tooling/Inclusions/StandardLibrary.cpp
diff --git a/clang/include/clang/Tooling/NodeIntrospection.h b/clang/include/clang/Tooling/NodeIntrospection.h
deleted file mode 100644
index 91552cad2eca3..0000000000000
--- a/clang/include/clang/Tooling/NodeIntrospection.h
+++ /dev/null
@@ -1,101 +0,0 @@
-//===- NodeIntrospection.h ------------------------------------*- C++ -*---===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-//  This file contains the implementation of the NodeIntrospection.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLING_NODEINTROSPECTION_H
-#define LLVM_CLANG_TOOLING_NODEINTROSPECTION_H
-
-#include "clang/AST/ASTTypeTraits.h"
-#include "clang/AST/DeclarationName.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include <set>
-
-namespace clang {
-
-class Stmt;
-class Decl;
-class CXXCtorInitializer;
-class NestedNameSpecifierLoc;
-class TemplateArgumentLoc;
-class CXXBaseSpecifier;
-struct DeclarationNameInfo;
-
-namespace tooling {
-
-class LocationCall;
-using SharedLocationCall = llvm::IntrusiveRefCntPtr<LocationCall>;
-
-class LocationCall : public llvm::ThreadSafeRefCountedBase<LocationCall> {
-public:
-  enum LocationCallFlags { NoFlags, ReturnsPointer, IsCast };
-  LocationCall(SharedLocationCall on, std::string name,
-               LocationCallFlags flags = NoFlags)
-      : m_flags(flags), m_on(std::move(on)), m_name(std::move(name)) {}
-
-  LocationCall *on() const { return m_on.get(); }
-  StringRef name() const { return m_name; }
-  bool returnsPointer() const { return m_flags & ReturnsPointer; }
-  bool isCast() const { return m_flags & IsCast; }
-
-private:
-  LocationCallFlags m_flags;
-  SharedLocationCall m_on;
-  std::string m_name;
-};
-
-class LocationCallFormatterCpp {
-public:
-  static void print(const LocationCall &Call, llvm::raw_ostream &OS);
-  static std::string format(const LocationCall &Call);
-};
-
-namespace internal {
-struct RangeLessThan {
-  bool operator()(std::pair<SourceRange, SharedLocationCall> const &LHS,
-                  std::pair<SourceRange, SharedLocationCall> const &RHS) const;
-  bool
-  operator()(std::pair<SourceLocation, SharedLocationCall> const &LHS,
-             std::pair<SourceLocation, SharedLocationCall> const &RHS) const;
-};
-
-} // namespace internal
-
-// Note that this container stores unique results in a deterministic, but
-// the location calls are in an unspecified order.  Clients which desire
-// a particular order for the location calls, such as alphabetical,
-// should sort results after retrieval, because the order is dependent
-// on how the LocationCalls are formatted.
-template <typename T, typename U>
-using UniqueMultiMap = std::set<std::pair<T, U>, internal::RangeLessThan>;
-
-using SourceLocationMap = UniqueMultiMap<SourceLocation, SharedLocationCall>;
-using SourceRangeMap = UniqueMultiMap<SourceRange, SharedLocationCall>;
-
-struct NodeLocationAccessors {
-  SourceLocationMap LocationAccessors;
-  SourceRangeMap RangeAccessors;
-};
-
-namespace NodeIntrospection {
-bool hasIntrospectionSupport();
-NodeLocationAccessors GetLocations(clang::Stmt const *Object);
-NodeLocationAccessors GetLocations(clang::Decl const *Object);
-NodeLocationAccessors GetLocations(clang::CXXCtorInitializer const *Object);
-NodeLocationAccessors GetLocations(clang::NestedNameSpecifierLoc const &);
-NodeLocationAccessors GetLocations(clang::TemplateArgumentLoc const &);
-NodeLocationAccessors GetLocations(clang::CXXBaseSpecifier const *);
-NodeLocationAccessors GetLocations(clang::TypeLoc const &);
-NodeLocationAccessors GetLocations(clang::DeclarationNameInfo const &);
-NodeLocationAccessors GetLocations(clang::DynTypedNode const &Node);
-} // namespace NodeIntrospection
-} // namespace tooling
-} // namespace clang
-#endif
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index 91e6cbdcbc44f..93a9e707a134c 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -9,98 +9,10 @@ add_subdirectory(Core)
 add_subdirectory(Inclusions)
 add_subdirectory(Refactoring)
 add_subdirectory(ASTDiff)
-add_subdirectory(DumpTool)
 add_subdirectory(Syntax)
 add_subdirectory(DependencyScanning)
 add_subdirectory(Transformer)
 
-# Replace the last lib component of the current binary directory with include
-string(FIND ${CMAKE_CURRENT_BINARY_DIR} "/lib/" PATH_LIB_START REVERSE)
-if(PATH_LIB_START EQUAL -1)
-  message(FATAL_ERROR "Couldn't find lib component in binary directory")
-endif()
-math(EXPR PATH_LIB_END "${PATH_LIB_START}+5")
-string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD)
-string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} ${PATH_LIB_END} -1 PATH_TAIL)
-string(CONCAT BINARY_INCLUDE_DIR ${PATH_HEAD} "/include/clang/" ${PATH_TAIL})
-
-if (NOT Python3_EXECUTABLE
-    OR APPLE
-    OR CMAKE_CROSSCOMPILING
-    OR GENERATOR_IS_MULTI_CONFIG
-    OR NOT LLVM_NATIVE_ARCH IN_LIST LLVM_TARGETS_TO_BUILD
-    )
-    configure_file(
-      EmptyNodeIntrospection.inc.in
-      ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
-      COPYONLY
-    )
-    set(CLANG_TOOLING_BUILD_AST_INTROSPECTION "OFF" CACHE BOOL "")
-else()
-  # The generation of ASTNodeAPI.json takes a long time in a
-  # Debug build due to parsing AST.h. Disable the processing
-  # but setting CLANG_TOOLING_BUILD_AST_INTROSPECTION as an
-  # internal hidden setting to override.
-  # When the processing is disabled, a trivial/empty JSON
-  # file is generated by clang-ast-dump and generate_cxx_src_locs.py
-  # generates the same API, but with a trivial implementation.
-  option(CLANG_TOOLING_BUILD_AST_INTROSPECTION "Enable AST introspection" TRUE)
-
-  set(skip_expensive_processing $<OR:$<CONFIG:Debug>,$<NOT:$<BOOL:${CLANG_TOOLING_BUILD_AST_INTROSPECTION}>>>)
-
-  set(implicitDirs)
-  foreach(implicitDir ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
-    list(APPEND implicitDirs -I ${implicitDir})
-  endforeach()
-
-  include(GetClangResourceDir)
-  get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
-  add_custom_command(
-      COMMENT Generate ASTNodeAPI.json
-      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
-      DEPENDS clang-ast-dump clang-resource-headers
-      COMMAND
-      $<TARGET_FILE:clang-ast-dump>
-        # Skip this in debug mode because parsing AST.h is too slow
-        --skip-processing=${skip_expensive_processing}
-        -I ${resource_dir}/include
-        -I...
[truncated]

Copy link

github-actions bot commented May 16, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Fixes an issue found by precommit CI
You would think that given how often I ask others to add a release note
to their change, this would have been something I did with the initial
commit...
@AaronBallman AaronBallman merged commit 371eccd into llvm:main May 17, 2024
4 of 5 checks passed
@AaronBallman AaronBallman deleted the aballman-remove-node-introspection branch May 17, 2024 12:06
@sam-mccall
Copy link
Collaborator

Just wanted to say thanks - I didn't ever entirely understand how this was used, but the build speed/complexity has been somewhat painful. Removing features is thankless and sometimes risky, so I was expecting we'd live with that speedbump forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:tooling LibTooling clang Clang issues not falling into any other category clang-query clang-tools-extra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang-query crashes when srcloc output mode is enabled
4 participants