Skip to content

Commit 46ef367

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 bb3f67d commit 46ef367

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
@@ -406,7 +406,7 @@ function cache_result!(interp::AbstractInterpreter, result::InferenceResult)
406406
code_cache(interp)[linfo] = ci = CodeInstance(interp, result, inferred_result, valid_worlds)
407407
if track_newly_inferred[]
408408
m = linfo.def
409-
if isa(m, Method) && m.module != Core
409+
if isa(m, Method)
410410
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
411411
end
412412
end

test/precompile.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,29 @@ precompile_test_harness("Issue #50538") do load_path
18541854
end
18551855

18561856

1857+
precompile_test_harness("Pre-compile Core methods") do load_path
1858+
# Core methods should support pre-compilation as external CI's like anything else
1859+
# https://github.com/JuliaLang/julia/issues/58497
1860+
write(joinpath(load_path, "CorePrecompilation.jl"),
1861+
"""
1862+
module CorePrecompilation
1863+
struct Foo end
1864+
precompile(Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}})
1865+
end
1866+
""")
1867+
ji, ofile = Base.compilecache(Base.PkgId("CorePrecompilation"))
1868+
@eval using CorePrecompilation
1869+
invokelatest() do
1870+
let tt = Tuple{Type{Vector{CorePrecompilation.Foo}}, UndefInitializer, Tuple{Int}},
1871+
match = first(Base._methods_by_ftype(tt, -1, Base.get_world_counter())),
1872+
mi = Base.specialize_method(match)
1873+
@test isdefined(mi, :cache)
1874+
@test mi.cache.max_world === typemax(UInt)
1875+
@test mi.cache.invoke != C_NULL
1876+
end
1877+
end
1878+
end
1879+
18571880
empty!(Base.DEPOT_PATH)
18581881
append!(Base.DEPOT_PATH, original_depot_path)
18591882
empty!(Base.LOAD_PATH)

0 commit comments

Comments
 (0)