Skip to content

Commit de3914e

Browse files
KenoKristofferC
authored andcommitted
Fix regression in inlining of invoke (#34906)
When we added the check to prevent inlining through ambiguous methods, we failed exclude this check for calls to `invoke` (which skip ambiguous methods, since the method is explicitly selected). Fixes #34900. (cherry picked from commit 6abc852)
1 parent b8e9a9e commit de3914e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ function analyze_method!(idx::Int, sig::Signature, @nospecialize(metharg), meths
682682
# Check if we intersect any of this method's ambiguities
683683
# TODO: We could split out the ambiguous case as another "union split" case.
684684
# For now, we just reject the method
685-
if method.ambig !== nothing
685+
if method.ambig !== nothing && invoke_data === nothing
686686
for entry::Core.TypeMapEntry in method.ambig
687687
if typeintersect(sig.atype, entry.sig) !== Bottom
688688
return nothing

test/compiler/inline.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Test
4+
using Base.Meta
45

56
"""
67
Helper to walk the AST and call a function on every node.
@@ -265,3 +266,12 @@ b30118(x...) = c30118(x)
265266

266267
@test_throws MethodError c30118((Base.RefValue{Type{Int64}}(), Ref(Int64)))
267268
@test_throws MethodError b30118(Base.RefValue{Type{Int64}}(), Ref(Int64))
269+
270+
# Issue #34900
271+
f34900(x::Int, y) = x
272+
f34900(x, y::Int) = y
273+
f34900(x::Int, y::Int) = invoke(f34900, Tuple{Int, Any}, x, y)
274+
let ci = code_typed(f34900, Tuple{Int, Int})[1].first
275+
@test length(ci.code) == 1 && isexpr(ci.code[1], :return) &&
276+
ci.code[1].args[1].id == 2
277+
end

0 commit comments

Comments
 (0)