Skip to content

Commit fbbe9ed

Browse files
authored
Merge pull request #49664 from JuliaLang/jn/ml-matches-rewritten
reorder ml-matches to avoid catastrophic performance case
2 parents 9dd3090 + ac1cb1c commit fbbe9ed

File tree

7 files changed

+420
-310
lines changed

7 files changed

+420
-310
lines changed

doc/src/manual/methods.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ julia> g(2.0, 3.0)
322322
ERROR: MethodError: g(::Float64, ::Float64) is ambiguous.
323323
324324
Candidates:
325-
g(x::Float64, y)
326-
@ Main none:1
327325
g(x, y::Float64)
328326
@ Main none:1
327+
g(x::Float64, y)
328+
@ Main none:1
329329
330330
Possible fix, define
331331
g(::Float64, ::Float64)

src/gf.c

Lines changed: 395 additions & 303 deletions
Large diffs are not rendered by default.

stdlib/REPL/test/replcompletions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ end
811811
let s = "CompletionFoo.test11(3, 4,"
812812
c, r, res = test_complete(s)
813813
@test !res
814-
@test length(c) == 4
814+
@test length(c) == 2
815815
@test any(str->occursin("test11(x::$Int, y::$Int, z)", str), c)
816816
@test any(str->occursin("test11(::Any, ::Any, s::String)", str), c)
817817
end

test/ambiguous.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,17 @@ let ambig = Ref{Int32}(0)
378378
@test ambig[] == 1
379379
end
380380

381+
fnoambig(::Int,::Int) = 1
382+
fnoambig(::Int,::Any) = 2
383+
fnoambig(::Any,::Int) = 3
384+
fnoambig(::Any,::Any) = 4
385+
let has_ambig = Ref(Int32(0))
386+
ms = Base._methods_by_ftype(Tuple{typeof(fnoambig), Any, Any}, nothing, 4, Base.get_world_counter(), false, Ref(typemin(UInt)), Ref(typemax(UInt)), has_ambig)
387+
@test ms isa Vector
388+
@test length(ms) == 4
389+
@test has_ambig[] == 0
390+
end
391+
381392
# issue #11407
382393
f11407(::Dict{K,V}, ::Dict{Any,V}) where {K,V} = 1
383394
f11407(::Dict{K,V}, ::Dict{K,Any}) where {K,V} = 2

test/compiler/AbstractInterpreter.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ end |> !Core.Compiler.is_nonoverlayed
4343
end |> !Core.Compiler.is_nonoverlayed
4444

4545
# account for overlay possibility in unanalyzed matching method
46-
callstrange(::Nothing) = Core.compilerbarrier(:type, nothing) # trigger inference bail out
4746
callstrange(::Float64) = strangesin(x)
47+
callstrange(::Nothing) = Core.compilerbarrier(:type, nothing) # trigger inference bail out
4848
callstrange_entry(x) = callstrange(x) # needs to be defined here because of world age
4949
let interp = MTOverlayInterp(Set{Any}())
5050
matches = Core.Compiler.findall(Tuple{typeof(callstrange),Any}, Core.Compiler.method_table(interp)).matches

test/errorshow.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ method_c2(x::Int32, y::Float64) = true
9292
method_c2(x::Int32, y::Int32, z::Int32) = true
9393
method_c2(x::T, y::T, z::T) where {T<:Real} = true
9494

95-
Base.show_method_candidates(buf, Base.MethodError(method_c2,(1., 1., 2)))
96-
@test occursin( "\n\nClosest candidates are:\n method_c2(!Matched::Int32, ::Float64, ::Any...)$cmod$cfile$(c2line+2)\n method_c2(::T, ::T, !Matched::T) where T<:Real$cmod$cfile$(c2line+5)\n method_c2(!Matched::Int32, ::Any...)$cmod$cfile$(c2line+1)\n ...\n", String(take!(buf)))
95+
let s
96+
Base.show_method_candidates(buf, Base.MethodError(method_c2, (1., 1., 2)))
97+
s = String(take!(buf))
98+
@test occursin("\n\nClosest candidates are:\n ", s)
99+
@test occursin("\n method_c2(!Matched::Int32, ::Float64, ::Any...)$cmod$cfile$(c2line+2)\n ", s)
100+
@test occursin("\n method_c2(::T, ::T, !Matched::T) where T<:Real$cmod$cfile$(c2line+5)\n ", s)
101+
@test occursin("\n method_c2(!Matched::Int32, ::Any...)$cmod$cfile$(c2line+1)\n ", s)
102+
@test occursin("\n ...\n", s)
103+
end
97104

98105
c3line = @__LINE__() + 1
99106
method_c3(x::Float64, y::Float64) = true

test/reflection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ let
547547
end
548548

549549
# code_typed_by_type
550-
@test Base.code_typed_by_type(Tuple{Type{<:Val}})[1][2] == Val
550+
@test Base.code_typed_by_type(Tuple{Type{<:Val}})[2][2] == Val
551551
@test Base.code_typed_by_type(Tuple{typeof(sin), Float64})[1][2] === Float64
552552

553553
# New reflection methods in 0.6

0 commit comments

Comments
 (0)