diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -97,22 +97,14 @@ /// Cached preambles are potentially large. If false, store them on disk. bool StorePreamblesInMemory = true; - /// Reuse even stale preambles, and rebuild them in the background. - /// This improves latency at the cost of accuracy. - bool AsyncPreambleBuilds = true; /// If true, ClangdServer builds a dynamic in-memory index for symbols in /// opened files and uses the index to augment code completion results. bool BuildDynamicSymbolIndex = false; - /// Use a heavier and faster in-memory index implementation. - bool HeavyweightDynamicSymbolIndex = true; /// If true, ClangdServer automatically indexes files in the current project /// on background threads. The index is stored in the project root. bool BackgroundIndex = false; - /// Store refs to main-file symbols in the index. - bool CollectMainFileRefs = true; - /// If set, use this index to augment code completion results. SymbolIndex *StaticIndex = nullptr; diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -122,7 +122,6 @@ Opts.StorePreamblesInMemory = true; Opts.AsyncThreadsCount = 4; // Consistent! Opts.TheiaSemanticHighlighting = true; - Opts.AsyncPreambleBuilds = true; return Opts; } @@ -132,7 +131,6 @@ Opts.RetentionPolicy = RetentionPolicy; Opts.StorePreamblesInMemory = StorePreamblesInMemory; Opts.UpdateDebounce = UpdateDebounce; - Opts.AsyncPreambleBuilds = AsyncPreambleBuilds; Opts.ContextProvider = ContextProvider; return Opts; } @@ -141,10 +139,7 @@ const ThreadsafeFS &TFS, const Options &Opts, Callbacks *Callbacks) : CDB(CDB), TFS(TFS), - DynamicIdx(Opts.BuildDynamicSymbolIndex - ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex, - Opts.CollectMainFileRefs) - : nullptr), + DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr), ClangTidyProvider(Opts.ClangTidyProvider), WorkspaceRoot(Opts.WorkspaceRoot), // Pass a callback into `WorkScheduler` to extract symbols from a newly @@ -175,7 +170,6 @@ Callbacks->onBackgroundIndexProgress(S); }; BGOpts.ContextProvider = Opts.ContextProvider; - BGOpts.CollectMainFileRefs = Opts.CollectMainFileRefs; BackgroundIdx = std::make_unique( TFS, CDB, BackgroundIndexStorage::createDiskBackedStorageFactory( diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -196,10 +196,6 @@ /// Determines when to keep idle ASTs in memory for future use. ASTRetentionPolicy RetentionPolicy; - /// Whether to run PreamblePeer asynchronously. - /// No-op if AsyncThreadsCount is 0. - bool AsyncPreambleBuilds = true; - /// Used to create a context that wraps each single operation. /// Typically to inject per-file configuration. /// If the path is empty, context sholud be "generic". diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -596,8 +596,8 @@ FileName(FileName), ContextProvider(Opts.ContextProvider), CDB(CDB), Callbacks(Callbacks), Barrier(Barrier), Done(false), Status(FileName, Callbacks), - PreamblePeer(FileName, Callbacks, Opts.StorePreamblesInMemory, - RunSync || !Opts.AsyncPreambleBuilds, Status, *this) { + PreamblePeer(FileName, Callbacks, Opts.StorePreamblesInMemory, RunSync, + Status, *this) { // Set a fallback command because compile command can be accessed before // `Inputs` is initialized. Other fields are only used after initialization // from client inputs. diff --git a/clang-tools-extra/clangd/index/Background.h b/clang-tools-extra/clangd/index/Background.h --- a/clang-tools-extra/clangd/index/Background.h +++ b/clang-tools-extra/clangd/index/Background.h @@ -143,8 +143,6 @@ // file. Called with the empty string for other tasks. // (When called, the context from BackgroundIndex construction is active). std::function ContextProvider = nullptr; - // Whether to collect references to main-file-only symbols. - bool CollectMainFileRefs = false; }; /// Creates a new background index and starts its threads. @@ -198,7 +196,6 @@ const ThreadsafeFS &TFS; const GlobalCompilationDatabase &CDB; std::function ContextProvider; - bool CollectMainFileRefs; llvm::Error index(tooling::CompileCommand); diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -97,7 +97,6 @@ BackgroundIndexStorage::Factory IndexStorageFactory, Options Opts) : SwapIndex(std::make_unique()), TFS(TFS), CDB(CDB), ContextProvider(std::move(Opts.ContextProvider)), - CollectMainFileRefs(Opts.CollectMainFileRefs), Rebuilder(this, &IndexedSymbols, Opts.ThreadPoolSize), IndexStorageFactory(std::move(IndexStorageFactory)), Queue(std::move(Opts.OnProgress)), @@ -304,7 +303,7 @@ return false; // Skip files that haven't changed, without errors. return true; }; - IndexOpts.CollectMainFileRefs = CollectMainFileRefs; + IndexOpts.CollectMainFileRefs = true; IndexFileIn Index; auto Action = createStaticIndexingAction( diff --git a/clang-tools-extra/clangd/index/FileIndex.h b/clang-tools-extra/clangd/index/FileIndex.h --- a/clang-tools-extra/clangd/index/FileIndex.h +++ b/clang-tools-extra/clangd/index/FileIndex.h @@ -107,7 +107,7 @@ /// FIXME: Expose an interface to remove files that are closed. class FileIndex : public MergedIndex { public: - FileIndex(bool UseDex = true, bool CollectMainFileRefs = false); + FileIndex(); /// Update preamble symbols of file \p Path with all declarations in \p AST /// and macros in \p PP. @@ -122,9 +122,6 @@ void profile(MemoryTree &MT) const; private: - bool UseDex; // FIXME: this should be always on. - bool CollectMainFileRefs; - // Contains information from each file's preamble only. Symbols and relations // are sharded per declaration file to deduplicate multiple symbols and reduce // memory usage. @@ -158,7 +155,7 @@ /// Retrieves symbols and refs of local top level decls in \p AST (i.e. /// `AST.getLocalTopLevelDecls()`). /// Exposed to assist in unit tests. -SlabTuple indexMainDecls(ParsedAST &AST, bool CollectMainFileRefs = false); +SlabTuple indexMainDecls(ParsedAST &AST); /// Index declarations from \p AST and macros from \p PP that are declared in /// included headers. diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp --- a/clang-tools-extra/clangd/index/FileIndex.cpp +++ b/clang-tools-extra/clangd/index/FileIndex.cpp @@ -217,11 +217,11 @@ return std::move(IF); } -SlabTuple indexMainDecls(ParsedAST &AST, bool CollectMainFileRefs) { +SlabTuple indexMainDecls(ParsedAST &AST) { return indexSymbols( AST.getASTContext(), AST.getPreprocessorPtr(), AST.getLocalTopLevelDecls(), &AST.getMacros(), AST.getCanonicalIncludes(), - /*IsIndexMainAST=*/true, AST.version(), CollectMainFileRefs); + /*IsIndexMainAST=*/true, AST.version(), /*CollectMainFileRefs=*/true); } SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST, @@ -410,9 +410,8 @@ } } -FileIndex::FileIndex(bool UseDex, bool CollectMainFileRefs) - : MergedIndex(&MainFileIndex, &PreambleIndex), UseDex(UseDex), - CollectMainFileRefs(CollectMainFileRefs), +FileIndex::FileIndex() + : MergedIndex(&MainFileIndex, &PreambleIndex), PreambleIndex(std::make_unique()), MainFileIndex(std::make_unique()) {} @@ -436,9 +435,8 @@ /*CountReferences=*/false); } size_t IndexVersion = 0; - auto NewIndex = - PreambleSymbols.buildIndex(UseDex ? IndexType::Heavy : IndexType::Light, - DuplicateHandling::PickOne, &IndexVersion); + auto NewIndex = PreambleSymbols.buildIndex( + IndexType::Heavy, DuplicateHandling::PickOne, &IndexVersion); { std::lock_guard Lock(UpdateIndexMu); if (IndexVersion <= PreambleIndexVersion) { @@ -455,7 +453,7 @@ } void FileIndex::updateMain(PathRef Path, ParsedAST &AST) { - auto Contents = indexMainDecls(AST, CollectMainFileRefs); + auto Contents = indexMainDecls(AST); MainFileSymbols.update( Path, std::make_unique(std::move(std::get<0>(Contents))), std::make_unique(std::move(std::get<1>(Contents))), diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -281,6 +281,11 @@ }; RetiredFlag EnableIndex("index"); +RetiredFlag SuggestMissingIncludes("suggest-missing-includes"); +RetiredFlag RecoveryAST("recovery-ast"); +RetiredFlag RecoveryASTType("recovery-ast-type"); +RetiredFlag AsyncPreamble("async-preamble"); +RetiredFlag CollectMainFileRefs("collect-main-file-refs"); opt LimitResults{ "limit-results", @@ -290,7 +295,6 @@ init(100), }; -RetiredFlag SuggestMissingIncludes("suggest-missing-includes"); list TweakList{ "tweaks", @@ -307,9 +311,6 @@ init(true), }; -RetiredFlag RecoveryAST("recovery-ast"); -RetiredFlag RecoveryASTType("recovery-ast-type"); - opt FoldingRanges{ "folding-ranges", cat(Features), @@ -450,16 +451,6 @@ init(false), }; -// FIXME: retire this flag in llvm 13 release cycle. -opt AsyncPreamble{ - "async-preamble", - cat(Misc), - desc("Reuse even stale preambles, and rebuild them in the background. This " - "improves latency at the cost of accuracy."), - init(ClangdServer::Options().AsyncPreambleBuilds), - Hidden, -}; - opt EnableConfig{ "enable-config", cat(Misc), @@ -474,15 +465,6 @@ init(true), }; -// FIXME: retire this flag in llvm 13 release cycle. -opt CollectMainFileRefs{ - "collect-main-file-refs", - cat(Misc), - desc("Store references to main-file-only symbols in the index"), - init(ClangdServer::Options().CollectMainFileRefs), - Hidden, -}; - #if defined(__GLIBC__) && CLANGD_MALLOC_TRIM opt EnableMallocTrim{ "malloc-trim", @@ -760,7 +742,6 @@ if (!ResourceDir.empty()) Opts.ResourceDir = ResourceDir; Opts.BuildDynamicSymbolIndex = true; - Opts.CollectMainFileRefs = CollectMainFileRefs; std::vector> IdxStack; std::unique_ptr StaticIdx; std::future AsyncIndexLoad; // Block exit while loading the index. @@ -860,7 +841,6 @@ ClangTidyOptProvider = combine(std::move(Providers)); Opts.ClangTidyProvider = ClangTidyOptProvider; } - Opts.AsyncPreambleBuilds = AsyncPreamble; Opts.QueryDriverGlobs = std::move(QueryDriverGlobs); Opts.TweakFilter = [&](const Tweak &T) { if (T.hidden() && !HiddenFeatures) diff --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp --- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp @@ -190,7 +190,6 @@ MemoryShardStorage MSS(Storage, CacheHits); OverlayCDB CDB(/*Base=*/nullptr); BackgroundIndex::Options Opts; - Opts.CollectMainFileRefs = true; BackgroundIndex Idx( FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts); @@ -241,52 +240,25 @@ FS.Files[testPath("root/A.cc")] = "#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }"; - // Check the behaviour with CollectMainFileRefs = false (the default - // at the SymbolCollector level). - { - llvm::StringMap Storage; - size_t CacheHits = 0; - MemoryShardStorage MSS(Storage, CacheHits); - OverlayCDB CDB(/*Base=*/nullptr); - BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return &MSS; }, - /*Opts=*/{}); - - tooling::CompileCommand Cmd; - Cmd.Filename = testPath("root/A.cc"); - Cmd.Directory = testPath("root"); - Cmd.CommandLine = {"clang++", testPath("root/A.cc")}; - CDB.setCompileCommand(testPath("root/A.cc"), Cmd); - - ASSERT_TRUE(Idx.blockUntilIdleForTest()); - EXPECT_THAT( - runFuzzyFind(Idx, ""), - UnorderedElementsAre(AllOf(Named("header_sym"), NumReferences(1U)), - AllOf(Named("main_sym"), NumReferences(0U)))); - } - - // Check the behaviour with CollectMainFileRefs = true. - { - llvm::StringMap Storage; - size_t CacheHits = 0; - MemoryShardStorage MSS(Storage, CacheHits); - OverlayCDB CDB(/*Base=*/nullptr); - BackgroundIndex::Options Opts; - Opts.CollectMainFileRefs = true; - BackgroundIndex Idx( - FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts); + llvm::StringMap Storage; + size_t CacheHits = 0; + MemoryShardStorage MSS(Storage, CacheHits); + OverlayCDB CDB(/*Base=*/nullptr); + BackgroundIndex::Options Opts; + BackgroundIndex Idx( + FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts); - tooling::CompileCommand Cmd; - Cmd.Filename = testPath("root/A.cc"); - Cmd.Directory = testPath("root"); - Cmd.CommandLine = {"clang++", testPath("root/A.cc")}; - CDB.setCompileCommand(testPath("root/A.cc"), Cmd); + tooling::CompileCommand Cmd; + Cmd.Filename = testPath("root/A.cc"); + Cmd.Directory = testPath("root"); + Cmd.CommandLine = {"clang++", testPath("root/A.cc")}; + CDB.setCompileCommand(testPath("root/A.cc"), Cmd); - ASSERT_TRUE(Idx.blockUntilIdleForTest()); - EXPECT_THAT( - runFuzzyFind(Idx, ""), - UnorderedElementsAre(AllOf(Named("header_sym"), NumReferences(1U)), - AllOf(Named("main_sym"), NumReferences(1U)))); - } + ASSERT_TRUE(Idx.blockUntilIdleForTest()); + EXPECT_THAT( + runFuzzyFind(Idx, ""), + UnorderedElementsAre(AllOf(Named("header_sym"), NumReferences(1U)), + AllOf(Named("main_sym"), NumReferences(1U)))); } TEST_F(BackgroundIndexTest, ShardStorageTest) { diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp --- a/clang-tools-extra/clangd/unittests/TestTU.cpp +++ b/clang-tools-extra/clangd/unittests/TestTU.cpp @@ -154,8 +154,7 @@ std::unique_ptr TestTU::index() const { auto AST = build(); - auto Idx = std::make_unique(/*UseDex=*/true, - /*CollectMainFileRefs=*/true); + auto Idx = std::make_unique(); Idx->updatePreamble(testPath(Filename), /*Version=*/"null", AST.getASTContext(), AST.getPreprocessorPtr(), AST.getCanonicalIncludes());