Skip to content
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

load extensions with fewer triggers earlier #49891

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
topolarity marked this conversation as resolved.
Show resolved Hide resolved
topolarity marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down