How can I convince the compiler that a recursion is finite and can be unrolled? It works for me when the recursion has one step (some function calling itself), but not for two steps (two functions calling each other).
Here is an example: I move elements from a tuple t2 to a tuple t1:
f(t1, ::Tuple{}) = t1
f(t1, t2) = f((t1..., t2[1]), t2[2:end])
ff(t) = f((), t)
g1(t1, ::Tuple{}) = t1
g1(t1, t2) = g2((t1..., t2[1]), t2[2:end])
g2(t1, t2) = g1(t1, t2)
gg(t) = g1((), t)
The compiler knows that the recursion in f ends, but it doesn’t know it for the one involving g1 and g2:
julia> t = (1, 2, 3); ff(t), gg(t)
((1, 2, 3), (1, 2, 3))
julia> using Chairmarks; @b ff($t), gg($t)
(2.456 ns, 26.151 ns (3 allocs: 80 bytes))
Is there a way to encourage the compiler to unroll the recursion for g1 and g2? I’ve tried to decorate the code with many @inline and @assume_effects :total, but that didn’t help.