This is an archive of the discontinued LLVM Phabricator instance.

[include-cleaner] Add an IgnoreHeaders flag to the command-line tool.
ClosedPublic

Authored by hokein on Jun 20 2023, 6:36 AM.

Diff Detail

Event Timeline

hokein created this revision.Jun 20 2023, 6:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2023, 6:36 AM
hokein requested review of this revision.Jun 20 2023, 6:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2023, 6:36 AM
kadircet added inline comments.Jun 22 2023, 6:46 AM
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
61

A comma-separated list of regexes to match against suffix of a header, and disable analysis if matched.

161–162

we actually want to perform filtering inside analyze. it's not enough to filter only when printing, we should also filter before applying fixes :D. but we should also be applying filtering to absolute paths in all cases, for missing includes this is being applied to spelling instead.

162

erroring out only after we performed all of our analysis and build a TU feels unfortunate. can we build these regexes and verify them at main and pass onto action instead? (in case the action is run on multiple files at once, we shouldn't compile/verify regexes over and over again)

hokein updated this revision to Diff 533896.Jun 23 2023, 1:31 AM
hokein marked 2 inline comments as done.

address comments:

  • move the filtering in analysis API
  • add an actual -edit lit test
hokein added inline comments.Jun 23 2023, 1:31 AM
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
161–162

oops, good catch. Added an actual --edit test.

kadircet added inline comments.Jul 3 2023, 8:27 AM
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
67–68

can you add some comments about how header filter works? A predicate that receives absolute path or spelling without quotes/brackets, when a phyiscal file doesn't exist. No analysis will be performed for headers that satisfy the predicate.

72

rather than a default here, can we just do no filtering when HeaderFilter is null ?

clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
137

again some comments here could be useful

clang-tools-extra/include-cleaner/lib/Analysis.cpp
65

can you drop Path or put it in comments

clang-tools-extra/include-cleaner/test/tool.cpp
17

can you ignore one but keep other?

it'd be useful to also test the regex behaviour

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
112

same as above, can you either drop or comment out Path

119

same here for Path

172

nit: braces

263

nit: might be better to extract this into a function like: std::function<bool(StringRef)> headerFilter() { /* parses flags, returns a null function on failure */ }

265

s/KeepEmpty/KeepEmpty=/

hokein updated this revision to Diff 536998.Jul 4 2023, 2:23 AM
hokein marked 10 inline comments as done.

address review comments.

hokein added inline comments.Jul 4 2023, 2:26 AM
clang-tools-extra/include-cleaner/test/tool.cpp
17

this tests aims to test filtering logic for both missing-includes and unused-includes cases.

added a new test.

kadircet accepted this revision.Jul 5 2023, 1:43 AM
kadircet added inline comments.
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
138

i think name and the comment are somewhat confusing, what about:

/// Absolute path for the header, when it's a physical file. Otherwise just the spelling without surrounding quotes/brackets.
clang-tools-extra/include-cleaner/lib/Analysis.cpp
84

nit: rather than checking this at every use, might be easier to have something like:

if (!HeaderFilter)
  HeaderFilter = +[](llvm::StringRef) { return false; };
clang-tools-extra/include-cleaner/test/tool.cpp
17

we're still lacking a test for regex behaviour, maybe change next one to foob.*\.h ?

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
221

nit: Drop Path

240

FilterRegs=std::move(FilterRegs) and drop the shared_ptr?

241

looks like debugging artifact

This revision is now accepted and ready to land.Jul 5 2023, 1:43 AM
hokein updated this revision to Diff 537631.Jul 6 2023, 2:15 AM
hokein marked 5 inline comments as done.

address comments

hokein added inline comments.Jul 6 2023, 2:18 AM
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
240

This was my first attempt, it didn't work, we're returning a lamdba function, which invokes a delete constructor of llvm::Regex.

This revision was landed with ongoing or failed builds.Jul 6 2023, 2:19 AM
This revision was automatically updated to reflect the committed changes.