Skip to content

Add GenServer.format_status/1 callback #13511

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

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

sabiwara
Copy link
Contributor

#11220

I'm not sure if something else has to be done, opening my progress so far for discussion.

  • Existing implementations (DynamicSupervisor, GenEvent) are defining new keys like supervisor which don't seem possible anymore?
  • DynamicSupervisor is adding a supervisor: [{~c"Callback", ... key, needed for the supervisor module. Unfortunately, I don't think there's a way to add something that will end up in the Misc part with format_status/1, so will probably need to revert this one to format_status/2?
  • GenEvent has been deprecated for 6y, maybe it can stay on the deprecated callback? :gen_event itself seems to be defining its own format_status/1 (source), but our docs encourage to use :gen_event directly so might be OK?

Comment on lines 761 to 762
@doc """
This function is called by a `GenServer` process in the following situations:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the erlang docs and tweaked them for Elixir

end

def format_status(_, [_pdict, %{mod: mod} = state]) do
[data: [{~c"State", state}], supervisor: [{~c"Callback", mod}]]
Copy link
Contributor Author

@sabiwara sabiwara Apr 23, 2024

Choose a reason for hiding this comment

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

I don't think we can reproduce this behavior with format_status/1, and this breaks a test - should I just keep this one around for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or we can just remove these tests, or implement them to use :mod?

If :supervisor.get_callback_module is used somewhere which matters, should erlang add a key to the format_status map?

Copy link
Member

Choose a reason for hiding this comment

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

@sabiwara we should mirror whatever the Erlang supervisor is doing. This was most likely just borrowed from them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK nice, seems they just removed it.
erlang/otp@67513dc#diff-030fc115adbcd287aecbd623b8355c9cf9aa1fd05ef07b4001b05ce927ec5e03

OK to remove the tests completely then?

Copy link
Member

Choose a reason for hiding this comment

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

Yes!

@@ -775,6 +807,7 @@ defmodule GenServer do
list of `{key, value}` tuples representing the current process dictionary of
the `GenServer` and `state` is the current state of the `GenServer`.
"""
@doc deprecated: "Use format_status/1 callback instead"
@callback format_status(reason, pdict_and_state :: list) :: term
when reason: :normal | :terminate
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should still document it. In any case, let's also add a TODO to remove it on 2.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, let's remove the docs completely.

Copy link
Member

Choose a reason for hiding this comment

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

Let's add the TODO and ship it!

@sabiwara sabiwara merged commit cb9c303 into elixir-lang:main Apr 24, 2024
10 checks passed
@sabiwara sabiwara deleted the format_status branch April 24, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants