Skip to content

Commit c3bb876

Browse files
committed
Don't inline ambiguous method calls
This will centralize our handling in the C code, since we have to handle it there anyway
1 parent af60baa commit c3bb876

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

base/inference.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,17 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
22812281
metharg = meth[1]::Type
22822282
methsp = meth[2]
22832283
method = meth[3]::Method
2284+
ambig = method.ambig
2285+
if ambig != nothing
2286+
# do the arguments apply?
2287+
for entry in ambig
2288+
modsig = Tuple{entry.sig.parameters[2:end]...}
2289+
modatypes = Tuple{atypes[2:end]...}
2290+
if typeintersect(modsig, modatypes) != Union{}
2291+
return NF
2292+
end
2293+
end
2294+
end
22842295
if isa(f, widenconst(ft)) && !method.isstaged && method.lambda_template.pure && (isType(e.typ) || isa(e.typ,Const))
22852296
# check if any arguments aren't effect_free and need to be kept around
22862297
stmts = Any[]

test/ambiguous.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# DO NOT CHANGE LINE NUMBERS BELOW
2-
@noinline foo(x, y) = 1
3-
@noinline foo(x::Integer, y) = 2
4-
@noinline foo(x, y::Integer) = 3
5-
@noinline foo(x::Int, y::Int) = 4
6-
@noinline foo(x::Number, y) = 5
2+
foo(x, y) = 1
3+
foo(x::Integer, y) = 2
4+
foo(x, y::Integer) = 3
5+
foo(x::Int, y::Int) = 4
6+
foo(x::Number, y) = 5
77
# END OF LINE NUMBER SENSITIVITY
88

99
ambigs = Any[[], [3], [2,5], [], [3]]
@@ -28,3 +28,7 @@ end
2828
@test foo(3, 4) == 4
2929
@test_throws ErrorException foo(0x03, 4)
3030
@test_throws ErrorException foo(0x03, 4) # test that not inserted into cache
31+
32+
# Ensure it still works with potential inlining
33+
bar(x, y) = foo(x, y)
34+
@test_throws ErrorException bar(0x03, 4)

0 commit comments

Comments
 (0)