Click for expanded @code_warntype info.
julia> function good_gen()
list = [ Good([i]) for i in 1:1000 ]
x -> [ fetch(x)*y for y ∈ list ]
end
good_gen (generic function with 2 methods)
julia> function bad_gen()
list = [ Bad([i]) for i in 1:1000 ]
x -> [ fetch(x)*y for y ∈ list ]
end
bad_gen (generic function with 2 methods)
julia> good_prod = good_gen()
#34 (generic function with 1 method)
julia> bad_prod = bad_gen()
#40 (generic function with 1 method)
julia> m_bad = Container{Bad}(Bad([1]))
Container{SMatrix{1, 1, Int64}}([1])
julia> m_good = Container{Good}(Good([1]))
Container{SMatrix{1, 1, Int64, 1}}([1])
julia> @code_warntype good_prod(m_good)
MethodInstance for (::var"#34#37"{Vector{SMatrix{1, 1, Int64, 1}}})(::Container{SMatrix{1, 1, Int64, 1}})
from (::var"#34#37")(x) in Main at REPL[35]:3
Arguments
#self#::var"#34#37"{Vector{SMatrix{1, 1, Int64, 1}}}
x::Container{SMatrix{1, 1, Int64, 1}}
Locals
#35::var"#35#38"{Container{SMatrix{1, 1, Int64, 1}}}
Body::Vector{SMatrix{1, 1, Int64, 1}}
1 ─ %1 = Main.:(var"#35#38")::Core.Const(var"#35#38")
│ %2 = Core.typeof(x)::Core.Const(Container{SMatrix{1, 1, Int64, 1}})
│ %3 = Core.apply_type(%1, %2)::Core.Const(var"#35#38"{Container{SMatrix{1, 1, Int64, 1}}})
│ (#35 = %new(%3, x))
│ %5 = #35::var"#35#38"{Container{SMatrix{1, 1, Int64, 1}}}
│ %6 = Core.getfield(#self#, :list)::Vector{SMatrix{1, 1, Int64, 1}}
│ %7 = Base.Generator(%5, %6)::Base.Generator{Vector{SMatrix{1, 1, Int64, 1}}, var"#35#38"{Container{SMatrix{1, 1, Int64, 1}}}}
│ %8 = Base.collect(%7)::Vector{SMatrix{1, 1, Int64, 1}}
└── return %8
julia> @code_warntype good_prod(m_bad)
MethodInstance for (::var"#34#37"{Vector{SMatrix{1, 1, Int64, 1}}})(::Container{SMatrix{1, 1, Int64}})
from (::var"#34#37")(x) in Main at REPL[35]:3
Arguments
#self#::var"#34#37"{Vector{SMatrix{1, 1, Int64, 1}}}
x::Container{SMatrix{1, 1, Int64}}
Locals
#35::var"#35#38"{Container{SMatrix{1, 1, Int64}}}
Body::Vector
1 ─ %1 = Main.:(var"#35#38")::Core.Const(var"#35#38")
│ %2 = Core.typeof(x)::Core.Const(Container{SMatrix{1, 1, Int64}})
│ %3 = Core.apply_type(%1, %2)::Core.Const(var"#35#38"{Container{SMatrix{1, 1, Int64}}})
│ (#35 = %new(%3, x))
│ %5 = #35::var"#35#38"{Container{SMatrix{1, 1, Int64}}}
│ %6 = Core.getfield(#self#, :list)::Vector{SMatrix{1, 1, Int64, 1}}
│ %7 = Base.Generator(%5, %6)::Base.Generator{Vector{SMatrix{1, 1, Int64, 1}}, var"#35#38"{Container{SMatrix{1, 1, Int64}}}}
│ %8 = Base.collect(%7)::Vector
└── return %8
julia> @code_warntype bad_prod(m_good)
MethodInstance for (::var"#40#43"{Vector{SMatrix{1, 1, Int64, 1}}})(::Container{SMatrix{1, 1, Int64, 1}})
from (::var"#40#43")(x) in Main at REPL[36]:3
Arguments
#self#::var"#40#43"{Vector{SMatrix{1, 1, Int64, 1}}}
x::Container{SMatrix{1, 1, Int64, 1}}
Locals
#41::var"#41#44"{Container{SMatrix{1, 1, Int64, 1}}}
Body::Vector{SMatrix{1, 1, Int64, 1}}
1 ─ %1 = Main.:(var"#41#44")::Core.Const(var"#41#44")
│ %2 = Core.typeof(x)::Core.Const(Container{SMatrix{1, 1, Int64, 1}})
│ %3 = Core.apply_type(%1, %2)::Core.Const(var"#41#44"{Container{SMatrix{1, 1, Int64, 1}}})
│ (#41 = %new(%3, x))
│ %5 = #41::var"#41#44"{Container{SMatrix{1, 1, Int64, 1}}}
│ %6 = Core.getfield(#self#, :list)::Vector{SMatrix{1, 1, Int64, 1}}
│ %7 = Base.Generator(%5, %6)::Base.Generator{Vector{SMatrix{1, 1, Int64, 1}}, var"#41#44"{Container{SMatrix{1, 1, Int64, 1}}}}
│ %8 = Base.collect(%7)::Vector{SMatrix{1, 1, Int64, 1}}
└── return %8
julia> @code_warntype bad_prod(m_bad)
MethodInstance for (::var"#40#43"{Vector{SMatrix{1, 1, Int64, 1}}})(::Container{SMatrix{1, 1, Int64}})
from (::var"#40#43")(x) in Main at REPL[36]:3
Arguments
#self#::var"#40#43"{Vector{SMatrix{1, 1, Int64, 1}}}
x::Container{SMatrix{1, 1, Int64}}
Locals
#41::var"#41#44"{Container{SMatrix{1, 1, Int64}}}
Body::Vector
1 ─ %1 = Main.:(var"#41#44")::Core.Const(var"#41#44")
│ %2 = Core.typeof(x)::Core.Const(Container{SMatrix{1, 1, Int64}})
│ %3 = Core.apply_type(%1, %2)::Core.Const(var"#41#44"{Container{SMatrix{1, 1, Int64}}})
│ (#41 = %new(%3, x))
│ %5 = #41::var"#41#44"{Container{SMatrix{1, 1, Int64}}}
│ %6 = Core.getfield(#self#, :list)::Vector{SMatrix{1, 1, Int64, 1}}
│ %7 = Base.Generator(%5, %6)::Base.Generator{Vector{SMatrix{1, 1, Int64, 1}}, var"#41#44"{Container{SMatrix{1, 1, Int64}}}}
│ %8 = Base.collect(%7)::Vector
└── return %8
I think those kinds of incompletely typed type parameters should at least be colored differently in @code_warntype
though, that would make the issue more apparent. Do you mind opening an issue about this?