From c610c970ceed3f21de5529db85d95362850def63 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 21 Jul 2022 18:49:28 -0500 Subject: [PATCH] Fix sparams generation --- base/loading.jl | 19 ++++++++----------- test/precompile.jl | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index ffb1679f00858..2a0d12756fcec 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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)) diff --git a/test/precompile.jl b/test/precompile.jl index 3ea5f83aa195c..f7560f5f6a455 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -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