Skip to content

Commit

Permalink
Avoid name lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 22, 2022
1 parent 737efc8 commit 5808545
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2284,20 +2284,20 @@ precompile(mi::Core.MethodInstance, world::UInt=get_world_counter()) =
(ccall(:jl_compile_method_instance, Cvoid, (Any, Any, UInt), mi, C_NULL, world); return true)

"""
precompile(m::Method, argtypes::Tuple{Vararg{Any}})
precompile(f, argtypes::Tuple{Vararg{Any}}, m::Method)
Precompile a specific method for the given argument types. This may be used to precompile
a different method than the one that would ordinarily be chosen by dispatch.
a different method than the one that would ordinarily be chosen by dispatch, for example
mimicking `invoke`.
"""
function precompile(m::Method, @nospecialize(argtypes::Tuple))
function precompile(@nospecialize(f), @nospecialize(argtypes::Tuple), m::Method)
world = get_world_counter()
f = getglobal(m.module, m.name)
matches = _methods(f, argtypes, -1, world)::Vector
for mtch in matches
mtch = mtch::Core.MethodMatch
if mtch.method == m
mi = Core.Compiler.specialize_method(m, mtch.spec_types, mtch.sparams)
return precompile(mi)
return precompile(mi, world)
end
end
return false
Expand Down
2 changes: 1 addition & 1 deletion test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ precompile_test_harness("invoke") do dir
invokeme(x) = 1
invokeme(::Int) = 2
m_any, m_int = sort(collect(methods(invokeme)); by=m->m.line)
precompile(m_any, (Int,))
precompile(invokeme, (Int,), m_any)
@test m_any.specializations[1].specTypes === Tuple{typeof(invokeme), Int}
@test isempty(m_int.specializations)
end
Expand Down

0 comments on commit 5808545

Please sign in to comment.