aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-09-04 16:16:50 +0000
committerSam McCall <sam.mccall@gmail.com>2018-09-04 16:16:50 +0000
commit50f3631057f717448ba34b4175daaa81215fbd5e (patch)
tree918408ccfd12bfc7187889ec77d341d17ae386a7 /clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
parent[clangd] NFC: Change quality type to float (diff)
downloadllvm-project-50f3631057f717448ba34b4175daaa81215fbd5e.tar.gz
llvm-project-50f3631057f717448ba34b4175daaa81215fbd5e.tar.bz2
llvm-project-50f3631057f717448ba34b4175daaa81215fbd5e.zip
[clangd] Define a compact binary serialization fomat for symbol slab/index.
Summary: This is intended to replace the current YAML format for general use. It's ~10x more compact than YAML, and ~40% more compact than gzipped YAML: llvmidx.riff = 20M, llvmidx.yaml = 272M, llvmidx.yaml.gz = 32M It's also simpler/faster to read and write. The format is a RIFF container (chunks of (type, size, data)) with: - a compressed string table - simple binary encoding of symbols (with varints for compactness) It can be extended to include occurrences, Dex posting lists, etc. There's no rich backwards-compatibility scheme, but a version number is included so we can detect incompatible files and do ad-hoc back-compat. Alternatives considered: - compressed YAML or JSON: bulky and slow to load - llvm bitstream: confusing model and libraries are hard to use. My attempt produced slightly larger files, and the code was longer and slower. - protobuf or similar: would be really nice (esp for back-compat) but the dependency is a big hassle - ad-hoc binary format without a container: it seems clear we're going to add posting lists and occurrences here, and that they will benefit from sharing a string table. The container makes it easy to debug these pieces in isolation, and make them optional. Reviewers: ioeric Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51585 llvm-svn: 341375
Diffstat (limited to 'clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp')
-rw-r--r--clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp79
1 files changed, 0 insertions, 79 deletions
diff --git a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
index cc3c7d186226..6688daee1901 100644
--- a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
@@ -48,7 +48,6 @@ using testing::UnorderedElementsAreArray;
MATCHER_P(Labeled, Label, "") {
return (arg.Name + arg.Signature).str() == Label;
}
-MATCHER(HasReturnType, "") { return !arg.ReturnType.empty(); }
MATCHER_P(ReturnType, D, "") { return arg.ReturnType == D; }
MATCHER_P(Doc, D, "") { return arg.Documentation == D; }
MATCHER_P(Snippet, S, "") {
@@ -744,84 +743,6 @@ TEST_F(SymbolCollectorTest, Snippet) {
Snippet("ff(${1:int x}, ${2:double y})"))));
}
-TEST_F(SymbolCollectorTest, YAMLConversions) {
- const std::string YAML1 = R"(
----
-ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
-Name: 'Foo1'
-Scope: 'clang::'
-SymInfo:
- Kind: Function
- Lang: Cpp
-CanonicalDeclaration:
- FileURI: file:///path/foo.h
- Start:
- Line: 1
- Column: 0
- End:
- Line: 1
- Column: 1
-IsIndexedForCodeCompletion: true
-Documentation: 'Foo doc'
-ReturnType: 'int'
-IncludeHeaders:
- - Header: 'include1'
- References: 7
- - Header: 'include2'
- References: 3
-...
-)";
- const std::string YAML2 = R"(
----
-ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF858
-Name: 'Foo2'
-Scope: 'clang::'
-SymInfo:
- Kind: Function
- Lang: Cpp
-CanonicalDeclaration:
- FileURI: file:///path/bar.h
- Start:
- Line: 1
- Column: 0
- End:
- Line: 1
- Column: 1
-IsIndexedForCodeCompletion: false
-Signature: '-sig'
-CompletionSnippetSuffix: '-snippet'
-...
-)";
-
- auto Symbols1 = symbolsFromYAML(YAML1);
-
- EXPECT_THAT(Symbols1,
- UnorderedElementsAre(AllOf(QName("clang::Foo1"), Labeled("Foo1"),
- Doc("Foo doc"), ReturnType("int"),
- DeclURI("file:///path/foo.h"),
- ForCodeCompletion(true))));
- auto &Sym1 = *Symbols1.begin();
- EXPECT_THAT(Sym1.IncludeHeaders,
- UnorderedElementsAre(IncludeHeaderWithRef("include1", 7u),
- IncludeHeaderWithRef("include2", 3u)));
- auto Symbols2 = symbolsFromYAML(YAML2);
- EXPECT_THAT(Symbols2, UnorderedElementsAre(AllOf(
- QName("clang::Foo2"), Labeled("Foo2-sig"),
- Not(HasReturnType()), DeclURI("file:///path/bar.h"),
- ForCodeCompletion(false))));
-
- std::string ConcatenatedYAML;
- {
- llvm::raw_string_ostream OS(ConcatenatedYAML);
- SymbolsToYAML(Symbols1, OS);
- SymbolsToYAML(Symbols2, OS);
- }
- auto ConcatenatedSymbols = symbolsFromYAML(ConcatenatedYAML);
- EXPECT_THAT(ConcatenatedSymbols,
- UnorderedElementsAre(QName("clang::Foo1"),
- QName("clang::Foo2")));
-}
-
TEST_F(SymbolCollectorTest, IncludeHeaderSameAsFileURI) {
CollectorOpts.CollectIncludePath = true;
runSymbolCollector("class Foo {};", /*Main=*/"");