Help understand inference problem

in the MWE

using StaticArrays
flat_outer_product(f::F, a, b) where {F} = mapreduce(a -> map(b -> f(a, b), b), vcat, a)
a = SVector(1, 2)
b = SVector(2, 3)
@code_warntype flat_outer_product(SVector, a, b) # does not infer
@code_warntype flat_outer_product((a, b) -> SVector(a, b), a, b) # infers

the first call does not infer, the second does.

Is arity the problem? I thought it was implied by the way f was used. Can someone please explain what is going on?

Should I open an issue about this?

1 Like

https://github.com/JuliaLang/julia/issues/23618

AFAIU, the closure doesn’t specialize on Type, same as in:

julia> struct Foo{T}
       v::T
       end

julia> Foo(Int64)
Foo{DataType}(Int64)
3 Likes

Thanks! Is there a workaround here (for generic f?)