Try finding unused includes by compiling without each include
In legacy/trac#32522 (moved), we deleted some includes and PRIVATE defines, because they were duplicate (or the defines were never actually checked in the headers).
But we could go further, using this algorithm:
- Make sure all the files are sorted
- Find all the includes (and maybe PRIVATE defines)
- Delete the first include
- Try compiling
- If the include is required to compile, revert
- Try again from step 3, with the next include
We'd need to skip conditional includes, and check the results in CI before merging.
I'll wait until legacy/trac#32522 (moved) is reviewed, and also see if we want this task on our roadmap.