Hello,
I noticed @code_warntype does not produce a helpful output when the function in question has keyword arguments. Is there a way to call @code_warntype, such that we get more information?
Here is a minimal example I could find in julia-1.3.0
. The following are two type unstable functions that do exactly the same thing.
function array1(arr)
if length(arr) > 3
result = rand(3)
else
result = arr
end
result
end
function array2(arr; Ο΅ = 10e-12)
if length(arr) > 3
result = rand(3)
else
result = arr
end
result
end
However, when called with @code_warntype, they return very different outputs.
@code_warntype array1([2,2])
Variables
#self#::Core.Compiler.Const(array1, false)
arr::Array{Int64,1}
result::Union{Array{Float64,1}, Array{Int64,1}}
Body::Union{Array{Float64,1}, Array{Int64,1}}
1 β Core.NewvarNode(:(result))
β %2 = Main.length(arr)::Int64
β %3 = (%2 > 3)::Bool
βββ goto #3 if not %3
2 β (result = Main.rand(3))
βββ goto #4
3 β (result = arr)
4 β return result
and
@code_warntype array2([2,2])
Variables
#self#::Core.Compiler.Const(array2, false)
arr::Array{Int64,1}
Body::Union{Array{Float64,1}, Array{Int64,1}}
1 β %1 = Main.:(var"#array2#9")(1.0e-11, #self#, arr)::Union{Array{Float64,1}, Array{Int64,1}}
βββ return %1
In the case of array1, @code_warntype tells us about internal function calls, such as Main.length, whereas in the case of array2, we only get a single Main.:(var"#array2#9")(1.0e-11, #self#, arr)
, and no information about whatβs happening inside the function.
When trying to understand type instability of complicated functions with keyword arguments, this is a pretty huge roadblock. Is there a way around this?
Thanks in advance!