From 60cbda8a40c2e152bb348680dbd0d02d61fc9c8d Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 17 Jan 2021 03:41:32 -0500 Subject: [PATCH] Force-specialize on `T` in `cat_similar` These methods are tiny (quick to compile), call methods that force-specialize on `T`, and are called by methods that force-specialize on `T`. Consequently, there does not seem to be any good reason to lose inferrability in these methods. --- base/abstractarray.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index ad32a102fa7aa..30072363a34c3 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1481,7 +1481,7 @@ vcat(V::AbstractVector{T}...) where {T} = typed_vcat(T, V...) # but that solution currently fails (see #27188 and #27224) AbstractVecOrTuple{T} = Union{AbstractVector{<:T}, Tuple{Vararg{T}}} -_typed_vcat_similar(V, T, n) = similar(V[1], T, n) +_typed_vcat_similar(V, ::Type{T}, n) where T = similar(V[1], T, n) _typed_vcat(::Type{T}, V::AbstractVecOrTuple{AbstractVector}) where T = _typed_vcat!(_typed_vcat_similar(V, T, mapreduce(length, +, V)), V) @@ -1577,8 +1577,8 @@ cat_size(A::AbstractArray, d) = size(A, d) cat_indices(A, d) = OneTo(1) cat_indices(A::AbstractArray, d) = axes(A, d) -cat_similar(A, T, shape) = Array{T}(undef, shape) -cat_similar(A::AbstractArray, T, shape) = similar(A, T, shape) +cat_similar(A, ::Type{T}, shape) where T = Array{T}(undef, shape) +cat_similar(A::AbstractArray, ::Type{T}, shape) where T = similar(A, T, shape) cat_shape(dims, shape::Tuple{Vararg{Int}}) = shape function cat_shape(dims, shapes::Tuple)