-
Notifications
You must be signed in to change notification settings - Fork 7.8k
#include cleanup #10216
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
#include cleanup #10216
Conversation
Add missing #include lines to the header, so it can always be included without figuring out its header dependencies.
In the C file, include the header first so missing #includes are detected by the compiler, and use lighter header dependencies in the header, to speed up compile times.
042540b
to
e39ba0b
Compare
Travis failure unrelated to this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling this!
I think this makes a lot of sense, and I've been annoyed at this in the past when trying to figure out where what is defined.
But maybe wait for the opinion of someone else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LCTM
Me too. Many of the "core" headers are really messed up (organic growth over two decades). Maybe I'll try to move some of the stuff to separate mini-headers to avoid slurping in everything everywhere. |
So basically Plan 9 style includes "light". I think we can do that, but need to be careful not to break too many external extensions/SAPIs etc. At least we need to prominently document any major change in UPGRADING.INTERNALS. |
cc @dstogov, @remicollet |
Lots of the internal extensions break because e.g. they forget to include |
Then we should at least add a note to UPGRADING.INTERNALS that the header includes have been changed, and maybe hint at this particular issue. |
Added to #10220 |
I don't think we should include the comments like I'm indifferent to these changes and don't object. |
IMO every |
FWIW, I disagree with this. Mostly, because these will never get updated so that this information becomes stale really quickly. |
Do you believe that nobody should ever write any code comments, API documentation and user manuals, because this information becomes stale just as quickly as code comments on Everybody can have their opinion, but yours sound rather unconvincing to me. |
PS: if the explanation of an |
Just chiming in: I agree with header cleanup, but not documenting why it's used. As Derick says, these often are not maintained, partially because if some header already included and I use something else now, why would I even think to go update that list? Thanks for cleaning it up! |
I'm not sure if I agree, having at least an initial reason as to why something is included is IMHO better than guessing why it exists. Moreover, how often are these files actually modified and the stated reason of the include becomes invalid? Some of these files are basically frozen because of their simplicity and "finished" implementation. |
There are may be hundreds of reasons to include a single file. It's not possible to maintain all of them. Documenting only a single reason can often be incorrect. Any changes in includes may violate these kind of include comments. I don't know where is our PHP @internal code style doc now (I can't find with google), but it definitely didn't recommend any include comments. If we are going to change our coding style, lets go through RFC and voting process. |
Cf. <#10220 (comment)>. This reverts commit e628c66.
It is in this repo: https://github.com/php/php-src/blob/master/CODING_STANDARDS.md Anyway, I have reverted the four PRs we had for these changes. Let's see what comes out of #10338 and the RFC. :) |
#include "../TSRM/TSRM.h" | ||
#include "zend.h" | ||
#include "zend_portability.h" // for BEGIN_EXTERN_C | ||
#include "zend_types.h" // for zend_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I have with such comments is that they are very fragile. As the code changes, it may use more of the things in this file. It may stop using zend_result. zend_result may be moved to another header file or cease to exist. But unless the file is going to go away completely, or similar major change happens, nobody would bother to update all comments of this nature. It is not realistic to expect from people who alter the code to evaluate each time whether their code was the last instance of using some particular construct introduced in some include, and whether now we need to change the comment to some other construct also introduced by that include - nobody ever is going to do that. So this may be technically true now - but in a year, we won't know if it's true, and in three years, it becomes just meaningless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be RFC vote "Is it allowed to document an #include line with a code comment?" - https://wiki.php.net/rfc/include_cleanup - please vote!
See also #10472
This PR is the start of an effort to reduce header bloat in the PHP code base. My idea is: in each
.c
file, include its own.h
file first, and ensure that the header includes only a minimal set of other headers, possibly using forward declarations.This increases code correctness and reduces compile times.
If you agree with this idea, I'll post more PRs.