Skip to content

Commit 346ff93

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 8b02eb4 commit 346ff93

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

base/compiler/typeinfer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ function cache_result!(interp::AbstractInterpreter, result::InferenceResult)
435435
code_cache(interp)[mi] = ci = CodeInstance(interp, result, valid_worlds)
436436
if track_newly_inferred[]
437437
m = mi.def
438-
if isa(m, Method) && m.module != Core
438+
if isa(m, Method)
439439
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
440440
end
441441
end

test/precompile.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,29 @@ if Base.get_bool_env("CI", false) && (Sys.ARCH === :x86_64 || Sys.ARCH === :aarc
21742174
end
21752175
end
21762176

2177+
precompile_test_harness("Pre-compile Core methods") do load_path
2178+
# Core methods should support pre-compilation as external CI's like anything else
2179+
# https://github.com/JuliaLang/julia/issues/58497
2180+
write(joinpath(load_path, "CorePrecompilation.jl"),
2181+
"""
2182+
module CorePrecompilation
2183+
struct Foo end
2184+
precompile(Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}})
2185+
end
2186+
""")
2187+
ji, ofile = Base.compilecache(Base.PkgId("CorePrecompilation"))
2188+
@eval using CorePrecompilation
2189+
invokelatest() do
2190+
let tt = Tuple{Type{Vector{CorePrecompilation.Foo}}, UndefInitializer, Tuple{Int}},
2191+
match = first(Base._methods_by_ftype(tt, -1, Base.get_world_counter())),
2192+
mi = Base.specialize_method(match)
2193+
@test isdefined(mi, :cache)
2194+
@test mi.cache.max_world === typemax(UInt)
2195+
@test mi.cache.invoke != C_NULL
2196+
end
2197+
end
2198+
end
2199+
21772200
precompile_test_harness("Issue #52063") do load_path
21782201
fname = joinpath(load_path, "i_do_not_exist.jl")
21792202
@test try

0 commit comments

Comments
 (0)