Closed
Description
So, this is a very annoying problem, and one that people don't seem to really know about. It's best demonstrated by example:
using Base: tail
function my_getindex(a_tuple, which_ones)
rest = my_getindex(tail(a_tuple), tail(which_ones))
if first(which_ones)
(first(a_tuple), rest...)
else
rest
end
end
function my_getindex(a_tuple::Tuple{}, which_ones::Tuple{})
()
end
function constant_select(a_tuple)
my_getindex(a_tuple, (true, false, true, false))
end
@code_warntype constant_select((1, 1.0, "a", :a))
# Body::Tuple{Int64,Vararg{Any,N} where N}
My naive understanding of what's going on is that when Julia recurs into my_getindex
, the compiler detects that which_ones
is still a tuple of Bools (just a smaller one), figures out that we are recurring, and bails on constant propagation.
I've always gotten the impression that this is an unfixable problem, but...if it's fixable, that would be super cool.
Metadata
Metadata
Assignees
Labels
No labels