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

Add full kwarg support to signature #6

Open
oxinabox opened this issue Mar 28, 2020 · 0 comments
Open

Add full kwarg support to signature #6

oxinabox opened this issue Mar 28, 2020 · 0 comments
Labels
signature relating to the signature function to get def from methods

Comments

@oxinabox
Copy link
Member

Follow up for once #1 is merged.
Adding keyword support.

It is just really fiddly.

The information is there but its not in a very easy to acess form:

julia> g(; x=1, y=3) = x+y
g (generic function with 2 methods)

julia> g(a; b=2) = a-b
g (generic function with 2 methods)

julia> meths = methods(g)
# 2 methods for generic function "g":
[1] g(; x, y) in Main at REPL[65]:1
[2] g(a; b) in Main at REPL[66]:1

julia> kwsorter_meths = methods(meths.mt.kwsorter)
# 2 methods for anonymous function "g##kw":
[1] (::var"#g##kw")(::Any, ::typeof(g)) in Main at REPL[65]:1
[2] (::var"#g##kw")(::Any, ::typeof(g), a) in Main at REPL[66]:1

julia> Base.uncompressed_ast(first(kwsorter_meths))
CodeInfo(
     @ REPL[65]:1 within `g##kw'
1 ── %1  = Base.haskey(@_2, :x)
└───       goto #3 if not %1
2 ──       @_6 = Base.getindex(@_2, :x)
└───       goto #4
3 ──       @_6 = 1
4 ┄─       x = @_6
│    %7  = Base.haskey(@_2, :y)
└───       goto #6 if not %7
5 ──       @_7 = Base.getindex(@_2, :y)
└───       goto #7
6 ──       @_7 = 3
7 ┄─       y = @_7
│    %13 = (:x, :y)
│    %14 = Core.apply_type(Core.NamedTuple, %13)
│    %15 = Base.structdiff(@_2, %14)
│    %16 = Base.pairs(%15)
│    %17 = Base.isempty(%16)
└───       goto #9 if not %17
8 ──       goto #10
9 ──       Base.kwerr(@_2, @_3)
10 ┄ %21 = Main.:(var"#g#10")(x, y, @_3)
└───       return %21
)
@oxinabox oxinabox changed the title Add kwarg support to signature Add full kwarg support to signature Apr 14, 2020
@oxinabox oxinabox added the signature relating to the signature function to get def from methods label Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
signature relating to the signature function to get def from methods
Projects
None yet
Development

No branches or pull requests

1 participant