-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IWYU support (part 2): Miscellaneous prep work #27683
Conversation
Add some pragmas to control what IWYU does.
When IWYU auto-moves these to the cpp file they lose the #ifdef
This stuff is only needed on Windows for the subsequent code in the file. On other platformas this header might as well be empty; let's make it so.
These are for gcc in debug mode; different ones would probably be required for other systems.
I see no evidence that they are needed, and if they are they should probably be using sdl_wrappers.h anyway.
The IWYU rule is that when you declare a function taking a class with an implicit conversion (from something), you must provide a definition of that class. e.g. ballistics.h defines projectile_attack, taking an argument of type const dispersion_sources &. dispersion_sources has an implicit conversion from double. Therefore, ballistics.h must include "dispersion.h" (rather than just the forward declaration that was previously present).
All headers used in src/lua/catabindings.cpp need pragmas to prevent IWYU removing them.
IWYU requires forward-declarations (or includes) of function return types in the file defining the function. Moreover, sometimes the lack of same can cause IWYU to break your build, so we must add some up front.
Add pragmas for some header inclusions which IWYU would otherwise remove.
IWYU dislikes using forward declarations as member typedefs, so move these two struct definitions into their own header so it can be included rather than forward-declared.
It needs access to explosion_data destructor, which was not necessarily available after IWYU messed with the headers.
Although technically permissible to IWYU, this ends up being mangled rather, and it seems inappropriate to have the implementation details of the unit tags scattered everywhere.
Fits better with typical include ordering
Move some from header to cpp, and use sdl_wrappers.h where appropriate rather than having more #ifdefs.
Gorgon isn't happy because I added a blank line to |
Have now calculated some build timings. These are times for a from-scratch rebuild with -j4. Debug build with all the features turned on. Three trials for each of three situations. on master:
on this branch:
after running IWYU on this branch:
So, as expected, not much difference. If anything it might be a little slower. |
I am not totally sure yet, but I suspect this PR causes linking issues under MSYS (and probably MinGW too): Possibly related - libSDL2pp/libSDL2pp#66. |
Android builds were also broken - https://ci.narc.ro/job/Cataclysm-Android/8389/console
|
Can confirm that I have same issue with compiling latest repo with MSYS. |
I've gone ahead and made the final PR in the set (#27713) because I thought that would probably break both Mingw and Android builds as well, and there's little point fixing them between this one and that one. |
Summary
SUMMARY: None
Purpose of change
To permit IWYU to run cleanly on the codebase requires various tweaks and tidying up. This PR makes the necessary changes. The plan is to follow up with a PR which contains only the changes made by IWYU once this is in. Don't want to put it all together because the header changes make other changes too difficult to find and review.
Describe the solution
Various things, including:
#ifdef
).io::..._archive_tag
definitions into a separate header and included it elsewhere instead of forward-declaring.sdl_wrappers
header, that deals with the platform-specific issues in one place.Describe alternatives you've considered
We could just not do this.
Additional context
To make this work I've also had to patch IWYU. I've made four PRs, of which two have so far been merged. The other two will need to be merged before anyone else can run IWYU without much hassle.
If you're curious as to whether IWYU will actually save us compile time: I'm now finally in a position to answer that,
but I haven't done the necessary experiments yetand the results are below. It doesn't make much difference; this is more about maintaining order in the codebase than getting build performance, but at least it means that future efforts towards compile-time optimization ought to be easier.