Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aqua.jl reports method ambiguities for InlineStrings.jl methods #64

Open
brainandforce opened this issue Mar 17, 2023 · 4 comments
Open

Comments

@brainandforce
Copy link
Contributor

I was considering adding InlineStrings.jl to a package I'm developing that uses Aqua.jl for automated testing, but during the CI run I found this in the report:

3 ambiguities found
Ambiguity #1
unsafe_convert(::Type{Ptr{UInt8}}, x::Ref{T}) where T<:InlineStrings.InlineString in InlineStrings at /home/runner/.julia/packages/InlineStrings/rlLZO/src/InlineStrings.jl:167
unsafe_convert(::Type{P}, x::Ptr) where P<:Ptr in Base at essentials.jl:416

Possible fix, define
  unsafe_convert(::Type{Ptr{UInt8}}, ::Ptr{T}) where T<:InlineStrings.InlineString

Ambiguity #2
unsafe_convert(::Type{Ptr{Int8}}, x::Ref{T}) where T<:InlineStrings.InlineString in InlineStrings at /home/runner/.julia/packages/InlineStrings/rlLZO/src/InlineStrings.jl:169
unsafe_convert(::Type{P}, x::Ptr) where P<:Ptr in Base at essentials.jl:416

Possible fix, define
  unsafe_convert(::Type{Ptr{Int8}}, ::Ptr{T}) where T<:InlineStrings.InlineString

Ambiguity #3
defalg(::AbstractArray{<:Union{Missing, InlineStrings.String1, InlineStrings.String15, InlineStrings.String3, InlineStrings.String7}}) in InlineStrings at /home/runner/.julia/packages/InlineStrings/rlLZO/src/InlineStrings.jl:942
defalg(v::AbstractArray{<:Union{Missing, Number}}) in Base.Sort at sort.jl:655

Possible fix, define
  defalg(::AbstractArray{<:Missing})

Method ambiguity: Test Failed at /home/runner/.julia/packages/Aqua/utObL/src/ambiguities.jl:117
  Expression: success(pipeline(cmd; stdout = stdout, stderr = stderr))

This is going to cause any package that uses Aqua.jl for testing to fail tests if they include InlineStrings as a dependency.

@brainandforce
Copy link
Contributor Author

There may be some ambiguities that are issues with Julia Base instead of this package. Julia 1.6 reports the following ambiguity:

getindex(s::InlineStrings.InlineString, r::AbstractUnitRange{T} where T<:Integer) in InlineStrings
getindex(s::AbstractString, r::UnitRange{T} where T<:Integer) in Base at strings/substring.jl:255

This is not present in Julia 1.9; this pull request fixed the issue. Similarly, the first method ambiguity for Base.Sort.defalg seems to exist because there is no definition of Base.Sort.defalg(::AbstractArray{Missing}), but this was fixed late last year and should make it into Julia 1.10.

I've gone ahead and filed a PR that should fix the Base.unsafe_convert ambiguities (#70).

@prbzrg
Copy link

prbzrg commented Dec 27, 2023

New report for Julia v1.10 issued in #71

@KristofferC
Copy link
Member

The ambiguities are now:

Ambiguity #1
defalg(::AbstractArray{<:Union{Missing, InlineStrings.String1, InlineStrings.String15, InlineStrings.String3, InlineStrings.String7}}) @ InlineStrings ~/JuliaPkgs/InlineStrings.jl/src/InlineStrings.jl:824
defalg(v::AbstractArray{<:Union{Missing, Number}}) @ Base.Sort sort.jl:1350

Possible fix, define
  defalg(::AbstractArray{<:Missing})

Ambiguity #2
map(f, avs::LinearAlgebra.Adjoint{T, <:AbstractVector} where T...) @ LinearAlgebra ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/adjtrans.jl:394
map(::Type{InlineStrings.InlineString}, A::AbstractArray) @ InlineStrings ~/JuliaPkgs/InlineStrings.jl/src/InlineStrings.jl:1003

Possible fix, define
  map(::Type{InlineStrings.InlineString}, ::LinearAlgebra.Adjoint{T, <:AbstractVector} where T)

Ambiguity #3
map(f, tvs::LinearAlgebra.Transpose{T, <:AbstractVector} where T...) @ LinearAlgebra ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/adjtrans.jl:395
map(::Type{InlineStrings.InlineString}, A::AbstractArray) @ InlineStrings ~/JuliaPkgs/InlineStrings.jl/src/InlineStrings.jl:1003

Possible fix, define
  map(::Type{InlineStrings.InlineString}, ::LinearAlgebra.Transpose{T, <:AbstractVector} where T)

Ambiguity #4
map(f, A::Union{LinearAlgebra.Bidiagonal, LinearAlgebra.Diagonal, LinearAlgebra.LowerTriangular, LinearAlgebra.SymTridiagonal, LinearAlgebra.Tridiagonal, LinearAlgebra.UnitLowerTriangular, LinearAlgebra.UnitUpperTriangular, LinearAlgebra.UpperTriangular}, Bs::Union{LinearAlgebra.Bidiagonal, LinearAlgebra.Diagonal, LinearAlgebra.LowerTriangular, LinearAlgebra.SymTridiagonal, LinearAlgebra.Tridiagonal, LinearAlgebra.UnitLowerTriangular, LinearAlgebra.UnitUpperTriangular, LinearAlgebra.UpperTriangular}...) @ LinearAlgebra ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/structuredbroadcast.jl:252
map(::Type{InlineStrings.InlineString}, A::AbstractArray) @ InlineStrings ~/JuliaPkgs/InlineStrings.jl/src/InlineStrings.jl:1003

Possible fix, define
  map(::Type{InlineStrings.InlineString}, ::Union{LinearAlgebra.Bidiagonal, LinearAlgebra.Diagonal, LinearAlgebra.LowerTriangular, LinearAlgebra.SymTridiagonal, LinearAlgebra.Tridiagonal, LinearAlgebra.UnitLowerTriangular, LinearAlgebra.UnitUpperTriangular, LinearAlgebra.UpperTriangular})

Skipping Base.active_repl
Skipping Base.active_repl_backend
Method ambiguity: Test Failed at /Users/kristoffercarlsson/.julia/packages/Aqua/tHrmY/src/ambiguities.jl:78
  Expression: iszero(num_ambiguities)

I don't think it is really reasonable to define any of the suggested methods.

@Azzaare
Copy link

Azzaare commented Jul 28, 2024

I also have stumbled upon this. The proposed solution for #1 is already implemented in Base, so I wonder why it is still raised as a suggested solution.
Would there be an issue if Missing is removed from the Union in InlineStrings.jl's version?

Moreover, the other ambiguities seem to disappear in 1.11-rc. New ones pop up, though:

Ambiguity #2
unsafe_convert(::Type{Ptr{UInt8}}, x::Ref{T}) where T<:InlineString @ InlineStrings C:\Users\jeanf\.julia\packages\InlineStrings\79NvI\src\InlineStrings.jl:165
unsafe_convert(::Type{Ptr{T}}, a::GenericMemoryRef) where T @ Base pointer.jl:90

Possible fix, define
  unsafe_convert(::Type{Ptr{UInt8}}, ::GenericMemoryRef{isatomic, T} where isatomic) where T<:InlineStrings.InlineString

Ambiguity #3
unsafe_convert(::Type{Ptr{Int8}}, x::Ref{T}) where T<:InlineString @ InlineStrings C:\Users\jeanf\.julia\packages\InlineStrings\79NvI\src\InlineStrings.jl:167
unsafe_convert(::Type{Ptr{T}}, a::GenericMemoryRef) where T @ Base pointer.jl:90

Possible fix, define
  unsafe_convert(::Type{Ptr{Int8}}, ::GenericMemoryRef{isatomic, T} where isatomic) where T<:InlineStrings.InlineString

Ambiguity #4
write(io::IO, x::T) where T<:InlineString @ InlineStrings C:\Users\jeanf\.julia\packages\InlineStrings\79NvI\src\InlineStrings.jl:362
write(io::Base.AnnotatedIOBuffer, x::AbstractString) @ Base strings\annotated.jl:505

Possible fix, define
  write(::Base.AnnotatedIOBuffer, ::T) where T<:InlineStrings.InlineString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants