Skip to content
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

More changes to make includes scope smaller #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gonzus
Copy link
Contributor

@gonzus gonzus commented Jul 27, 2020

  • Get rid of a large list of includes in file d.h, and add only the needed H files in each C file.
  • Remove unused functions and defines.
  • Move #defines that are used by a single C file, into the C file.
  • Make functions static if they are only used internally in a C file.
  • Add some missing prototypes including missing (void) decls.
  • Move some prototypes to a more appropriate H file.
  • Add some FIXME comments → PLEASE CHECK

* Get rid of a large list of includes in file d.h, and add only the
  needed H files in each C file.
* Remove unused functions and defines.
* Move #defines that are used by a single C file, into the C file.
* Make functions static if they are only used internally in a C file.
* Add some missing prototypes including missing `(void)` decls.
* Move some prototypes to a more appropriate H file.
* Add some FIXME comments.
Copy link
Owner

@jplevyak jplevyak left a comment

Choose a reason for hiding this comment

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

Could you resync? I had to make some changes to the python code in order to get it to work.

Generally I think that this smaller include scopes isn't such a great idea. I very intentionally include everything so as to prevent conflicts and to fix the include order. This change has caused no end of problems and to what benefit? The # of lines of code has increase, instability has increased and I don't think it compiles any faster. It is also a maintainace nightmare since any reoganization in headers touches a bunch of files.

@jplevyak
Copy link
Owner

So, I backed out the previous header change. It messed up the tests and the python code.

The core problem is that DParser has dependencies between headers and #defines which are then checked e.g. D_ParserNode_User which cause hidden failures. The internal dependencies between the headers are also not
enforced by #includes between headers.

If you really want to unravel this, we need to have a include/ directory with "public" headers which are used by consumers
of the libraries and then we can hide the internal headers in src and then we need to have the internal dependencies in
the headers themselves.

Generally I believe that the "include what you use" principle is a failure in practice. It increased toil and maintainance
costs without providing any benefit. Instead I would prefer that headers would include their dependencies,
things like D_SymHash be isolated to the .c file, the public headers are separated from internal headers and
the code and internal headers for be separated by directory (as you suggested). For DParser that would be things
like the bootstrapping code, the code to make the parsing tables, the code to execute the parser and then optional
parsing support (e.g. the symbol table). If there are blocks of headers that are needed together their can be a common header file to ensure that they are all included and in the right order (like LLVM does).

@gonzus
Copy link
Contributor Author

gonzus commented Jul 29, 2020

I am having second thoughts as well. If you feel the change is not beneficial, please feel free to reject it. Also, my apologies for the unintended consequences -- I was trying to wrap my mind around the code. Maybe it is better to have a sounder strategy about how to clean things up, as you mentioned above.

There were some juicy bits in the PR, though: some functions being declared as static, some declarations being moved around (a function defined in util.c but declared on a different header), etc.

How about you revert the patch to the point you feel comfortable and I send you smaller PRs for some of the changes? I would initially focus on these changes, with separate PRs:

  • Remove unused functions and defines.
  • Move #defines that are used by a single C file, into the C file.
  • Make functions static if they are only used internally in a C file.
  • Add some missing prototypes including missing (void) decls.
  • Move some prototypes to a more appropriate H file.
  • Add some FIXME comments → PLEASE CHECK

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.

2 participants