Yes, https://github.com/JuliaLang/julia/issues/13254 and
https://github.com/JuliaLang/julia/issues/13665
is what I meant. I'm not sure any more whether "type instability" is the
right expression, since the type inferencer indeed consistently gives you
Array{T,N} for [[1,2];3] for all values. But you'd get more efficient code
if the type inferencer gave you Array{Int64,1} instead of Array{T,N} for
vcat.
It doesn't look like a regression to me, I get this already on Julia 0.3:
julia> g() = [[1,2];3]
g (generic function with 1 method)
julia> @code_typed g()
1-element Array{Any,1}:
:($(Expr(:lambda, {}, {{:_var0,:_var1},{{:_var0,(Array{Int64,1},Int64),0
},{:_var1,Array{Int64,1},18}},{}}, :(begin # none, line 1:
_var1 = vcat(1,2)::Array{Int64,1}
return cat(1,_var1::Array{Int64,1},3)::Array{T,N}
end::Array{T,N}))))
On Monday, October 19, 2015 at 5:02:57 PM UTC+2, Kristoffer Carlsson wrote:
>
> [a;b] is a bit regressed now when it comes to type stability, see:
> https://github.com/JuliaLang/julia/issues/13254
>
> On Monday, October 19, 2015 at 4:56:40 PM UTC+2, Josh Langsfeld wrote:
>>
>> [a; b] / vcat(...) is type stable. It may produce different output
>> depending on the types of a and b but it won't change behavior depending on
>> their values.
>>
>> On Monday, October 19, 2015 at 10:20:06 AM UTC-4, Andras Niedermayer
>> wrote:
>>>
>>> In light of the recent discussions (
>>> https://groups.google.com/forum/#!topic/julia-users/xJ7GpKAa16E and
>>> https://groups.google.com/forum/#!topic/julia-users/_lIVpV0e_WI) I got
>>> curious, whether there is a non-modifying version of push!, since
>>> push!(copy(a),b) doesn't feel right (I try to avoid modifying functions,
>>> except if I really need performance) and [a; b] is not type stable:
>>>
>>> f(a) = [a; 3]
>>> f2(a) = push!(copy(a),3)
>>>
>>>
>>> julia> Base.return_types(f,(Array{Int64,1},))
>>> 1-element Array{Any,1}:
>>> Array{T,N}
>>>
>>>
>>> julia> Base.return_types(f2,(Array{Int64,1},))
>>> 1-element Array{Any,1}:
>>> Array{Int64,1}
>>>
>>>
>>> I couldn't find anything in the Julia docs. Of course, I could just
>>> define my own
>>>
>>> push(a,vars...) = push!(copy(a),vars...)
>>>
>>>
>>> but if there is a standard way to do that, I'd prefer that. Maybe
>>> there's also some clever way to avoid making a copy if `a` is a literal
>>> (e.g.
>>> push([1,2])
>>> ).
>>>
>>> The same applies to unshift, etc.
>>>
>>> (Non-modifying `shift!` and `pop!` already exist with the names `first`
>>> and `last`. I'd find it easier to remember `shift` and `pop` -- it would
>>> also be more similar to `merge` vs `merge!` for dictionaries, but I guess
>>> that's just my taste.)
>>>
>>