Skip to content

Commit

Permalink
reflection: remove _methods_by_ftype with array arguments (#43710)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 10, 2022
1 parent f7bb391 commit dbd10e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
9 changes: 1 addition & 8 deletions base/compiler/typeutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ end

hasintersect(@nospecialize(a), @nospecialize(b)) = typeintersect(a, b) !== Bottom

function tvar_extent(@nospecialize t)
while t isa TypeVar
t = t.ub
end
return t
end

_typename(@nospecialize a) = Union{}
_typename(a::TypeVar) = Core.TypeName
function _typename(a::Union)
Expand All @@ -201,7 +194,7 @@ function tuple_tail_elem(@nospecialize(init), ct::Vector{Any})
t = init
for x in ct
# FIXME: this is broken: it violates subtyping relations and creates invalid types with free typevars
t = tmerge(t, tvar_extent(unwrapva(x)))
t = tmerge(t, unwraptv(unwrapva(x)))
end
return Vararg{widenconst(t)}
end
Expand Down
9 changes: 3 additions & 6 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,6 @@ end
function _methods_by_ftype(@nospecialize(t), mt::Union{Core.MethodTable, Nothing}, lim::Int, world::UInt)
return _methods_by_ftype(t, mt, lim, world, false, RefValue{UInt}(typemin(UInt)), RefValue{UInt}(typemax(UInt)), Ptr{Int32}(C_NULL))
end
function _methods_by_ftype(@nospecialize(t), mt::Union{Core.MethodTable, Nothing}, lim::Int, world::UInt, ambig::Bool, min::Array{UInt,1}, max::Array{UInt,1}, has_ambig::Array{Int32,1})
return ccall(:jl_matching_methods, Any, (Any, Any, Cint, Cint, UInt, Ptr{UInt}, Ptr{UInt}, Ptr{Int32}), t, mt, lim, ambig, world, min, max, has_ambig)::Union{Array{Any,1}, Bool}
end
function _methods_by_ftype(@nospecialize(t), mt::Union{Core.MethodTable, Nothing}, lim::Int, world::UInt, ambig::Bool, min::Ref{UInt}, max::Ref{UInt}, has_ambig::Ref{Int32})
return ccall(:jl_matching_methods, Any, (Any, Any, Cint, Cint, UInt, Ptr{UInt}, Ptr{UInt}, Ptr{Int32}), t, mt, lim, ambig, world, min, max, has_ambig)::Union{Array{Any,1}, Bool}
end
Expand Down Expand Up @@ -1571,9 +1568,9 @@ function isambiguous(m1::Method, m2::Method; ambiguous_bottom::Bool=false)
has_bottom_parameter(ti) && return false
end
world = get_world_counter()
min = UInt[typemin(UInt)]
max = UInt[typemax(UInt)]
has_ambig = Int32[0]
min = Ref{UInt}(typemin(UInt))
max = Ref{UInt}(typemax(UInt))
has_ambig = Ref{Int32}(0)
ms = _methods_by_ftype(ti, nothing, -1, world, true, min, max, has_ambig)::Vector
has_ambig[] == 0 && return false
if !ambiguous_bottom
Expand Down
18 changes: 9 additions & 9 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,26 @@ f35983(::Type, ::Type) = 2
@test first(Base.methods_including_ambiguous(f35983, (Any, Any))).sig == Tuple{typeof(f35983), Type, Type}
@test length(Base.methods(f35983, (Any, Any))) == 2
@test first(Base.methods(f35983, (Any, Any))).sig == Tuple{typeof(f35983), Type, Type}
let ambig = Int32[0]
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, UInt[typemin(UInt)], UInt[typemax(UInt)], ambig)
let ambig = Ref{Int32}(0)
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
@test length(ms) == 1
@test ambig[1] == 0
@test ambig[] == 0
end
f35983(::Type{Int16}, ::Any) = 3
@test length(Base.methods_including_ambiguous(f35983, (Type, Type))) == 2
@test length(Base.methods(f35983, (Type, Type))) == 2
let ambig = Int32[0]
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, UInt[typemin(UInt)], UInt[typemax(UInt)], ambig)
let ambig = Ref{Int32}(0)
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
@test length(ms) == 2
@test ambig[1] == 1
@test ambig[] == 1
end

struct B38280 <: Real; val; end
let ambig = Int32[0]
ms = Base._methods_by_ftype(Tuple{Type{B38280}, Any}, nothing, 1, typemax(UInt), false, UInt[typemin(UInt)], UInt[typemax(UInt)], ambig)
let ambig = Ref{Int32}(0)
ms = Base._methods_by_ftype(Tuple{Type{B38280}, Any}, nothing, 1, typemax(UInt), false, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
@test ms isa Vector
@test length(ms) == 1
@test ambig[1] == 1
@test ambig[] == 1
end

# issue #11407
Expand Down

0 comments on commit dbd10e0

Please sign in to comment.