[clangd] Get rid of move semantics to unbreak windows build bots
authorKadir Cetinkaya <kadircet@google.com>
Thu, 30 Apr 2020 14:40:56 +0000 (16:40 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Thu, 30 Apr 2020 14:43:50 +0000 (16:43 +0200)
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/FileIndex.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp

index 9880c6b..cc2c288 100644 (file)
@@ -199,19 +199,19 @@ void BackgroundIndex::update(
   // 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));
 
@@ -231,9 +231,9 @@ void BackgroundIndex::update(
       // 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);
     }
   }
index b6ee91d..79ec112 100644 (file)
@@ -379,13 +379,14 @@ void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,
       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(
index f1ddc02..371388e 100644 (file)
@@ -573,37 +573,42 @@ TEST(FileShardedIndexTest, Sharding) {
               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