I find that it is relatively easy to get non-inferred code where the mapfoldl family is involved, because their implementation has so many layers. Eg a simple example is
_length(c::Real) = 1
_length(c::Tuple) = mapfoldl(_length, +, c; init = 0)
_length(c::NamedTuple) = _length(values(c))
_length(c::AbstractArray) = sum(_length, c; init = 0)
x = (a = 1, b = [2.0, 3.0], d = (4, 5f0))
@code_warntype _length(x)
using JET
@report_opt _length(x)
My understanding is that #48059 is meant to address this, but it is currently dormant.
Am I abusing the inference engine with simple code as above? Should I do something differently, eg use generated functions for the tuples?
Just to clarify, I am looking for general advice, the above is an MWE. I routinely write code that fails inference because of deeply nested mapXXX functions. I am wondering if I should give that up, or do it differently.