Skip to content

Commit b02d0c6

Browse files
committed
eachindex for linear indexing for Array and Memory: typeassert
The method return type is known concretely as `OneTo{Int}`, however the compiler can't tell because there are too many methods matching `length(::Array)`, over the world-splitting threshold, `max_methods`. Cross-reference WIP PR JuliaLang#57627, which might help here in another way by decreasing the number of unnecessary methods, however merging that PR would also cause regressions if world-splitting is not disabled first for `length` (xref WIP PR JuliaLang#59377). Fix that by asserting the return type of the `length` call as `Int`. The `typeassert` should improve abstract return type inference, and consequently make the sysimage more resistant to invalidation.
1 parent cbea8cf commit b02d0c6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ function eachindex(A::AbstractArray, B::AbstractArray...)
387387
@inline
388388
eachindex(IndexStyle(A,B...), A, B...)
389389
end
390-
eachindex(::IndexLinear, A::Union{Array, Memory}) = unchecked_oneto(length(A))
390+
eachindex(::IndexLinear, A::Union{Array, Memory}) = unchecked_oneto(length(A)::Int)
391391
eachindex(::IndexLinear, A::AbstractArray) = (@inline; oneto(length(A)))
392392
eachindex(::IndexLinear, A::AbstractVector) = (@inline; axes1(A))
393393
function eachindex(::IndexLinear, A::AbstractArray, B::AbstractArray...)

0 commit comments

Comments
 (0)