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

Export oft-used types #2994

Closed
wants to merge 1 commit into from
Closed

Conversation

mheiber
Copy link
Contributor

@mheiber mheiber commented Jan 21, 2021

Export more types that meet these criteria:

  • Documented
  • Convenient for client code. They are already
    used in specs of public functions of their respective
    modules.
  • These types do not expose implementation details.

The types are:

ets.erl:

  • type() :: set | ordered_set | bag | duplicate_bag.

supervisor.erl:

  • `restart() :: 'permanent' | 'transient' | 'temporary'
  • shutdown() :: 'brutal_kill' | timeout().

The reason for this change is to fix the status quo, which is
that teams either must:

  • copy/pasta the types into client code, leading to code bloat and having
    to manually keep the types in sync.
  • OR refer to non-exported types, which will mean either more noise
    or less accuracy from code analysis tools. For example,
    Dialyzer will either warn or treat the types as term().

@rickard-green rickard-green added team:VM Assigned to OTP team VM team:PS Assigned to OTP team PS labels Jan 25, 2021
@IngelaAndin
Copy link
Contributor

IngelaAndin commented Feb 9, 2021

We discussed this in the PS team, and we feel that the exports are motivated. We would however prefer that the type mfargs() is changed to only mfa(), which we think is the natural name. @rickard-green what do the VM team think?

Or just realized it is probably because of the inclusion of the internal undefined. Maybe it should be changed to mfa() | sup_internal() which can be specified as undefined. I just remembered after reading the docs again that is used for temporary processes instead of saving potentially big argument lists for no purpose. That could make it clearer that undefined is nothing that should be used by the user.

@paulo-ferraz-oliveira
Copy link
Contributor

paulo-ferraz-oliveira commented Feb 9, 2021

Do you think this reasoning (probably clearer than mine, initially) could be applied to #2961, which I could resurrect?

Edit: I closed it (#2961), at that time, understanding that it wouldn't be accepted, but it was probably not discussed enough.

@IngelaAndin IngelaAndin added the stalled waiting for input by the Erlang/OTP team label Feb 16, 2021
Export types that will be convenient for client
code where doing so will not expoose implementation
details or promote bad practices.

These are the types exported:

ets.erl:
- type() :: set | ordered_set | bag | duplicate_bag.

re.erl:
- mp() :: {re_pattern,_ ,_ ,_ ,_ }.*

supervisor.erl:
- `restart() :: 'permanent' | 'transient' | 'temporary'.`
   | undefined}.`
- `shutdown() :: 'brutal_kill' | timeout().`
@mheiber
Copy link
Contributor Author

mheiber commented Jun 9, 2021

@IngelaAndin , I updated the PR to not export mfargs(), since that type requires more care than the others.
I can do a follow-on for mfargs, following your suggestion in #2994 (comment).

@KennethL
Copy link
Contributor

KennethL commented Jun 9, 2021

We are not through the internal discussion about when and why to export types in general yet. Will try to finish that soon.
When it comes to the specific types in this PR I have the following so far personal opinions:

  • ets:type(), could be ok to export but I really think it should be named table_type() in that case.
  • re:mp(), today there are no types at all exported from the re module and the mp() type is intended to be opaque so I wonder why you propose to export that one? Exporting that one requires some thinking both about its name and its spec.
  • supervisor:shutdown() , would be ok to export and is analogous with the newly introduced type auto_shutdown() which is exported. For consistency this one should also be exported.

@mheiber
Copy link
Contributor Author

mheiber commented Jun 9, 2021

We are not through the internal discussion about when and why to export types in general yet. Will try to finish that soon.

What is the best way for me to contribute and to follow the work? Since you're taking a broader look at the general problem, would it be easier for you if I close this PR and open an issue in the bug tracker instead?

@mheiber
Copy link
Contributor Author

mheiber commented Jun 9, 2021

  • re:mp(), today there are no types at all exported from the re module and the mp() type is intended to be opaque so I wonder why you propose to export that one? Exporting that one requires some thinking both about its name and its spec.

We have code that takes regexes as parameters and then uses the re module under the hood.

fwiw, my two cents is there is sufficient reason to expose a type (or an opaque wrapper of a type) when the type appears in the signature of an exported function. Otherwise it can be hard to spec functions that use those exported functions.

@KennethL
Copy link
Contributor

We are not through the internal discussion about when and why to export types in general yet. Will try to finish that soon.

What is the best way for me to contribute and to follow the work? Since you're taking a broader look at the general problem, would it be easier for you if I close this PR and open an issue in the bug tracker instead?

Yes I think it is a good idea to close the PR and that you create an issue per API where you think there are types that should be exported. In this case one for ets one for supervisor and one for re. This since the PR does not add any valuable code and we might want to change the name if a type goes from internal to external.

@mheiber mheiber changed the title Export oft-used types w/o exposing implementation Export oft-used types Jun 15, 2021
@mheiber
Copy link
Contributor Author

mheiber commented Jun 15, 2021

Yes I think it is a good idea to close the PR and that you create an issue per API where you think there are types that should be exported.

Thanks @KennethL , I've converted to issues:

@mheiber mheiber closed this Jun 15, 2021
@potatosalad potatosalad deleted the export-more-types branch May 31, 2022 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stalled waiting for input by the Erlang/OTP team team:PS Assigned to OTP team PS team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants