Skip to content

Array constructors ignored in precompile(...) statements #58497

Closed
@topolarity

Description

@topolarity

If you create a package that tries to precompile an Array constructor:

module PrecompileVector

struct Foo end
precompile(Tuple{Type{Array{Foo, 1}}, UndefInitializer, Tuple{Int64}})
export Foo

end # module PrecompileVector

This doesn't seem to "stick":

$ julia +nightly --project=PrecompileVector --trace-compile=stderr -e "using PrecompileVector; Vector{Foo}(undef, (3,))"
precompile(Tuple{Type{Array{PrecompileVector.Foo, 1}}, UndefInitializer, Tuple{Int64}})

The problem seems to be that this doesn't make it into our "newly-inferred" list:

julia> using PrecompileVector
julia> tt = Tuple{Type{Vector{Foo}}, UndefInitializer, Tuple{Int}}
julia> mi = ccall(:jl_method_lookup_by_tt, Any,
                   (Any, Csize_t, Any),
                   tt, Base.get_world_counter(), #= mt =# nothing)
julia> isdefined(mi, :cache)
false

julia> inferred = Any[]; ccall(:jl_set_newly_inferred, Cvoid, (Any,), inferred);
julia> Vector{Foo}(undef, (3,)); # trigger compilation
julia> ccall(:jl_set_newly_inferred, Cvoid, (Any,), nothing)

julia> mi.cache
CodeInstance for MethodInstance for Vector{Foo}(::UndefInitializer, ::Tuple{Int64})

julia> mi.cache in inferred
false

Vector{Foo}(::UndefInitializer, ::Tuple{Int64}) was compiled (and inferred) for the first time, but it didn't make it into the list due to this m.module != Core check:

if isa(m, Method) && m.module != Core

I'm not sure why we have that guard, but it has the un-intended side effect that precompile(...) statements are less effective over re-exported Core methods in Base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions