JuliaLang / JuliaLang/PrecompileTools.jl

PrecompileTools doesn't run `__init__()` so some functionality may not work during package compilation?

Open
#32 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
249
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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:
```julia
module TestPackage

using PrecompileTools

const PORT = Ref(0)

function __init__()
PORT[] = rand(2222:8888)
end

function test()
# start up a server and run the tests...
@assert PORT[] != 0
# ...
end

@compile_workload begin
test()
end

end # module TestPackage
```

Then:
```julia
julia> using TestPackage
[ Info: Precompiling TestPackage [13cf7a4f-c364-47a8-9398-f77e91fc5657]
ERROR: LoadError: AssertionError: PORT[] != 0
Stacktrace:
[1] test
@ ~/tmp/TestPackage/src/TestPackage.jl:13 [inlined]
[2] macro expansion
@ ~/tmp/TestPackage/src/TestPackage.jl:18 [inlined]
[3] top-level scope
@ ~/.julia/packages/PrecompileTools/kmH5L/src/workloads.jl:78
[4] include
@ ./Base.jl:457 [inlined]
[5] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
@ Base ./loading.jl:2049
[6] top-level scope
@ stdin:3
in expression starting at /Users/nathandaly/tmp/TestPackage/src/TestPackage.jl:1
```

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 :)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.