Find "perfect aliases" and remove them from the list of checks to run.
On large codebases, this can save up to 30% runtime, which is not negligible.
A "perfect alias" is an alias that:
- Is of the same check class as the primary check.
- Has all configuration options the same as the primary check.
NOTE TO REVIEWERS:
This is a WIP, quick and dirty PoC, so the code is not pretty, well structured
nor optimal.
The intention is to make this feature opt-in via config/CLI.
I.e. turned off by default -> should not break things.
Before polishing the patch I'd like to get feedback about whether this
is the desired direction, and in general if I'm putting the pieces in the right places.
DESIGN GOALS:
- No impact on check developers, other than having to register the check via the new macro instead of the regular function.
- Only perfect aliases to be removed.
MISSING BITS/REQUIREMENTS FROM THE RFC:
- It would be desirable to still keep the diagnostic/fixit for the alias checks. I don't know how to implement this in practice. It would require each check to call the diag() function in a loop for all alias checks. This would be very disruptive for check developers. I cannot implement this in the ClangTidyCheck class because the diag() function returns an object, so I can't put a loop there.
- Ideally, it would be nice to show "CACHED - 0 seconds" or "SKIPPED - 0 seconds" in the profiling output (currently, the alias check just doesn't show up). Again, I don't know how to implement this feature in a non-intrusive way that makes sense.
Suggestions are very welcome for these two bits! Otherwise I am personally
happy to skip them.
Current working test:
clang-tidy -checks=-*,*-c-arrays,*-in-classes
The result is:
- Only one of the 3 "c-arrays" check is run (the primary check), because the other 2 checks are perfect aliases.
- Both of the "-in-classes" checks (cppcoreguidelines, misc) are run, because they have different configuration options.
I'm not sure if you have this in for testing purpose or not, though I really like to have this message. If I would be having 2 aliases active with different options, it would be nice to know about that. So please keep this in!
Preferably, we would only configure it once, though that's dreaming.