Skip to content

Commit 1923df5

Browse files
authored
optimize abstract_invoke (JuliaLang#56560)
- removed unnecessary `Core.Box` allocation - made the type of the closure that is passed to `Future` concrete That said, it doesn’t seem ideal to require this sort of manual optimizations.. The value of using closures cannot be denied in this code base, and I feel that it would be better to work towards optimizing closures more (as we do with JuliaLang#56532)?
1 parent 351b41a commit 1923df5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/abstractinterpretation.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,27 +2182,26 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
21822182
lookupsig = rewrap_unionall(Tuple{ft, unwrapped.parameters...}, types)::Type
21832183
nargtype = Tuple{ft, nargtype.parameters...}
21842184
argtype = Tuple{ft, argtype.parameters...}
2185-
match, valid_worlds = findsup(lookupsig, method_table(interp))
2186-
match === nothing && return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
2185+
matched, valid_worlds = findsup(lookupsig, method_table(interp))
2186+
matched === nothing && return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
21872187
update_valid_age!(sv, valid_worlds)
2188-
method = match.method
2188+
method = matched.method
21892189
tienv = ccall(:jl_type_intersection_with_env, Any, (Any, Any), nargtype, method.sig)::SimpleVector
21902190
ti = tienv[1]
21912191
env = tienv[2]::SimpleVector
21922192
mresult = abstract_call_method(interp, method, ti, env, false, si, sv)::Future
21932193
match = MethodMatch(ti, env, method, argtype <: method.sig)
2194-
ft_box = Core.Box(ft)
21952194
ft′_box = Core.Box(ft′)
2195+
lookupsig_box = Core.Box(lookupsig)
2196+
invokecall = InvokeCall(types, lookupsig)
21962197
return Future{CallMeta}(mresult, interp, sv) do result, interp, sv
21972198
(; rt, exct, effects, edge, volatile_inf_result) = result
2198-
local argtypes = arginfo.argtypes
2199-
local ft = ft_box.contents
22002199
local ft′ = ft′_box.contents
22012200
sig = match.spec_types
2202-
argtypes′ = invoke_rewrite(argtypes)
2201+
argtypes′ = invoke_rewrite(arginfo.argtypes)
22032202
fargs = arginfo.fargs
22042203
fargs′ = fargs === nothing ? nothing : invoke_rewrite(fargs)
2205-
arginfo = ArgInfo(fargs′, argtypes′)
2204+
arginfo = ArgInfo(fargs′, argtypes′)
22062205
# # typeintersect might have narrowed signature, but the accuracy gain doesn't seem worth the cost involved with the lattice comparisons
22072206
# for i in 1:length(argtypes′)
22082207
# t, a = ti.parameters[i], argtypes′[i]
@@ -2211,9 +2210,8 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
22112210
𝕃ₚ = ipo_lattice(interp)
22122211
, , = partialorder(𝕃ₚ), strictneqpartialorder(𝕃ₚ), join(𝕃ₚ)
22132212
f = singleton_type(ft′)
2214-
invokecall = InvokeCall(types, lookupsig)
22152213
const_call_result = abstract_call_method_with_const_args(interp,
2216-
result, f, arginfo, si, match, sv, invokecall)
2214+
result, f, arginfo, si, match, sv, invokecall)
22172215
const_result = volatile_inf_result
22182216
if const_call_result !== nothing
22192217
const_edge = nothing
@@ -2227,8 +2225,8 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
22272225
edge = const_edge
22282226
end
22292227
end
2230-
rt = from_interprocedural!(interp, rt, sv, arginfo, sig)
2231-
info = InvokeCallInfo(edge, match, const_result, lookupsig)
2228+
rt = from_interprocedural!(interp, rt, sv, arginfo, sig)
2229+
info = InvokeCallInfo(edge, match, const_result, lookupsig_box.contents)
22322230
if !match.fully_covers
22332231
effects = Effects(effects; nothrow=false)
22342232
exct = exct TypeError

0 commit comments

Comments
 (0)