kadircet updated this revision to Diff 271357. kadircet added a comment. - Rebase
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D81998/new/ https://reviews.llvm.org/D81998 Files: clang-tools-extra/clangd/ClangdLSPServer.cpp clang-tools-extra/clangd/ClangdLSPServer.h clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/ClangdServer.h clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/Compiler.cpp clang-tools-extra/clangd/Compiler.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h clang-tools-extra/clangd/index/Background.cpp clang-tools-extra/clangd/index/Background.h clang-tools-extra/clangd/support/FSProvider.cpp clang-tools-extra/clangd/support/FSProvider.h clang-tools-extra/clangd/tool/ClangdMain.cpp clang-tools-extra/clangd/unittests/ClangdTests.cpp clang-tools-extra/clangd/unittests/HeadersTests.cpp clang-tools-extra/clangd/unittests/PreambleTests.cpp clang-tools-extra/clangd/unittests/TestFS.h
Index: clang-tools-extra/clangd/unittests/TestFS.h =================================================================== --- clang-tools-extra/clangd/unittests/TestFS.h +++ clang-tools-extra/clangd/unittests/TestFS.h @@ -31,17 +31,14 @@ llvm::StringMap<time_t> const &Timestamps = {}); // A VFS provider that returns TestFSes containing a provided set of files. -class MockFSProvider : public FileSystemProvider { +class MockFSProvider : public ThreadSafeFS { public: - // Prevent name hiding caused by the overload below. - using FileSystemProvider::getFileSystem; - IntrusiveRefCntPtr<llvm::vfs::FileSystem> getFileSystem() const { return buildTestFS(Files, Timestamps); } IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(llvm::NoneType) const override { + view(llvm::NoneType) const override { return getFileSystem(); } Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/PreambleTests.cpp +++ clang-tools-extra/clangd/unittests/PreambleTests.cpp @@ -74,7 +74,7 @@ std::move(CI), &BaselinePreamble->Preamble, llvm::MemoryBuffer::getMemBufferCopy( ModifiedContents.slice(0, Bounds.Size).str()), - PI.FSProvider->getFileSystem(PI.CompileCommand.Directory), Diags); + PI.FSProvider->view(PI.CompileCommand.Directory), Diags); PreprocessOnlyAction Action; if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) { ADD_FAILURE() << "failed begin source file"; Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HeadersTests.cpp +++ clang-tools-extra/clangd/unittests/HeadersTests.cpp @@ -53,7 +53,7 @@ EXPECT_TRUE(static_cast<bool>(CI)); // The diagnostic options must be set before creating a CompilerInstance. CI->getDiagnosticOpts().IgnoreWarnings = true; - auto VFS = PI.FSProvider->getFileSystem(Cmd->Directory); + auto VFS = PI.FSProvider->view(Cmd->Directory); auto Clang = prepareCompilerInstance( std::move(CI), /*Preamble=*/nullptr, llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile), Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -272,9 +272,9 @@ TEST_F(ClangdVFSTest, PropagatesContexts) { static Key<int> Secret; - struct FSProvider : public FileSystemProvider { + struct FSProvider : public ThreadSafeFS { IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(llvm::NoneType) const override { + view(llvm::NoneType) const override { Got = Context::current().getExisting(Secret); return buildTestFS({}); } @@ -924,13 +924,13 @@ // Check that running code completion doesn't stat() a bunch of files from the // preamble again. (They should be using the preamble's stat-cache) TEST(ClangdTests, PreambleVFSStatCache) { - class ListenStatsFSProvider : public FileSystemProvider { + class ListenStatsFSProvider : public ThreadSafeFS { public: ListenStatsFSProvider(llvm::StringMap<unsigned> &CountStats) : CountStats(CountStats) {} IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(llvm::NoneType) const override { + view(llvm::NoneType) const override { class ListenStatVFS : public llvm::vfs::ProxyFileSystem { public: ListenStatVFS(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS, Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -719,7 +719,7 @@ tidy::ClangTidyGlobalOptions(), /* Default */ EmptyDefaults, /* Override */ OverrideClangTidyOptions, - FSProvider.getFileSystem(/*CWD=*/llvm::None)); + FSProvider.view(/*CWD=*/llvm::None)); Opts.GetClangTidyOptions = [&](llvm::vfs::FileSystem &, llvm::StringRef File) { // This function must be thread-safe and tidy option providers are not. Index: clang-tools-extra/clangd/support/FSProvider.h =================================================================== --- clang-tools-extra/clangd/support/FSProvider.h +++ clang-tools-extra/clangd/support/FSProvider.h @@ -21,28 +21,28 @@ // Wrapper for vfs::FileSystem for use in multithreaded programs like clangd. // As FileSystem is not threadsafe, concurrent threads must each obtain one. -class FileSystemProvider { +class ThreadSafeFS { public: - virtual ~FileSystemProvider() = default; + virtual ~ThreadSafeFS() = default; /// Called by ClangdServer to obtain a vfs::FileSystem to be used for parsing. /// Context::current() will be the context passed to the clang entrypoint, /// such as addDocument(), and will also be propagated to result callbacks. /// Embedders may use this to isolate filesystem accesses. /// Initial working directory is arbitrary. virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(llvm::NoneType CWD) const = 0; + view(llvm::NoneType CWD) const = 0; /// As above, except it will try to set current working directory to \p CWD. /// This is an overload instead of an optional to make implicit string -> /// StringRef conversion possible. virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(PathRef CWD) const; + view(PathRef CWD) const; }; -class RealFileSystemProvider : public FileSystemProvider { +class RealFileSystemProvider : public ThreadSafeFS { public: llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(llvm::NoneType) const override; + view(llvm::NoneType) const override; }; } // namespace clangd Index: clang-tools-extra/clangd/support/FSProvider.cpp =================================================================== --- clang-tools-extra/clangd/support/FSProvider.cpp +++ clang-tools-extra/clangd/support/FSProvider.cpp @@ -75,15 +75,15 @@ } // namespace llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> -FileSystemProvider::getFileSystem(PathRef CWD) const { - auto FS = getFileSystem(/*CWD=*/llvm::None); +ThreadSafeFS::view(PathRef CWD) const { + auto FS = view(llvm::None); if (auto EC = FS->setCurrentWorkingDirectory(CWD)) elog("VFS: failed to set CWD to {0}: {1}", CWD, EC.message()); return FS; } llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> -clang::clangd::RealFileSystemProvider::getFileSystem(llvm::NoneType) const { +RealFileSystemProvider::view(llvm::NoneType) const { // Avoid using memory-mapped files. // FIXME: Try to use a similar approach in Sema instead of relying on // propagation of the 'isVolatile' flag through all layers. Index: clang-tools-extra/clangd/index/Background.h =================================================================== --- clang-tools-extra/clangd/index/Background.h +++ clang-tools-extra/clangd/index/Background.h @@ -132,7 +132,7 @@ /// rebuilt periodically (one per \p BuildIndexPeriodMs); otherwise, index is /// rebuilt for each indexed file. BackgroundIndex( - Context BackgroundContext, const FileSystemProvider &, + Context BackgroundContext, const ThreadSafeFS &, const GlobalCompilationDatabase &CDB, BackgroundIndexStorage::Factory IndexStorageFactory, size_t ThreadPoolSize = 0, // 0 = use all hardware threads @@ -178,7 +178,7 @@ bool HadErrors); // configuration - const FileSystemProvider &FSProvider; + const ThreadSafeFS &FSProvider; const GlobalCompilationDatabase &CDB; Context BackgroundContext; Index: clang-tools-extra/clangd/index/Background.cpp =================================================================== --- clang-tools-extra/clangd/index/Background.cpp +++ clang-tools-extra/clangd/index/Background.cpp @@ -90,7 +90,7 @@ } // namespace BackgroundIndex::BackgroundIndex( - Context BackgroundContext, const FileSystemProvider &FSProvider, + Context BackgroundContext, const ThreadSafeFS &FSProvider, const GlobalCompilationDatabase &CDB, BackgroundIndexStorage::Factory IndexStorageFactory, size_t ThreadPoolSize, std::function<void(BackgroundQueue::Stats)> OnProgress) @@ -244,7 +244,7 @@ SPAN_ATTACH(Tracer, "file", Cmd.Filename); auto AbsolutePath = getAbsolutePath(Cmd); - auto FS = FSProvider.getFileSystem(Cmd.Directory); + auto FS = FSProvider.view(Cmd.Directory); auto Buf = FS->getBufferForFile(AbsolutePath); if (!Buf) return llvm::errorCodeToError(Buf.getError()); @@ -381,7 +381,7 @@ Rebuilder.loadedShard(LoadedShards); Rebuilder.doneLoading(); - auto FS = FSProvider.getFileSystem(/*CWD=*/llvm::None); + auto FS = FSProvider.view(/*CWD=*/llvm::None); llvm::DenseSet<PathRef> TUsToIndex; // We'll accept data from stale shards, but ensure the files get reindexed // soon. Index: clang-tools-extra/clangd/SourceCode.h =================================================================== --- clang-tools-extra/clangd/SourceCode.h +++ clang-tools-extra/clangd/SourceCode.h @@ -168,7 +168,7 @@ /// though the latter may have been overridden in main()! format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, - const FileSystemProvider &FSProvider); + const ThreadSafeFS &FSProvider); /// Cleanup and format the given replacements. llvm::Expected<tooling::Replacements> Index: clang-tools-extra/clangd/SourceCode.cpp =================================================================== --- clang-tools-extra/clangd/SourceCode.cpp +++ clang-tools-extra/clangd/SourceCode.cpp @@ -575,12 +575,12 @@ return digest(Content); } -format::FormatStyle -getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, - const FileSystemProvider &FSProvider) { - auto Style = format::getStyle( - format::DefaultFormatStyle, File, format::DefaultFallbackStyle, Content, - FSProvider.getFileSystem(/*CWD=*/llvm::None).get()); +format::FormatStyle getFormatStyleForFile(llvm::StringRef File, + llvm::StringRef Content, + const ThreadSafeFS &FSProvider) { + auto Style = format::getStyle(format::DefaultFormatStyle, File, + format::DefaultFallbackStyle, Content, + FSProvider.view(/*CWD=*/llvm::None).get()); if (!Style) { log("getStyle() failed for file {0}: {1}. Fallback is LLVM style.", File, Style.takeError()); Index: clang-tools-extra/clangd/Preamble.cpp =================================================================== --- clang-tools-extra/clangd/Preamble.cpp +++ clang-tools-extra/clangd/Preamble.cpp @@ -233,12 +233,12 @@ // than vfs::FileSystem, that way we can just use ParseInputs without this // hack. auto GetFSProvider = [](llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) { - class VFSProvider : public FileSystemProvider { + class VFSProvider : public ThreadSafeFS { public: VFSProvider(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) : VFS(std::move(FS)) {} llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> - getFileSystem(llvm::NoneType) const override { + view(llvm::NoneType) const override { return VFS; } @@ -356,7 +356,7 @@ CI.getPreprocessorOpts().WriteCommentListToPCH = false; CppFilePreambleCallbacks SerializedDeclsCollector(FileName, PreambleCallback); - auto VFS = Inputs.FSProvider->getFileSystem(Inputs.CompileCommand.Directory); + auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); llvm::SmallString<32> AbsFileName(FileName); VFS->makeAbsolute(AbsFileName); auto StatCache = std::make_unique<PreambleFileStatusCache>(AbsFileName); @@ -393,7 +393,7 @@ llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName); auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0); - auto VFS = Inputs.FSProvider->getFileSystem(Inputs.CompileCommand.Directory); + auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); return compileCommandsAreEqual(Inputs.CompileCommand, Preamble.CompileCommand) && Preamble.Preamble.CanReuse(CI, ContentsBuffer.get(), Bounds, @@ -421,7 +421,7 @@ SPAN_ATTACH(Tracer, "File", FileName); assert(llvm::sys::path::is_absolute(FileName) && "relative FileName!"); auto VFS = Baseline.StatCache->getConsumingFS( - Modified.FSProvider->getFileSystem(/*CWD=*/llvm::None)); + Modified.FSProvider->view(/*CWD=*/llvm::None)); // First scan preprocessor directives in Baseline and Modified. These will be // used to figure out newly added directives in Modified. Scanning can fail, // the code just bails out and creates an empty patch in such cases, as: Index: clang-tools-extra/clangd/ParsedAST.cpp =================================================================== --- clang-tools-extra/clangd/ParsedAST.cpp +++ clang-tools-extra/clangd/ParsedAST.cpp @@ -249,7 +249,7 @@ trace::Span Tracer("BuildAST"); SPAN_ATTACH(Tracer, "File", Filename); - auto VFS = Inputs.FSProvider->getFileSystem(Inputs.CompileCommand.Directory); + auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); if (Preamble && Preamble->StatCache) VFS = Preamble->StatCache->getConsumingFS(std::move(VFS)); Index: clang-tools-extra/clangd/Compiler.h =================================================================== --- clang-tools-extra/clangd/Compiler.h +++ clang-tools-extra/clangd/Compiler.h @@ -46,7 +46,7 @@ /// Information required to run clang, e.g. to parse AST or do code completion. struct ParseInputs { tooling::CompileCommand CompileCommand; - const FileSystemProvider *FSProvider; + const ThreadSafeFS *FSProvider; std::string Contents; // Version identifier for Contents, provided by the client and opaque to us. std::string Version = "null"; Index: clang-tools-extra/clangd/Compiler.cpp =================================================================== --- clang-tools-extra/clangd/Compiler.cpp +++ clang-tools-extra/clangd/Compiler.cpp @@ -48,7 +48,7 @@ for (const auto &S : Inputs.CompileCommand.CommandLine) ArgStrs.push_back(S.c_str()); - auto VFS = Inputs.FSProvider->getFileSystem(Inputs.CompileCommand.Directory); + auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CommandLineDiagsEngine = CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false); std::unique_ptr<CompilerInvocation> CI = createInvocationFromCommandLine( Index: clang-tools-extra/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/clangd/CodeComplete.cpp +++ clang-tools-extra/clangd/CodeComplete.cpp @@ -1113,7 +1113,7 @@ // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise // the remapped buffers do not get freed. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = - Input.ParseInput.FSProvider->getFileSystem( + Input.ParseInput.FSProvider->view( Input.ParseInput.CompileCommand.Directory); if (Input.Preamble.StatCache) VFS = Input.Preamble.StatCache->getConsumingFS(std::move(VFS)); @@ -1364,7 +1364,7 @@ } CodeCompleteResult runWithoutSema(llvm::StringRef Content, size_t Offset, - const FileSystemProvider &FSProvider) && { + const ThreadSafeFS &FSProvider) && { trace::Span Tracer("CodeCompleteWithoutSema"); // Fill in fields normally set by runWithSema() HeuristicPrefix = guessCompletionPrefix(Content, Offset); Index: clang-tools-extra/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/clangd/ClangdServer.h +++ clang-tools-extra/clangd/ClangdServer.h @@ -172,7 +172,7 @@ /// those arguments for subsequent reparses. However, ClangdServer will check /// if compilation arguments changed on calls to forceReparse(). ClangdServer(const GlobalCompilationDatabase &CDB, - const FileSystemProvider &FSProvider, const Options &Opts, + const ThreadSafeFS &FSProvider, const Options &Opts, Callbacks *Callbacks = nullptr); /// Add a \p File to the list of tracked C++ files or update the contents if @@ -330,7 +330,7 @@ formatCode(llvm::StringRef Code, PathRef File, ArrayRef<tooling::Range> Ranges); - const FileSystemProvider &FSProvider; + const ThreadSafeFS &FSProvider; Path ResourceDir; // The index used to look up symbols. This could be: Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -129,8 +129,8 @@ } ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB, - const FileSystemProvider &FSProvider, - const Options &Opts, Callbacks *Callbacks) + const ThreadSafeFS &FSProvider, const Options &Opts, + Callbacks *Callbacks) : FSProvider(FSProvider), DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex) @@ -183,8 +183,8 @@ Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults(); // FIXME: call tidy options builder on the worker thread, it can do IO. if (GetClangTidyOptions) - Opts.ClangTidyOpts = GetClangTidyOptions( - *FSProvider.getFileSystem(/*CWD=*/llvm::None), File); + Opts.ClangTidyOpts = + GetClangTidyOptions(*FSProvider.view(/*CWD=*/llvm::None), File); Opts.SuggestMissingIncludes = SuggestMissingIncludes; // Compile command is set asynchronously during update, as it can be slow. @@ -318,9 +318,9 @@ llvm::Expected<size_t> CursorPos = positionToOffset(Code, Pos); if (!CursorPos) return CursorPos.takeError(); - auto Style = format::getStyle( - format::DefaultFormatStyle, File, format::DefaultFallbackStyle, Code, - FSProvider.getFileSystem(/*CWD=*/llvm::None).get()); + auto Style = format::getStyle(format::DefaultFormatStyle, File, + format::DefaultFallbackStyle, Code, + FSProvider.view(/*CWD=*/llvm::None).get()); if (!Style) return Style.takeError(); @@ -549,7 +549,7 @@ // 2) if 1) fails, we use the AST&Index approach, it is slower but supports // different code layout. if (auto CorrespondingFile = getCorrespondingHeaderOrSource( - std::string(Path), FSProvider.getFileSystem(llvm::None))) + std::string(Path), FSProvider.view(llvm::None))) return CB(std::move(CorrespondingFile)); auto Action = [Path = Path.str(), CB = std::move(CB), this](llvm::Expected<InputsAndAST> InpAST) mutable { Index: clang-tools-extra/clangd/ClangdLSPServer.h =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.h +++ clang-tools-extra/clangd/ClangdLSPServer.h @@ -41,7 +41,7 @@ /// for compile_commands.json in all parent directories of each file. /// If UseDirBasedCDB is false, compile commands are not read from disk. // FIXME: Clean up signature around CDBs. - ClangdLSPServer(Transport &Transp, const FileSystemProvider &FSProvider, + ClangdLSPServer(Transport &Transp, const ThreadSafeFS &FSProvider, const clangd::CodeCompleteOptions &CCOpts, const clangd::RenameOptions &RenameOpts, llvm::Optional<Path> CompileCommandsDir, bool UseDirBasedCDB, @@ -207,7 +207,7 @@ notify("$/progress", Params); } - const FileSystemProvider &FSProvider; + const ThreadSafeFS &FSProvider; /// Options used for code completion clangd::CodeCompleteOptions CCOpts; /// Options used for rename. Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -1340,7 +1340,7 @@ } ClangdLSPServer::ClangdLSPServer( - class Transport &Transp, const FileSystemProvider &FSProvider, + class Transport &Transp, const ThreadSafeFS &FSProvider, const clangd::CodeCompleteOptions &CCOpts, const clangd::RenameOptions &RenameOpts, llvm::Optional<Path> CompileCommandsDir, bool UseDirBasedCDB,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits