Skip to content

Commit

Permalink
Fix sparams generation
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Jul 21, 2022
1 parent 59ca796 commit c610c97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2284,20 +2284,17 @@ precompile(mi::Core.MethodInstance, world::UInt=get_world_counter()) =
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, for example
a different method than the one that would ordinarily be chosen by dispatch, thus
mimicking `invoke`.
"""
function precompile(@nospecialize(f), @nospecialize(argtypes::Tuple), m::Method)
world = get_world_counter()
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, world)
end
end
return false
precompile(Tuple{Core.Typeof(f), argtypes...}, m)
end

function precompile(@nospecialize(argt::Type), m::Method)
atype, sparams = ccall(:jl_type_intersection_with_env, Any, (Any, Any), argt, m.sig)::SimpleVector
mi = Core.Compiler.specialize_method(m, atype, sparams)
return precompile(mi)
end

precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), Nothing))
Expand Down
4 changes: 2 additions & 2 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ precompile_test_harness("invoke") do dir
# Precompile specific methods for arbitrary arg types
invokeme(x) = 1
invokeme(::Int) = 2
m_any, m_int = sort(collect(methods(invokeme)); by=m->m.line)
precompile(invokeme, (Int,), m_any)
m_any, m_int = sort(collect(methods(invokeme)); by=m->(m.file,m.line))
@test 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 c610c97

Please sign in to comment.