[Enhancement] Enable include-what-you-use
** Issue ** Best Practices for C++ Development recommend that includes are not implicit. What that means is every file should have all the include statements necessary.
See https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rs-implicit
** Proposed Enhancement **
There is a clang tool called include-what-you-use or IWYU that will parse files and report what includes need to be added or deleted.
Installing IWYU is:
brew install include-what-you-use
Building with the IWYU flag is:
mkdir build && cd build
cmake .. -DMLX_ENABLE_IWYU=ON
make -j
Attached is the output of IWYU for the current codebase.
I'm including a git pull request to make this enhancement
While "C++ Core Guidelines" was created by very well known developers (I have read several books by them) it is not widely adopted as far as I know. For include-what-you-use I think unless it brings actual benefits adopting it only adds overheads.
Well the overhead is related to linting which is something that should be done and doesn't add any actual overhead during use of the program. It's just something to enable as a test and for code review.
The benefit is you will never be in a situation where you include header A but really you needed to include header C for some reason. Meaning you reduce bugs / compile errors.
If you add an explicit #include statement it shouldn't add any additional overhead because an implicit include means it's already in the build.
Thoughts?
Sorry by overhead I meant maintenance overhead: an extra lint that requires you adding a new include when building and testing pass. I worked with a few projects linting IWYU before, it was really annoying and never caught a bug.
Regarding the benefits:
The benefit is you will never be in a situation where you include header A but really you needed to include header C for some reason.
I don't think the linting fixes this situation, it just asks you to add a header and is not capable of detecting unneeded includes.
Meaning you reduce bugs / compile errors.
I'm not aware of any bug would be caused by an implicit include. For compilation error, it is already tested by CI.