Skip to content

Remove lots of useless/misplaced includes#7999

Merged
JohannesLorenz merged 6 commits intoLMMS:masterfrom
JohannesLorenz:iwyu
Jul 21, 2025
Merged

Remove lots of useless/misplaced includes#7999
JohannesLorenz merged 6 commits intoLMMS:masterfrom
JohannesLorenz:iwyu

Conversation

@JohannesLorenz
Copy link
Contributor

Follow-Up of 7db3fa9 .

This was done by setting CMAKE_C_INCLUDE_WHAT_YOU_USE and CMAKE_CXX_INCLUDE_WHAT_YOU_USE to (broken down into multiple lines here, note, all below FL/x.h is not required for C):

include-what-you-use;
    -Xiwyu;--mapping_file=/usr/share/include-what-you-use/qt5_11.imp;
    -Xiwyu;--keep=*/xmmintrin.h;
    -Xiwyu;--keep=*/lmmsconfig.h;
    -Xiwyu;--keep=*/weak_libjack.h;
    -Xiwyu;--keep=*/sys/*;
    -Xiwyu;--keep=*/debug.h;
    -Xiwyu;--keep=*/SDL/*;
    -Xiwyu;--keep=*/alsa/*;
    -Xiwyu;--keep=*/FL/x.h;
    -Xiwyu;--keep=*/MidiApple.h;
    -Xiwyu;--keep=*/MidiWinMM.h;
    -Xiwyu;--keep=*/AudioSoundIo.h;
    -Xiwyu;--keep=*/OpulenZ/adplug/*;
    -Xiwyu;--keep=QPainterPath;
    -Xiwyu;--keep=QtTest

FAQ:

  • Q: Does this speed-up a completely fresh compile?

  • A: No, I measured it.

  • Q: Does it speed up anything else?

  • A: Yes. If you change one header, it can reduce the number of CPP files that your compiler needs to recompile, or your IDE has to re-scan.

  • Q: What other reasons are for this PR?

  • A: It's idiomatic to only include headers if you need them. Also, it will reduce output for those who want to use IWYU for new PRs.

Background:

This is just a remainder PR of what I planned. My original idea was to setup a CI which warns you of useless includes (but not of all issues that IWYU complains about). However, I could not see that this was favored on Discord. A full IWYU CI also has the problem that it (possibly??) needs to compile with make -j 1, which would make CI really slow.

However, for that plan, I had to fix the whole code base to be IWYU compliant - which it now is.

@JohannesLorenz
Copy link
Contributor Author

JohannesLorenz commented Jul 10, 2025

For reference: For zyn we have planned an action which greps for these unnecessary includes, and here is example output of the job.

@JohannesLorenz JohannesLorenz force-pushed the iwyu branch 2 times, most recently from 7fb1853 to 2ca0889 Compare July 10, 2025 09:26
@JohannesLorenz JohannesLorenz changed the title Remove 311 useless/misplaced includes Remove lots of useless/misplaced includes Jul 10, 2025
@JohannesLorenz JohannesLorenz force-pushed the iwyu branch 2 times, most recently from 7ceb7e2 to 59a6359 Compare July 10, 2025 11:51
Follow-Up of 7db3fa9 .

This was done by setting `CMAKE_C_INCLUDE_WHAT_YOU_USE` and
`CMAKE_CXX_INCLUDE_WHAT_YOU_USE` to (broken down into multiple lines here,
note, all below `FL/x.h` is not required for C):

```
include-what-you-use;
    -Xiwyu;--mapping_file=/usr/share/include-what-you-use/qt5_11.imp;
    -Xiwyu;--keep=*/xmmintrin.h;
    -Xiwyu;--keep=*/lmmsconfig.h;
    -Xiwyu;--keep=*/weak_libjack.h;
    -Xiwyu;--keep=*/sys/*;
    -Xiwyu;--keep=*/debug.h;
    -Xiwyu;--keep=*/SDL/*;
    -Xiwyu;--keep=*/alsa/*;
    -Xiwyu;--keep=*/FL/x.h;
    -Xiwyu;--keep=*/MidiApple.h;
    -Xiwyu;--keep=*/MidiWinMM.h;
    -Xiwyu;--keep=*/AudioSoundIo.h;
    -Xiwyu;--keep=*/OpulenZ/adplug/*;
    -Xiwyu;--keep=QPainterPath;
    -Xiwyu;--keep=QtTest
```

FAQ:

* Q: Does this speed-up a completely fresh compile?
* A: No, I measured it.

* Q: Does it speed up anything else?
* A: Yes. If you change one header, it can reduce the number of CPP files
     that your compiler needs to recompile, or your IDE has to re-scan.

* Q: What other reasons are for this PR?
* A: It's idiomatic to only include headers if you need them. Also, it will
     reduce output for those who want to use IWYU for new PRs.

Background:

This is just a remainder PR of what I planned. My original idea was to setup
a CI which warns you of useless includes (but not of all issues that IWYU
complains about). However, I could not see that this was favored on Discord.
A full IWYU CI also has the problem that it (possibly??) needs to compile
with `make -j 1`, which would make CI really slow.

However, for that plan, I had to fix the whole code base to be IWYU
compliant - which it now is.
@JohannesLorenz JohannesLorenz marked this pull request as ready for review July 10, 2025 19:05
Copy link
Contributor

@allejok96 allejok96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice housekeeping. I just glanced through it. If it builds it works™

#include <QString>

#include "lmms_export.h"
#ifdef PLUGIN_NAME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this have to do with IWYU? just curious, not even trying

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LmmsCommonMacros.h only defines two macros: LMMS_STR and LMMS_STRINGIFY. Both are used in embed.h only if PLUGIN_NAME is defined. So the change seems sane.

My guess why I did this: I probably compiled a CPP file which include embed.h while PLUGIN_NAME was undefined - so IWYU likely told me: "You're including that header, but in this translation unit, you are not using anything from that header" - so I wrapped the #if around the include to make IWYU happy.

@JohannesLorenz
Copy link
Contributor Author

This PR still need one approval of a reviewer with write access. I guess this should be easy to finish, after 2 devs have already reviewed?

JohannesLorenz and others added 2 commits July 21, 2025 22:35
Copy link
Member

@messmerd messmerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JohannesLorenz JohannesLorenz merged commit 71ce49d into LMMS:master Jul 21, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants