Skip to content

Commit dbd10e0

Browse files
authored
reflection: remove _methods_by_ftype with array arguments (#43710)
1 parent f7bb391 commit dbd10e0

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

base/compiler/typeutils.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,6 @@ end
177177

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

180-
function tvar_extent(@nospecialize t)
181-
while t isa TypeVar
182-
t = t.ub
183-
end
184-
return t
185-
end
186-
187180
_typename(@nospecialize a) = Union{}
188181
_typename(a::TypeVar) = Core.TypeName
189182
function _typename(a::Union)
@@ -201,7 +194,7 @@ function tuple_tail_elem(@nospecialize(init), ct::Vector{Any})
201194
t = init
202195
for x in ct
203196
# FIXME: this is broken: it violates subtyping relations and creates invalid types with free typevars
204-
t = tmerge(t, tvar_extent(unwrapva(x)))
197+
t = tmerge(t, unwraptv(unwrapva(x)))
205198
end
206199
return Vararg{widenconst(t)}
207200
end

base/reflection.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,6 @@ end
926926
function _methods_by_ftype(@nospecialize(t), mt::Union{Core.MethodTable, Nothing}, lim::Int, world::UInt)
927927
return _methods_by_ftype(t, mt, lim, world, false, RefValue{UInt}(typemin(UInt)), RefValue{UInt}(typemax(UInt)), Ptr{Int32}(C_NULL))
928928
end
929-
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})
930-
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}
931-
end
932929
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})
933930
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}
934931
end
@@ -1571,9 +1568,9 @@ function isambiguous(m1::Method, m2::Method; ambiguous_bottom::Bool=false)
15711568
has_bottom_parameter(ti) && return false
15721569
end
15731570
world = get_world_counter()
1574-
min = UInt[typemin(UInt)]
1575-
max = UInt[typemax(UInt)]
1576-
has_ambig = Int32[0]
1571+
min = Ref{UInt}(typemin(UInt))
1572+
max = Ref{UInt}(typemax(UInt))
1573+
has_ambig = Ref{Int32}(0)
15771574
ms = _methods_by_ftype(ti, nothing, -1, world, true, min, max, has_ambig)::Vector
15781575
has_ambig[] == 0 && return false
15791576
if !ambiguous_bottom

test/ambiguous.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,26 +347,26 @@ f35983(::Type, ::Type) = 2
347347
@test first(Base.methods_including_ambiguous(f35983, (Any, Any))).sig == Tuple{typeof(f35983), Type, Type}
348348
@test length(Base.methods(f35983, (Any, Any))) == 2
349349
@test first(Base.methods(f35983, (Any, Any))).sig == Tuple{typeof(f35983), Type, Type}
350-
let ambig = Int32[0]
351-
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, UInt[typemin(UInt)], UInt[typemax(UInt)], ambig)
350+
let ambig = Ref{Int32}(0)
351+
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
352352
@test length(ms) == 1
353-
@test ambig[1] == 0
353+
@test ambig[] == 0
354354
end
355355
f35983(::Type{Int16}, ::Any) = 3
356356
@test length(Base.methods_including_ambiguous(f35983, (Type, Type))) == 2
357357
@test length(Base.methods(f35983, (Type, Type))) == 2
358-
let ambig = Int32[0]
359-
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, UInt[typemin(UInt)], UInt[typemax(UInt)], ambig)
358+
let ambig = Ref{Int32}(0)
359+
ms = Base._methods_by_ftype(Tuple{typeof(f35983), Type, Type}, nothing, -1, typemax(UInt), true, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
360360
@test length(ms) == 2
361-
@test ambig[1] == 1
361+
@test ambig[] == 1
362362
end
363363

364364
struct B38280 <: Real; val; end
365-
let ambig = Int32[0]
366-
ms = Base._methods_by_ftype(Tuple{Type{B38280}, Any}, nothing, 1, typemax(UInt), false, UInt[typemin(UInt)], UInt[typemax(UInt)], ambig)
365+
let ambig = Ref{Int32}(0)
366+
ms = Base._methods_by_ftype(Tuple{Type{B38280}, Any}, nothing, 1, typemax(UInt), false, Ref{UInt}(typemin(UInt)), Ref{UInt}(typemax(UInt)), ambig)
367367
@test ms isa Vector
368368
@test length(ms) == 1
369-
@test ambig[1] == 1
369+
@test ambig[] == 1
370370
end
371371

372372
# issue #11407

0 commit comments

Comments
 (0)