Skip to content

Commit 11c72c0

Browse files
committed
inlining: remove (probably) dead handling for unmatched params
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 85d7cca commit 11c72c0

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
@@ -1382,12 +1382,10 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13821382
nunion === nothing && return nothing
13831383
cases = InliningCase[]
13841384
argtypes = sig.argtypes
1385-
local handled_all_cases::Bool = true
1386-
local revisit_idx = local only_method = nothing
1387-
local meth::MethodLookupResult
1385+
local handled_all_cases = local fully_covered = true
1386+
local revisit_idx = nothing
13881387
local all_result_count = 0
1389-
local joint_effects::Effects = EFFECTS_TOTAL
1390-
local fully_covered::Bool = true
1388+
local joint_effects = EFFECTS_TOTAL
13911389
for i = 1:nunion
13921390
meth = getsplit(info, i)
13931391
if meth.ambig
@@ -1398,18 +1396,8 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
13981396
# No applicable methods; try next union split
13991397
handled_all_cases = false
14001398
continue
1401-
else
1402-
if length(meth) == 1 && only_method !== missing
1403-
if only_method === nothing
1404-
only_method = meth[1].method
1405-
elseif only_method !== meth[1].method
1406-
only_method = missing
1407-
end
1408-
else
1409-
only_method = missing
1410-
end
14111399
end
1412-
local split_fully_covered::Bool = false
1400+
local split_fully_covered = false
14131401
for (j, match) in enumerate(meth)
14141402
all_result_count += 1
14151403
result = getresult(info, all_result_count)
@@ -1436,33 +1424,17 @@ function compute_inlining_cases(@nospecialize(info::CallInfo), flag::UInt32, sig
14361424

14371425
(handled_all_cases && fully_covered) || (joint_effects = Effects(joint_effects; nothrow=false))
14381426

1439-
if handled_all_cases && revisit_idx !== nothing
1440-
# we handled everything except one match with unmatched sparams,
1441-
# so try to handle it by bypassing validate_sparams
1442-
(i, j, k) = revisit_idx
1443-
match = getsplit(info, i)[j]
1444-
result = getresult(info, k)
1445-
handled_all_cases &= handle_any_const_result!(cases,
1446-
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
1447-
elseif length(cases) == 0 && only_method isa Method
1448-
# if the signature is fully covered and there is only one applicable method,
1449-
# we can try to inline it even in the presence of unmatched sparams
1450-
# -- But don't try it if we already tried to handle the match in the revisit_idx
1451-
# case, because that'll (necessarily) be the same method.
1452-
if nsplit(info)::Int > 1
1453-
atype = argtypes_to_type(argtypes)
1454-
(metharg, methsp) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), atype, only_method.sig)::SimpleVector
1455-
match = MethodMatch(metharg, methsp::SimpleVector, only_method, true)
1456-
result = nothing
1457-
else
1458-
@assert length(meth) == 1
1459-
match = meth[1]
1460-
result = getresult(info, 1)
1427+
if handled_all_cases
1428+
if revisit_idx !== nothing
1429+
# we handled everything except one match with unmatched sparams,
1430+
# so try to handle it by bypassing validate_sparams
1431+
(i, j, k) = revisit_idx
1432+
match = getsplit(info, i)[j]
1433+
result = getresult(info, k)
1434+
handled_all_cases &= handle_any_const_result!(cases,
1435+
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
14611436
end
1462-
handle_any_const_result!(cases,
1463-
result, match, argtypes, info, flag, state; allow_abstract=true, allow_typevars=true)
1464-
fully_covered = handled_all_cases = match.fully_covers
1465-
elseif !handled_all_cases
1437+
elseif !isempty(cases)
14661438
# if we've not seen all candidates, union split is valid only for dispatch tuples
14671439
filter!(case::InliningCase->isdispatchtuple(case.sig), cases)
14681440
end

0 commit comments

Comments
 (0)