Skip to content

Modules' __init__ should be called in imported order #192

Closed
@tkf

Description

@tkf

Currently, compile_incremental(:PyCall) generates incremental_precompile.jl containing something like

using Pkg, Statistics, Test, Libdl, Conda, Serialization, LinearAlgebra,
    PyCall, VersionParsing, MacroTools, Dates, PackageCompiler
for Mod in [Pkg, Statistics, Test, Libdl, Conda, Serialization, LinearAlgebra,
    PyCall, VersionParsing, MacroTools, Dates, PackageCompiler]
    isdefined(Mod, :__init__) && Mod.__init__()
end

PyCall depends on MacroTools (Conda, and VersionParsing). Furthermore, in principle, PyCall's top-level code and macros can depend on the global state configured in MacroTools.__init__ (PyCall does not depend on it ATM. However, you can check it by adding, e.g., println(MacroTools.@expand @time foo()) in PyCall.__init__). So, shouldn't using MacroTools and MacroTools.__init__() come before using PyCall? That is to say, I think incremental_precompile.jl needs to contain something like

for name in [...,
            :MacroTools,
            :VersionParsing,
            :Conda,
            :PyCall,
            ...]
    Core.eval(@__MODULE__, :(using $name))
    Mod = Core.eval(@__MODULE__, name)
    isdefined(Mod, :__init__) && Mod.__init__()
end

In general, I think the packages have to be imported and __init__'ed in the topologically sorted order. Or maybe it is better be fixed in Julia side? JuliaLang/julia#22910

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions