-
Notifications
You must be signed in to change notification settings - Fork 30k
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
src,doc: add C++ internals documentation #30552
Conversation
This aims to help explain some of the internal patterns and utilities that we use. It is by no means exhaustive, and suggestions for additions are welcome. Some of this is based on the existing work from nodejs#26929. Refs: nodejs#26929
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.
Nice!
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.
I am strongly inclined to add link to https://github.com/nodejs/node/blob/master/doc/api/addons.md. Also maybe put it docs ?
Co-Authored-By: mscdex <[email protected]>
Co-Authored-By: Jiawen Geng <[email protected]>
The addon docs aren’t good for this, imo. The parts about describing how to set up addons are not relevant here (e.g.
If you mean moving it to |
Addon can use v8 api,
To be fare, they are still in the same repo if we put it in |
Yeah, and if we had good addon docs, that would be massively helpful and I’d totally be in favour of linking them- But imo they’re not helpful in their current state which is kind of okay for me given that we’ve been pushing N-API for a while.
I mean, these are docs about internals specifically. I sure hope that they are helpful and valuable to people who work on files in |
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.
I have some comments, but nothing blocking. Thanks for working on this!
|
||
There is no way to abort libuv requests in general. If a libuv request is not | ||
managed through a [`ReqWrap`][] instance, the | ||
`env->IncreaseWaitingRequestCounter()` and |
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.
I am slightly concerned direct references to these methods could get out of date. Can't we just write these down in env.h and link to the headers instead?
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.
Can't we just write these down in env.h and link to the headers instead?
I’m not sure what you mean? But either way, I think keeping this doc up to date and making sure of that during reviews is something we’ll have to do either way.
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.
I think keeping this doc up to date and making sure of that during reviews is something we’ll have to do either way.
I think if keeping this doc up-to-date is going to be a blocker for landing changes in src/
, we should just move the information about the internal classes into the headers as comments, and link to those in the README. For one if the README is too long it becomes difficult to read, also it's going to be a pain to remember updating this doc while changing the code - but slightly less so if the comments live in the headers.
Also it feels weird to me that in order to understand some of these classes at a higher level, you either have to read the code, or read this doc because what's supposed to be said in comments are moved into a markdown file...I think it would be more helpful if the README is just a table of contents.
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.
tbh, I really like the proposed format. It has a flow, the necessary level of abstraction, example code at right places, and caveats and cautions as appropriate - something either not possible in code comments, or not easily consumable. IMO inline comments are rich with the context, but weak in connecting bigger views, and more importantly, discoverability.
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.
If you have items that you feel should also be documented more explicitly in a header file, I’m happy to do that, but generally I agree with @gireeshpunathil – this is not supposed to be an exhaustive guide or reference documentation, but rather paint the big picture and distinguish what’s important from what’s not.
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.
and more importantly, discoverability.
I feel the opposite - I think content in the README is more difficult to discover than content in the headers, especially when the README becomes long. For me it's rare that I'll read a doc, top to bottom, to understand a code base and remember all these identifier names. I usually run into these names when I hack on the code and I expect to see explanations in the headers.
this is not supposed to be an exhaustive guide or reference documentation, but rather paint the big picture and distinguish what’s important from what’s not.
That's what I think this document should be like as well, but with details like
They can be added and removed through by using
env->AddCleanupHook(callback, hint);
andenv->RemoveCleanupHook(callback, hint);
, where callback takes avoid* hint
argument.
and
If a libuv request is not managed through a [
ReqWrap
][] instance, theenv->IncreaseWaitingRequestCounter()
andenv->DecreaseWaitingRequestCounter()
functions need to be used to keep track of the number of active libuv requests.
It does not seem to be the case. These references to specific method names and their arguments do not seem to be necessary in terms of giving the reader a bigger view of the code base.
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.
and more importantly, discoverability.
I feel the opposite - I think content in the README is more difficult to discover than content in the headers, especially when the README becomes long.
That’s somewhat solvable by adding a table of contents, if you like?
this is not supposed to be an exhaustive guide or reference documentation, but rather paint the big picture and distinguish what’s important from what’s not.
That's what I think this document should be like as well, but with details like
They can be added and removed through by using
env->AddCleanupHook(callback, hint);
andenv->RemoveCleanupHook(callback, hint);
, where callback takes avoid* hint
argument.and
If a libuv request is not managed through a [
ReqWrap
][] instance, theenv->IncreaseWaitingRequestCounter()
andenv->DecreaseWaitingRequestCounter()
functions need to be used to keep track of the number of active libuv requests.It does not seem to be the case. These references to specific method names and their arguments do not seem to be necessary in terms of giving the reader a bigger view of the code base.
Well … where would you document these, especially the latter one? It’s easy to add inline docs to ReqWrap
but what do you do when you want to describe when it’s about not using ReqWrap
?
In any case, I don’t feel like these give away too much detail. Judging from the current contents of the file in this PR, the number of yearly PRs that would require updating it is probably in the single digits.
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’s somewhat solvable by adding a table of contents, if you like?
I think that does not help in this case. To quote my edit:
For me it's rare that I'll read a doc, top to bottom, to understand a code base and remember all these identifier names. I usually run into these names when I hack on the code and I expect to see explanations in the headers.
Now this is solvable if in the headers we point the readers to the README for more information, but that feels kind of weird.
where would you document these, especially the latter one?
I think if the goal is to give a big picture in the README, for the latter one it can just say something like:
If a libuv request is not managed through a [ReqWrap][] instance, a counter is used to make sure it gets cleaned up.
And the method names can be documented in the req_wrap.h
or env.h
. The README can just point the readers to that header to see these details. This is a README for src/
after all, so I'd expect it to be more of a table of contents for all these files under src/
.
Co-Authored-By: Colin Ihrig <[email protected]>
Co-Authored-By: Colin Ihrig <[email protected]>
@cjihrig Done, and added documentation for internal fields; PTAL |
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.
LGTM, great work.
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.
WOO! 🎉 💯 🥇
Co-Authored-By: Denys Otrishko <[email protected]>
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.
LGTM, @addaleax thanks for putting it together. Great resource for new contributors.
This aims to help explain some of the internal patterns and utilities that we use. It is by no means exhaustive, and suggestions for additions are welcome. Some of this is based on the existing work from #26929. Refs: #26929 PR-URL: #30552 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Landed in c132035, thanks for the reviews! |
[`async_wrap.h`]: async_wrap.h | ||
[`base_object.h`]: base_object.h | ||
[`handle_wrap.h`]: handle_wrap.h | ||
[`memory_retainer.h`]: memory_retainer.h |
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.
Sorry to be late. This link seems 404 now.
[cleanup hooks]: #cleanup-hooks | ||
[event loop]: #event-loop | ||
[exception handling]: #exception-handling | ||
[internal field]: #internal-field |
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.
- [internal field]: #internal-field
+ [internal field]: #internal-fields
data if it is typically expected to be small (e.g. file paths). | ||
|
||
The `Utf8Value`, `TwoByteValue` (i.e. UTF-16 value) and `BufferValue` | ||
(`Utf8Value` but copy data from a `Buffer` is that is passed) helpers |
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.
Is there a typo here?
Refs: #30552 (review) PR-URL: #30693 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
This aims to help explain some of the internal patterns and utilities that we use. It is by no means exhaustive, and suggestions for additions are welcome. Some of this is based on the existing work from #26929. Refs: #26929 PR-URL: #30552 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Refs: #30552 (review) PR-URL: #30693 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
This aims to help explain some of the internal patterns and utilities that we use. It is by no means exhaustive, and suggestions for additions are welcome. Some of this is based on the existing work from #26929. Refs: #26929 PR-URL: #30552 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Refs: #30552 (review) PR-URL: #30693 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
This aims to help explain some of the internal patterns and utilities that we use. It is by no means exhaustive, and suggestions for additions are welcome. Some of this is based on the existing work from #26929. Refs: #26929 PR-URL: #30552 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Refs: #30552 (review) PR-URL: #30693 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
This aims to help explain some of the internal patterns and utilities
that we use. It is by no means exhaustive, and suggestions for
additions are welcome.
Some of this is based on the existing work from #26929.
Refs: #26929
/cc @vsemozhetbyt @jasnell @sam-github
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes