This is an archive of the discontinued LLVM Phabricator instance.

[include-cleaner] Introduce support for always_keep pragma
ClosedPublic

Authored by kadircet on Jul 24 2023, 6:58 AM.

Diff Detail

Event Timeline

kadircet created this revision.Jul 24 2023, 6:58 AM
Herald added a project: Restricted Project. · View Herald Transcript
kadircet requested review of this revision.Jul 24 2023, 6:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2023, 6:58 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
VitaNuo added inline comments.Jul 31 2023, 5:16 AM
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
63

Why wouldn't you actually inline the implementation for both these functions? The implementations seem trivial enough.

clang-tools-extra/include-cleaner/lib/Record.cpp
38

I don't think you've added a dependency on all these headers in this patch. Nice if you've actually fixed the missing include violations all over the file, but please double-check that there are no debugging etc. artefacts left.

277

I believe you need to check FE for nullptr, similar to private pragma handling above.
Also, the code above does FE->getLastRef().getUniqueID(), is there any difference to FE->getUniqueID()? I wouldn't expect so, but then you could maybe unify this one with the above, this way or the other.

277

You might want to inline this call, it seems to have a single usage right below.

427

As mentioned above, consider inlining.

kadircet marked an inline comment as done.Aug 1 2023, 4:13 AM
kadircet added inline comments.
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
63

most of the binaries are build with LTO nowadays, so inlining code into headers doesn't really gain much from performance perspective. moreover, these are not really hot functions, they're invoked once per #include directive inside the main file, at the end of analysis.

OTOH, when they're inlined and there needs to be a change to these function definitions, it requires all the translation units depending on this header to be recompiled. Hence I think having them in the cpp file is a not benefit for development cycles.

clang-tools-extra/include-cleaner/lib/Record.cpp
38

yes these are all fixes generated by include-cleaner, I don't have any unused include findings.

277

do you mean initializer for CommentFID? if so CommentFID is actually used in more places below

277

thanks missed that. unified all the usages for getUniqueID, they all should be the same.

you're absolutely right about checking for FE, in practice it's almost never null as it's the file in which we've found the IWYU pragma. But SourceManager actually allows working with virtual files, in which case there might not be a phyiscal file entry.
code in rest of this logic was also relying on FE being non-null without checking for it. Moved code around a little bit and used filename inside the SourceManager instead to make sure export/keep logic can work with virtual files too.

for now not adding support to always_keep and private pragmas for virtual files, as it requires deeper changes in the way we store uniqueids (we can no longer depend on them) and they're not common in practice (usually those virtual files are provided as predefines from the compiler and they likely won't contain IWYU pragmas).

kadircet updated this revision to Diff 546001.Aug 1 2023, 4:13 AM
kadircet marked an inline comment as done.
  • Rebase
  • Properly check for null-ness of FileEntry.
VitaNuo accepted this revision.Aug 1 2023, 5:43 AM

Thanks!

This revision is now accepted and ready to land.Aug 1 2023, 5:43 AM