Skip to content

Commit 76ddbb1

Browse files
committed
Revert "[clangd] Indexing of standard library"
This reverts commit ecaa4d9.
1 parent f31d39c commit 76ddbb1

18 files changed

+21
-713
lines changed

clang-tools-extra/clangd/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ add_clang_library(clangDaemon
119119
index/Ref.cpp
120120
index/Relation.cpp
121121
index/Serialization.cpp
122-
index/StdLib.cpp
123122
index/Symbol.cpp
124123
index/SymbolCollector.cpp
125124
index/SymbolID.cpp

clang-tools-extra/clangd/ClangdServer.cpp

+6-39
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "index/CanonicalIncludes.h"
2727
#include "index/FileIndex.h"
2828
#include "index/Merge.h"
29-
#include "index/StdLib.h"
3029
#include "refactor/Rename.h"
3130
#include "refactor/Tweak.h"
3231
#include "support/Cancellation.h"
@@ -60,39 +59,16 @@ namespace {
6059
// Update the FileIndex with new ASTs and plumb the diagnostics responses.
6160
struct UpdateIndexCallbacks : public ParsingCallbacks {
6261
UpdateIndexCallbacks(FileIndex *FIndex,
63-
ClangdServer::Callbacks *ServerCallbacks,
64-
const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks)
65-
: FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
66-
Tasks(Tasks) {}
62+
ClangdServer::Callbacks *ServerCallbacks)
63+
: FIndex(FIndex), ServerCallbacks(ServerCallbacks) {}
6764

68-
void onPreambleAST(PathRef Path, llvm::StringRef Version,
69-
const CompilerInvocation &CI, ASTContext &Ctx,
65+
void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
7066
Preprocessor &PP,
7167
const CanonicalIncludes &CanonIncludes) override {
72-
// If this preamble uses a standard library we haven't seen yet, index it.
73-
if (FIndex)
74-
if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
75-
indexStdlib(CI, std::move(*Loc));
76-
7768
if (FIndex)
7869
FIndex->updatePreamble(Path, Version, Ctx, PP, CanonIncludes);
7970
}
8071

81-
void indexStdlib(const CompilerInvocation &CI, StdLibLocation Loc) {
82-
auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
83-
CI(std::make_unique<CompilerInvocation>(CI))]() mutable {
84-
IndexFileIn IF;
85-
IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
86-
if (Stdlib.isBest(LO))
87-
FIndex->updatePreamble(std::move(IF));
88-
};
89-
if (Tasks)
90-
// This doesn't have a semaphore to enforce -j, but it's rare.
91-
Tasks->runAsync("IndexStdlib", std::move(Task));
92-
else
93-
Task();
94-
}
95-
9672
void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
9773
if (FIndex)
9874
FIndex->updateMain(Path, AST);
@@ -127,9 +103,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
127103
private:
128104
FileIndex *FIndex;
129105
ClangdServer::Callbacks *ServerCallbacks;
130-
const ThreadsafeFS &TFS;
131-
StdLibSet Stdlib;
132-
AsyncTaskRunner *Tasks;
133106
};
134107

135108
class DraftStoreFS : public ThreadsafeFS {
@@ -181,15 +154,12 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
181154
Transient(Opts.ImplicitCancellation ? TUScheduler::InvalidateOnUpdate
182155
: TUScheduler::NoInvalidation),
183156
DirtyFS(std::make_unique<DraftStoreFS>(TFS, DraftMgr)) {
184-
if (Opts.AsyncThreadsCount != 0)
185-
IndexTasks.emplace();
186157
// Pass a callback into `WorkScheduler` to extract symbols from a newly
187158
// parsed file and rebuild the file index synchronously each time an AST
188159
// is parsed.
189-
WorkScheduler.emplace(CDB, TUScheduler::Options(Opts),
190-
std::make_unique<UpdateIndexCallbacks>(
191-
DynamicIdx.get(), Callbacks, TFS,
192-
IndexTasks ? IndexTasks.getPointer() : nullptr));
160+
WorkScheduler.emplace(
161+
CDB, TUScheduler::Options(Opts),
162+
std::make_unique<UpdateIndexCallbacks>(DynamicIdx.get(), Callbacks));
193163
// Adds an index to the stack, at higher priority than existing indexes.
194164
auto AddIndex = [&](SymbolIndex *Idx) {
195165
if (this->Index != nullptr) {
@@ -1005,9 +975,6 @@ ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
1005975
// and we're blocking the main thread.
1006976
if (!WorkScheduler->blockUntilIdle(timeoutSeconds(TimeoutSeconds)))
1007977
return false;
1008-
// TUScheduler is the only thing that starts background indexing work.
1009-
if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
1010-
return false;
1011978

1012979
// Unfortunately we don't have strict topological order between the rest of
1013980
// the components. E.g. CDB broadcast triggers backrgound indexing.

clang-tools-extra/clangd/ClangdServer.h

-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ class ClangdServer {
427427
mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
428428

429429
llvm::Optional<std::string> WorkspaceRoot;
430-
llvm::Optional<AsyncTaskRunner> IndexTasks; // for stdlib indexing.
431430
llvm::Optional<TUScheduler> WorkScheduler;
432431
// Invalidation policy used for actions that we assume are "transient".
433432
TUScheduler::ASTActionInvalidation Transient;

clang-tools-extra/clangd/Config.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ struct Config {
8181
/// forward-slashes.
8282
std::string MountPoint;
8383
};
84-
/// Controls index behavior.
84+
/// Controls background-index behavior.
8585
struct {
86-
/// Whether this TU should be background-indexed.
86+
/// Whether this TU should be indexed.
8787
BackgroundPolicy Background = BackgroundPolicy::Build;
8888
ExternalIndexSpec External;
89-
bool StandardLibrary = false;
9089
} Index;
9190

9291
enum UnusedIncludesPolicy { Strict, None };

clang-tools-extra/clangd/ConfigCompile.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,6 @@ struct FragmentCompiler {
332332
}
333333
if (F.External)
334334
compile(std::move(**F.External), F.External->Range);
335-
if (F.StandardLibrary)
336-
Out.Apply.push_back(
337-
[Val(**F.StandardLibrary)](const Params &, Config &C) {
338-
C.Index.StandardLibrary = Val;
339-
});
340335
}
341336

342337
void compile(Fragment::IndexBlock::ExternalBlock &&External,

clang-tools-extra/clangd/ConfigFragment.h

-3
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ struct Fragment {
199199
llvm::Optional<Located<std::string>> MountPoint;
200200
};
201201
llvm::Optional<Located<ExternalBlock>> External;
202-
// Whether the standard library visible from this file should be indexed.
203-
// This makes all standard library symbols available, included or not.
204-
llvm::Optional<Located<bool>> StandardLibrary;
205202
};
206203
IndexBlock Index;
207204

clang-tools-extra/clangd/ConfigYAML.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ class Parser {
184184
F.External.emplace(std::move(External));
185185
F.External->Range = N.getSourceRange();
186186
});
187-
Dict.handle("StandardLibrary", [&](Node &N) {
188-
if (auto StandardLibrary = boolValue(N, "StandardLibrary"))
189-
F.StandardLibrary = *StandardLibrary;
190-
});
191187
Dict.parse(N);
192188
}
193189

clang-tools-extra/clangd/TUScheduler.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,9 @@ void PreambleThread::build(Request Req) {
10131013
bool IsFirstPreamble = !LatestBuild;
10141014
LatestBuild = clang::clangd::buildPreamble(
10151015
FileName, *Req.CI, Inputs, StoreInMemory,
1016-
[&](ASTContext &Ctx, Preprocessor &PP,
1017-
const CanonicalIncludes &CanonIncludes) {
1018-
Callbacks.onPreambleAST(FileName, Inputs.Version, *Req.CI, Ctx, PP,
1019-
CanonIncludes);
1016+
[this, Version(Inputs.Version)](ASTContext &Ctx, Preprocessor &PP,
1017+
const CanonicalIncludes &CanonIncludes) {
1018+
Callbacks.onPreambleAST(FileName, Version, Ctx, PP, CanonIncludes);
10201019
},
10211020
&Stats);
10221021
if (!LatestBuild)

clang-tools-extra/clangd/TUScheduler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class ParsingCallbacks {
133133
/// contains only AST nodes from the #include directives at the start of the
134134
/// file. AST node in the current file should be observed on onMainAST call.
135135
virtual void onPreambleAST(PathRef Path, llvm::StringRef Version,
136-
const CompilerInvocation &CI, ASTContext &Ctx,
137-
Preprocessor &PP, const CanonicalIncludes &) {}
136+
ASTContext &Ctx, Preprocessor &PP,
137+
const CanonicalIncludes &) {}
138138

139139
/// The argument function is run under the critical section guarding against
140140
/// races when closing the files.

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,12 @@ FileIndex::FileIndex()
425425
MainFileSymbols(IndexContents::All),
426426
MainFileIndex(std::make_unique<MemIndex>()) {}
427427

428-
void FileIndex::updatePreamble(IndexFileIn IF) {
428+
void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,
429+
ASTContext &AST, Preprocessor &PP,
430+
const CanonicalIncludes &Includes) {
431+
IndexFileIn IF;
432+
std::tie(IF.Symbols, std::ignore, IF.Relations) =
433+
indexHeaderSymbols(Version, AST, PP, Includes);
429434
FileShardedIndex ShardedIndex(std::move(IF));
430435
for (auto Uri : ShardedIndex.getAllSources()) {
431436
auto IF = ShardedIndex.getShard(Uri);
@@ -456,15 +461,6 @@ void FileIndex::updatePreamble(IndexFileIn IF) {
456461
}
457462
}
458463

459-
void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,
460-
ASTContext &AST, Preprocessor &PP,
461-
const CanonicalIncludes &Includes) {
462-
IndexFileIn IF;
463-
std::tie(IF.Symbols, std::ignore, IF.Relations) =
464-
indexHeaderSymbols(Version, AST, PP, Includes);
465-
updatePreamble(std::move(IF));
466-
}
467-
468464
void FileIndex::updateMain(PathRef Path, ParsedAST &AST) {
469465
auto Contents = indexMainDecls(AST);
470466
MainFileSymbols.update(

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

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class FileIndex : public MergedIndex {
114114
/// and macros in \p PP.
115115
void updatePreamble(PathRef Path, llvm::StringRef Version, ASTContext &AST,
116116
Preprocessor &PP, const CanonicalIncludes &Includes);
117-
void updatePreamble(IndexFileIn);
118117

119118
/// Update symbols and references from main file \p Path with
120119
/// `indexMainDecls`.

0 commit comments

Comments
 (0)