Skip to content

Commit 798e447

Browse files
fingolfinaviatesk
authored andcommitted
Fix JET warning related to _array_for (#60461)
Calls to this method are produced by syntax lowering for simple typed comprehensions. The current signature is ambiguous, making JET believe that the modified method could have ended up invoking itself. Resolve this by renaming the other methods. These are the the warnings I am seeing while JETing a package: ``` ││┌ _array_for(::Type{T}, itr::AbstractVector{T} where T<:NCRingElement, isz::Any) where T @ Base ./array.jl:673 │││┌ _array_for(::Type, itr::Base.SizeUnknown, isz::Any) @ Base ./array.jl:673 ││││┌ _similar_shape(itr::Base.SizeUnknown, ::Base.HasLength) @ Base ./array.jl:657 │││││ no matching method found `length(::Base.SizeUnknown)`: length(itr::Base.SizeUnknown) ││││└──────────────────── ││││┌ _similar_shape(itr::Base.SizeUnknown, ::Base.HasShape) @ Base ./array.jl:658 │││││┌ axes(A::Base.SizeUnknown) @ Base ./abstractarray.jl:98 ││││││ no matching method found `size(::Base.SizeUnknown)`: size(A::Base.SizeUnknown) │││││└──────────────────── ``` and ``` ││││││││┌ Base.AnnotatedString(s::String, annots::Any) @ Base ./strings/annotated.jl:107 │││││││││┌ collect(::Type{@NamedTuple{region::UnitRange{Int64}, label::Symbol, value}}, itr::Any) @ Base ./array.jl:641 ││││││││││┌ _collect(::Type{@NamedTuple{…}}, itr::Any, isz::Union{Base.HasLength, Base.HasShape}) @ Base ./array.jl:643 │││││││││││┌ _array_for(::Type{@NamedTuple{region::UnitRange{Int64}, label::Symbol, value}}, itr::Base.HasLength, isz::Any) @ Base ./array.jl:673 ││││││││││││┌ _similar_shape(itr::Base.HasLength, ::Base.HasLength) @ Base ./array.jl:657 │││││││││││││ no matching method found `length(::Base.HasLength)`: length(itr::Base.HasLength) ││││││││││││└──────────────────── ││││││││││││┌ _similar_shape(itr::Base.HasLength, ::Base.HasShape) @ Base ./array.jl:658 │││││││││││││┌ axes(A::Base.HasLength) @ Base ./abstractarray.jl:98 ││││││││││││││ no matching method found `size(::Base.HasLength)`: size(A::Base.HasLength) │││││││││││││└──────────────────── ││││││││││││┌ _array_for(::Type{@NamedTuple{region::UnitRange{Int64}, label::Symbol, value}}, itr::Base.HasLength, isz::Nothing) @ Base ./array.jl:673 │││││││││││││ no matching method found `_similar_shape(::Base.HasLength, ::Nothing)`: Base._similar_shape(itr::Base.HasLength, isz::Nothing) ││││││││││││└──────────────────── ```
1 parent fb87ed4 commit 798e447

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

base/array.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ julia> collect(Float64, 1:2:5)
641641
collect(::Type{T}, itr) where {T} = _collect(T, itr, IteratorSize(itr))
642642

643643
_collect(::Type{T}, itr, isz::Union{HasLength,HasShape}) where {T} =
644-
copyto!(_array_for(T, isz, _similar_shape(itr, isz)), itr)
644+
copyto!(_array_for_inner(T, isz, _similar_shape(itr, isz)), itr)
645645
function _collect(::Type{T}, itr, isz::SizeUnknown) where T
646646
a = Vector{T}()
647647
for x in itr
@@ -665,12 +665,12 @@ _similar_for(c::AbstractArray, ::Type{T}, itr, ::HasShape, axs) where {T} =
665665
similar(c, T, axs)
666666

667667
# make a collection appropriate for collecting `itr::Generator`
668-
_array_for(::Type{T}, ::SizeUnknown, ::Nothing) where {T} = Vector{T}(undef, 0)
669-
_array_for(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, Int(len))
670-
_array_for(::Type{T}, ::HasShape{N}, axs) where {T,N} = similar(Array{T,N}, axs)
668+
_array_for_inner(::Type{T}, ::SizeUnknown, ::Nothing) where {T} = Vector{T}(undef, 0)
669+
_array_for_inner(::Type{T}, ::HasLength, len::Integer) where {T} = Vector{T}(undef, Int(len))
670+
_array_for_inner(::Type{T}, ::HasShape{N}, axs) where {T,N} = similar(Array{T,N}, axs)
671671

672672
# used by syntax lowering for simple typed comprehensions
673-
_array_for(::Type{T}, itr, isz) where {T} = _array_for(T, isz, _similar_shape(itr, isz))
673+
_array_for(::Type{T}, itr, isz) where {T} = _array_for_inner(T, isz, _similar_shape(itr, isz))
674674

675675

676676
"""
@@ -789,10 +789,10 @@ function collect(itr::Generator)
789789
shp = _similar_shape(itr, isz)
790790
y = iterate(itr)
791791
if y === nothing
792-
return _array_for(et, isz, shp)
792+
return _array_for_inner(et, isz, shp)
793793
end
794794
v1, st = y
795-
dest = _array_for(typeof(v1), isz, shp)
795+
dest = _array_for_inner(typeof(v1), isz, shp)
796796
# The typeassert gives inference a helping hand on the element type and dimensionality
797797
# (work-around for #28382)
798798
et′ = et <: Type ? Type : et

0 commit comments

Comments
 (0)