How keyword arguments kwfuncs work

A collegue who was contributing to the internals of Zygote wanted to understand what was going on with

https://github.com/FluxML/Zygote.jl/blob/ed366f32c0f520567526040d9f8acaf0d83613c3/src/compiler/chainrules.jl#L33
and
https://github.com/FluxML/ZygoteRules.jl/blob/699dbc293dc27f21e82460d87b7e58dd3f388984/src/adjoint.jl#L52

I gave a bit of an explination of f(x, kwargs...) lowering to f(::Core.kwfunc(typeof(f)), kwargs, x)
and the kwfunc function handling sorting the order of the keywords and filling in missing ones.
But I don’t fully understand it myself.
Where should someone go looking if they wanted to understand what is going on with these?

5 Likes

There is a short section about this in the devdocs:

https://docs.julialang.org/en/v1.6-dev/devdocs/functions/#Keyword-arguments

1 Like