Skip to content

reviving instancemethods #52304

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

matthias314
Copy link
Contributor

@matthias314 matthias314 commented Nov 25, 2023

The purpose of this PR is to finally add instancemethods to master. This function was created by @algunion in #50898 and #51068 in response to a question of mine on Discourse. @algunion seems to be busy at the moment and said that I could complete the PR.

Recall that the idea of instancemethods(T::Type) is to return all methods for instances of T without the need to instantiate any object. I believe I have addressed all comments made in #51068. Some remarks about the current version:

  • The code for methods contains the line

world == typemax(UInt) && error("code reflection cannot be used from generated functions")

which is currently not in instancemethods. Does it need to be added?

  • The following gives an error at present:
julia> length(instancemethods(Function))   # OK
24726

julia> length(instancemethods(Any))   # EDIT: OUTDATED
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty
   @ ./Base.jl:49 [inlined]
 [2] instancemethods(t::Type, tmatch::Any, mod::Nothing)
   @ Base ./reflection.jl:1275
 [3] instancemethods
   @ Base ./reflection.jl:1283 [inlined]
 [4] instancemethods(t::Type)
   @ Base ./reflection.jl:1283
 [5] top-level scope
   @ REPL[9]:1

EDIT: Besides Function (which is already dealt with), also Any and Core.Builtin have the property that Base.typename(T) has no field mt. This is fixed now.

EDIT 2: instancemethods(Core.Builtin) gives an empty method list although builtin functions are instances of this type. Is this a problem?

  • If/when the PR gets accepted, we need to add something to NEWS.md. Where would it go there? To "New language features", to "New library features" or elsewhere?

@brenhinkeller brenhinkeller added the feature Indicates new feature / enhancement requests label Dec 7, 2023
Co-authored-by: Max Horn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants