[PATCH] D52274: [clangd] Collect and store expected types in the index
This revision was automatically updated to reflect the committed changes. Closed by commit rL347560: [clangd] Collect and store expected types in the index (authored by ibiryukov, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D52274/new/ https://reviews.llvm.org/D52274 Files: clang-tools-extra/trunk/clangd/index/Index.h clang-tools-extra/trunk/clangd/index/Serialization.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp Index: clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp === --- clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp +++ clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp @@ -197,6 +197,7 @@ IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); +IO.mapOptional("Type", Sym.Type); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); } }; Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp === --- clang-tools-extra/trunk/clangd/index/Serialization.cpp +++ clang-tools-extra/trunk/clangd/index/Serialization.cpp @@ -264,6 +264,7 @@ writeVar(Strings.index(Sym.CompletionSnippetSuffix), OS); writeVar(Strings.index(Sym.Documentation), OS); writeVar(Strings.index(Sym.ReturnType), OS); + writeVar(Strings.index(Sym.Type), OS); auto WriteInclude = [&](const Symbol::IncludeHeaderWithReferences ) { writeVar(Strings.index(Include.IncludeHeader), OS); @@ -290,6 +291,7 @@ Sym.CompletionSnippetSuffix = Data.consumeString(Strings); Sym.Documentation = Data.consumeString(Strings); Sym.ReturnType = Data.consumeString(Strings); + Sym.Type = Data.consumeString(Strings); Sym.IncludeHeaders.resize(Data.consumeVar()); for (auto : Sym.IncludeHeaders) { I.IncludeHeader = Data.consumeString(Strings); @@ -339,7 +341,7 @@ // The current versioning scheme is simple - non-current versions are rejected. // If you make a breaking change, bump this version number to invalidate stored // data. Later we may want to support some backward compatibility. -constexpr static uint32_t Version = 7; +constexpr static uint32_t Version = 8; Expected readRIFF(StringRef Data) { auto RIFF = riff::readFile(Data); Index: clang-tools-extra/trunk/clangd/index/Index.h === --- clang-tools-extra/trunk/clangd/index/Index.h +++ clang-tools-extra/trunk/clangd/index/Index.h @@ -10,6 +10,7 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" @@ -242,6 +243,10 @@ /// e.g. return type of a function, or type of a variable. llvm::StringRef ReturnType; + /// Raw representation of the OpaqueType of the symbol, used for scoring + /// purposes. + llvm::StringRef Type; + struct IncludeHeaderWithReferences { IncludeHeaderWithReferences() = default; @@ -300,6 +305,7 @@ CB(S.CompletionSnippetSuffix); CB(S.Documentation); CB(S.ReturnType); + CB(S.Type); auto RawCharPointerCB = [](const char *) { llvm::StringRef S(P); CB(S); Index: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + if (S.Flags & Symbol::IndexedForCodeCompletion) { +if (auto T = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion)) + S.Type = T->raw(); + } + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp === --- clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp +++ clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp @@ -197,6 +197,7 @@ IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); +IO.mapOptional("Type", Sym.Type); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); } }; Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp === --- clang-tools-extra/trunk/clangd/index/Serialization.cpp +++ clang-tools-extra/trunk/clangd/index/Serialization.cpp @@ -264,6 +264,7
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov updated this revision to Diff 175254. ilya-biryukov added a comment. - Remove unused #include Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D52274/new/ https://reviews.llvm.org/D52274 Files: clangd/index/Index.h clangd/index/Serialization.cpp clangd/index/SymbolCollector.cpp clangd/index/YAMLSerialization.cpp Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -197,6 +197,7 @@ IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); +IO.mapOptional("Type", Sym.Type); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + if (S.Flags & Symbol::IndexedForCodeCompletion) { +if (auto T = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion)) + S.Type = T->raw(); + } + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Serialization.cpp === --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -264,6 +264,7 @@ writeVar(Strings.index(Sym.CompletionSnippetSuffix), OS); writeVar(Strings.index(Sym.Documentation), OS); writeVar(Strings.index(Sym.ReturnType), OS); + writeVar(Strings.index(Sym.Type), OS); auto WriteInclude = [&](const Symbol::IncludeHeaderWithReferences ) { writeVar(Strings.index(Include.IncludeHeader), OS); @@ -290,6 +291,7 @@ Sym.CompletionSnippetSuffix = Data.consumeString(Strings); Sym.Documentation = Data.consumeString(Strings); Sym.ReturnType = Data.consumeString(Strings); + Sym.Type = Data.consumeString(Strings); Sym.IncludeHeaders.resize(Data.consumeVar()); for (auto : Sym.IncludeHeaders) { I.IncludeHeader = Data.consumeString(Strings); @@ -339,7 +341,7 @@ // The current versioning scheme is simple - non-current versions are rejected. // If you make a breaking change, bump this version number to invalidate stored // data. Later we may want to support some backward compatibility. -constexpr static uint32_t Version = 7; +constexpr static uint32_t Version = 8; Expected readRIFF(StringRef Data) { auto RIFF = riff::readFile(Data); Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,6 +10,7 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" @@ -242,6 +243,10 @@ /// e.g. return type of a function, or type of a variable. llvm::StringRef ReturnType; + /// Raw representation of the OpaqueType of the symbol, used for scoring + /// purposes. + llvm::StringRef Type; + struct IncludeHeaderWithReferences { IncludeHeaderWithReferences() = default; @@ -300,6 +305,7 @@ CB(S.CompletionSnippetSuffix); CB(S.Documentation); CB(S.ReturnType); + CB(S.Type); auto RawCharPointerCB = [](const char *) { llvm::StringRef S(P); CB(S); Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -197,6 +197,7 @@ IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); +IO.mapOptional("Type", Sym.Type); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + if (S.Flags & Symbol::IndexedForCodeCompletion) { +if (auto T = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion)) + S.Type = T->raw(); + } + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Serialization.cpp === --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -264,6 +264,7 @@ writeVar(Strings.index(Sym.CompletionSnippetSuffix), OS);
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov marked 3 inline comments as done. ilya-biryukov added inline comments. Comment at: clangd/index/Index.h:283 + /// Type of the symbol, used for scoring purposes. + llvm::StringRef Type; sammccall wrote: > either call this OpaqueType or point at in in the comment? > > I'd put this below the `ReturnType` string too, it seems out of place here. > But up to you. - Added a comment. OpaqueType would clash with the type name, something I'd prefer to avoid. - Moved to live after `ReturnType`. I initially thought it'd be nice to keep them apart, since `ReturnType` is for showing it to the users and `Type` is for scoring. Now that I think about it does not look like a good idea, since keeping them apart means the user might read the comment for one of them, but not the other and end up inferring the other one on their own. Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D52274/new/ https://reviews.llvm.org/D52274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov updated this revision to Diff 175246. ilya-biryukov marked an inline comment as done. ilya-biryukov added a comment. - Bump the RIFF version number - Place the Type field after the ReturnType - Address other comments Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D52274/new/ https://reviews.llvm.org/D52274 Files: clangd/index/Index.h clangd/index/Serialization.cpp clangd/index/SymbolCollector.cpp clangd/index/YAMLSerialization.cpp Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -197,6 +197,7 @@ IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); +IO.mapOptional("Type", Sym.Type); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + if (S.Flags & Symbol::IndexedForCodeCompletion) { +if (auto T = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion)) + S.Type = T->raw(); + } + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Serialization.cpp === --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -264,6 +264,7 @@ writeVar(Strings.index(Sym.CompletionSnippetSuffix), OS); writeVar(Strings.index(Sym.Documentation), OS); writeVar(Strings.index(Sym.ReturnType), OS); + writeVar(Strings.index(Sym.Type), OS); auto WriteInclude = [&](const Symbol::IncludeHeaderWithReferences ) { writeVar(Strings.index(Include.IncludeHeader), OS); @@ -290,6 +291,7 @@ Sym.CompletionSnippetSuffix = Data.consumeString(Strings); Sym.Documentation = Data.consumeString(Strings); Sym.ReturnType = Data.consumeString(Strings); + Sym.Type = Data.consumeString(Strings); Sym.IncludeHeaders.resize(Data.consumeVar()); for (auto : Sym.IncludeHeaders) { I.IncludeHeader = Data.consumeString(Strings); @@ -339,7 +341,7 @@ // The current versioning scheme is simple - non-current versions are rejected. // If you make a breaking change, bump this version number to invalidate stored // data. Later we may want to support some backward compatibility. -constexpr static uint32_t Version = 7; +constexpr static uint32_t Version = 8; Expected readRIFF(StringRef Data) { auto RIFF = riff::readFile(Data); Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,12 +10,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -242,6 +244,10 @@ /// e.g. return type of a function, or type of a variable. llvm::StringRef ReturnType; + /// Raw representation of the OpaqueType of the symbol, used for scoring + /// purposes. + llvm::StringRef Type; + struct IncludeHeaderWithReferences { IncludeHeaderWithReferences() = default; @@ -300,6 +306,7 @@ CB(S.CompletionSnippetSuffix); CB(S.Documentation); CB(S.ReturnType); + CB(S.Type); auto RawCharPointerCB = [](const char *) { llvm::StringRef S(P); CB(S); Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -197,6 +197,7 @@ IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix); IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); +IO.mapOptional("Type", Sym.Type); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + if (S.Flags & Symbol::IndexedForCodeCompletion) { +if (auto T = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion)) + S.Type = T->raw(); + } + S.Origin = Opts.Origin; if
[PATCH] D52274: [clangd] Collect and store expected types in the index
sammccall accepted this revision. sammccall added inline comments. This revision is now accepted and ready to land. Comment at: clangd/index/Index.h:283 + /// Type of the symbol, used for scoring purposes. + llvm::StringRef Type; either call this OpaqueType or point at in in the comment? I'd put this below the `ReturnType` string too, it seems out of place here. But up to you. Comment at: clangd/index/SymbolCollector.cpp:591 + llvm::Optional Type; + if (S.Flags & Symbol::IndexedForCodeCompletion) +Type = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion); nit: like this? ``` if (indexed for code completion) if (auto T = ...) S.Type = T->raw(); ``` Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D52274/new/ https://reviews.llvm.org/D52274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov added inline comments. Comment at: clangd/index/Index.cpp:118 +static void own(Symbol , UniqueStringSaver , +BumpPtrAllocator ) { visitStrings(S, [&](StringRef ) { V = Strings.save(V); }); sammccall wrote: > why these changes? Sorry, leftovers from the times we had arrays of sha hashes. Comment at: clangd/index/SymbolCollector.h:80 +/// Collect type information. Used to improve code completion ranking. +bool CollectTypes = true; }; sammccall wrote: > Why make this an option? Is it expensive in time/size? Was there for experiments. They're not expensive, removed it. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov updated this revision to Diff 175104. ilya-biryukov added a comment. - Remove another accidental change Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 Files: clangd/index/Index.h clangd/index/Serialization.cpp clangd/index/SymbolCollector.cpp clangd/index/YAMLSerialization.cpp Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -198,6 +198,7 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +IO.mapOptional("Type", Sym.Type); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + llvm::Optional Type; + if (S.Flags & Symbol::IndexedForCodeCompletion) +Type = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion); + S.Type = Type ? Type->raw() : ""; + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Serialization.cpp === --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -272,6 +272,7 @@ writeVar(Sym.IncludeHeaders.size(), OS); for (const auto : Sym.IncludeHeaders) WriteInclude(Include); + writeVar(Strings.index(Sym.Type), OS); } Symbol readSymbol(Reader , ArrayRef Strings) { @@ -295,6 +296,7 @@ I.IncludeHeader = Data.consumeString(Strings); I.References = Data.consumeVar(); } + Sym.Type = Data.consumeString(Strings); return Sym; } Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,12 +10,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -278,6 +280,9 @@ ImplementationDetail = 1 << 2, }; + /// Type of the symbol, used for scoring purposes. + llvm::StringRef Type; + SymbolFlag Flags = SymbolFlag::None; /// FIXME: also add deprecation message and fixit? }; @@ -311,6 +316,7 @@ for (auto : S.IncludeHeaders) CB(Include.IncludeHeader); + CB(S.Type); } // Computes query-independent quality score for a Symbol. Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -198,6 +198,7 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +IO.mapOptional("Type", Sym.Type); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + llvm::Optional Type; + if (S.Flags & Symbol::IndexedForCodeCompletion) +Type = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion); + S.Type = Type ? Type->raw() : ""; + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Serialization.cpp === --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -272,6 +272,7 @@ writeVar(Sym.IncludeHeaders.size(), OS); for (const auto : Sym.IncludeHeaders) WriteInclude(Include); + writeVar(Strings.index(Sym.Type), OS); } Symbol readSymbol(Reader , ArrayRef Strings) { @@ -295,6 +296,7 @@ I.IncludeHeader = Data.consumeString(Strings); I.References = Data.consumeVar(); } + Sym.Type = Data.consumeString(Strings); return Sym; } Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,12 +10,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov updated this revision to Diff 175103. ilya-biryukov marked an inline comment as done. ilya-biryukov added a comment. - Remove accidental changes - Add types to binary serialization Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 Files: clangd/index/Index.h clangd/index/Serialization.cpp clangd/index/SymbolCollector.cpp clangd/index/YAMLSerialization.cpp clangd/indexer/IndexerMain.cpp Index: clangd/indexer/IndexerMain.cpp === --- clangd/indexer/IndexerMain.cpp +++ clangd/indexer/IndexerMain.cpp @@ -42,9 +42,8 @@ IndexActionFactory(IndexFileIn ) : Result(Result) {} clang::FrontendAction *create() override { -SymbolCollector::Options Opts; return createStaticIndexingAction( - Opts, + SymbolCollector::Options(), [&](SymbolSlab S) { // Merge as we go. std::lock_guard Lock(SymbolsMu); Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -198,6 +198,7 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +IO.mapOptional("Type", Sym.Type); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + llvm::Optional Type; + if (S.Flags & Symbol::IndexedForCodeCompletion) +Type = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion); + S.Type = Type ? Type->raw() : ""; + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Serialization.cpp === --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -272,6 +272,7 @@ writeVar(Sym.IncludeHeaders.size(), OS); for (const auto : Sym.IncludeHeaders) WriteInclude(Include); + writeVar(Strings.index(Sym.Type), OS); } Symbol readSymbol(Reader , ArrayRef Strings) { @@ -295,6 +296,7 @@ I.IncludeHeader = Data.consumeString(Strings); I.References = Data.consumeVar(); } + Sym.Type = Data.consumeString(Strings); return Sym; } Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,12 +10,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -278,6 +280,9 @@ ImplementationDetail = 1 << 2, }; + /// Type of the symbol, used for scoring purposes. + llvm::StringRef Type; + SymbolFlag Flags = SymbolFlag::None; /// FIXME: also add deprecation message and fixit? }; @@ -311,6 +316,7 @@ for (auto : S.IncludeHeaders) CB(Include.IncludeHeader); + CB(S.Type); } // Computes query-independent quality score for a Symbol. Index: clangd/indexer/IndexerMain.cpp === --- clangd/indexer/IndexerMain.cpp +++ clangd/indexer/IndexerMain.cpp @@ -42,9 +42,8 @@ IndexActionFactory(IndexFileIn ) : Result(Result) {} clang::FrontendAction *create() override { -SymbolCollector::Options Opts; return createStaticIndexingAction( - Opts, + SymbolCollector::Options(), [&](SymbolSlab S) { // Merge as we go. std::lock_guard Lock(SymbolsMu); Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -198,6 +198,7 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +IO.mapOptional("Type", Sym.Type); } }; Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + llvm::Optional Type; + if (S.Flags & Symbol::IndexedForCodeCompletion) +Type =
[PATCH] D52274: [clangd] Collect and store expected types in the index
sammccall added inline comments. Comment at: clangd/index/Index.cpp:118 +static void own(Symbol , UniqueStringSaver , +BumpPtrAllocator ) { visitStrings(S, [&](StringRef ) { V = Strings.save(V); }); why these changes? Comment at: clangd/index/SymbolCollector.h:80 +/// Collect type information. Used to improve code completion ranking. +bool CollectTypes = true; }; Why make this an option? Is it expensive in time/size? Comment at: clangd/index/YAMLSerialization.cpp:182 IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +IO.mapOptional("Type", Sym.Type); } also need to update the binary serialization? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov updated this revision to Diff 173340. ilya-biryukov added a comment. - Rebase and update after dependent changes. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 Files: clangd/index/Index.cpp clangd/index/Index.h clangd/index/SymbolCollector.cpp clangd/index/SymbolCollector.h clangd/index/YAMLSerialization.cpp clangd/indexer/IndexerMain.cpp Index: clangd/indexer/IndexerMain.cpp === --- clangd/indexer/IndexerMain.cpp +++ clangd/indexer/IndexerMain.cpp @@ -37,12 +37,18 @@ "binary RIFF format")), cl::init(IndexFileFormat::RIFF)); +static llvm::cl::opt +CollectTypes("collect-types", + llvm::cl::desc("Collect type information during indexing"), + llvm::cl::init(false), llvm::cl::Hidden); + class IndexActionFactory : public tooling::FrontendActionFactory { public: IndexActionFactory(IndexFileIn ) : Result(Result) {} clang::FrontendAction *create() override { SymbolCollector::Options Opts; +Opts.CollectTypes = CollectTypes; return createStaticIndexingAction( Opts, [&](SymbolSlab S) { Index: clangd/index/YAMLSerialization.cpp === --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -179,6 +179,7 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +IO.mapOptional("Type", Sym.Type); } }; Index: clangd/index/SymbolCollector.h === --- clangd/index/SymbolCollector.h +++ clangd/index/SymbolCollector.h @@ -76,6 +76,8 @@ /// If this is set, only collect symbols/references from a file if /// `FileFilter(SM, FID)` is true. If not set, all files are indexed. std::function FileFilter = nullptr; +/// Collect type information. Used to improve code completion ranking. +bool CollectTypes = true; }; SymbolCollector(Options Opts); Index: clangd/index/SymbolCollector.cpp === --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -596,6 +596,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + llvm::Optional Type; + if (Opts.CollectTypes && (S.Flags & Symbol::IndexedForCodeCompletion)) +Type = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion); + S.Type = Type ? Type->rawStr() : ""; + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/Index.h === --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,12 +10,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -270,6 +272,9 @@ ImplementationDetail = 1 << 2, }; + /// Type of the symbol, used for scoring purposes. + llvm::StringRef Type; + SymbolFlag Flags = SymbolFlag::None; /// FIXME: also add deprecation message and fixit? }; @@ -285,7 +290,8 @@ // Invokes Callback with each StringRef& contained in the Symbol. // Useful for deduplicating backing strings. -template void visitStrings(Symbol , const Callback ) { +inline void visitStrings(Symbol , + llvm::function_ref CB) { CB(S.Name); CB(S.Scope); CB(S.CanonicalDeclaration.FileURI); @@ -296,6 +302,7 @@ CB(S.ReturnType); for (auto : S.IncludeHeaders) CB(Include.IncludeHeader); + CB(S.Type); } // Computes query-independent quality score for a Symbol. Index: clangd/index/Index.cpp === --- clangd/index/Index.cpp +++ clangd/index/Index.cpp @@ -114,18 +114,19 @@ } // Copy the underlying data of the symbol into the owned arena. -static void own(Symbol , UniqueStringSaver ) { +static void own(Symbol , UniqueStringSaver , +BumpPtrAllocator ) { visitStrings(S, [&](StringRef ) { V = Strings.save(V); }); } void SymbolSlab::Builder::insert(const Symbol ) { auto R = SymbolIndex.try_emplace(S.ID, Symbols.size()); if (R.second) { Symbols.push_back(S); -own(Symbols.back(), UniqueStrings); +own(Symbols.back(), UniqueStrings, Arena); } else { auto = Symbols[R.first->second] = S; -own(Copy, UniqueStrings); +
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov planned changes to this revision. ilya-biryukov added a comment. Need to store the types in RIFF format too Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52274: [clangd] Collect and store expected types in the index
ilya-biryukov created this revision. ilya-biryukov added reviewers: ioeric, sammccall. Herald added subscribers: kadircet, arphaman, jkorous, MaskRay. And add a hidden option to control whether the types are collected. For experiments, will be removed when expected types implementation is stabilized. The index size is almost unchanged, e.g. the YAML index for all clangd sources increased from 53MB to 54MB. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52274 Files: clangd/index/Index.cpp clangd/index/Index.h clangd/index/Serialization.cpp clangd/index/SymbolCollector.cpp clangd/index/SymbolCollector.h clangd/index/SymbolYAML.cpp clangd/indexer/IndexerMain.cpp Index: clangd/indexer/IndexerMain.cpp === --- clangd/indexer/IndexerMain.cpp +++ clangd/indexer/IndexerMain.cpp @@ -67,6 +67,11 @@ clEnumValN(Binary, "binary", "binary RIFF format")), llvm::cl::init(YAML)); +static llvm::cl::opt +CollectTypes("collect-types", + llvm::cl::desc("Collect type information during indexing"), + llvm::cl::init(false), llvm::cl::Hidden); + /// Responsible for aggregating symbols from each processed file and producing /// the final results. All methods in this class must be thread-safe, /// 'consumeSymbols' may be called from multiple threads. @@ -142,6 +147,7 @@ CollectorOpts.CollectIncludePath = true; CollectorOpts.CountReferences = true; CollectorOpts.Origin = SymbolOrigin::Static; +CollectorOpts.CollectTypes = CollectTypes; auto Includes = llvm::make_unique(); addSystemHeadersMapping(Includes.get()); CollectorOpts.Includes = Includes.get(); Index: clangd/index/SymbolYAML.cpp === --- clangd/index/SymbolYAML.cpp +++ clangd/index/SymbolYAML.cpp @@ -8,6 +8,7 @@ //===--===// #include "SymbolYAML.h" +#include "ExpectedTypes.h" #include "Index.h" #include "Serialization.h" #include "Trace.h" @@ -21,10 +22,12 @@ LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(clang::clangd::Symbol) LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Symbol::IncludeHeaderWithReferences) +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::SType); namespace llvm { namespace yaml { +using clang::clangd::SType; using clang::clangd::Symbol; using clang::clangd::SymbolID; using clang::clangd::SymbolLocation; @@ -94,6 +97,44 @@ } }; +template <> struct ScalarTraits { + static void output(const SType , void *, llvm::raw_ostream ) { +Out << Value.toHexStr(); + } + static StringRef input(StringRef Scalar, void *, SType ) { +Type = SType::fromHexStr(Scalar); +return StringRef(); + } + + static QuotingType mustQuote(StringRef) { return QuotingType::None; } +}; + +// A YamlIO normalizer for fields of type "ArrayRef" with underlying +// array allocated on an arena. Normalizes to std::vector, so traits +// should be provided for std::vector. +template struct ArenaArrayPtr { + ArenaArrayPtr(IO &) {} + ArenaArrayPtr(IO &, llvm::ArrayRef D) { +Normalized.assign(D.begin(), D.end()); + } + + llvm::ArrayRef denormalize(IO ) { +assert(IO.getContext() && "Expecting an arena (as context) to allocate " + "data for read symbols."); +if (Normalized.empty()) + return llvm::ArrayRef(); +// Allocate an array on the Arena and copy-construct the objects. +auto *Allocator = static_cast(IO.getContext()); +T *Items = Allocator->Allocate(Normalized.size()); +for (size_t I = 0, Size = Normalized.size(); I < Size; ++I) + new (Items + I) T(Normalized[I]); +// Return a reference to the array. +return llvm::ArrayRef(Items, Items + Normalized.size()); + } + + std::vector Normalized; +}; + template <> struct MappingTraits { static void mapping(IO , Symbol ) { MappingNormalization NSymbolID(IO, Sym.ID); @@ -113,6 +154,9 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); +MappingNormalization, llvm::ArrayRef> NTypes( +IO, Sym.Types); +IO.mapOptional("Types", NTypes->Normalized); } }; @@ -169,7 +213,9 @@ namespace clangd { SymbolSlab symbolsFromYAML(llvm::StringRef YAMLContent) { - llvm::yaml::Input Yin(YAMLContent); + // Store data of pointer fields (excl. StringRef) like `Types`. + llvm::BumpPtrAllocator Arena; + llvm::yaml::Input Yin(YAMLContent, ); std::vector S; Yin >> S; Index: clangd/index/SymbolCollector.h === --- clangd/index/SymbolCollector.h +++ clangd/index/SymbolCollector.h @@ -62,6 +62,8 @@ /// collect macros. For example, `indexTopLevelDecls` will not index any /// macro even if this is true. bool CollectMacro =