-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Get rid of #includes that do not spark joy #32080
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
Get rid of #includes that do not spark joy #32080
Conversation
@swift-ci please test |
Build failed |
@swift-ci please test Linux platform |
Could you please clang-format the patches? I noticed at least one where I expect clang-format will change the diff. Im not sure I understand the change ... is this effectively attempting to run IWYU over the tree without running IWYU? (https://include-what-you-use.org/). If so, the IWYU might be better to use (as it is better known/understood) than "redundant headers" as I was expecting the headers to be listed twice in the file based on the name. |
That's surprising, I've formatted things based on the style we use today. I will try this out.
I said "redundant" because those includes are redundant in a way; they are not getting used in the file they are being included in. I don't know if there's a standard adjective for "include that is not being used directly in the same file the include is present in". It just so happened that some files were not including what they were using, and that only showed up because I removed some includes higher up the chain, so I manually did an include-what-you-use to fix that. I did not realize that IWYU also removed includes. I thought it only added includes based on the name and second-hand information I read in a StackOverflow answer (which I hit when I was searching for tools to do this). Now that I know that my initial impression was incorrect, I'm going to try to use it. |
Ah, okay, so it was an attempt to do the IWYU cleanup, that sounds great! I don't know if you have the time to do more here, but a bot would be great to have to ensure that we don't regress (hey, I can dream right? :-D) BTW, if you have time, grabbing some numbers would be cool - I imagine that you are not just cleaning the code base, you are also reducing compile times (not necessary, just for feeding the number monster). These exercises are often undervalued but they really do help the project. |
Thanks. (Tangent: I think IWYU should be rebranded to IOWYU (include-only-what-you-use), because that also carries the nuance of don't-include-what-you-don't-use but that's a different matter.)
I think of this enterprise in baby steps.
I don't want to prematurely sign myself up to do things on this list. You mentioned "grabbing numbers would be cool", yes -- I deliberately avoided mentioning that in the PR text because I didn't want people to hold me to it. 😛 This is all "bonus" work. I'll see what I can get done, 2 seems very much within reach, 3 also seems do-able-ish without too much time (famous last words etc.), but I don't want to make promises I can't keep. |
^ Adding to this, I immediately ran into to two issues trying to use IWYU.
These are certainly solvable problems, it's just that I'm skeptical that it will be directly usable in the imminent future given such issues. E.g. if we're changing Xcodes and it hits spurious errors like this, that'd block people from getting work done. |
Oh, agreed, thats why I said that would be nice - I wouldn't say that they are needed for the cleanup that you are doing. But, I figured that Id push my luck and see if there is more good stuff the project could get out of your efforts 😄. Personally, I would raise 3 over 2 - making it easier for others to do is more valuable than the measurements - it is improving the quality of the code, the benefits to build times are pure icing! If you drop 2 to get 4/5, I would be fine with that even. I think that the one thing that would be nice is that you actually put that list into the commit message so that even if you don't get to it, someone else may be able to follow up. Or maybe there should be a "things that would be nice to do" list that is separate? |
Fair enough, I was overinterpreting what you said. My bad.
Hmm. That's a good point. I was thinking that making it easier is valuable if there are tangible benefits. Otherwise, maybe people wouldn't want to use it, because there was no demonstrated benefit.
I think it's easier to miss if it's in a commit message. I can add new documentation on this though with the list. |
Build failed |
Hmm, maybe I'm mistaken in this, but I thought it was generally pretty well accepted that reducing preprocessed content is beneficial. It reduces compile times, reduce file system overheads, reduces object size (intermediate build artifacts), and link times while also reducing unnecessary recompilation. |
Well, it kinda' depends on who is the target audience. I certainly didn't know about the impact until reading Bruce Dawson's blog posts related to compile time. In any case, let's not debate the nitty-gritties, since we seem to mostly be in agreement. I am going to try to get IWYU to work. If I am able to get it working in the time that I have, I'll add some documentation on how to set it up and use it (in a separate PR, not this one). If you have any specific suggestions on rewording the commit messages in this PR to not use the word "redundant", I'm happy to change the commit messages to make things clearer based on your suggestion. |
Yeah, I think that we are in agreement and are discussing hypotheticals. I think that just referencing the operation as "include what you use" is a good balance as most other projects also refer to it that way, although referring to them as "unused headers" is also reasonable. |
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Following up here: I think there are one or more bugs in
It is being overly aggressive in rearranging The other examples are similar. As for include-what-you-use, I do have it finally working. Here's a gist of the output (I haven't fiddled with IWYU's settings, this output was produced with the default settings). Some suggestions seem janky, like this one:
I don't want to use this PR to discuss this more, this is mostly FYI. I'm hoping to submit a documentation PR on building/running/roadblocks some time next week and create a forum post to discuss potential steps forward. I'll cc you on the documentation PR and forum post. |
cb6cbe8
to
8eb7fc3
Compare
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci please test Windows platform |
I don't follow what you believe to be a bug in I don't think that the suggestions there are janky - they are valid. The specific sized typedef require those headers. Can you share why you believe them to be janky? Awesome, thank you for writing up the documentation for this, I think it will make it easier for others to replicate this. |
The windows failure seems legitimate:
|
8eb7fc3
to
77dbf62
Compare
Hmm. I thought if I used the diff tool, it would automatically narrow down the context. I'll retry. FWIW, the way I ran it was
Are you running the command with specific flags to narrow down the diff further?
Maybe I'm missing something, but isn't
Yeah, I re-added some |
@swift-ci please test Windows platform |
|
@swift-ci please test Windows platform |
@swift-ci please clean test macOS platform |
@swift-ci please clean test Linux platform |
Build failed |
There seems to be absolutely no difference in compile times. 🤷
|
Aww, that’s too bad. Would be expected if you are building with modules, not without modules. This is still a clean up that’s good to do IMO, and we should see it through. Thanks for grabbing the numbers! |
@swift-ci please test Linux platform |
In case anyone is interested in how I did this, I basically ran the following script with the different headers:
Try removing includes from each group one by one, fixing compiler errors as necessary.
This mostly works, except sometimes StringRef gets used for StringLiteral.