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 callsuper macro. #20131

Closed
wants to merge 3 commits into from
Closed

Add callsuper macro. #20131

wants to merge 3 commits into from

Conversation

simonbyrne
Copy link
Contributor

@simonbyrne simonbyrne commented Jan 19, 2017

Fixes #18252 and #7045.

@simonbyrne
Copy link
Contributor Author

Feel free to bikeshed names.

kwargs = Any[]
blk = quote end
for arg in args
if isa(arg,Expr) && arg.head == :kw
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not entirely correct. A few cases that should be handled and possibly tested are. (These are the reason I started but didn't finish the pr yet...)

  1. Evaluation order

    Currently :parameters are always evaluated the first. It's not necessarily the best choice but this should be consisent with normal calls.

  2. :parameters can have ...

  3. :parameters can have non :kw in it

  4. positional arguments can also have ...

  5. if parameter only have ...s and all of them are empty, the non-kw version should be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what non-:kw can a :parameters have other than ...?

Copy link
Contributor

Choose a reason for hiding this comment

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

Any, iterable objects

julia> f(;kws...) = kws
f (generic function with 1 method)

julia> j = [:j, :k]
2-element Array{Symbol,1}:
 :j
 :k

julia> f(;:a=>:b, (:c, :d), [:e, :f], (:g, :h, :i), j)
5-element Array{Any,1}:
 (:a,:b)
 (:c,:d)
 (:e,:f)
 (:g,:h)
 (:j,:k)

Copy link
Member

Choose a reason for hiding this comment

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

@yuyichao, wouldn't be easier all around if you just did this PR? There was a similar back and forth when I proposed a possible implementation

Copy link
Contributor

@yuyichao yuyichao Jan 22, 2017

Choose a reason for hiding this comment

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

Maybe. I started an implementation but haven't finished it yet (collecting data of what input should/can be supported and what generic fallback path I can use).....

push!(vals, val)
push!(types, typ)
if isa(arg,Expr) && arg.head == :(::) && length(arg.args) == 2
push!(blk.args, :($typ = $(esc(arg.args[2]))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, val should be evaluated before the type.

end
end
if isempty(kwargs)
push!(blk.args, :(invoke($(esc(fname)), Tuple{$(types...)}, $(vals...))))
Copy link
Contributor

Choose a reason for hiding this comment

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

And fname should be evaluated before the arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, fname evaluation is a bit weird:

julia> f(args...; kwargs...) = (args,kwargs)
f (generic function with 1 method)

julia> (println("f"); f)((println("a"); "a"); [:y,(println("b"); "b")])
b
f
f
a
(("a",),Any[(:y,"b")])

julia> (println("f"); f)((println("a"); "a"); [:y => (println("b"); "b")]...)
b
f
a
f
f
(("a",),Any[(:y,"b")])

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a lowering bug. The lowering code should emit a temporary variable to hold f if it cannot proof that evaluating f is "pure".

@StefanKarpinski
Copy link
Member

I like the name, @simonbyrne. Thanks for pushing this forward – it's a much nicer interface than bare invoke.

@JeffBezanson
Copy link
Member

IIUC, this doesn't fully fix #7045 since it doesn't fix the case of using invoke directly.

@jlumpe
Copy link
Contributor

jlumpe commented Dec 29, 2019

This would be a really nice feature, is anyone still working on it?

@Keno
Copy link
Member

Keno commented Dec 25, 2020

If I understand correctly this is superseded by #38438. Let me know if I misunderstood.

@Keno Keno closed this Dec 25, 2020
@simonbyrne
Copy link
Contributor Author

Indeed it is.

@simonbyrne simonbyrne deleted the sb/callsuper branch January 4, 2021 16:40
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.

add @callsuper macro
7 participants