This is an archive of the discontinued LLVM Phabricator instance.

[include-cleaner] Unify always_keep with rest of the keep logic
ClosedPublic

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

Diff Detail

Event Timeline

kadircet created this revision.Jul 24 2023, 6:59 AM
Herald added a project: Restricted Project. · View Herald Transcript
kadircet requested review of this revision.Jul 24 2023, 6:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2023, 6:59 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/lib/Record.cpp
248

If I understand correctly, you should be able to extract IncludedFile from IncludedHeader->physical() and then you don't need the extra parameter.

Also, technically this and the below code used to work for standard and verbatim headers before this change. Now it probably won't, since there will be no corresponding IncludedFile. Is this actually something to worry about?

262

nit: remove braces.

419

Consider inlining this function.

kadircet added inline comments.Aug 1 2023, 8:04 AM
clang-tools-extra/include-cleaner/lib/Record.cpp
248

If I understand correctly, you should be able to extract IncludedFile from IncludedHeader->physical() and then you don't need the extra parameter.

Not really, if included file is recognized as a system include we won't have a physical file entry.

Also, technically this and the below code used to work for standard and verbatim headers before this change. Now it probably won't, since there will be no corresponding IncludedFile. Is this actually something to worry about?

It still does (and I am adding tests for those). All of them were still recorded based on their line number into this structure, now instead we're recording them through their fileentry (even if their include_cleaner::Header representation is non-physical, we're talking about an include here, so it must have a logical file it resolves to, when it exists). So this still implies some behavior changes of course:

  • We no longer respect IWYU pragmas assoaciated with non-existent/virtual files, but all of the users already suppress unused diagnostics for unresolved files and moreover the new shouldKeep API forces the caller to pass in a file-entry. Hence going forward we give explicit info to the callers that they should deal with unresolved headers on their own way.
  • If there are multiple include directives resolving to the same physical file, we'll bind their fate. We already assume in other places that a file will be included at most once, so I don't think that's also a worth concern.

WDYT?

262

because the condition is spanning multiple lines, i'd rather keep it

419

same concerns about inlining as in the previous patch

kadircet updated this revision to Diff 546070.Aug 1 2023, 8:04 AM
  • Add tests for pragmas on stdlib headers
VitaNuo accepted this revision.Aug 1 2023, 8:13 AM
This revision is now accepted and ready to land.Aug 1 2023, 8:13 AM
This revision was landed with ongoing or failed builds.Aug 2 2023, 3:58 AM
This revision was automatically updated to reflect the committed changes.