-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
PrecompileTools doesn't run __init__()
so some functionality may not work during package compilation?
#32
Comments
And if there are nested modules in the package, how do we ensure that we can find an init all of those? EDIT: I don't think this would work either |
😁 this is really dumb, but this seems to at least unblock me for now lol recursively_init_modules(m::Module) = _recursively_init_modules(m, m)
function _recursively_init_modules(root::Module, m::Module)
# iterate all recursively reachable modules from m and call __init__() on them:
for name in names(m, all=true)
# @show name
if name isa Symbol && name != :Base && name != :Core && name != nameof(m)
m2 = try Core.eval(m, name) catch ; continue ; end
# @show m2
if m2 isa Module && fullname(m2)[1] == nameof(root)
_recursively_init_modules(root, m2)
end
end
end
@info m
if isdefined(m, :__init__)
@info "init $m"
@eval m __init__()
end
end
@setup_workload begin
recursively_init_modules(TestPackage)
@info PORT[]
@compile_workload begin
test()
end
end EDIT: This is the slightly more robust terrible really dumb thing that I'm trying now |
Precompilation doesn't run |
@vchuravy and I talked about this on slack, and it seems like a nice change to make to julia would be to move the compile_workload step to after the Module is closed, so that we can run after the module is initialized, and we don't need to worry about modifying state in the module. Can we do something where packages can register a compilation callback / function that runs after we've finalized the module for serialization? Something like this?: module MyPackage
...
end
Base.precompilation(MyPackage) do
@setup_workload begin
# ...
@compile_workload begin
# ...
end
end
end and then Base would deepcopy the MyPackage module, run the callback, and then only keep the new compilations but serialize the original copy of the module? It's a bit convoluted, but it would ensure that precompilation snoop scripts don't mutate the state of the module, and that they can run after the init() is called, so the expected state is present. (Or maybe the PrecompileTools macros would expand to setting this callback or something.) Thoughts? |
If I have a package's workfile file that runs functionality in the package, from what I understand
@compile_workload
doesn't run the package's__init__()
function, so the package's module will still be uninitialized during the workload?For example:
Then:
Does that make sense?
What do other packages usually do here? Are we meant to call
__init__()
manually? I didn't see anything about this in the docs.Thanks :)
The text was updated successfully, but these errors were encountered: