[PATCH] D149165: [clangd] Deduplicate missing-include findings

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 00:27:45 PDT 2023


kadircet marked 3 inline comments as done.
kadircet added inline comments.


================
Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:419
       });
+  // Put possibly equal diagnostics together for deduplication.
+  // The duplicates might be from macro arguments that get expanded multiple
----------------
VitaNuo wrote:
> Could you move the below to a separate function with a descriptive name? IMO taking care of the special cases inline makes functions very long and distracts the reader from their main purpose.
but this is not a special case, this is still part of "missing include information gathering", and is being applied to all of the findings (just like how all the used headers get accumulated in a `set`, the only problem is members of `MissingIncludeDiagInfo` is hard to order, hence we can't directly use a `set`)


================
Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:432
+  });
+  MissingIncludes.erase(llvm::unique(MissingIncludes), MissingIncludes.end());
   std::vector<const Inclusion *> UnusedIncludes =
----------------
VitaNuo wrote:
> Nit: maybe add a comment explaining that `llvm::unique` returns a past-the-end iterator after deduplicating elements? I've spent a bit of time deciphering this line.
yeah the language isn't really helpful in that regard but unfortunately `unique & erase` pattern is pretty much the idiomatic way of deduplicating a sorted container. I can add it here but we have some more mentions of it across the code that doesn't have any explanations. so I am not sure what kind of weight it would carry.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149165/new/

https://reviews.llvm.org/D149165



More information about the cfe-commits mailing list