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

Is edit(::Callable) broken on v0.4? #9866

Closed
Sean1708 opened this issue Jan 21, 2015 · 3 comments
Closed

Is edit(::Callable) broken on v0.4? #9866

Sean1708 opened this issue Jan 21, 2015 · 3 comments

Comments

@Sean1708
Copy link
Contributor

I noticed the following behaviour on the master branch from 7 days ago, but it's also present on the current master.

julia> versioninfo()
Julia Version 0.4.0-dev+2833
Commit 5c5bf9d (2015-01-20 23:10 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin14.0.0)
  CPU: Intel(R) Core(TM) i7-2635QM CPU @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

julia> edit(length)  # doesn't work
ERROR: no method found for the specified argument types
 in which at reflection.jl:178
 in edit at interactiveutil.jl:55

julia> edit(edit)  # :(
ERROR: no method found for the specified argument types
 in which at reflection.jl:178
 in edit at interactiveutil.jl:55

julia> edit(length, (AbstractArray,))  # works if you supply the types

julia> edit(length, (AbstractVector,))  # and the type doesn't have to be exact

On v0.3, however

julia> versioninfo()
Julia Version 0.3.5
Commit a05f87b* (2015-01-08 22:33 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin14.0.0)
  CPU: Intel(R) Core(TM) i7-2635QM CPU @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

julia> edit(length)  # works fine

julia> edit(edit)  # also works fine

Running edit(which, (Function, Any...)) takes me to this line suggesting that the issue might be related to the deprecation of which(f, args...).

Possibly also related to #9471 or #9536?

@mbauman
Copy link
Member

mbauman commented Jan 21, 2015

I noticed this, too. I have the following in my .juliarc.jl, but haven't submitted it since it's not really the right solution here:

Base.functionloc(f::Base.Callable) = (m = methods(f); isempty(m) ? error("no methods for $f found") : functionloc(first(m)))

As I remember it, the issue is that you often want the inverse of jl_gf_invoke_lookup. That is, given a set of types that don't match any methods, you want the first method that is a subtype of the request. jl_gf_invoke_lookup does the opposite - it finds the most-specific signature such that the request is a subtype of the signature.

This is most important for things like call overloads. You want to find all signatures that are a subtype of (T, Any...).

@Sean1708
Copy link
Contributor Author

Awesome thanks, for most of my use-cases the methods are in the same file so this is good enough for me.

@JeffBezanson
Copy link
Member

Yes, we used to use the most specific matching method here. However that is really quite arbitrary. In the version of julia I happen to be looking at now, edit(length) would take you to length(mt::MethodTable) at reflection.jl:133. I don't think that's useful.

However you can get that behavior with edit(methods(length, (Any...))[1]).

We should remove the default value for the type argument to functionloc, and instead make functionloc(f) only work if f has one definition.

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

3 participants