RuntimeGeneratedFunctions.jl icon indicating copy to clipboard operation
RuntimeGeneratedFunctions.jl copied to clipboard

Support default argument values

Open shashi opened this issue 4 years ago • 1 comments

Is this supposed to work?

julia> f = @RuntimeGeneratedFunction(:(f(x,z=3) = y))
ERROR: argument malformed. Got $(Expr(:kw, :z, 3))
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33

Can it be made to work? I'm trying to use this to get stuff like this https://github.com/mcabbott/Tullio.jl/pull/81/files#diff-5e84de38fb08a2615207f16bf896e93ccb8c58bbfa50e6420fc8d54d88daca84R1082 to work since I want to use the @tullio macro inside generated function body... is it technically infeasible?

shashi avatar Feb 03 '21 15:02 shashi

I think this is probably feasible. f(x,z=3) is normally lowered to a pair of methods and dispatch figures out which one to call. For RGFs we only really have one method (albeit parametric) so it's probably necessary to add some dynamic code to the body of the RGF to simply fill in any default arguments if the args list is too short. I think this would be compiled efficiently, though you'd have to check.

c42f avatar Feb 06 '21 03:02 c42f