Skip to content

Commit 2e876fc

Browse files
authored
inlining: remove ineffective handling for unmatched params (#52092)
The deleted branch was added in #45062, although it had not been tested. I tried the following diff to find cases optimized by that, but I just found the handling proved to be in vain in all cases I tried. ```diff diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index 318b21b..7e42a65aa4 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -1473,6 +1473,14 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig handle_any_const_result!(cases, result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true) fully_covered = handled_all_cases = match.fully_covers + if length(cases) == 1 && fully_covered + println("first case: ", only_method) + elseif length(cases) == 1 + atype = argtypes_to_type(sig.argtypes) + if atype isa DataType && cases[1].sig isa DataType + println("second case: ", only_method) + end + end elseif !handled_all_cases # if we've not seen all candidates, union split is valid only for dispatch tuples filter!(case::InliningCase->isdispatchtuple(case.sig), cases) ```
1 parent 3d34f11 commit 2e876fc

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,12 +1333,10 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13331333
nunion === nothing && return nothing
13341334
cases = InliningCase[]
13351335
argtypes = sig.argtypes
1336-
local handled_all_cases::Bool = true
1337-
local revisit_idx = local only_method = nothing
1338-
local meth::MethodLookupResult
1336+
local handled_all_cases = local fully_covered = true
1337+
local revisit_idx = nothing
13391338
local all_result_count = 0
1340-
local joint_effects::Effects = EFFECTS_TOTAL
1341-
local fully_covered::Bool = true
1339+
local joint_effects = EFFECTS_TOTAL
13421340
for i = 1:nunion
13431341
meth = getsplit(info, i)
13441342
if meth.ambig
@@ -1349,18 +1347,8 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13491347
# No applicable methods; try next union split
13501348
handled_all_cases = false
13511349
continue
1352-
else
1353-
if length(meth) == 1 && only_method !== missing
1354-
if only_method === nothing
1355-
only_method = meth[1].method
1356-
elseif only_method !== meth[1].method
1357-
only_method = missing
1358-
end
1359-
else
1360-
only_method = missing
1361-
end
13621350
end
1363-
local split_fully_covered::Bool = false
1351+
local split_fully_covered = false
13641352
for (j, match) in enumerate(meth)
13651353
all_result_count += 1
13661354
result = getresult(info, all_result_count)
@@ -1387,33 +1375,17 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13871375

13881376
(handled_all_cases & fully_covered) || (joint_effects = Effects(joint_effects; nothrow=false))
13891377

1390-
if handled_all_cases && revisit_idx !== nothing
1391-
# we handled everything except one match with unmatched sparams,
1392-
# so try to handle it by bypassing validate_sparams
1393-
(i, j, k) = revisit_idx
1394-
match = getsplit(info, i)[j]
1395-
result = getresult(info, k)
1396-
handled_all_cases &= handle_any_const_result!(cases,
1397-
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
1398-
elseif length(cases) == 0 && only_method isa Method
1399-
# if the signature is fully covered and there is only one applicable method,
1400-
# we can try to inline it even in the presence of unmatched sparams
1401-
# -- But don't try it if we already tried to handle the match in the revisit_idx
1402-
# case, because that'll (necessarily) be the same method.
1403-
if nsplit(info)::Int > 1
1404-
atype = argtypes_to_type(argtypes)
1405-
(metharg, methsp) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), atype, only_method.sig)::SimpleVector
1406-
match = MethodMatch(metharg, methsp::SimpleVector, only_method, true)
1407-
result = nothing
1408-
else
1409-
@assert length(meth) == 1
1410-
match = meth[1]
1411-
result = getresult(info, 1)
1378+
if handled_all_cases
1379+
if revisit_idx !== nothing
1380+
# we handled everything except one match with unmatched sparams,
1381+
# so try to handle it by bypassing validate_sparams
1382+
(i, j, k) = revisit_idx
1383+
match = getsplit(info, i)[j]
1384+
result = getresult(info, k)
1385+
handled_all_cases &= handle_any_const_result!(cases,
1386+
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
14121387
end
1413-
handle_any_const_result!(cases,
1414-
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
1415-
fully_covered = handled_all_cases = match.fully_covers
1416-
elseif !handled_all_cases
1388+
elseif !isempty(cases)
14171389
# if we've not seen all candidates, union split is valid only for dispatch tuples
14181390
filter!(case::InliningCase->isdispatchtuple(case.sig), cases)
14191391
end

0 commit comments

Comments
 (0)