Consider the following code and its @code_warntype
t = table([1,1,2,2], [1,2,1,2], [1,2,3,4], names=[:a,:b,:c], pkey = (:a, :b))
function my_function(t::T) where {T<:IndexedTable}
IndexedTables.select(t, IndexedTables.Not(:c))
return IndexedTables.transform(t, :c => collect(5:8))
end
julia> @code_warntype my_function(t)
Variables
#self#::Core.Compiler.Const(my_function, false)
t::IndexedTable{StructArrays.StructArray{NamedTuple{(:a, :b, :c),Tuple{Int64,Int64,Int64}},1,NamedTuple{(:a, :b, :c),Tuple{Array{Int64,1},Array{Int64,1},Array{Int64,1}}},Int64}}
Body::Any
1 ─ %1 = IndexedTables.select::Core.Compiler.Const(IndexedTables.select, false)
│ %2 = IndexedTables.Not::Core.Compiler.Const(IndexedTables.Not, false)
│ %3 = (%2)(:c)::Core.Compiler.Const(IndexedTables.Not{Symbol}(:c), false)
│ (%1)(t, %3)
│ %5 = IndexedTables.transform::Core.Compiler.Const(IndexedTables.transform, false)
│ %6 = (5:8)::Core.Compiler.Const(5:8, false)
│ %7 = Main.collect(%6)::Array{Int64,1}
│ %8 = (:c => %7)::Core.Compiler.PartialStruct(Pair{Symbol,Array{Int64,1}}, Any[Core.Compiler.Const(:c, false), Array{Int64,1}])
│ %9 = (%5)(t, %8)::Any
└── return %9
Is the possible to fix such a “type-instability” so that return type is not Any
but a concrete type? Given that I know the types of each column of the IndexedTable, I was thinking that one should be able to patch this up but maybe I’m misunderstanding and any explanation will be instructive for me. Thanks!