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

ftp: fix types in ftp module #6545

Conversation

kikofernandez
Copy link
Contributor

Fixes some type specs from the ftp module. These have been validated by eqWAlizer.

@kikofernandez kikofernandez added team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI bug Issue is reported as a bug labels Dec 9, 2022
@kikofernandez kikofernandez self-assigned this Dec 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

CT Test Results

    2 files    13 suites   5m 35s ⏱️
144 tests 142 ✔️ 2 💤 0
204 runs  202 ✔️ 2 💤 0

Results for commit 8122362.

♻️ 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

lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from 9407e3d to 47d2683 Compare December 12, 2022 10:56
@IngelaAndin
Copy link
Contributor

Branch name and comments are misleading as you also change inets files!

@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from 71d4dad to 227be9e Compare December 19, 2022 11:53
@kikofernandez
Copy link
Contributor Author

Thanks for the feedback.

I am updating two modules and will close this PR and create the appropriate one with a better branch name.

I would like to get feedback regarding the changes, if we think that those guards make sense.

  • If we add them, eqWAlizer is happy about the types because it can type check those functions.
  • If we do not have them, it would reject those functions.

From my point of view:

  • it makes sense to add them, to say that the function expects lists / values different from undefined or similar
  • there will be a small overhead in those checks, but AFAIK they are almost for free (?)
  • if there is a catch all clause in those functions, adding these guards changes the semantics of the program, as instead of crashing at runtime, the code will go through the catch-all function

@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from 227be9e to a9a8ab9 Compare January 12, 2023 11:34
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from 7e82162 to 809b452 Compare January 13, 2023 07:31
@kikofernandez
Copy link
Contributor Author

I have remove the parts that dealt with the inets module to be in its own PR (#6661 )
A new review is welcome :)

lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
@IngelaAndin IngelaAndin removed the testing currently being tested, tag is used by OTP internal CI label Jan 25, 2023
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch 2 times, most recently from 8892e05 to b91fc18 Compare January 26, 2023 13:55
lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from b91fc18 to 5ccc7ad Compare January 27, 2023 14:26
lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
lib/ftp/src/ftp.erl Outdated Show resolved Hide resolved
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch 3 times, most recently from b6e1a0e to bc72a44 Compare February 13, 2023 08:37
@kikofernandez
Copy link
Contributor Author

  • I decided that to keep the types that OTP maintainers could benefit, and leave a more general interface to our users; I used an internal FTP module that contains the expected types for maintainers (ftp_internal.erl), while I removed the expected reason of the error from the public API (ftp.erl). In this way, ftp.erl is simply a wrapper around our internal API.

  • Type-wise, we are not breaking anything in Dialyzer or other typing tools, since the change means that (Reason :: {error, common_reason() | ...}) <: (Reason :: {error, term()}) because (common_reason() | ...) <: term()

Please let me know if this is a viable solution or if we need to find another way. Alternatives:

  • Remove the reason types (but I think that we maintainers do benefit from having the expected type error...)
  • Collpase all Reason types into a single one (but I think this gives a superset of types to some functions where we do not expect certain kinds of errors)

@IngelaAndin
Copy link
Contributor

I think that this solution feels good. I do not think that for example then commit
[ftp: removal of defensive programming checks] feels like an interesting one to keep for the final solution. I think you should try to squash some of the commits to logical steps of what we think the final result should look like.

@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from bc72a44 to 8de8903 Compare February 17, 2023 14:24
@kikofernandez
Copy link
Contributor Author

Thanks for the feedback. I have placed everything in two commits.

  1. Added the documentation to be read from source (at least the types) instead of hard-coded in XML
  2. Created the ftp_internal.erl module and made ftp.erl a simple wrapper around ftp_internal.erl, such that ftp.erl contains the user types (and documentation) and ftp_internal.erl contains the types that OTP team may care (and dialyzer 😄 )

@IngelaAndin IngelaAndin added this to the OTP-26.0-rc2 milestone Feb 20, 2023
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from 8de8903 to 27d1ea3 Compare February 20, 2023 14:38
@kikofernandez kikofernandez added the testing currently being tested, tag is used by OTP internal CI label Feb 20, 2023
Generates the types in the documentation of `ftp` from the source code.
Before this change, the documentation was hard-coded in `ftp.xml`.
removes some type information from module `ftp.erl` because this
information should not be needed by users of `ftp`.

before this change, users of `ftp` module knew that if they get an error
as follows `{error, Reason}`, `Reason` was a specific atom(), i.e.,
`Reason :: 'ehost' | ...`. users of `ftp` should not rely on the
internal atom used, since they are expected to call `ftp:formaterror/1` to
understand the reason behind the error, as in any other OTP app.

however, this type information can be useful to maintainers of OTP.
Thus, `ftp.erl` contains the necessary type information for users of the
ftp application. the new module `ftp_internal.erl` has been introduced and
contains the actual implementation of the functions from `ftp.erl`, so that
`ftp.erl` is now a simple wrapper around `ftp_internal.erl`.

`ftp_internal.erl` contains the more precise error types for the type
variable `Reason` and also contains the implementation of the `ftp`
functions.
@kikofernandez kikofernandez force-pushed the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch from 27d1ea3 to 8122362 Compare February 21, 2023 14:44
@kikofernandez kikofernandez merged commit de95f00 into erlang:master Feb 22, 2023
@kikofernandez kikofernandez deleted the kiko/ftp/fix-types-in-ftp-module/OTP-18359 branch February 22, 2023 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug documentation team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants