Include what you use / include cleanup

Hey folks, some updates:

First, big thanks to @MaskRay @RKSimon and @lenary for reviewing most of the commits, that’s greatly appreciated.

The following graph shows the number of lines output by the preprocessor when building libLLVM.so

log

on the x axis, number of preprocessor output line, on the y axis, commits starting with 07486395d2d05c9c567994456774cafdcc1611d0.

As big drops and big increase are the most interesting ones, here is a dump of the major changes, sorted in ascending order:

Nothing to surprising there: header cleanup removes lines and new features add lines.

It’s also interesting to see the scale of the changes: I’ve been investing tons of hours in the process, leading to more than 6M lines of preprocessed code being removed but libLLVM requires ~238M lines of preprocessed code to build, so that’s largely negligible in terms of impact on the whole code base.

I still think this is useful, even just considering the (assumed) lower coupling that results from the cleanup.

So what’s next? I still need to finish the cleanup for libLLVM, and I’m probably not going further down that slope.

I also would love to improve the IncludeCleaner step from clangd to output less false positive on LLVM codebase (not to self: track those bugs somewhere…), so that we could use it in the CI. I’ve submitted a first step to be able to use that engine as a stand-alone tool here: ⚙ D121593 [clangd][WIP] Provide clang-include-cleaner.

Alternatively, I wrote a python script that runs IWYU twice, once before and once after a patch, and makes a diff of the output to detect added dependencies. Would someone be interested in taking that script and plug it in the CI?

That’s probably too long for a summary, but hey, that’s how it is.

PS: I’ve been diligently breaking the CI with the cleanup commits. I do test all projects on my setup, but not in a multi-platform way, and not under EXPENSIVE_CHECKS neither under NDEBUG. My future self is working on more diligently checking pre-commit CI.

2 Likes