When I run your code the example with f(rand(Int, 3)) also fails. I donβt think this is too surprising since your code is type unstable. x is changing from an Int to a Float64 here. If we initialize x in a type stable manner, everything is fine:
julia> function f(v)
x = zero(promote_type(Float64, eltype(v)))
@turbo for i β eachindex(v)
amt = v[i] * 0.1
x += amt
end
x
end
f (generic function with 1 method)
julia> f(rand(Int, 2))
2.6610511336745555e17
julia> f([1, 2])
0.30000000000000004
julia> f([1, 2, 3])
0.6000000000000001
LoopVectorization.jl is pretty brittle around things like this.
Yes, it generally assumes code is type stable.
This is a case where a better error message would be preferable over getting the example to work.
Unfortunately, an error message would probably be more difficult.