Open MilesCranmer opened 1 month ago
Note also you can get around this with a trick:
julia> f(; t::Val{T}) where {T} = T
f (generic function with 1 method)
julia> Test.@inferred f(t=Val(Float32))
Float32
Also posted an issue on Julia https://github.com/JuliaLang/julia/issues/54661
The following behavior occurs:
I think this may be "real" and in some ways a fundamental issue with how Julia handles keyword calls. Actually
Test.@inferred
does the same thing:Keyword arguments are passed to Julia functions as a
NamedTuple
viaCore.kwcall
. However, we have thatand thus Julia relies on constant propagation for this to not be type unstable, it seems. Or at least
Base.promote_op
can't figure it out from the types alone. The only way this is type stable is if you rely constant propagation.In other words, if your function's return type depends on a keyword argument which is itself a type (NOT a value, it must be a
DataType
!), then that function seems to be type unstable, and so should be rewritten. The only way it can be type stable is if you get constant propagation.