Skip to content

Commit 4d6fece

Browse files
topolarityKristofferC
authored andcommitted
Don't filter Core methods from newly-inferred list (#58510)
This allows constructors like `Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}}` to precompile as usual Appears to have a minimal effect on the stdlib pkgimages: ```julia --- before.txt 2025-05-23 08:36:20.171870043 -0400 +++ after.txt 2025-05-22 14:48:49.003869097 -0400 @@ -47,7 +47,7 @@ 20K ../julia/usr/share/julia/compiled/v1.13/Logging/pkgimage.so 20K ../julia/usr/share/julia/compiled/v1.13/Logging/pkgimage.so 3.5M ../julia/usr/share/julia/compiled/v1.13/Markdown/pkgimage.so -3.5M ../julia/usr/share/julia/compiled/v1.13/Markdown/pkgimage.so +3.6M ../julia/usr/share/julia/compiled/v1.13/Markdown/pkgimage.so 184K ../julia/usr/share/julia/compiled/v1.13/Mmap/pkgimage.so 184K ../julia/usr/share/julia/compiled/v1.13/Mmap/pkgimage.so 28K ../julia/usr/share/julia/compiled/v1.13/MozillaCACerts_jll/pkgimage.so ``` Resolves #58497. (cherry picked from commit f8ece05)
1 parent f7136c9 commit 4d6fece

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Compiler/src/cicache.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
function setindex!(cache::InternalCodeCache, ci::CodeInstance, mi::MethodInstance)
1515
@assert ci.owner === cache.owner
1616
m = mi.def
17-
if isa(m, Method) && m.module != Core
17+
if isa(m, Method)
1818
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
1919
end
2020
ccall(:jl_mi_cache_insert, Cvoid, (Any, Any), mi, ci)

test/precompile.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,29 @@ precompile_test_harness("No backedge precompile") do load_path
21192119
end
21202120
end
21212121

2122+
precompile_test_harness("Pre-compile Core methods") do load_path
2123+
# Core methods should support pre-compilation as external CI's like anything else
2124+
# https://github.com/JuliaLang/julia/issues/58497
2125+
write(joinpath(load_path, "CorePrecompilation.jl"),
2126+
"""
2127+
module CorePrecompilation
2128+
struct Foo end
2129+
precompile(Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}})
2130+
end
2131+
""")
2132+
ji, ofile = Base.compilecache(Base.PkgId("CorePrecompilation"))
2133+
@eval using CorePrecompilation
2134+
invokelatest() do
2135+
let tt = Tuple{Type{Vector{CorePrecompilation.Foo}}, UndefInitializer, Tuple{Int}},
2136+
match = first(Base._methods_by_ftype(tt, -1, Base.get_world_counter())),
2137+
mi = Base.specialize_method(match)
2138+
@test isdefined(mi, :cache)
2139+
@test mi.cache.max_world === typemax(UInt)
2140+
@test mi.cache.invoke != C_NULL
2141+
end
2142+
end
2143+
end
2144+
21222145
# Test precompilation of generated functions that return opaque closures
21232146
# (with constprop marker set to false).
21242147
precompile_test_harness("Generated Opaque") do load_path

0 commit comments

Comments
 (0)