Auto-conversion of keyword arguments, status?

I know there have been some discussions (and issues) about this in the past, but I’m curious what the current position on “auto-conversions for keyword arguments” is.

Is that something that will/could be added in future Julia versions? This would make it easier to write type-safe functions that have keyword arguments - e.g. one would declare the function with arg::Int = 42 instead of arg::Integer = 42.

Could you give some example when the type stability is a problem? Just trying something naively doesn’t show it:

julia> @noinline f(;x::Integer=3) = x
f (generic function with 1 method)

julia> g(x) = f(;x=x) + f(;x=x)
g (generic function with 2 methods)

julia> @code_warntype g(3)
Body::Int64
1 ── %1  = Main.f::Core.Compiler.Const(f, false)
│    %2  = (Base.sle_int)(1, 1)::Bool
└───       goto #3 if not %2
2 ── %4  = (Base.sle_int)(1, 0)::Bool
└───       goto #4
3 ──       nothing
4 ┄─ %7  = φ (#2 => %4, #3 => false)::Bool
└───       goto #6 if not %7
5 ──       invoke Base.getindex(()::Tuple, 1::Int64)
└───       $(Expr(:unreachable))
6 ┄─       goto #7
7 ──       goto #8
8 ──       goto #9
9 ──       goto #10
10 ─ %15 = invoke Main.:(#f#12)(_2::Int64, %1::Function)::Int64
└───       goto #11
11 ─ %17 = Main.f::Core.Compiler.Const(f, false)
│    %18 = (Base.sle_int)(1, 1)::Bool
└───       goto #13 if not %18
12 ─ %20 = (Base.sle_int)(1, 0)::Bool
└───       goto #14
13 ─       nothing
14 ┄ %23 = φ (#12 => %20, #13 => false)::Bool
└───       goto #16 if not %23
15 ─       invoke Base.getindex(()::Tuple, 1::Int64)
└───       $(Expr(:unreachable))
16 ┄       goto #17
17 ─       goto #18
18 ─       goto #19
19 ─       goto #20
20 ─ %31 = invoke Main.:(#f#12)(_2::Int64, %17::Function)::Int64
└───       goto #21
21 ─ %33 = (Base.add_int)(%15, %31)::Int64
└───       return %33
2 Likes

My bad - I think I was stuck in v0.6 times here, mentally. This used not to be type stable, and I always meant to ask about it, but now it seems to be. So while we don’t dispatch on keyword arguments, code generation does generate different code for different kwarg types now? Sorry, wasn’t aware of this!