Skip to content

Commit f8ece05

Browse files
authored
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.
1 parent 8c6e4ad commit f8ece05

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
@@ -2145,6 +2145,29 @@ precompile_test_harness("No backedge precompile") do load_path
21452145
end
21462146
end
21472147

2148+
precompile_test_harness("Pre-compile Core methods") do load_path
2149+
# Core methods should support pre-compilation as external CI's like anything else
2150+
# https://github.com/JuliaLang/julia/issues/58497
2151+
write(joinpath(load_path, "CorePrecompilation.jl"),
2152+
"""
2153+
module CorePrecompilation
2154+
struct Foo end
2155+
precompile(Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}})
2156+
end
2157+
""")
2158+
ji, ofile = Base.compilecache(Base.PkgId("CorePrecompilation"))
2159+
@eval using CorePrecompilation
2160+
invokelatest() do
2161+
let tt = Tuple{Type{Vector{CorePrecompilation.Foo}}, UndefInitializer, Tuple{Int}},
2162+
match = first(Base._methods_by_ftype(tt, -1, Base.get_world_counter())),
2163+
mi = Base.specialize_method(match)
2164+
@test isdefined(mi, :cache)
2165+
@test mi.cache.max_world === typemax(UInt)
2166+
@test mi.cache.invoke != C_NULL
2167+
end
2168+
end
2169+
end
2170+
21482171
# Test precompilation of generated functions that return opaque closures
21492172
# (with constprop marker set to false).
21502173
precompile_test_harness("Generated Opaque") do load_path

0 commit comments

Comments
 (0)