Consider this:
using ComponentArrays, Parameters
function test(g, a; data=data)
@unpack P = data
if g == 1
oc = (g, a) -> P[g, a]
elseif g == 2
oc = (g, a) -> P[g, a] + 1
end
return oc(g, a)
end
const testca = ComponentArray{Float64}(P = [1 2; 3 4])
How can I get rid of those Any
s in the following?
@code_warntype test(1, 2; data = testca)
Variables
#unused#::Core.Compiler.Const(var"#test##kw"(), false)
@_2::NamedTuple{(:data,),Tuple{ComponentVector{Float64}}}
@_3::Core.Compiler.Const(test, false)
g::Int64
a::Int64
data::ComponentVector{Float64}
@_7::ComponentVector{Float64}
Body::Any
1 β %1 = Base.haskey(@_2, :data)::Core.Compiler.Const(true, false)
β %1
β (@_7 = Base.getindex(@_2, :data))
βββ goto #3
2 β Core.Compiler.Const(:(@_7 = Main.data), false)
3 β %6 = @_7::ComponentVector{Float64}
β (data = %6)
β %8 = (:data,)::Core.Compiler.Const((:data,), false)
β %9 = Core.apply_type(Core.NamedTuple, %8)::Core.Compiler.Const(NamedTuple{(:data,),T} where T<:Tuple, false)
β %10 = Base.structdiff(@_2, %9)::Core.Compiler.Const(NamedTuple(), false)
β %11 = Base.pairs(%10)::Core.Compiler.Const(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}(), false)
β %12 = Base.isempty(%11)::Core.Compiler.Const(true, false)
β %12
βββ goto #5
4 β Core.Compiler.Const(:(Base.kwerr(@_2, @_3, g, a)), false)
5 β %16 = Main.:(var"#test#5")(data, @_3, g, a)::Any
βββ return %16