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 at-invoke and make it use Core.Typeof instead of Any #45807

Merged
merged 1 commit into from
Jun 27, 2022

Conversation

ararslan
Copy link
Member

The macro was introduced in Julia 1.7 but was not exported. Previously, when an argument's type was unspecified, the type used was Any. This doesn't play well with types passed as arguments: for example, x % T has different meanings for T a type or a value, so if T is left untyped in @invoke rem(x::S, T), the method to call is ambiguous. On the other hand, if the macro expands rem(x::S, T) to use Core.Typeof(T), the resulting expression will interpret T as a type and the likelihood of method ambiguities is significantly decreased.

As pointed out by Stefan in Slack.

@ararslan ararslan requested a review from StefanKarpinski June 24, 2022 17:03
@ararslan ararslan marked this pull request as draft June 24, 2022 17:19
@ararslan
Copy link
Member Author

Converting to draft until I figure out what's up with the build failure this causes. My guess is I need to pull some particular symbol into Core.Compiler explicitly so that everything the expanded expression uses is defined.

@giordano
Copy link
Contributor

Related to #44902?

@ararslan
Copy link
Member Author

Ah, yes indeed! Thanks for the link.

@ararslan
Copy link
Member Author

Currently this breaks a test:

Test Failed at /cache/build/default-amdci4-4/julialang/julia-master/julia-4200ed52b3/share/julia/test/compiler/inference.jl:2299
  Expression: Base.return_types((Any, Any)) do x, y
  #= /cache/build/default-amdci4-4/julialang/julia-master/julia-4200ed52b3/share/julia/test/compiler/inference.jl:2300 =# @invoke ifelselike(x isa Int, x, y::Int)
  end |> only == Int
  Evaluated: Any == Int64

Copy link
Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

Maybe we also want to export Base.@invokelatest also
on this opportunity?

test/compiler/inference.jl Outdated Show resolved Hide resolved
@ararslan
Copy link
Member Author

Maybe we also want to export Base.@invokelatest

We could, although the corresponding function, Base.invokelatest, isn't exported. If we export the macro then we should export the function as well, IMO.

@ararslan ararslan marked this pull request as ready for review June 24, 2022 21:10
@aviatesk
Copy link
Member

Maybe we also want to export Base.@invokelatest

We could, although the corresponding function, Base.invokelatest, isn't exported. If we export the macro then we should export the function as well, IMO.

Makes sense. Let's leave it as is for now, I don't want to block this PR by that.

base/reflection.jl Outdated Show resolved Hide resolved
The macro was introduced in Julia 1.7 but was not exported. Previously,
when an argument's type was unspecified, the type used was `Any`. This
doesn't play well with types passed as arguments: for example, `x % T`
has different meanings for `T` a type or a value, so if `T` is left
untyped in `at-invoke rem(x::S, T)`, the method to call is ambiguous. On
the other hand, if the macro expands `rem(x::S, T)` to use
`Core.Typeof(T)`, the resulting expression will interpret `T` as a type
and the likelihood of method ambiguities is significantly decreased.
Copy link
Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

Retriggered CI. Once they pass this should be good to go.

@aviatesk aviatesk merged commit a549929 into master Jun 27, 2022
@aviatesk aviatesk deleted the aa/at-invoke branch June 27, 2022 03:57
`@invoke f(arg1::T, arg2)` will be expanded into `invoke(f, Tuple{T,Any}, arg1, arg2)`.
Provides a convenient way to call [`invoke`](@ref) by expanding
`@invoke f(arg1::T1, arg2::T2; kwargs...)` to `invoke(f, Tuple{T1,T2}, arg1, arg2; kwargs...)`.
When an argument's type annotation is omitted, it's replaced with `Core.Typeof` that argument.
Copy link
Member

Choose a reason for hiding this comment

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

This documentation is not particularly helpful, since Core.Typeof is currently undocumented.

pcjentsch pushed a commit to pcjentsch/julia that referenced this pull request Aug 18, 2022
…liaLang#45807)

The macro was introduced in Julia 1.7 but was not exported. Previously,
when an argument's type was unspecified, the type used was `Any`. This
doesn't play well with types passed as arguments: for example, `x % T`
has different meanings for `T` a type or a value, so if `T` is left
untyped in `at-invoke rem(x::S, T)`, the method to call is ambiguous. On
the other hand, if the macro expands `rem(x::S, T)` to use
`Core.Typeof(T)`, the resulting expression will interpret `T` as a type
and the likelihood of method ambiguities is significantly decreased.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants