kbobyrev updated this revision to Diff 161679. kbobyrev marked 2 inline comments as done. kbobyrev added a comment.
Aww, the previous diff was the wrong one and didn't contain docs. The move of the code to the middle of Clangd driver was justified by the assumption that it might be better to move the code that uses `UseDex` flag closer to the flag itself, but I agree: it looks strange. I moved it back. https://reviews.llvm.org/D50897 Files: clang-tools-extra/clangd/index/MemIndex.cpp clang-tools-extra/clangd/index/MemIndex.h clang-tools-extra/clangd/index/dex/DexIndex.cpp clang-tools-extra/clangd/index/dex/DexIndex.h clang-tools-extra/clangd/tool/ClangdMain.cpp
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -12,6 +12,7 @@ #include "Path.h" #include "Trace.h" #include "index/SymbolYAML.h" +#include "index/dex/DexIndex.h" #include "clang/Basic/Version.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -29,6 +30,7 @@ using namespace clang::clangd; namespace { + enum class PCHStorageFlag { Disk, Memory }; // Build an in-memory static index for global symbols from a YAML-format file. @@ -45,8 +47,10 @@ for (auto Sym : Slab) SymsBuilder.insert(Sym); - return MemIndex::build(std::move(SymsBuilder).build()); + return UseDex ? DexIndex::build(std::move(SymsBuilder).build()) + : MemIndex::build(std::move(SymsBuilder).build()); } + } // namespace static llvm::cl::opt<Path> CompileCommandsDir( @@ -185,6 +189,11 @@ "'compile_commands.json' files")), llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden); +static llvm::cl::opt<bool> + UseDex("use-dex-index", + llvm::cl::desc("Use experimental Dex static index."), + llvm::cl::init(false), llvm::cl::Hidden); + int main(int argc, char *argv[]) { llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) { Index: clang-tools-extra/clangd/index/dex/DexIndex.h =================================================================== --- clang-tools-extra/clangd/index/dex/DexIndex.h +++ clang-tools-extra/clangd/index/dex/DexIndex.h @@ -43,6 +43,9 @@ /// accessible as long as `Symbols` is kept alive. void build(std::shared_ptr<std::vector<const Symbol *>> Symbols); + /// \brief Build index from a symbol slab. + static std::unique_ptr<SymbolIndex> build(SymbolSlab Slab); + bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref<void(const Symbol &)> Callback) const override; Index: clang-tools-extra/clangd/index/dex/DexIndex.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/DexIndex.cpp +++ clang-tools-extra/clangd/index/dex/DexIndex.cpp @@ -69,6 +69,12 @@ } } +std::unique_ptr<SymbolIndex> DexIndex::build(SymbolSlab Slab) { + auto Idx = llvm::make_unique<MemIndex>(); + Idx->build(getSymbolsFromSlab(std::move(Slab))); + return std::move(Idx); +} + /// Constructs iterators over tokens extracted from the query and exhausts it /// while applying Callback to each symbol in the order of decreasing quality /// of the matched symbols. Index: clang-tools-extra/clangd/index/MemIndex.h =================================================================== --- clang-tools-extra/clangd/index/MemIndex.h +++ clang-tools-extra/clangd/index/MemIndex.h @@ -47,6 +47,11 @@ mutable std::mutex Mutex; }; +// Returns pointers to the symbols in given slab and bundles slab lifetime with +// returned symbol pointers so that the pointers are never invalid. +std::shared_ptr<std::vector<const Symbol *>> +getSymbolsFromSlab(SymbolSlab Slab); + } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/index/MemIndex.cpp =================================================================== --- clang-tools-extra/clangd/index/MemIndex.cpp +++ clang-tools-extra/clangd/index/MemIndex.cpp @@ -28,6 +28,12 @@ } } +std::unique_ptr<SymbolIndex> MemIndex::build(SymbolSlab Slab) { + auto Idx = llvm::make_unique<MemIndex>(); + Idx->build(getSymbolsFromSlab(std::move(Slab))); + return std::move(Idx); +} + bool MemIndex::fuzzyFind( const FuzzyFindRequest &Req, llvm::function_ref<void(const Symbol &)> Callback) const { @@ -72,26 +78,24 @@ } } -std::unique_ptr<SymbolIndex> MemIndex::build(SymbolSlab Slab) { +void MemIndex::findOccurrences( + const OccurrencesRequest &Req, + llvm::function_ref<void(const SymbolOccurrence &)> Callback) const { + log("findOccurrences is not implemented."); +} + +std::shared_ptr<std::vector<const Symbol *>> +getSymbolsFromSlab(SymbolSlab Slab) { struct Snapshot { SymbolSlab Slab; std::vector<const Symbol *> Pointers; }; auto Snap = std::make_shared<Snapshot>(); Snap->Slab = std::move(Slab); for (auto &Sym : Snap->Slab) Snap->Pointers.push_back(&Sym); - auto S = std::shared_ptr<std::vector<const Symbol *>>(std::move(Snap), - &Snap->Pointers); - auto MemIdx = llvm::make_unique<MemIndex>(); - MemIdx->build(std::move(S)); - return std::move(MemIdx); -} - -void MemIndex::findOccurrences( - const OccurrencesRequest &Req, - llvm::function_ref<void(const SymbolOccurrence &)> Callback) const { - log("findOccurrences is not implemented."); + return std::shared_ptr<std::vector<const Symbol *>>(std::move(Snap), + &Snap->Pointers); } } // namespace clangd
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits