Should I expect the following to be type-stable? I think the types are inferrable in principle, but maybe the Tuple-of-Pairs structure is just too ‘complicated’?
julia> using Cthulhu
julia> function foo(t::Pair{Symbol,Int64}...)
t1 = Tuple(x[1] for x in t)
t2 = Tuple(x[2] for x in t)
return nothing
end
foo (generic function with 1 method)
julia> @descend foo(:a=>1, :b=>2, :c=>3)
foo(t::Pair{Symbol, Int64}...) @ Main REPL[25]:1
1 function foo(t::Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}::Pair{Symbol,Int64}...)::Core.Const(nothing)
2 t1::Tuple{Vararg{Symbol}} = Tuple(x[1] for x in t::Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}::Base.Generator{Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}, var"#foo##12#foo##13"})
3 t2::Tuple{Vararg{Int64}} = Tuple(x[2] for x in t::Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}::Base.Generator{Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}, var"#foo##14#foo##15"})
4 return nothing::Core.Const(nothing)
5 end
Select a call to descend into or ↩ to ascend. [q]uit. [b]ookmark.
Toggles: [w]arn, [h]ide type-stable statements, [t]ype annotations, [s]yntax highlight for Source/LLVM/Native, [j]ump to source always.
Show: [S]ource code, [A]ST, [T]yped code, [L]LVM IR, [N]ative code
Actions: [E]dit source code, [R]evise and redisplay
• x in t::Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}
t1
x in t::Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}, Pair{Symbol, Int64}}
t2
↩
I tried several variations, e.g. making t
an NTuple
rather than splatting, but didn’t find any that made any difference.
This is an issue for me because for example trying to use t2
to create an array a = zeros(t2...)
will not know the dimension of the array, introducing more type instability. Going to try to work around this somehow, but suspect alternatives will make my code a little bit less readable…