Skip to content

Commit d77cab8

Browse files
Revert "[clangd] Support outgoing calls in call hierarchy (llvm#77556)" (llvm#117668)
This reverts commit ca184cf.
1 parent ca184cf commit d77cab8

23 files changed

+73
-505
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -1415,12 +1415,6 @@ void ClangdLSPServer::onInlayHint(const InlayHintsParams &Params,
14151415
std::move(Reply));
14161416
}
14171417

1418-
void ClangdLSPServer::onCallHierarchyOutgoingCalls(
1419-
const CallHierarchyOutgoingCallsParams &Params,
1420-
Callback<std::vector<CallHierarchyOutgoingCall>> Reply) {
1421-
Server->outgoingCalls(Params.item, std::move(Reply));
1422-
}
1423-
14241418
void ClangdLSPServer::applyConfiguration(
14251419
const ConfigurationSettings &Settings) {
14261420
// Per-file update to the compilation database.
@@ -1699,7 +1693,6 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
16991693
Bind.method("typeHierarchy/subtypes", this, &ClangdLSPServer::onSubTypes);
17001694
Bind.method("textDocument/prepareCallHierarchy", this, &ClangdLSPServer::onPrepareCallHierarchy);
17011695
Bind.method("callHierarchy/incomingCalls", this, &ClangdLSPServer::onCallHierarchyIncomingCalls);
1702-
Bind.method("callHierarchy/outgoingCalls", this, &ClangdLSPServer::onCallHierarchyOutgoingCalls);
17031696
Bind.method("textDocument/selectionRange", this, &ClangdLSPServer::onSelectionRange);
17041697
Bind.method("textDocument/documentLink", this, &ClangdLSPServer::onDocumentLink);
17051698
Bind.method("textDocument/semanticTokens/full", this, &ClangdLSPServer::onSemanticTokens);

clang-tools-extra/clangd/ClangdLSPServer.h

-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
156156
void onCallHierarchyIncomingCalls(
157157
const CallHierarchyIncomingCallsParams &,
158158
Callback<std::vector<CallHierarchyIncomingCall>>);
159-
void onCallHierarchyOutgoingCalls(
160-
const CallHierarchyOutgoingCallsParams &,
161-
Callback<std::vector<CallHierarchyOutgoingCall>>);
162159
void onClangdInlayHints(const InlayHintsParams &,
163160
Callback<llvm::json::Value>);
164161
void onInlayHint(const InlayHintsParams &, Callback<std::vector<InlayHint>>);

clang-tools-extra/clangd/ClangdServer.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -912,15 +912,6 @@ void ClangdServer::inlayHints(PathRef File, std::optional<Range> RestrictRange,
912912
WorkScheduler->runWithAST("InlayHints", File, std::move(Action), Transient);
913913
}
914914

915-
void ClangdServer::outgoingCalls(
916-
const CallHierarchyItem &Item,
917-
Callback<std::vector<CallHierarchyOutgoingCall>> CB) {
918-
WorkScheduler->run("Outgoing Calls", "",
919-
[CB = std::move(CB), Item, this]() mutable {
920-
CB(clangd::outgoingCalls(Item, Index));
921-
});
922-
}
923-
924915
void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
925916
// FIXME: Do nothing for now. This will be used for indexing and potentially
926917
// invalidating other caches.

clang-tools-extra/clangd/ClangdServer.h

-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ class ClangdServer {
292292
void incomingCalls(const CallHierarchyItem &Item,
293293
Callback<std::vector<CallHierarchyIncomingCall>>);
294294

295-
/// Resolve outgoing calls for a given call hierarchy item.
296-
void outgoingCalls(const CallHierarchyItem &Item,
297-
Callback<std::vector<CallHierarchyOutgoingCall>>);
298-
299295
/// Resolve inlay hints for a given document.
300296
void inlayHints(PathRef File, std::optional<Range> RestrictRange,
301297
Callback<std::vector<InlayHint>>);

clang-tools-extra/clangd/XRefs.cpp

-59
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,6 @@ declToHierarchyItem(const NamedDecl &ND, llvm::StringRef TUPath) {
17021702

17031703
HierarchyItem HI;
17041704
HI.name = printName(Ctx, ND);
1705-
// FIXME: Populate HI.detail the way we do in symbolToHierarchyItem?
17061705
HI.kind = SK;
17071706
HI.range = Range{sourceLocToPosition(SM, DeclRange->getBegin()),
17081707
sourceLocToPosition(SM, DeclRange->getEnd())};
@@ -1754,7 +1753,6 @@ static std::optional<HierarchyItem> symbolToHierarchyItem(const Symbol &S,
17541753
}
17551754
HierarchyItem HI;
17561755
HI.name = std::string(S.Name);
1757-
HI.detail = (S.Scope + S.Name).str();
17581756
HI.kind = indexSymbolKindToSymbolKind(S.SymInfo.Kind);
17591757
HI.selectionRange = Loc->range;
17601758
// FIXME: Populate 'range' correctly
@@ -2321,63 +2319,6 @@ incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
23212319
return Results;
23222320
}
23232321

2324-
std::vector<CallHierarchyOutgoingCall>
2325-
outgoingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
2326-
std::vector<CallHierarchyOutgoingCall> Results;
2327-
if (!Index || Item.data.empty())
2328-
return Results;
2329-
auto ID = SymbolID::fromStr(Item.data);
2330-
if (!ID) {
2331-
elog("outgoingCalls failed to find symbol: {0}", ID.takeError());
2332-
return Results;
2333-
}
2334-
// In this function, we find outgoing calls based on the index only.
2335-
ContainedRefsRequest Request;
2336-
Request.ID = *ID;
2337-
// Initially store the ranges in a map keyed by SymbolID of the callee.
2338-
// This allows us to group different calls to the same function
2339-
// into the same CallHierarchyOutgoingCall.
2340-
llvm::DenseMap<SymbolID, std::vector<Range>> CallsOut;
2341-
// We can populate the ranges based on a refs request only. As we do so, we
2342-
// also accumulate the callee IDs into a lookup request.
2343-
LookupRequest CallsOutLookup;
2344-
Index->containedRefs(Request, [&](const auto &R) {
2345-
auto Loc = indexToLSPLocation(R.Location, Item.uri.file());
2346-
if (!Loc) {
2347-
elog("outgoingCalls failed to convert location: {0}", Loc.takeError());
2348-
return;
2349-
}
2350-
auto It = CallsOut.try_emplace(R.Symbol, std::vector<Range>{}).first;
2351-
It->second.push_back(Loc->range);
2352-
2353-
CallsOutLookup.IDs.insert(R.Symbol);
2354-
});
2355-
// Perform the lookup request and combine its results with CallsOut to
2356-
// get complete CallHierarchyOutgoingCall objects.
2357-
Index->lookup(CallsOutLookup, [&](const Symbol &Callee) {
2358-
// The containedRefs request should only return symbols which are
2359-
// function-like, i.e. symbols for which references to them can be "calls".
2360-
using SK = index::SymbolKind;
2361-
auto Kind = Callee.SymInfo.Kind;
2362-
assert(Kind == SK::Function || Kind == SK::InstanceMethod ||
2363-
Kind == SK::ClassMethod || Kind == SK::StaticMethod ||
2364-
Kind == SK::Constructor || Kind == SK::Destructor ||
2365-
Kind == SK::ConversionFunction);
2366-
2367-
auto It = CallsOut.find(Callee.ID);
2368-
assert(It != CallsOut.end());
2369-
if (auto CHI = symbolToCallHierarchyItem(Callee, Item.uri.file()))
2370-
Results.push_back(
2371-
CallHierarchyOutgoingCall{std::move(*CHI), std::move(It->second)});
2372-
});
2373-
// Sort results by name of the callee.
2374-
llvm::sort(Results, [](const CallHierarchyOutgoingCall &A,
2375-
const CallHierarchyOutgoingCall &B) {
2376-
return A.to.name < B.to.name;
2377-
});
2378-
return Results;
2379-
}
2380-
23812322
llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
23822323
const FunctionDecl *FD) {
23832324
if (!FD->hasBody())

clang-tools-extra/clangd/XRefs.h

-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ prepareCallHierarchy(ParsedAST &AST, Position Pos, PathRef TUPath);
150150
std::vector<CallHierarchyIncomingCall>
151151
incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index);
152152

153-
std::vector<CallHierarchyOutgoingCall>
154-
outgoingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index);
155-
156153
/// Returns all decls that are referenced in the \p FD except local symbols.
157154
llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
158155
const FunctionDecl *FD);

clang-tools-extra/clangd/index/Index.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ bool SwapIndex::refs(const RefsRequest &R,
6666
llvm::function_ref<void(const Ref &)> CB) const {
6767
return snapshot()->refs(R, CB);
6868
}
69-
bool SwapIndex::containedRefs(
70-
const ContainedRefsRequest &R,
71-
llvm::function_ref<void(const ContainedRefsResult &)> CB) const {
72-
return snapshot()->containedRefs(R, CB);
73-
}
7469
void SwapIndex::relations(
7570
const RelationsRequest &R,
7671
llvm::function_ref<void(const SymbolID &, const Symbol &)> CB) const {

clang-tools-extra/clangd/index/Index.h

-35
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,13 @@ struct RefsRequest {
7777
bool WantContainer = false;
7878
};
7979

80-
struct ContainedRefsRequest {
81-
/// Note that RefKind::Call just restricts the matched SymbolKind to
82-
/// functions, not the form of the reference (e.g. address-of-function,
83-
/// which can indicate an indirect call, should still be caught).
84-
static const RefKind SupportedRefKinds = RefKind::Call;
85-
86-
SymbolID ID;
87-
/// If set, limit the number of refers returned from the index. The index may
88-
/// choose to return less than this, e.g. it tries to avoid returning stale
89-
/// results.
90-
std::optional<uint32_t> Limit;
91-
};
92-
9380
struct RelationsRequest {
9481
llvm::DenseSet<SymbolID> Subjects;
9582
RelationKind Predicate;
9683
/// If set, limit the number of relations returned from the index.
9784
std::optional<uint32_t> Limit;
9885
};
9986

100-
struct ContainedRefsResult {
101-
/// The source location where the symbol is named.
102-
SymbolLocation Location;
103-
RefKind Kind = RefKind::Unknown;
104-
/// The ID of the symbol which is referred to
105-
SymbolID Symbol;
106-
};
107-
10887
/// Describes what data is covered by an index.
10988
///
11089
/// Indexes may contain symbols but not references from a file, etc.
@@ -162,17 +141,6 @@ class SymbolIndex {
162141
virtual bool refs(const RefsRequest &Req,
163142
llvm::function_ref<void(const Ref &)> Callback) const = 0;
164143

165-
/// Find all symbols that are referenced by a symbol and apply
166-
/// \p Callback on each result.
167-
///
168-
/// Results should be returned in arbitrary order.
169-
/// The returned result must be deep-copied if it's used outside Callback.
170-
///
171-
/// Returns true if there will be more results (limited by Req.Limit);
172-
virtual bool containedRefs(
173-
const ContainedRefsRequest &Req,
174-
llvm::function_ref<void(const ContainedRefsResult &)> Callback) const = 0;
175-
176144
/// Finds all relations (S, P, O) stored in the index such that S is among
177145
/// Req.Subjects and P is Req.Predicate, and invokes \p Callback for (S, O) in
178146
/// each.
@@ -207,9 +175,6 @@ class SwapIndex : public SymbolIndex {
207175
llvm::function_ref<void(const Symbol &)>) const override;
208176
bool refs(const RefsRequest &,
209177
llvm::function_ref<void(const Ref &)>) const override;
210-
bool containedRefs(
211-
const ContainedRefsRequest &,
212-
llvm::function_ref<void(const ContainedRefsResult &)>) const override;
213178
void relations(const RelationsRequest &,
214179
llvm::function_ref<void(const SymbolID &, const Symbol &)>)
215180
const override;

clang-tools-extra/clangd/index/MemIndex.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "MemIndex.h"
1010
#include "FuzzyMatch.h"
1111
#include "Quality.h"
12-
#include "index/Index.h"
1312
#include "support/Trace.h"
1413

1514
namespace clang {
@@ -86,25 +85,6 @@ bool MemIndex::refs(const RefsRequest &Req,
8685
return false; // We reported all refs.
8786
}
8887

89-
bool MemIndex::containedRefs(
90-
const ContainedRefsRequest &Req,
91-
llvm::function_ref<void(const ContainedRefsResult &)> Callback) const {
92-
trace::Span Tracer("MemIndex refersTo");
93-
uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
94-
for (const auto &Pair : Refs) {
95-
for (const auto &R : Pair.second) {
96-
if (!static_cast<int>(ContainedRefsRequest::SupportedRefKinds & R.Kind) ||
97-
Req.ID != R.Container)
98-
continue;
99-
if (Remaining == 0)
100-
return true; // More refs were available.
101-
--Remaining;
102-
Callback({R.Location, R.Kind, Pair.first});
103-
}
104-
}
105-
return false; // We reported all refs.
106-
}
107-
10888
void MemIndex::relations(
10989
const RelationsRequest &Req,
11090
llvm::function_ref<void(const SymbolID &, const Symbol &)> Callback) const {

clang-tools-extra/clangd/index/MemIndex.h

-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class MemIndex : public SymbolIndex {
7272
bool refs(const RefsRequest &Req,
7373
llvm::function_ref<void(const Ref &)> Callback) const override;
7474

75-
bool containedRefs(const ContainedRefsRequest &Req,
76-
llvm::function_ref<void(const ContainedRefsResult &)>
77-
Callback) const override;
78-
7975
void relations(const RelationsRequest &Req,
8076
llvm::function_ref<void(const SymbolID &, const Symbol &)>
8177
Callback) const override;

clang-tools-extra/clangd/index/Merge.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -155,40 +155,6 @@ bool MergedIndex::refs(const RefsRequest &Req,
155155
return More || StaticHadMore;
156156
}
157157

158-
bool MergedIndex::containedRefs(
159-
const ContainedRefsRequest &Req,
160-
llvm::function_ref<void(const ContainedRefsResult &)> Callback) const {
161-
trace::Span Tracer("MergedIndex refersTo");
162-
bool More = false;
163-
uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
164-
// We don't want duplicated refs from the static/dynamic indexes,
165-
// and we can't reliably deduplicate them because offsets may differ slightly.
166-
// We consider the dynamic index authoritative and report all its refs,
167-
// and only report static index refs from other files.
168-
More |= Dynamic->containedRefs(Req, [&](const auto &O) {
169-
Callback(O);
170-
assert(Remaining != 0);
171-
--Remaining;
172-
});
173-
if (Remaining == 0 && More)
174-
return More;
175-
auto DynamicContainsFile = Dynamic->indexedFiles();
176-
// We return less than Req.Limit if static index returns more refs for dirty
177-
// files.
178-
bool StaticHadMore = Static->containedRefs(Req, [&](const auto &O) {
179-
if ((DynamicContainsFile(O.Location.FileURI) & IndexContents::References) !=
180-
IndexContents::None)
181-
return; // ignore refs that have been seen from dynamic index.
182-
if (Remaining == 0) {
183-
More = true;
184-
return;
185-
}
186-
--Remaining;
187-
Callback(O);
188-
});
189-
return More || StaticHadMore;
190-
}
191-
192158
llvm::unique_function<IndexContents(llvm::StringRef) const>
193159
MergedIndex::indexedFiles() const {
194160
return [DynamicContainsFile{Dynamic->indexedFiles()},

clang-tools-extra/clangd/index/Merge.h

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class MergedIndex : public SymbolIndex {
3838
llvm::function_ref<void(const Symbol &)>) const override;
3939
bool refs(const RefsRequest &,
4040
llvm::function_ref<void(const Ref &)>) const override;
41-
bool containedRefs(
42-
const ContainedRefsRequest &,
43-
llvm::function_ref<void(const ContainedRefsResult &)>) const override;
4441
void relations(const RelationsRequest &,
4542
llvm::function_ref<void(const SymbolID &, const Symbol &)>)
4643
const override;

clang-tools-extra/clangd/index/ProjectAware.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class ProjectAwareIndex : public SymbolIndex {
3535
/// Query all indexes while prioritizing the associated one (if any).
3636
bool refs(const RefsRequest &Req,
3737
llvm::function_ref<void(const Ref &)> Callback) const override;
38-
/// Query all indexes while prioritizing the associated one (if any).
39-
bool containedRefs(const ContainedRefsRequest &Req,
40-
llvm::function_ref<void(const ContainedRefsResult &)>
41-
Callback) const override;
4238

4339
/// Queries only the associates index when Req.RestrictForCodeCompletion is
4440
/// set, otherwise queries all.
@@ -98,15 +94,6 @@ bool ProjectAwareIndex::refs(
9894
return false;
9995
}
10096

101-
bool ProjectAwareIndex::containedRefs(
102-
const ContainedRefsRequest &Req,
103-
llvm::function_ref<void(const ContainedRefsResult &)> Callback) const {
104-
trace::Span Tracer("ProjectAwareIndex::refersTo");
105-
if (auto *Idx = getIndex())
106-
return Idx->containedRefs(Req, Callback);
107-
return false;
108-
}
109-
11097
bool ProjectAwareIndex::fuzzyFind(
11198
const FuzzyFindRequest &Req,
11299
llvm::function_ref<void(const Symbol &)> Callback) const {

clang-tools-extra/clangd/index/Ref.h

-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ enum class RefKind : uint8_t {
6363
// ^ this references Foo, but does not explicitly spell out its name
6464
// };
6565
Spelled = 1 << 3,
66-
// A reference which is a call. Used as a filter for which references
67-
// to store in data structures used for computing outgoing calls.
68-
Call = 1 << 4,
6966
All = Declaration | Definition | Reference | Spelled,
7067
};
7168

0 commit comments

Comments
 (0)