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 Mar 1, 2024
1 parent c9e44e3 commit 3417484
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 150 deletions.
3 changes: 2 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,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 @@ -544,6 +543,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
15 changes: 8 additions & 7 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2147,8 +2147,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 @@ -2262,8 +2260,9 @@ function set_pkgorigin_version_path(pkg::PkgId, path::String)
nothing
end

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

# Returns `nothing` or the new(ish) module
function _require(pkg::PkgId, env=nothing)
Expand All @@ -2284,7 +2283,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 @@ -2314,11 +2313,13 @@ 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 !generating_output() && !parallel_precompile_attempted && !disable_parallel_precompile && @isdefined(PrecompilePkgs) && project !== nothing &&
isfile(project) && project_file_manifest_path(project) !== nothing
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 3417484

Please sign in to comment.