Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Compiler/src/cicache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
function setindex!(cache::InternalCodeCache, ci::CodeInstance, mi::MethodInstance)
@assert ci.owner === cache.owner
m = mi.def
if isa(m, Method) && m.module != Core
if isa(m, Method)
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
end
ccall(:jl_mi_cache_insert, Cvoid, (Any, Any), mi, ci)
Expand Down
23 changes: 23 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,29 @@ precompile_test_harness("No backedge precompile") do load_path
end
end

precompile_test_harness("Pre-compile Core methods") do load_path
# Core methods should support pre-compilation as external CI's like anything else
# https://github.com/JuliaLang/julia/issues/58497
write(joinpath(load_path, "CorePrecompilation.jl"),
"""
module CorePrecompilation
struct Foo end
precompile(Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}})
end
""")
ji, ofile = Base.compilecache(Base.PkgId("CorePrecompilation"))
@eval using CorePrecompilation
invokelatest() do
let tt = Tuple{Type{Vector{CorePrecompilation.Foo}}, UndefInitializer, Tuple{Int}},
match = first(Base._methods_by_ftype(tt, -1, Base.get_world_counter())),
mi = Base.specialize_method(match)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mi = Base.specialize_method(match)
mi = first(Base.specializations(match.method))

to be certain that you're not generating that mi with this call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is very general though, it has many specializations:

julia> match.method
Vector{T}(::UndefInitializer, d::Tuple{Int64}) where T
     @ Core boot.jl:660

julia> length(Base.specializations(match.method))
108

I think the cache checks should guarantee that we're picking up an existing MethodInstance (the test fails as expected on current master)

@test isdefined(mi, :cache)
@test mi.cache.max_world === typemax(UInt)
@test mi.cache.invoke != C_NULL
end
end
end

# Test precompilation of generated functions that return opaque closures
# (with constprop marker set to false).
precompile_test_harness("Generated Opaque") do load_path
Expand Down