-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module import order in the source code is not maintained #45888
Comments
If this is not an issue, I'd change it to feature request.. |
Definitely not a valid assumption, as these packages need to ensure for themselves that they are loading in the correct order (alternatively instead, delayed initialization till first use is generally better than having |
Not sure if I understand the correct order. I'd call the loading order without any precompiled cache is the "correct" one. If one writes a module that Will it cause issues if I sort |
We can't guarantee the order of initializing modules that don't have a dependency relationship. For example, a user could independently import |
I think this is expected. Maybe I didn't express my idea properly. My request is to make sure the shallow loading order obey user require order. However, the process of the deeper module loading is maintained by themselves, so calling If a Julia package provides configurations used by independent packages, it should be the user's duty to firstly call the former package. |
May be this is also linked to this issue: |
The related discourse post: loading a precompiled module does not respect the module import order.
P.S: not asking resources for this. I'll make a PR if this gets confirmed to be an issue.
Consequences
This issue affects the initialization order of package dependencies. The initialization order is inconsistent with that seen from the source code.
Description
Suppose we are making a Julia package
TestLoadOrder
which references two dependenciesA
andB
, and the main module is created as follow:It works when loading the package without precompilation, e.g., loading the package for the first time.
However, the issue may occur when the package
TestLoadOrder
is loaded from precompiled cache. If we expectsA
does some initialization tasks to configure how to loadB
(EDIT: see Real-world concerns below), it might not work because the loading order is NOT consistent with what we see in the source code.The issue comes from the results of
Base.parse_cache_header
.julia/base/loading.jl
Lines 2014 to 2022 in bd7bd5e
Modules are loaded according to the order in
required_modules::Vector{Pair{Base.PkgId, UInt64}}
returned fromBase.parse_cache_header
, but the correct order of user imports seems kept inrequires::Vector{Pair{Base.PkgId, Base.PkgId}}
. These orders can be different.As a consequence, the current module loading implementation may cause inconsistency when loading a precompiled module.
Reproduction
Environment:
Repro steps:
generate a package
TestLoadOrder
, and another two packagesDepA
,DepB
asTestLoadOrder
's dependencies.add
DepA
andDepB
toTestLoadOrder/Project.toml
's[deps]
section, and develop these three packages locally.open julia REPL,
import TestLoadOrder
, the output:close julia REPL and open again,
import TestLoadOrder
, now the precompiled caches are used:As can bee seen, the initialization order is inconsistent with that seen from the source code.
Real-world concerns
In the Julia ecosystem, there are many packages that read environment configurations before initialization.
For instance,
PyCall
andPythonCall
, which give us pretty smooth interoperability with Python, require configurations to initialize a Python interpreter. These kind developers fromPyCall
andPythonCall
have to consider much about the "non-core" parts, i.e., finding the correct configurations such as Python executable paths/package install locations/in-process library address.Frankly speaking, these two great packages never provide a solid solution to such configuration, although it is not their fault at all. For instance, recently I need to make a julia package that requires PythonCall(or PyCall), and this package should automatically and dynamically select the Python executable specified in my separate environment. However, I didn't find out how to achieve this with PyCall, and too much configuration outside Julia are neeeded if I use PythonCall (configuration in Julia is invalid due to this issue!). I cannot create a Julia package to do so, due to this issue.
IMHO, these awesome developers should have a chance to ignore on the "non-core" parts, and deliver the configuration job to other dedicated packages. This is now do-able with a
__precompile__(false)
package, but if we want more like bundling a sysimage, we'd better fix this issue to support more consistent precompilation loading.The text was updated successfully, but these errors were encountered: