-
-
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
precompilepkgs: respect loaded dependencies when precompiling for load #56901
Merged
IanButterworth
merged 3 commits into
JuliaLang:master
from
IanButterworth:ib/precompile_respect_loaded_loading
Dec 30, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,11 +418,12 @@ function precompilepkgs(pkgs::Vector{String}=String[]; | |
io::IO=stderr, | ||
# asking for timing disables fancy mode, as timing is shown in non-fancy mode | ||
fancyprint::Bool = can_fancyprint(io) && !timing, | ||
manifest::Bool=false,) | ||
manifest::Bool=false, | ||
ignore_loaded::Bool=true) | ||
# monomorphize this to avoid latency problems | ||
_precompilepkgs(pkgs, internal_call, strict, warn_loaded, timing, _from_loading, | ||
configs isa Vector{Config} ? configs : [configs], | ||
IOContext{IO}(io), fancyprint, manifest) | ||
IOContext{IO}(io), fancyprint, manifest, ignore_loaded) | ||
end | ||
|
||
function _precompilepkgs(pkgs::Vector{String}, | ||
|
@@ -434,7 +435,8 @@ function _precompilepkgs(pkgs::Vector{String}, | |
configs::Vector{Config}, | ||
io::IOContext{IO}, | ||
fancyprint::Bool, | ||
manifest::Bool) | ||
manifest::Bool, | ||
ignore_loaded::Bool) | ||
requested_pkgs = copy(pkgs) # for understanding user intent | ||
|
||
time_start = time_ns() | ||
|
@@ -918,7 +920,7 @@ function _precompilepkgs(pkgs::Vector{String}, | |
wait(was_processed[(dep,config)]) | ||
end | ||
circular = pkg in circular_deps | ||
is_stale = !Base.isprecompiled(pkg; ignore_loaded=true, stale_cache, cachepath_cache, cachepaths, sourcepath, flags=cacheflags) | ||
is_stale = !Base.isprecompiled(pkg; ignore_loaded, stale_cache, cachepath_cache, cachepaths, sourcepath, flags=cacheflags) | ||
if !circular && is_stale | ||
Base.acquire(parallel_limiter) | ||
is_project_dep = pkg in project_deps | ||
|
@@ -944,10 +946,10 @@ function _precompilepkgs(pkgs::Vector{String}, | |
try | ||
# allows processes to wait if another process is precompiling a given package to | ||
# a functionally identical package cache (except for preferences, which may differ) | ||
t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock(io, print_lock, fancyprint, pkg_config, pkgspidlocked, hascolor, parallel_limiter) do | ||
t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock(io, print_lock, fancyprint, pkg_config, pkgspidlocked, hascolor, parallel_limiter, ignore_loaded) do | ||
Base.with_logger(Base.NullLogger()) do | ||
# The false here means we ignore loaded modules, so precompile for a fresh session | ||
keep_loaded_modules = false | ||
# whether to respect already loaded dependency versions | ||
keep_loaded_modules = !ignore_loaded | ||
# for extensions, any extension in our direct dependencies is one we have a right to load | ||
# for packages, we may load any extension (all possible triggers are accounted for above) | ||
loadable_exts = haskey(ext_to_parent, pkg) ? filter((dep)->haskey(ext_to_parent, dep), direct_deps[pkg]) : nothing | ||
|
@@ -1037,9 +1039,11 @@ function _precompilepkgs(pkgs::Vector{String}, | |
plural1 = length(configs) > 1 ? "dependency configurations" : n_loaded == 1 ? "dependency" : "dependencies" | ||
plural2 = n_loaded == 1 ? "a different version is" : "different versions are" | ||
plural3 = n_loaded == 1 ? "" : "s" | ||
plural4 = n_loaded == 1 ? "this package" : "these packages" | ||
print(iostr, "\n ", | ||
color_string(string(n_loaded), Base.warn_color()), | ||
" $(plural1) precompiled but $(plural2) currently loaded. Restart julia to access the new version$(plural3)" | ||
" $(plural1) precompiled but $(plural2) currently loaded. Restart julia to access the new version$(plural3). \ | ||
Otherwise, loading dependents of $(plural4) may trigger further precompilation to work with the unexpected version$(plural3)." | ||
) | ||
end | ||
if !isempty(precomperr_deps) | ||
|
@@ -1130,7 +1134,7 @@ function _color_string(cstr::String, col::Union{Int64, Symbol}, hascolor) | |
end | ||
|
||
# Can be merged with `maybe_cachefile_lock` in loading? | ||
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg_config, pkgspidlocked, hascolor, parallel_limiter::Base.Semaphore) | ||
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg_config, pkgspidlocked, hascolor, parallel_limiter::Base.Semaphore, ignore_loaded::Bool) | ||
if !(isdefined(Base, :mkpidlock_hook) && isdefined(Base, :trymkpidlock_hook) && Base.isdefined(Base, :parse_pidfile_hook)) | ||
return f() | ||
end | ||
|
@@ -1158,7 +1162,7 @@ function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLo | |
# wait until the lock is available | ||
@invokelatest Base.mkpidlock_hook(() -> begin | ||
# double-check in case the other process crashed or the lock expired | ||
if Base.isprecompiled(pkg; ignore_loaded=true, flags=cacheflags) # don't use caches for this as the env state will have changed | ||
if Base.isprecompiled(pkg; ignore_loaded, flags=cacheflags) # don't use caches for this as the env state will have changed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't recall a reason for this to be forced false. I'm assuming it was just missed. |
||
return nothing # returning nothing indicates a process waited for another | ||
else | ||
delete!(pkgspidlocked, pkg_config) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this was to allow the user to compute the best pkg to load for
compilecache_path
, even if it is currently loaded at a different version?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe it was just missed originally? c24136d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could've been. It's not mentioned in the PR #50218