-
Notifications
You must be signed in to change notification settings - Fork 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
Improve supervisor
specs and docs
#8015
Improve supervisor
specs and docs
#8015
Conversation
supervisor
specs and docs
CT Test Results 2 files 93 suites 34m 8s ⏱️ Results for commit 1f66c14. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
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.
😍
🚀 |
lib/stdlib/doc/src/supervisor.xml
Outdated
@@ -401,8 +401,101 @@ child_spec() = #{id => child_id(), % mandatory | |||
only. A map is preferred; see more details | |||
<seeerl marker="#sup_flags">above</seeerl>.</p></desc> | |||
</datatype> | |||
<datatype> | |||
<name name="sup_name"/> |
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.
This type has been introduced in order to pull it and the accompanying documentation out of start_link/2,3
. Inspiration has been taken from the related server_name()
types in gen_server
and gen_statem
.
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 it makes sense to have this type, it makes it flexible for this abstractions.
lib/stdlib/doc/src/supervisor.xml
Outdated
<datatype> | ||
<name name="sup_ref"/> | ||
<desc> |
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.
Inspiration for this type has been taken from the related server_ref()
types in gen_server
and gen_statem
.
A description of sup_ref
has been located in start_child/2
(but not in other functions using this type, like terminate_child/2
, restart_child/2
etc), but I think it is much better placed here, and has therefore been removed from the start_child/2
function docs.
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.
Yes something that we might consider is if proc_lib (that is the main building block) should have some
register_name type that all the behaviors and supervisors (that are implemented as gen_servers) could refer to. But I think this is an improvement over what we have and motivate by the behaviour modules current documentation.
lib/stdlib/doc/src/supervisor.xml
Outdated
@@ -534,38 +627,26 @@ child_spec() = #{id => child_id(), % mandatory | |||
</func> | |||
|
|||
<func> | |||
<name name="start_child" arity="2" since=""/> |
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 docs for this function conflated both variants of the function, namely the one that accepts a child spec as second argument which can only be used for one_for_one
, one_for_all
and rest_for_one
supervisors, and the one that accepts a list of additional start args as second argument which can only be used for simple_one_for_one
supervisors.
Accordingly, the description had several passages like "(unless the supervisor is a simple_one_for_one
supervisor, see below)" and "For a simple_one_for_one
supervisor...".
This is a bit confusing IMO, since you always have to have a kind of filter running on in your head, increasing cognitive load 😅
For this reason, I split the function documentation in two, one for each of the two clauses, and thereby one for each kind/class of supervisors that it will work with, and how.
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 agree that current formulation is hard to read. However clause_i will not be possible to use with the new
documentation format from #8026 so we have to come up with an alternative solution. clause_i is sometimes convenient but also quite error prone if the code changes it implementation adds/removes clauses. I am all for splitting it into "most supervisors" and "simple one for one supervisors"
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.
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 we do not want add new things that will need to be change once #8026 is merged. PR-8026 will not aim to be the final version, and other changes will be needed to make everything as we like it but we need to start somewhere.
Probably for now we will have to make some solution referring to if the function is called like x then otherwise if it is called like y then ... I have a similar problem in ssl docs but have not yet had time to make a solution.
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.
No, what I mean is, how should I proceed with this PR in general? The most sensible way seems to be to "put it on hold" for now, wait for #8026 to be merged, then sort of write it again, this part and the others, according to the new way. This is ok for me, I don't mind 😉 WDYT?
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.
Sure if you feel that is easier its planed for master anyway. I will put a stalled label on it, and remove it once #8026 is merged.
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 this is the best course, yes :)
lib/stdlib/doc/src/supervisor.xml
Outdated
<marker id="start_child-not_simple_one_for_one"/> | ||
<note> | ||
<p>This version of <c>start_child/2</c> can only be used with | ||
<c>one_for_one</c>, <c>one_for_all</c> and <c>rest_for_one</c> | ||
supervisors. For <c>simple_one_for_one</c> supervisors, the version | ||
<seemfa marker="#start_child-simple_one_for_one"><c>start_child(SupRef, ExtraArgs)</c></seemfa> | ||
must be used instead, see below.</p> | ||
</note> |
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'm not quite happy with this linking and the "see above"/"see below"... However, I couldn't find a way to link to the descriptions of specific function clauses, only to functions as a whole...
That said, there are some things that pop up once in a while for which I can't find any documentation for, namely the name_i
and clause_i
attributes. I use them here, but TBH I only picked that up from other documentation files where they are used. It works, and I can guess at what they do, but... 😅
@elbrujohalcon @vkatsuba thanks guys 🤗 I didn't expect reactions so quick TBH |
ca84b58
to
b5c1fe5
Compare
lib/stdlib/doc/src/supervisor.xml
Outdated
@@ -401,8 +401,101 @@ child_spec() = #{id => child_id(), % mandatory | |||
only. A map is preferred; see more details | |||
<seeerl marker="#sup_flags">above</seeerl>.</p></desc> | |||
</datatype> | |||
<datatype> | |||
<name name="sup_name"/> |
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 it makes sense to have this type, it makes it flexible for this abstractions.
lib/stdlib/doc/src/supervisor.xml
Outdated
<datatype> | ||
<name name="sup_ref"/> | ||
<desc> |
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.
Yes something that we might consider is if proc_lib (that is the main building block) should have some
register_name type that all the behaviors and supervisors (that are implemented as gen_servers) could refer to. But I think this is an improvement over what we have and motivate by the behaviour modules current documentation.
lib/stdlib/doc/src/supervisor.xml
Outdated
@@ -534,38 +627,26 @@ child_spec() = #{id => child_id(), % mandatory | |||
</func> | |||
|
|||
<func> | |||
<name name="start_child" arity="2" since=""/> |
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 agree that current formulation is hard to read. However clause_i will not be possible to use with the new
documentation format from #8026 so we have to come up with an alternative solution. clause_i is sometimes convenient but also quite error prone if the code changes it implementation adds/removes clauses. I am all for splitting it into "most supervisors" and "simple one for one supervisors"
@Maria-12648430 Lukas has merged his doc PR #8026 |
Thanks for the heads-up @IngelaAndin, I'll get back to this one in the next couple of days then 👍 |
Co-authored-by: Jan Uhlig <[email protected]>
b5c1fe5
to
1f66c14
Compare
@IngelaAndin I changed this PR to use the new format. The rendered documentation for the |
Thanks for the PR :) |
Prompted by discussions on the Erlang Forum, I took a look at the
supervisor
documentation and found some ways to improve it (or so I hope). However, this PR does not really improve the issue that lead to the confusion as discussed in the linked Forum post, as the roots for this lie deeper.I'll put some more inline comments on what I did any why.