This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Deduplicate missing-include findings
ClosedPublic

Authored by kadircet on Apr 25 2023, 9:52 AM.

Diff Detail

Event Timeline

kadircet created this revision.Apr 25 2023, 9:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 9:52 AM
Herald added a subscriber: arphaman. · View Herald Transcript
kadircet requested review of this revision.Apr 25 2023, 9:52 AM

Thank you!

clang-tools-extra/clangd/IncludeCleaner.cpp
419

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.

432

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.

clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
417

Nit: move )cpp"); to the next line please.

421

Nit: use the same style for multiline strings, i.e., R"cpp(.

423

Nit: move closing tokens of the multiline string to next line.

kadircet marked 3 inline comments as done.Apr 26 2023, 12:27 AM
kadircet added inline comments.
clang-tools-extra/clangd/IncludeCleaner.cpp
419

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)

432

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.

kadircet updated this revision to Diff 517076.Apr 26 2023, 12:27 AM
  • Reorganize string literals in tests
VitaNuo accepted this revision.Apr 26 2023, 1:32 AM
This revision is now accepted and ready to land.Apr 26 2023, 1:32 AM
This revision was landed with ongoing or failed builds.Apr 26 2023, 1:40 AM
This revision was automatically updated to reflect the committed changes.

Hello! After this change IncludeCleaner.GenerateMissingHeaderDiags unit test from ClangdTests.exe is failing on Windows for Debug build. Could you please take a look.
It looks like error appears because comparator doesn't satisfy strict weak ordering.
I.e. it fails on verification of the comparator (with "invalid comparator" message) at the following line:

MissingIncludes.erase(llvm::unique(MissingIncludes), MissingIncludes.end());
[----------] 1 test from IncludeCleaner
[ RUN      ] IncludeCleaner.GenerateMissingHeaderDiags
Built preamble of size 193724 for file C:\clangd-test\foo.cpp version null in 0.07 seconds
Exception Code: 0x80000003
0x00007FF66CA142FE, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5D342FE byte(s), std::_Debug_lt_pred<`clang::clangd::computeIncludeCleanerFindings'::`2'::<lambda_2> &,clang::clangd::MissingIncludeDiagInfo &,clang::clangd::MissingIncludeDiagInfo &,0>() + 0x8E byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.33.31629\include\xutility, line 1532 + 0x55 byte(s)
0x00007FF66CA1645F, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5D3645F byte(s), std::_Insertion_sort_unchecked<clang::clangd::MissingIncludeDiagInfo *,`clang::clangd::computeIncludeCleanerFindings'::`2'::<lambda_2> >() + 0xAF byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.33.31629\include\algorithm, line 7154 + 0x1A byte(s)
0x00007FF66CA19D05, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5D39D05 byte(s), std::stable_sort<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<clang::clangd::MissingIncludeDiagInfo> > >,`clang::clangd::computeIncludeCleanerFindings'::`2'::<lambda_2> >() + 0xC5 byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.33.31629\include\algorithm, line 7714 + 0x0 byte(s)
0x00007FF66CA19C18, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5D39C18 byte(s), llvm::stable_sort<std::vector<clang::clangd::MissingIncludeDiagInfo,std::allocator<clang::clangd::MissingIncludeDiagInfo> > &,`clang::clangd::computeIncludeCleanerFindings'::`2'::<lambda_2> >() + 0x68 byte(s), C:\iusers\againull\llvm-project\llvm\include\llvm\ADT\STLExtras.h, line 2070 + 0x0 byte(s)
0x00007FF66CA0CC3A, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5D2CC3A byte(s), clang::clangd::computeIncludeCleanerFindings() + 0x3FA byte(s), C:\iusers\againull\llvm-project\clang-tools-extra\clangd\IncludeCleaner.cpp, line 433 + 0x0 byte(s)
0x00007FF66CA0CF74, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5D2CF74 byte(s), clang::clangd::issueIncludeCleanerDiagnostics() + 0xF4 byte(s), C:\iusers\againull\llvm-project\clang-tools-extra\clangd\IncludeCleaner.cpp, line 561 + 0x15 byte(s)
0x00007FF66C1E2385, C:\iusers\againull\llvm-project\build\tools\clang\tools\extra\clangd\unittests\ClangdTests.exe(0x00007FF666CE0000) + 0x5502385 byte(s), clang::clangd::ParsedAST::build() + 0x2C15 byte(s),
C:\iusers\againull\llvm-project\clang-tools-extra\clangd\ParsedAST.cpp, line 691 + 0x88 byte(s)
...