Skip to content

Commit

Permalink
make precompile work in Base
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 20, 2024
1 parent f906e95 commit 1666dc0
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 143 deletions.
3 changes: 2 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ include("pkgid.jl")
include("toml_parser.jl")
include("linking.jl")
include("loading.jl")
include("precompile.jl")

# misc useful functions & macros
include("timing.jl")
Expand All @@ -543,6 +542,8 @@ if isdefined(Core, :Compiler) && is_primary_base_module
Docs.loaddocs(Core.Compiler.CoreDocs.DOCS)
end

include("precompile.jl")

# finally, now make `include` point to the full version
for m in methods(include)
delete_method(m)
Expand Down
13 changes: 6 additions & 7 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2137,8 +2137,6 @@ end

require(uuidkey::PkgId) = @lock require_lock _require_prelocked(uuidkey)

const REPL_PKGID = PkgId(UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL")

function _require_prelocked(uuidkey::PkgId, env=nothing)
if _require_world_age[] != typemax(UInt)
Base.invoke_in_world(_require_world_age[], __require_prelocked, uuidkey, env)
Expand Down Expand Up @@ -2254,7 +2252,7 @@ function set_pkgorigin_version_path(pkg::PkgId, path::Union{String,Nothing})
nothing
end

# A hook to allow code load to use Pkg.precompile
# Unused
const PKG_PRECOMPILE_HOOK = Ref{Function}()

# Returns `nothing` or the new(ish) module
Expand All @@ -2276,7 +2274,7 @@ function _require(pkg::PkgId, env=nothing)
end
set_pkgorigin_version_path(pkg, path)

pkg_precompile_attempted = false # being safe to avoid getting stuck in a Pkg.precompile loop
parallel_precompile_attempted = false # being safe to avoid getting stuck in a precompilepkgs loop
reasons = Dict{String,Int}()
# attempt to load the module file via the precompile cache locations
if JLOptions().use_compiled_modules != 0
Expand Down Expand Up @@ -2306,11 +2304,12 @@ function _require(pkg::PkgId, env=nothing)

if JLOptions().use_compiled_modules == 1
if !generating_output(#=incremental=#false)
if !pkg_precompile_attempted && isinteractive() && isassigned(PKG_PRECOMPILE_HOOK)
pkg_precompile_attempted = true
project = active_project()
if !parallel_precompile_attempted && @isdefined(PrecompilePkgs) && project !== nothing && isfile(project)
parallel_precompile_attempted = true
unlock(require_lock)
try
@invokelatest PKG_PRECOMPILE_HOOK[](pkg.name, _from_loading = true)
PrecompilePkgs.precompilepkgs([pkg.name]; _from_loading=true)
finally
lock(require_lock)
end
Expand Down
Loading

0 comments on commit 1666dc0

Please sign in to comment.