ArrayInterface.jl icon indicating copy to clipboard operation
ArrayInterface.jl copied to clipboard

`getindex` method ambiguities with `AbstractTrees`, `Base`, and `OffsetArrays`

Open chriselrod opened this issue 3 years ago • 2 comments

julia> using ArrayInterface, OffsetArrays, Test

julia> amb = Test.detect_ambiguities(ArrayInterface, OffsetArrays)
5-element Vector{Tuple{Method, Method}}:
 (getindex(x::ArrayInterface.LazyAxis, i::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/axes.jl:293, getindex(r::AbstractUnitRange, s::Base.IdentityUnitRange{var"#s1"} where var"#s1"<:(AbstractUnitRange{var"#s2"} where var"#s2"<:Integer)) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513)
 (getindex(r::ArrayInterface.OptionallyStaticUnitRange, s::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/ranges.jl:296, getindex(r::AbstractUnitRange, s::OffsetArrays.IdOffsetRange) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513)
 (getindex(r::ArrayInterface.OptionallyStaticUnitRange, s::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/ranges.jl:296, getindex(r::AbstractUnitRange, s::Base.IdentityUnitRange{var"#s1"} where var"#s1"<:(AbstractUnitRange{var"#s2"} where var"#s2"<:Integer)) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513)
 (getindex(x::AbstractArray, ::AbstractTrees.ImplicitRootState) in AbstractTrees at /home/chriselrod/.julia/packages/AbstractTrees/oHb1F/src/iteration.jl:103, getindex(A::ArrayInterface.AbstractArray2, args...) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/ArrayInterface.jl:607)
 (getindex(x::ArrayInterface.LazyAxis, i::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/axes.jl:293, getindex(r::AbstractUnitRange, s::OffsetArrays.IdOffsetRange) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513)

julia> for (a1,a2) ∈ amb
           println(a1, "\n", a2, "\n")
       end
getindex(x::ArrayInterface.LazyAxis, i::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/axes.jl:293
getindex(r::AbstractUnitRange, s::Base.IdentityUnitRange{var"#s1"} where var"#s1"<:(AbstractUnitRange{var"#s2"} where var"#s2"<:Integer)) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513

getindex(r::ArrayInterface.OptionallyStaticUnitRange, s::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/ranges.jl:296
getindex(r::AbstractUnitRange, s::OffsetArrays.IdOffsetRange) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513

getindex(r::ArrayInterface.OptionallyStaticUnitRange, s::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/ranges.jl:296
getindex(r::AbstractUnitRange, s::Base.IdentityUnitRange{var"#s1"} where var"#s1"<:(AbstractUnitRange{var"#s2"} where var"#s2"<:Integer)) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513

getindex(x::AbstractArray, ::AbstractTrees.ImplicitRootState) in AbstractTrees at /home/chriselrod/.julia/packages/AbstractTrees/oHb1F/src/iteration.jl:103
getindex(A::ArrayInterface.AbstractArray2, args...) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/ArrayInterface.jl:607

getindex(x::ArrayInterface.LazyAxis, i::AbstractUnitRange{var"#s15"} where var"#s15"<:Integer) in ArrayInterface at /home/chriselrod/.julia/packages/ArrayInterface/CYf5x/src/axes.jl:293
getindex(r::AbstractUnitRange, s::OffsetArrays.IdOffsetRange) in OffsetArrays at /home/chriselrod/.julia/packages/OffsetArrays/EYLoR/src/OffsetArrays.jl:513

So:

  1. (::ArrayInterface.LazyAxis)[i::Base.IdentityUnitRange]
  2. (::ArrayInterface.OptionallyStaticUnitRange)[::OffsetArrays.IdOffsetrange]
  3. (::ArrayInterface.OptionallyStaticUnitRange)[::Base.IdentityUnitRange]
  4. (::ArrayInterface.AbstractArray2)[::AbstractTrees.ImplicitRootState]
  5. (ArrayInterface.LazyAxis)[OffsetArrays.IdOffsetRange]

chriselrod avatar Jun 18 '21 02:06 chriselrod

This is partly due to a new type piracy in https://github.com/JuliaArrays/OffsetArrays.jl/pull/244, a patch might need https://github.com/JuliaLang/julia/pull/41224 merged first.

cc: @jishnub

johnnychen94 avatar Jun 18 '21 02:06 johnnychen94

As a temporary fix perhaps OffsetArrays may limit its piracy to ranges defined in Base. That should fix this, and it's unlikely that packages specifically depend on this behavior for range types that that they define.

jishnub avatar Jun 20 '21 07:06 jishnub