// Build and store new slabs for each updated file.
for (const auto &FileIt : FilesToUpdate) {
auto Uri = FileIt.first();
- // ShardedIndex should always have a shard for a file in Index.Sources.
- auto IF = std::move(ShardedIndex.getShard(Uri).getValue());
+ auto IF = ShardedIndex.getShard(Uri);
+ assert(IF && "no shard for file in Index.Sources?");
PathRef Path = FileIt.getValue().first;
// Only store command line hash for main files of the TU, since our
// current model keeps only one version of a header file.
if (Path != MainFile)
- IF.Cmd.reset();
+ IF->Cmd.reset();
// We need to store shards before updating the index, since the latter
// consumes slabs.
// FIXME: Also skip serializing the shard if it is already up-to-date.
- if (auto Error = IndexStorageFactory(Path)->storeShard(Path, IF))
+ if (auto Error = IndexStorageFactory(Path)->storeShard(Path, *IF))
elog("Failed to write background-index shard for file {0}: {1}", Path,
std::move(Error));
// this thread sees the older version but finishes later. This should be
// rare in practice.
IndexedSymbols.update(
- Path, std::make_unique<SymbolSlab>(std::move(*IF.Symbols)),
- std::make_unique<RefSlab>(std::move(*IF.Refs)),
- std::make_unique<RelationSlab>(std::move(*IF.Relations)),
+ Path, std::make_unique<SymbolSlab>(std::move(*IF->Symbols)),
+ std::make_unique<RefSlab>(std::move(*IF->Refs)),
+ std::make_unique<RelationSlab>(std::move(*IF->Relations)),
Path == MainFile);
}
}
indexHeaderSymbols(Version, AST, std::move(PP), Includes);
FileShardedIndex ShardedIndex(std::move(IF));
for (auto Uri : ShardedIndex.getAllSources()) {
+ auto IF = ShardedIndex.getShard(Uri);
// We are using the key received from ShardedIndex, so it should always
// exist.
- auto IF = std::move(ShardedIndex.getShard(Uri).getValue());
+ assert(IF);
PreambleSymbols.update(
- Uri, std::make_unique<SymbolSlab>(std::move(*IF.Symbols)),
+ Uri, std::make_unique<SymbolSlab>(std::move(*IF->Symbols)),
std::make_unique<RefSlab>(),
- std::make_unique<RelationSlab>(std::move(*IF.Relations)),
+ std::make_unique<RelationSlab>(std::move(*IF->Relations)),
/*CountReferences=*/false);
}
PreambleIndex.reset(
UnorderedElementsAre(AHeaderUri, BHeaderUri, BSourceUri));
{
- auto Shard = *ShardedIndex.getShard(AHeaderUri);
- EXPECT_THAT(*Shard.Symbols, UnorderedElementsAre(QName("1")));
- EXPECT_THAT(*Shard.Refs, IsEmpty());
- EXPECT_THAT(*Shard.Relations, UnorderedElementsAre(Relation{
- Sym1.ID, RelationKind::BaseOf, Sym2.ID}));
- ASSERT_THAT(Shard.Sources->keys(), UnorderedElementsAre(AHeaderUri));
- EXPECT_THAT(Shard.Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
- EXPECT_TRUE(Shard.Cmd.hasValue());
+ auto Shard = ShardedIndex.getShard(AHeaderUri);
+ ASSERT_TRUE(Shard);
+ EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(QName("1")));
+ EXPECT_THAT(*Shard->Refs, IsEmpty());
+ EXPECT_THAT(
+ *Shard->Relations,
+ UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID}));
+ ASSERT_THAT(Shard->Sources->keys(), UnorderedElementsAre(AHeaderUri));
+ EXPECT_THAT(Shard->Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
+ EXPECT_TRUE(Shard->Cmd.hasValue());
}
{
- auto Shard = *ShardedIndex.getShard(BHeaderUri);
- EXPECT_THAT(*Shard.Symbols, UnorderedElementsAre(QName("2")));
- EXPECT_THAT(*Shard.Refs, IsEmpty());
- EXPECT_THAT(*Shard.Relations, UnorderedElementsAre(Relation{
- Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
- ASSERT_THAT(Shard.Sources->keys(),
+ auto Shard = ShardedIndex.getShard(BHeaderUri);
+ ASSERT_TRUE(Shard);
+ EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(QName("2")));
+ EXPECT_THAT(*Shard->Refs, IsEmpty());
+ EXPECT_THAT(
+ *Shard->Relations,
+ UnorderedElementsAre(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
+ ASSERT_THAT(Shard->Sources->keys(),
UnorderedElementsAre(BHeaderUri, AHeaderUri));
- EXPECT_THAT(Shard.Sources->lookup(BHeaderUri).DirectIncludes,
+ EXPECT_THAT(Shard->Sources->lookup(BHeaderUri).DirectIncludes,
UnorderedElementsAre(AHeaderUri));
- EXPECT_TRUE(Shard.Cmd.hasValue());
+ EXPECT_TRUE(Shard->Cmd.hasValue());
}
{
- auto Shard = *ShardedIndex.getShard(BSourceUri);
- EXPECT_THAT(*Shard.Symbols, UnorderedElementsAre(QName("2")));
- EXPECT_THAT(*Shard.Refs, UnorderedElementsAre(Pair(Sym1.ID, _)));
- EXPECT_THAT(*Shard.Relations, IsEmpty());
- ASSERT_THAT(Shard.Sources->keys(),
+ auto Shard = ShardedIndex.getShard(BSourceUri);
+ ASSERT_TRUE(Shard);
+ EXPECT_THAT(*Shard->Symbols, UnorderedElementsAre(QName("2")));
+ EXPECT_THAT(*Shard->Refs, UnorderedElementsAre(Pair(Sym1.ID, _)));
+ EXPECT_THAT(*Shard->Relations, IsEmpty());
+ ASSERT_THAT(Shard->Sources->keys(),
UnorderedElementsAre(BSourceUri, BHeaderUri));
- EXPECT_THAT(Shard.Sources->lookup(BSourceUri).DirectIncludes,
+ EXPECT_THAT(Shard->Sources->lookup(BSourceUri).DirectIncludes,
UnorderedElementsAre(BHeaderUri));
- EXPECT_TRUE(Shard.Cmd.hasValue());
+ EXPECT_TRUE(Shard->Cmd.hasValue());
}
}
} // namespace