From ae59d29da316a998b21f4e1c6343fb32ab2eb91b Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 19 May 2023 16:37:33 +0200 Subject: [PATCH 1/2] load extensions with fewer triggers earlier --- base/loading.jl | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index a7d05e5940ef3..320e5f2c8c03a 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1180,6 +1180,7 @@ end mutable struct ExtensionId const id::PkgId const parentid::PkgId # just need the name, for printing + const n_total_triggers::Int ntriggers::Int # how many more packages must be defined until this is loaded end @@ -1262,7 +1263,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any} continue # extension is already primed or loaded, don't add it again end EXT_PRIMED[id] = parent - gid = ExtensionId(id, parent, 1 + length(triggers)) + gid = ExtensionId(id, parent, 1 + length(triggers), 1 + length(triggers)) trigger1 = get!(Vector{ExtensionId}, EXT_DORMITORY, parent) push!(trigger1, gid) for trigger in triggers @@ -1306,25 +1307,21 @@ function run_extension_callbacks(pkgid::PkgId) # take ownership of extids that depend on this pkgid extids = pop!(EXT_DORMITORY, pkgid, nothing) extids === nothing && return + extids_to_load = Vector{ExtensionId}() for extid in extids - if extid.ntriggers > 0 - # indicate pkgid is loaded - extid.ntriggers -= 1 - end - if extid.ntriggers < 0 - # indicate pkgid is loaded - extid.ntriggers += 1 - succeeded = false - else - succeeded = true - end + extid.ntriggers -= 1 if extid.ntriggers == 0 - # actually load extid, now that all dependencies are met, - # and record the result - succeeded = succeeded && run_extension_callbacks(extid) - succeeded || push!(EXT_DORMITORY_FAILED, extid) + push!(extids_to_load, extid) end end + # Load extensions with the fewest triggers first + sort!(extids_to_load, by=extid->extid.n_total_triggers) + for extid in extids_to_load + # actually load extid, now that all dependencies are met, + succeeded = run_extension_callbacks(extid) + succeeded || push!(EXT_DORMITORY_FAILED, extid) + end + return end From 1fd6b72ce7e0599c966d7e0b6ddd164dda08e1d3 Mon Sep 17 00:00:00 2001 From: Cody Tapscott <84105208+topolarity@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:26:44 -0400 Subject: [PATCH 2/2] Update base/loading.jl --- base/loading.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/base/loading.jl b/base/loading.jl index efa0bb2ee6923..ab46329d801cd 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1601,6 +1601,7 @@ function run_extension_callbacks(pkgid::PkgId) extids === nothing && return extids_to_load = Vector{ExtensionId}() for extid in extids + @assert extid.ntriggers > 0 extid.ntriggers -= 1 if extid.ntriggers == 0 push!(extids_to_load, extid)