I think I am getting a type instability in my code, but I'm not sure why. Consider the following code.
module test
mutable struct Data
arr::Array{Int64, 1}
Data(n) = new(zeros(n))
end
function main()
data = Data(5)
data.arr
end
println(main())
@code_warntype main()
end
The output of @code_warntype main() starts with the following three lines
Variables:
#self#::test.#main
data::Any
^^^
Maybe I am not interpreting the output of @code_warntype correctly, but it seems that I have a type-instability for the data variable. Can someone shed some light on what is going on here? I'm using 0.6.2 if that helps.
Variables: #self# <optimized out> data <optimized out>. However, the body contains references toArray{Float64,1}which I can clean out by usingData(n) = new(zeros(Int64, n)). This also reduces the length of the native code (@code_native). There are still references tosvec(Any, Int64), but you'll need someone cleverer than me to tell you what that means! - Mark BirtwistleDatais defining an outer constructorData(n::Integer) = Data(zeros(n)). - Gnimuc@code_warntypeof your real code? If it is too long, you could pick some red marked lines. - Gnimuc