[PATCH] D42113: [clangd] Deduplicate symbols collected in global-symbol-builder tool.

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 10:03:24 PST 2018


ioeric created this revision.
ioeric added reviewers: bkramer, sammccall.
Herald added subscribers: cfe-commits, ilya-biryukov, klimek.

After https://reviews.llvm.org/D42111, the executor framework no longer deduplicate tool results.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42113

Files:
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp


Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===================================================================
--- clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -105,7 +105,17 @@
     llvm::errs() << llvm::toString(std::move(Err)) << "\n";
   }
 
+  // Deduplicate the result by key.
+  // FIXME(ioeric): we need a better way to merge symbols with the same key. For
+  // example, class forward-declarations can have the same key as the class
+  // definition, and we should merge them instead of ignoring one of them. We
+  // would also need to aggregate signals like usage count when they are added.
+  llvm::StringMap<llvm::StringRef> ReducedSymbols;
   Executor->get()->getToolResults()->forEachResult(
-      [](llvm::StringRef, llvm::StringRef Value) { llvm::outs() << Value; });
+      [&ReducedSymbols](llvm::StringRef Key, llvm::StringRef Value) {
+        ReducedSymbols[Key] = Value;
+      });
+  for (const auto &Sym : ReducedSymbols)
+    llvm::outs() << Sym.second;
   return 0;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42113.129984.patch
Type: text/x-patch
Size: 1094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180116/84235e04/attachment.bin>


More information about the cfe-commits mailing list