Skip to content

Commit ce0f113

Browse files
committed
Revert "[clangd] Re-land "support outgoing calls in call hierarchy" (#117673)"
This reverts commit 7be3326. Per https://protobuf.dev/programming-guides/dos-donts/#add-required this will re-land tomorrow without the required fields.
1 parent 7954a05 commit ce0f113

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+169
-768
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 0 additions & 8 deletions
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,8 +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-
if (Opts.EnableOutgoingCalls)
1703-
Bind.method("callHierarchy/outgoingCalls", this, &ClangdLSPServer::onCallHierarchyOutgoingCalls);
17041696
Bind.method("textDocument/selectionRange", this, &ClangdLSPServer::onSelectionRange);
17051697
Bind.method("textDocument/documentLink", this, &ClangdLSPServer::onDocumentLink);
17061698
Bind.method("textDocument/semanticTokens/full", this, &ClangdLSPServer::onSemanticTokens);

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 0 additions & 3 deletions
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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
215215
const ThreadsafeFS &TFS, const Options &Opts,
216216
Callbacks *Callbacks)
217217
: FeatureModules(Opts.FeatureModules), CDB(CDB), TFS(TFS),
218-
DynamicIdx(Opts.BuildDynamicSymbolIndex
219-
? new FileIndex(Opts.EnableOutgoingCalls)
220-
: nullptr),
218+
DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
221219
ModulesManager(Opts.ModulesManager),
222220
ClangTidyProvider(Opts.ClangTidyProvider),
223221
UseDirtyHeaders(Opts.UseDirtyHeaders),
@@ -258,7 +256,6 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
258256
Callbacks->onBackgroundIndexProgress(S);
259257
};
260258
BGOpts.ContextProvider = Opts.ContextProvider;
261-
BGOpts.SupportContainedRefs = Opts.EnableOutgoingCalls;
262259
BackgroundIdx = std::make_unique<BackgroundIndex>(
263260
TFS, CDB,
264261
BackgroundIndexStorage::createDiskBackedStorageFactory(
@@ -915,15 +912,6 @@ void ClangdServer::inlayHints(PathRef File, std::optional<Range> RestrictRange,
915912
WorkScheduler->runWithAST("InlayHints", File, std::move(Action), Transient);
916913
}
917914

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

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ class ClangdServer {
110110
/// Cached preambles are potentially large. If false, store them on disk.
111111
bool StorePreamblesInMemory = true;
112112

113-
/// Call hierarchy's outgoing calls feature requires additional index
114-
/// serving structures which increase memory usage. If false, these are
115-
/// not created and the feature is not enabled.
116-
bool EnableOutgoingCalls = true;
117-
118113
/// This throttler controls which preambles may be built at a given time.
119114
clangd::PreambleThrottler *PreambleThrottler = nullptr;
120115

@@ -297,10 +292,6 @@ class ClangdServer {
297292
void incomingCalls(const CallHierarchyItem &Item,
298293
Callback<std::vector<CallHierarchyIncomingCall>>);
299294

300-
/// Resolve outgoing calls for a given call hierarchy item.
301-
void outgoingCalls(const CallHierarchyItem &Item,
302-
Callback<std::vector<CallHierarchyOutgoingCall>>);
303-
304295
/// Resolve inlay hints for a given document.
305296
void inlayHints(PathRef File, std::optional<Range> RestrictRange,
306297
Callback<std::vector<InlayHint>>);

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 0 additions & 61 deletions
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,65 +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-
(void)Kind;
2367-
(void)SK::Function;
2368-
2369-
auto It = CallsOut.find(Callee.ID);
2370-
assert(It != CallsOut.end());
2371-
if (auto CHI = symbolToCallHierarchyItem(Callee, Item.uri.file()))
2372-
Results.push_back(
2373-
CallHierarchyOutgoingCall{std::move(*CHI), std::move(It->second)});
2374-
});
2375-
// Sort results by name of the callee.
2376-
llvm::sort(Results, [](const CallHierarchyOutgoingCall &A,
2377-
const CallHierarchyOutgoingCall &B) {
2378-
return A.to.name < B.to.name;
2379-
});
2380-
return Results;
2381-
}
2382-
23832322
llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
23842323
const FunctionDecl *FD) {
23852324
if (!FD->hasBody())

clang-tools-extra/clangd/XRefs.h

Lines changed: 0 additions & 3 deletions
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/Background.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ BackgroundIndex::BackgroundIndex(
9696
: SwapIndex(std::make_unique<MemIndex>()), TFS(TFS), CDB(CDB),
9797
IndexingPriority(Opts.IndexingPriority),
9898
ContextProvider(std::move(Opts.ContextProvider)),
99-
IndexedSymbols(IndexContents::All, Opts.SupportContainedRefs),
99+
IndexedSymbols(IndexContents::All),
100100
Rebuilder(this, &IndexedSymbols, Opts.ThreadPoolSize),
101101
IndexStorageFactory(std::move(IndexStorageFactory)),
102102
Queue(std::move(Opts.OnProgress)),

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ class BackgroundIndex : public SwapIndex {
145145
// file. Called with the empty string for other tasks.
146146
// (When called, the context from BackgroundIndex construction is active).
147147
std::function<Context(PathRef)> ContextProvider = nullptr;
148-
// Whether the index needs to support the containedRefs() operation.
149-
// May use extra memory.
150-
bool SupportContainedRefs = true;
151148
};
152149

153150
/// Creates a new background index and starts its threads.

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST,
239239
/*CollectMainFileRefs=*/false);
240240
}
241241

242-
FileSymbols::FileSymbols(IndexContents IdxContents, bool SupportContainedRefs)
243-
: IdxContents(IdxContents), SupportContainedRefs(SupportContainedRefs) {}
242+
FileSymbols::FileSymbols(IndexContents IdxContents)
243+
: IdxContents(IdxContents) {}
244244

245245
void FileSymbols::update(llvm::StringRef Key,
246246
std::unique_ptr<SymbolSlab> Symbols,
@@ -395,7 +395,7 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle,
395395
std::move(AllRelations), std::move(Files), IdxContents,
396396
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
397397
std::move(RefsStorage), std::move(SymsStorage)),
398-
StorageSize, SupportContainedRefs);
398+
StorageSize);
399399
}
400400
llvm_unreachable("Unknown clangd::IndexType");
401401
}
@@ -419,12 +419,11 @@ void FileSymbols::profile(MemoryTree &MT) const {
419419
}
420420
}
421421

422-
FileIndex::FileIndex(bool SupportContainedRefs)
422+
FileIndex::FileIndex()
423423
: MergedIndex(&MainFileIndex, &PreambleIndex),
424-
PreambleSymbols(IndexContents::Symbols | IndexContents::Relations,
425-
SupportContainedRefs),
424+
PreambleSymbols(IndexContents::Symbols | IndexContents::Relations),
426425
PreambleIndex(std::make_unique<MemIndex>()),
427-
MainFileSymbols(IndexContents::All, SupportContainedRefs),
426+
MainFileSymbols(IndexContents::All),
428427
MainFileIndex(std::make_unique<MemIndex>()) {}
429428

430429
void FileIndex::updatePreamble(IndexFileIn IF) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ enum class DuplicateHandling {
6969
/// locking when we swap or obtain references to snapshots.
7070
class FileSymbols {
7171
public:
72-
FileSymbols(IndexContents IdxContents, bool SupportContainedRefs);
72+
FileSymbols(IndexContents IdxContents);
7373
/// Updates all slabs associated with the \p Key.
7474
/// If either is nullptr, corresponding data for \p Key will be removed.
7575
/// If CountReferences is true, \p Refs will be used for counting references
@@ -91,7 +91,6 @@ class FileSymbols {
9191

9292
private:
9393
IndexContents IdxContents;
94-
bool SupportContainedRefs;
9594

9695
struct RefSlabAndCountReferences {
9796
std::shared_ptr<RefSlab> Slab;
@@ -109,7 +108,7 @@ class FileSymbols {
109108
/// FIXME: Expose an interface to remove files that are closed.
110109
class FileIndex : public MergedIndex {
111110
public:
112-
FileIndex(bool SupportContainedRefs);
111+
FileIndex();
113112

114113
/// Update preamble symbols of file \p Path with all declarations in \p AST
115114
/// and macros in \p PP.

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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 0 additions & 35 deletions
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

Lines changed: 0 additions & 20 deletions
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

Lines changed: 0 additions & 4 deletions
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;

0 commit comments

Comments
 (0)