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

Invoking Core._apply #30105

Closed
dalum opened this issue Nov 21, 2018 · 3 comments
Closed

Invoking Core._apply #30105

dalum opened this issue Nov 21, 2018 · 3 comments

Comments

@dalum
Copy link
Contributor

dalum commented Nov 21, 2018

This one has left me head scratching:

julia> hasmethod(Core._apply, Tuple{typeof(+), Tuple{Float64, Float64}})
true

julia> applicable(Core._apply, +, (2.0, 2.0))
true

julia> applicable(invoke, Core._apply, Tuple{typeof(+), Tuple{Float64, Float64}}, +, (2.0, 2.0))
true

julia> invoke(Core._apply, Tuple{typeof(+), Tuple{Float64, Float64}}, +, (2.0, 2.0))
ERROR: MethodError: no method matching _apply(::typeof(+), ::Tuple{Float64,Float64})
Stacktrace:
 [1] top-level scope at none:0

The issue is that invoke(Core._apply, ...) doesn't work for any arguments. The easiest fix would be to make applicable not lie about being able to call invoke with the given arguments, but I think it would be even better if invoke(Core._apply, ...) worked. 🙂

I discovered this when using Cassette to replace internal calls by invoke, but the fact that Core._apply can't be used with invoke breaks my assumption that f(x, y) == invoke(f, Tuple{typeof(x), typeof(y)}, x, y).

@JeffBezanson
Copy link
Member

Making invoke just work is probably the best thing to do. _apply and other "builtins" aren't generic functions, but they can probably consistently behave as if they had a single Any... method for most purposes.

@laborg
Copy link
Contributor

laborg commented Feb 8, 2022

I assume this isn't relevant after #39115 anymore.

@laborg laborg closed this as completed Feb 8, 2022
@vtjnash
Copy link
Member

vtjnash commented Feb 8, 2022

Fixed by #43865 actually!

julia> invoke(Core._apply_iterate, Tuple{typeof(iterate), typeof(+), Tuple{Float64, Float64}}, iterate, +, (2.0, 2.0))
4.0

julia> typeof(Core._apply_iterate).name.mt.defs.func.invokes
Core.TypeMapEntry(nothing, Tuple{typeof(Core._apply_iterate), typeof(iterate), typeof(+), Tuple{Float64, Float64}}, nothing, svec(), 0x0000000000000001, 0xffffffffffffffff, MethodInstance for _apply_iterate(...), true, true, false)

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

No branches or pull requests

4 participants