-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Some extended documentation for Core.Compiler.return_type usage as promote_op
#44340
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
Conversation
Core.Compiler.return_typeCore.Compiler.return_type
|
Maybe |
|
Note of course that we already have Lines 443 to 454 in 9b8253c
With the documentation/warning being relevant to |
If you mean that it's too long, I think we need to find a location in the manual or the API docs. Since devdoc documents a lot of internal details, I think it blurs what is public. Ideally, it should be possible to write correct and efficient Julia program without ever reading devdoc.
Thanks for bringing it up. I should've probably discussed Also, another (albeit non-fundamental) reason why Footnotes
|
|
The inference of Lines 1976 to 1979 in 685d905
So it's still best if you can avoid using return_type.
|
Maybe #40302 (comment)? |
My suggestion in this PR is to make absolutely no guarantee at the API level about how efficient a program written using That said, this does look scary:
I was aware of the comment I have no expertise for judging how severe it is. I hoped that the bug is rare enough, given that
I think going with the first option is totally reasonable if you folks are uncomfortable with the possibility of a further increase in the use of One conservative option may be to define a public API (the name is TBD) public_api_return_type(args...) = Core.Compiler.return_type(inferencebarrier(args)...)for now as a "safer" version of |
Core.Compiler.return_typeCore.Compiler.return_type usage as promote_op
base/promotion.jl
Outdated
| responsibility to ensure that the API guarantees provided by the package do not depend on | ||
| the exact type `R` obtained from `promote_op`.** | ||
| Additionally, the result may depend upon return overly exact types, such as `DataType`, |
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.
may depend upon return?
Many publicly registered packages use
Core.Compiler.return_type. Given the popularity of its usage, keeping it as an internal just doesn't reflect the current reality. Unfortunately, it is used often in a way that makes their behavior depend on subtle implementation details in the compiler. Of course, there are valid ways to useCore.Compiler.return_typefor optimizations while making the packages' API-level behavior robust against possible other typocalypses. However, I don't believe the usual caution "it's an internal function so be careful" is enough. Furthermore, keeping it internal makes it hard to document the correct usage and explain the subtle nuances. So, I suggest addingCore.Compiler.return_typeto the public API and explaining exactly what guarantees it provides. Importantly, this can be done without sacrificing any future improvement possibilities in the compiler.I think the main difficulty of using
Core.Compiler.return_typecorrectly is that you need to do reasoning with "inequality" rather than "equality." 1 This of course interacts with what you exactly guarantee in your package. So, I tried to clarify these aspects. Are they enough? Are there other nuances that I miss?I created a markdown file so that it is easy to review. For rendered version, please see: https://github.com/tkf/julia/blob/return_type/return_type.md
I posted this in the draft mode since it has to be turned into a docstring (using the technique @jw3126 used in #36834) before it is ready to merge. But other than that, I think it's ready for review.
Footnotes
This is akin to the difficulty of university math compared to high school math. The rigor and flexibility brought through the reasoning with inequalities (e.g., epsilon-delta arguments) do require some changes in the thought process. ↩