Hello,
Iβm facing type instabilities with a struct containing a Ref value. Here I show a minimal example
struct Prova{T1<:Integer}
a::Ref{T1}
function Prova(a::T1) where {T1}
new{T1}(Ref(a))
end
end
function function_test(p::Prova)
c = p.a[]
if !iszero(c)
return c
end
return 46
end
p = Prova(42)
Prova{Int64}(Base.RefValue{Int64}(42))
But if I test the type instabilities I get
@code_warntype function_test(p)
MethodInstance for function_test(::Prova{Int64})
from function_test(p::Prova) @ Main Untitled-1:111
Arguments
#self#::Core.Const(function_test)
p::Prova{Int64}
Locals
c::Any
Body::Any
1 β %1 = Base.getproperty(p, :a)::Ref{Int64}
β (c = Base.getindex(%1))
β %3 = Main.iszero(c)::Any
β %4 = !%3::Any
βββ goto #3 if not %4
2 β return c
3 β return 46