Skip to content

Commit b0d865e

Browse files
committed
account for extensions indirectly depending on eachother in parallel package precompilation
1 parent 59c3c71 commit b0d865e

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

base/precompilation.jl

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ function precompilepkgs(pkgs::Vector{String}=String[];
402402
depsmap[pkg] = filter!(!Base.in_sysimage, deps)
403403
# add any extensions
404404
pkg_exts = Dict{Base.PkgId, Vector{Base.PkgId}}()
405-
prev_ext = nothing
406405
for (ext_name, extdep_uuids) in env.extensions[dep]
407406
ext_deps = Base.PkgId[]
408407
push!(ext_deps, pkg) # depends on parent package
@@ -417,13 +416,8 @@ function precompilepkgs(pkgs::Vector{String}=String[];
417416
end
418417
end
419418
all_extdeps_available || continue
420-
if prev_ext isa Base.PkgId
421-
# also make the exts depend on eachother sequentially to avoid race
422-
push!(ext_deps, prev_ext)
423-
end
424419
ext_uuid = Base.uuid5(pkg.uuid, ext_name)
425420
ext = Base.PkgId(ext_uuid, ext_name)
426-
prev_ext = ext
427421
filter!(!Base.in_sysimage, ext_deps)
428422
depsmap[ext] = ext_deps
429423
exts[ext] = pkg.name
@@ -434,6 +428,51 @@ function precompilepkgs(pkgs::Vector{String}=String[];
434428
end
435429
end
436430

431+
# An extension effectively depends on another extension if it has all the the
432+
# dependencies of that other extension
433+
function expand_dependencies(depsmap)
434+
function visit!(visited, node, all_deps)
435+
if node in visited
436+
return
437+
end
438+
push!(visited, node)
439+
for dep in get(Set{Base.PkgId}, depsmap, node)
440+
if !(dep in all_deps)
441+
push!(all_deps, dep)
442+
visit!(visited, dep, all_deps)
443+
end
444+
end
445+
end
446+
447+
depsmap_transitive = Dict{Base.PkgId, Set{Base.PkgId}}()
448+
for package in keys(depsmap)
449+
# Initialize a set to keep track of all dependencies for 'package'
450+
all_deps = Set{Base.PkgId}()
451+
visited = Set{Base.PkgId}()
452+
visit!(visited, package, all_deps)
453+
# Update depsmap with the complete set of dependencies for 'package'
454+
depsmap_transitive[package] = all_deps
455+
end
456+
return depsmap_transitive
457+
end
458+
459+
depsmap_transitive = expand_dependencies(depsmap)
460+
461+
for (_, extensions_1) in pkg_exts_map
462+
for extension_1 in extensions_1
463+
deps_ext_1 = depsmap_transitive[extension_1]
464+
for (_, extensions_2) in pkg_exts_map
465+
for extension_2 in extensions_2
466+
extension_1 == extension_2 && continue
467+
deps_ext_2 = depsmap_transitive[extension_2]
468+
if issubset(deps_ext_2, deps_ext_1)
469+
push!(depsmap[extension_1], extension_2)
470+
end
471+
end
472+
end
473+
end
474+
end
475+
437476
@debug "precompile: deps collected"
438477
# this loop must be run after the full depsmap has been populated
439478
for (pkg, pkg_exts) in pkg_exts_map
@@ -748,6 +787,7 @@ function precompilepkgs(pkgs::Vector{String}=String[];
748787
end
749788
@debug "precompile: starting precompilation loop" depsmap direct_deps
750789
## precompilation loop
790+
751791
for (pkg, deps) in depsmap
752792
cachepaths = Base.find_all_in_cache_path(pkg)
753793
sourcepath = Base.locate_package(pkg)
@@ -820,6 +860,7 @@ function precompilepkgs(pkgs::Vector{String}=String[];
820860
end
821861
loaded && (n_loaded += 1)
822862
catch err
863+
@show err
823864
close(std_pipe.in) # close pipe to end the std output monitor
824865
wait(t_monitor)
825866
if err isa ErrorException || (err isa ArgumentError && startswith(err.msg, "Invalid header in cache file"))
@@ -843,7 +884,8 @@ function precompilepkgs(pkgs::Vector{String}=String[];
843884
notify(was_processed[pkg_config])
844885
catch err_outer
845886
# For debugging:
846-
# println("Task failed $err_outer") # logging doesn't show here
887+
println("Task failed $err_outer")
888+
Base.display_error(ErrorException(""), Base.catch_backtrace())# logging doesn't show here
847889
handle_interrupt(err_outer) || rethrow()
848890
notify(was_processed[pkg_config])
849891
finally

0 commit comments

Comments
 (0)