Index: clang-tools-extra/trunk/clangd/index/MemIndex.h =================================================================== --- clang-tools-extra/trunk/clangd/index/MemIndex.h +++ clang-tools-extra/trunk/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> +getSymbolsFromSlab(SymbolSlab Slab); + } // namespace clangd } // namespace clang Index: clang-tools-extra/trunk/clangd/index/MemIndex.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/MemIndex.cpp +++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp @@ -28,6 +28,12 @@ } } +std::unique_ptr MemIndex::build(SymbolSlab Slab) { + auto Idx = llvm::make_unique(); + Idx->build(getSymbolsFromSlab(std::move(Slab))); + return std::move(Idx); +} + bool MemIndex::fuzzyFind( const FuzzyFindRequest &Req, llvm::function_ref Callback) const { @@ -72,7 +78,14 @@ } } -std::unique_ptr MemIndex::build(SymbolSlab Slab) { +void MemIndex::findOccurrences( + const OccurrencesRequest &Req, + llvm::function_ref Callback) const { + log("findOccurrences is not implemented."); +} + +std::shared_ptr> +getSymbolsFromSlab(SymbolSlab Slab) { struct Snapshot { SymbolSlab Slab; std::vector Pointers; @@ -81,17 +94,8 @@ Snap->Slab = std::move(Slab); for (auto &Sym : Snap->Slab) Snap->Pointers.push_back(&Sym); - auto S = std::shared_ptr>(std::move(Snap), - &Snap->Pointers); - auto MemIdx = llvm::make_unique(); - MemIdx->build(std::move(S)); - return std::move(MemIdx); -} - -void MemIndex::findOccurrences( - const OccurrencesRequest &Req, - llvm::function_ref Callback) const { - log("findOccurrences is not implemented."); + return std::shared_ptr>(std::move(Snap), + &Snap->Pointers); } } // namespace clangd Index: clang-tools-extra/trunk/clangd/index/dex/DexIndex.h =================================================================== --- clang-tools-extra/trunk/clangd/index/dex/DexIndex.h +++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.h @@ -43,6 +43,9 @@ /// accessible as long as `Symbols` is kept alive. void build(std::shared_ptr> Symbols); + /// \brief Build index from a symbol slab. + static std::unique_ptr build(SymbolSlab Slab); + bool fuzzyFind(const FuzzyFindRequest &Req, llvm::function_ref Callback) const override; Index: clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp +++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp @@ -69,6 +69,12 @@ } } +std::unique_ptr DexIndex::build(SymbolSlab Slab) { + auto Idx = llvm::make_unique(); + 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/trunk/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/trunk/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 CompileCommandsDir( @@ -185,6 +189,11 @@ "'compile_commands.json' files")), llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden); +static llvm::cl::opt + 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) {