<< "-" << L.End.line() << ":" << L.End.column() << ")";
}
-SymbolID::SymbolID(StringRef USR)
- : HashValue(SHA1::hash(arrayRefFromStringRef(USR))) {}
+SymbolID::SymbolID(StringRef USR) {
+ auto Hash = SHA1::hash(arrayRefFromStringRef(USR));
+ static_assert(sizeof(Hash) >= RawSize, "RawSize larger than SHA1");
+ memcpy(HashValue.data(), Hash.data(), RawSize);
+}
raw_ostream &operator<<(raw_ostream &OS, const SymbolID &ID) {
return OS << toHex(ID.raw());
// The class identifies a particular C++ symbol (class, function, method, etc).
//
// As USRs (Unified Symbol Resolution) could be large, especially for functions
-// with long type arguments, SymbolID is using 160-bits SHA1(USR) values to
+// with long type arguments, SymbolID is using truncated SHA1(USR) values to
// guarantee the uniqueness of symbols while using a relatively small amount of
// memory (vs storing USRs directly).
//
return HashValue < Sym.HashValue;
}
- constexpr static size_t RawSize = 20;
+ // The stored hash is truncated to RawSize bytes.
+ // This trades off memory against the number of symbols we can handle.
+ // FIXME: can we reduce this further to 8 bytes?
+ constexpr static size_t RawSize = 16;
llvm::StringRef raw() const {
return StringRef(reinterpret_cast<const char *>(HashValue.data()), RawSize);
}
static SymbolID fromRaw(llvm::StringRef);
- // Returns a 40-bytes hex encoded string.
+ // Returns a hex encoded string.
std::string str() const;
static llvm::Expected<SymbolID> fromStr(llvm::StringRef);
// REFS ENCODING
// A refs section has data grouped by Symbol. Each symbol has:
-// - SymbolID: 20 bytes
+// - SymbolID: 16 bytes
// - NumRefs: varint
// - Ref[NumRefs]
// Fields of Ref are encoded in turn, see implementation.
// 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 = 5;
+constexpr static uint32_t Version = 6;
Expected<IndexFileIn> readRIFF(StringRef Data) {
auto RIFF = riff::readFile(Data);
const char *YAML = R"(
---
!Symbol
-ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
+ID: 057557CEBF6E6B2DD437FBF60CC58F35
Name: 'Foo1'
Scope: 'clang::'
SymInfo:
...
---
!Symbol
-ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF858
+ID: 057557CEBF6E6B2DD437FBF60CC58F36
Name: 'Foo2'
Scope: 'clang::'
SymInfo:
CompletionSnippetSuffix: '-snippet'
...
!Refs
-ID: 057557CEBF6E6B2DD437FBF60CC58F352D1DF856
+ID: 057557CEBF6E6B2DD437FBF60CC58F35
References:
- Kind: 4
Location:
auto ParsedYAML = readIndexFile(YAML);
ASSERT_TRUE(bool(ParsedYAML)) << ParsedYAML.takeError();
ASSERT_TRUE(bool(ParsedYAML->Symbols));
- EXPECT_THAT(
- *ParsedYAML->Symbols,
- UnorderedElementsAre(ID("057557CEBF6E6B2DD437FBF60CC58F352D1DF856"),
- ID("057557CEBF6E6B2DD437FBF60CC58F352D1DF858")));
+ EXPECT_THAT(*ParsedYAML->Symbols,
+ UnorderedElementsAre(ID("057557CEBF6E6B2DD437FBF60CC58F35"),
+ ID("057557CEBF6E6B2DD437FBF60CC58F36")));
auto Sym1 = *ParsedYAML->Symbols->find(
- cantFail(SymbolID::fromStr("057557CEBF6E6B2DD437FBF60CC58F352D1DF856")));
+ cantFail(SymbolID::fromStr("057557CEBF6E6B2DD437FBF60CC58F35")));
auto Sym2 = *ParsedYAML->Symbols->find(
- cantFail(SymbolID::fromStr("057557CEBF6E6B2DD437FBF60CC58F352D1DF858")));
+ cantFail(SymbolID::fromStr("057557CEBF6E6B2DD437FBF60CC58F36")));
EXPECT_THAT(Sym1, QName("clang::Foo1"));
EXPECT_EQ(Sym1.Signature, "");
EXPECT_TRUE(Sym2.Flags & Symbol::Deprecated);
ASSERT_TRUE(bool(ParsedYAML->Refs));
- EXPECT_THAT(*ParsedYAML->Refs,
- UnorderedElementsAre(
- Pair(cantFail(SymbolID::fromStr(
- "057557CEBF6E6B2DD437FBF60CC58F352D1DF856")),
- testing::SizeIs(1))));
+ EXPECT_THAT(
+ *ParsedYAML->Refs,
+ UnorderedElementsAre(
+ Pair(cantFail(SymbolID::fromStr("057557CEBF6E6B2DD437FBF60CC58F35")),
+ testing::SizeIs(1))));
auto Ref1 = ParsedYAML->Refs->begin()->second.front();
EXPECT_EQ(Ref1.Kind, RefKind::Reference);
EXPECT_EQ(Ref1.Location.FileURI, "file:///path/foo.cc");