Skip to content

Commit

Permalink
Revert "Reland(2) "[clangd] Indexing of standard library""
Browse files Browse the repository at this point in the history
This reverts commit ca87553.
  • Loading branch information
sam-mccall committed May 18, 2022
1 parent e44fe27 commit 77533ea
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 713 deletions.
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ add_clang_library(clangDaemon
index/Ref.cpp
index/Relation.cpp
index/Serialization.cpp
index/StdLib.cpp
index/Symbol.cpp
index/SymbolCollector.cpp
index/SymbolID.cpp
Expand Down
45 changes: 6 additions & 39 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "index/CanonicalIncludes.h"
#include "index/FileIndex.h"
#include "index/Merge.h"
#include "index/StdLib.h"
#include "refactor/Rename.h"
#include "refactor/Tweak.h"
#include "support/Cancellation.h"
Expand Down Expand Up @@ -60,39 +59,16 @@ namespace {
// Update the FileIndex with new ASTs and plumb the diagnostics responses.
struct UpdateIndexCallbacks : public ParsingCallbacks {
UpdateIndexCallbacks(FileIndex *FIndex,
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks)
: FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
Tasks(Tasks) {}
ClangdServer::Callbacks *ServerCallbacks)
: FIndex(FIndex), ServerCallbacks(ServerCallbacks) {}

void onPreambleAST(PathRef Path, llvm::StringRef Version,
const CompilerInvocation &CI, ASTContext &Ctx,
void onPreambleAST(PathRef Path, llvm::StringRef Version, ASTContext &Ctx,
Preprocessor &PP,
const CanonicalIncludes &CanonIncludes) override {
// If this preamble uses a standard library we haven't seen yet, index it.
if (FIndex)
if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
indexStdlib(CI, std::move(*Loc));

if (FIndex)
FIndex->updatePreamble(Path, Version, Ctx, PP, CanonIncludes);
}

void indexStdlib(const CompilerInvocation &CI, StdLibLocation Loc) {
auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
CI(std::make_unique<CompilerInvocation>(CI))]() mutable {
IndexFileIn IF;
IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
if (Stdlib.isBest(LO))
FIndex->updatePreamble(std::move(IF));
};
if (Tasks)
// This doesn't have a semaphore to enforce -j, but it's rare.
Tasks->runAsync("IndexStdlib", std::move(Task));
else
Task();
}

void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override {
if (FIndex)
FIndex->updateMain(Path, AST);
Expand Down Expand Up @@ -127,9 +103,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
private:
FileIndex *FIndex;
ClangdServer::Callbacks *ServerCallbacks;
const ThreadsafeFS &TFS;
StdLibSet Stdlib;
AsyncTaskRunner *Tasks;
};

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

// Unfortunately we don't have strict topological order between the rest of
// the components. E.g. CDB broadcast triggers backrgound indexing.
Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ class ClangdServer {
mutable std::mutex CachedCompletionFuzzyFindRequestMutex;

llvm::Optional<std::string> WorkspaceRoot;
llvm::Optional<AsyncTaskRunner> IndexTasks; // for stdlib indexing.
llvm::Optional<TUScheduler> WorkScheduler;
// Invalidation policy used for actions that we assume are "transient".
TUScheduler::ASTActionInvalidation Transient;
Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clangd/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ struct Config {
/// forward-slashes.
std::string MountPoint;
};
/// Controls index behavior.
/// Controls background-index behavior.
struct {
/// Whether this TU should be background-indexed.
/// Whether this TU should be indexed.
BackgroundPolicy Background = BackgroundPolicy::Build;
ExternalIndexSpec External;
bool StandardLibrary = false;
} Index;

enum UnusedIncludesPolicy { Strict, None };
Expand Down
5 changes: 0 additions & 5 deletions clang-tools-extra/clangd/ConfigCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ struct FragmentCompiler {
}
if (F.External)
compile(std::move(**F.External), F.External->Range);
if (F.StandardLibrary)
Out.Apply.push_back(
[Val(**F.StandardLibrary)](const Params &, Config &C) {
C.Index.StandardLibrary = Val;
});
}

void compile(Fragment::IndexBlock::ExternalBlock &&External,
Expand Down
3 changes: 0 additions & 3 deletions clang-tools-extra/clangd/ConfigFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ struct Fragment {
llvm::Optional<Located<std::string>> MountPoint;
};
llvm::Optional<Located<ExternalBlock>> External;
// Whether the standard library visible from this file should be indexed.
// This makes all standard library symbols available, included or not.
llvm::Optional<Located<bool>> StandardLibrary;
};
IndexBlock Index;

Expand Down
4 changes: 0 additions & 4 deletions clang-tools-extra/clangd/ConfigYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ class Parser {
F.External.emplace(std::move(External));
F.External->Range = N.getSourceRange();
});
Dict.handle("StandardLibrary", [&](Node &N) {
if (auto StandardLibrary = boolValue(N, "StandardLibrary"))
F.StandardLibrary = *StandardLibrary;
});
Dict.parse(N);
}

Expand Down
7 changes: 3 additions & 4 deletions clang-tools-extra/clangd/TUScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,9 @@ void PreambleThread::build(Request Req) {
bool IsFirstPreamble = !LatestBuild;
LatestBuild = clang::clangd::buildPreamble(
FileName, *Req.CI, Inputs, StoreInMemory,
[&](ASTContext &Ctx, Preprocessor &PP,
const CanonicalIncludes &CanonIncludes) {
Callbacks.onPreambleAST(FileName, Inputs.Version, *Req.CI, Ctx, PP,
CanonIncludes);
[this, Version(Inputs.Version)](ASTContext &Ctx, Preprocessor &PP,
const CanonicalIncludes &CanonIncludes) {
Callbacks.onPreambleAST(FileName, Version, Ctx, PP, CanonIncludes);
},
&Stats);
if (!LatestBuild)
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/TUScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class ParsingCallbacks {
/// contains only AST nodes from the #include directives at the start of the
/// file. AST node in the current file should be observed on onMainAST call.
virtual void onPreambleAST(PathRef Path, llvm::StringRef Version,
const CompilerInvocation &CI, ASTContext &Ctx,
Preprocessor &PP, const CanonicalIncludes &) {}
ASTContext &Ctx, Preprocessor &PP,
const CanonicalIncludes &) {}

/// The argument function is run under the critical section guarding against
/// races when closing the files.
Expand Down
16 changes: 6 additions & 10 deletions clang-tools-extra/clangd/index/FileIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ FileIndex::FileIndex()
MainFileSymbols(IndexContents::All),
MainFileIndex(std::make_unique<MemIndex>()) {}

void FileIndex::updatePreamble(IndexFileIn IF) {
void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,
ASTContext &AST, Preprocessor &PP,
const CanonicalIncludes &Includes) {
IndexFileIn IF;
std::tie(IF.Symbols, std::ignore, IF.Relations) =
indexHeaderSymbols(Version, AST, PP, Includes);
FileShardedIndex ShardedIndex(std::move(IF));
for (auto Uri : ShardedIndex.getAllSources()) {
auto IF = ShardedIndex.getShard(Uri);
Expand Down Expand Up @@ -456,15 +461,6 @@ void FileIndex::updatePreamble(IndexFileIn IF) {
}
}

void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,
ASTContext &AST, Preprocessor &PP,
const CanonicalIncludes &Includes) {
IndexFileIn IF;
std::tie(IF.Symbols, std::ignore, IF.Relations) =
indexHeaderSymbols(Version, AST, PP, Includes);
updatePreamble(std::move(IF));
}

void FileIndex::updateMain(PathRef Path, ParsedAST &AST) {
auto Contents = indexMainDecls(AST);
MainFileSymbols.update(
Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/index/FileIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class FileIndex : public MergedIndex {
/// and macros in \p PP.
void updatePreamble(PathRef Path, llvm::StringRef Version, ASTContext &AST,
Preprocessor &PP, const CanonicalIncludes &Includes);
void updatePreamble(IndexFileIn);

/// Update symbols and references from main file \p Path with
/// `indexMainDecls`.
Expand Down
Loading

0 comments on commit 77533ea

Please sign in to comment.