Build_function: stack overflow in type inference

I have tried using symbolic arrays and symbolic array expressions, but I had problems [1] where substitute and build_function both failed to replace all occurences of the variables, and I therefore started to scalarize my expressions to obtain correct results.

I now sometimes define symbolic arrays, but I always scalarize them before using them in mathematical operations.

By the way, I never spent enough time debugging my issues with symbolic arrays, but I think some may have been related to getindex expressions like (broadcast(-, K))[1, 2] perhaps being considered non-composite expressions, due to [2].

[1] Symbolics build_function issues on complicated expressions

[2] In Symbolics.jl, in the file utils.jl, getindex operations are all treated the same, regardless of the complexity of the argument to getindex, in the following function.

function is_singleton(e)
    if istree(e)
        op = operation(e)
        op === getindex && return true
        istree(op) && return is_singleton(op) # recurse to reach getindex for array element variables
        return issym(op)
    else
        return issym(e)
    end
end