Author: sammccall Date: Tue Oct 23 06:14:02 2018 New Revision: 345024 URL: http://llvm.org/viewvc/llvm-project?rev=345024&view=rev Log: [clangd] Remove caching of compilation database commands.
Summary: The CDB implementations used in open-source code are fast, and our private slow CDB will soon do the relevant caching itself. Simplifying the GlobalCDB layer in clangd is important to get auto-index implemented at the right layer. Reviewers: ioeric, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53439 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/ClangdLSPServer.h clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=345024&r1=345023&r2=345024&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Oct 23 06:14:02 2018 @@ -783,7 +783,7 @@ void ClangdLSPServer::reparseOpenedFiles } ClangdLSPServer::CompilationDB ClangdLSPServer::CompilationDB::makeInMemory() { - return CompilationDB(llvm::make_unique<InMemoryCompilationDb>(), nullptr, + return CompilationDB(llvm::make_unique<InMemoryCompilationDb>(), /*IsDirectoryBased=*/false); } @@ -792,16 +792,13 @@ ClangdLSPServer::CompilationDB::makeDire Optional<Path> CompileCommandsDir) { auto CDB = llvm::make_unique<DirectoryBasedGlobalCompilationDatabase>( std::move(CompileCommandsDir)); - auto CachingCDB = llvm::make_unique<CachingCompilationDb>(*CDB); - return CompilationDB(std::move(CDB), std::move(CachingCDB), + return CompilationDB(std::move(CDB), /*IsDirectoryBased=*/true); } void ClangdLSPServer::CompilationDB::invalidate(PathRef File) { if (!IsDirectoryBased) static_cast<InMemoryCompilationDb *>(CDB.get())->invalidate(File); - else - CachingCDB->invalidate(File); } bool ClangdLSPServer::CompilationDB::setCompilationCommandForFile( @@ -826,7 +823,6 @@ void ClangdLSPServer::CompilationDB::set } static_cast<DirectoryBasedGlobalCompilationDatabase *>(CDB.get()) ->setExtraFlagsForFile(File, std::move(ExtraFlags)); - CachingCDB->invalidate(File); } void ClangdLSPServer::CompilationDB::setCompileCommandsDir(Path P) { @@ -837,13 +833,6 @@ void ClangdLSPServer::CompilationDB::set } static_cast<DirectoryBasedGlobalCompilationDatabase *>(CDB.get()) ->setCompileCommandsDir(P); - CachingCDB->clear(); -} - -GlobalCompilationDatabase &ClangdLSPServer::CompilationDB::getCDB() { - if (CachingCDB) - return *CachingCDB; - return *CDB; } } // namespace clangd Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=345024&r1=345023&r2=345024&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Oct 23 06:14:02 2018 @@ -135,21 +135,17 @@ private: /// Returns a CDB that should be used to get compile commands for the /// current instance of ClangdLSPServer. - GlobalCompilationDatabase &getCDB(); + GlobalCompilationDatabase &getCDB() { return *CDB; } private: CompilationDB(std::unique_ptr<GlobalCompilationDatabase> CDB, - std::unique_ptr<CachingCompilationDb> CachingCDB, bool IsDirectoryBased) - : CDB(std::move(CDB)), CachingCDB(std::move(CachingCDB)), - IsDirectoryBased(IsDirectoryBased) {} + : CDB(std::move(CDB)), IsDirectoryBased(IsDirectoryBased) {} // if IsDirectoryBased is true, an instance of InMemoryCDB. // If IsDirectoryBased is false, an instance of DirectoryBasedCDB. // unique_ptr<GlobalCompilationDatabase> CDB; std::unique_ptr<GlobalCompilationDatabase> CDB; - // Non-null only for directory-based CDB - std::unique_ptr<CachingCompilationDb> CachingCDB; bool IsDirectoryBased; }; Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=345024&r1=345023&r2=345024&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original) +++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Tue Oct 23 06:14:02 2018 @@ -116,38 +116,6 @@ DirectoryBasedGlobalCompilationDatabase: return nullptr; } -CachingCompilationDb::CachingCompilationDb( - const GlobalCompilationDatabase &InnerCDB) - : InnerCDB(InnerCDB) {} - -Optional<tooling::CompileCommand> -CachingCompilationDb::getCompileCommand(PathRef File) const { - std::unique_lock<std::mutex> Lock(Mut); - auto It = Cached.find(File); - if (It != Cached.end()) - return It->second; - - Lock.unlock(); - Optional<tooling::CompileCommand> Command = InnerCDB.getCompileCommand(File); - Lock.lock(); - return Cached.try_emplace(File, std::move(Command)).first->getValue(); -} - -tooling::CompileCommand -CachingCompilationDb::getFallbackCommand(PathRef File) const { - return InnerCDB.getFallbackCommand(File); -} - -void CachingCompilationDb::invalidate(PathRef File) { - std::unique_lock<std::mutex> Lock(Mut); - Cached.erase(File); -} - -void CachingCompilationDb::clear() { - std::unique_lock<std::mutex> Lock(Mut); - Cached.clear(); -} - Optional<tooling::CompileCommand> InMemoryCompilationDb::getCompileCommand(PathRef File) const { std::lock_guard<std::mutex> Lock(Mutex); Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h?rev=345024&r1=345023&r2=345024&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h (original) +++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Tue Oct 23 06:14:02 2018 @@ -86,33 +86,6 @@ private: llvm::Optional<Path> CompileCommandsDir; }; -/// A wrapper around GlobalCompilationDatabase that caches the compile commands. -/// Note that only results of getCompileCommand are cached. -class CachingCompilationDb : public GlobalCompilationDatabase { -public: - explicit CachingCompilationDb(const GlobalCompilationDatabase &InnerCDB); - - /// Gets compile command for \p File from cache or CDB if it's not in the - /// cache. - llvm::Optional<tooling::CompileCommand> - getCompileCommand(PathRef File) const override; - - /// Forwards to the inner CDB. Results of this function are not cached. - tooling::CompileCommand getFallbackCommand(PathRef File) const override; - - /// Removes an entry for \p File if it's present in the cache. - void invalidate(PathRef File); - - /// Removes all cached compile commands. - void clear(); - -private: - const GlobalCompilationDatabase &InnerCDB; - mutable std::mutex Mut; - mutable llvm::StringMap<llvm::Optional<tooling::CompileCommand>> - Cached; /* GUARDED_BY(Mut) */ -}; - /// Gets compile args from an in-memory mapping based on a filepath. Typically /// used by clients who provide the compile commands themselves. class InMemoryCompilationDb : public GlobalCompilationDatabase { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits