-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
define at-invoke
macro
#38438
Merged
Merged
define at-invoke
macro
#38438
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
My inclination is that an omitted type annotation should be equivalent to
arg::typeof(arg)
, notarg::Any
.That is, it should be like passing the argument as-is, so that
@invoke f(x,y)
dispatches like an ordinaryf(x,y)
call.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.
Fair.
Why I didn't introduce
arg::typeof(arg)
pattern was it may lead to slower dynamic method lookup when used carelessly:Well, I'm fine either way;
arg::typeof(arg)
is certainly intuitive, and we can assume@invoke
is used carefully (it's so much reflective, anyway),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.
And, with some cases like below, the current behavior might look more "intuitive"
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 find it more intuitive that unspecified argument types correspond to "ordinary" dispatch rules.
(In many cases there won't even be an
Any
method.)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 unspecified types meaning
x::typeof(x)
seems more useful thanx::Any
, but usingtypeof
here might lead to some unexpected edge cases, for examplef(Int)
dispatching tof(::DataType)
instead off(::Type{Int})
. Ideally we'd useCore.Typeof
instead, but IIRC that has some performance gotchas.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.
@JeffBezanson, what is the best way to fall back to “ordinary” dispatch here?
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 realize this is merged and out in the wild, but I'd like to express support for applying ordinary dispatch rules to arguments without specified types within
@invoke
. Here's an example of why, distilled from a real-world use case:I think consistent dispatch is more important than avoiding dynamic dispatch here. Unless there's some subtlety I don't understand, the dispatch of
@invoke f(x::Foo, y)
would only have to be dynamic when the type ofy
can't be inferred, in which casef(x, y)
and any other dispatch on the type ofy
would also be dynamic, so there's not much lost. (However, I know nothing about the gotchas withCore.Typeof
. Suppose the type ofx
is not inferred: isinvoke(f, Tuple{Core.Typeof(x)}, x)
much slower thanf(x)
?)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 fully agree that this current behavior is undesirable, arguably even buggy. We should really consider changing this.