Skip to content

Commit

Permalink
alt implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jan 12, 2024
1 parent be8fe90 commit a7c0985
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,6 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi
return nothing
end

# Modules that have been explicitly `require`d in the Julia session,
const required_modules = Set{PkgId}()

function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}, weakdeps::Dict{String, Any})
for (ext, triggers) in extensions
Expand All @@ -1352,7 +1350,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
# TODO: Better error message if this lookup fails?
uuid_trigger = UUID(weakdeps[trigger]::String)
trigger_id = PkgId(uuid_trigger, trigger)
if !(trigger_id in required_modules) || haskey(package_locks, trigger_id)
if !haskey(explicit_loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
trigger1 = get!(Vector{ExtensionId}, EXT_DORMITORY, trigger_id)
push!(trigger1, gid)
else
Expand Down Expand Up @@ -1974,8 +1972,6 @@ end

function __require_prelocked(uuidkey::PkgId, env=nothing)
assert_havelock(require_lock)
first_require = !(uuidkey in required_modules)
push!(required_modules, uuidkey)
if !root_module_exists(uuidkey)
newm = _require(uuidkey, env)
if newm === nothing
Expand All @@ -1986,7 +1982,6 @@ function __require_prelocked(uuidkey::PkgId, env=nothing)
# After successfully loading, notify downstream consumers
run_package_callbacks(uuidkey)
else
first_require && run_package_callbacks(uuidkey)
newm = root_module(uuidkey)
end
return newm
Expand All @@ -2001,6 +1996,8 @@ PkgOrigin() = PkgOrigin(nothing, nothing, nothing)
const pkgorigins = Dict{PkgId,PkgOrigin}()

const loaded_modules = Dict{PkgId,Module}()
# Zerod out on Julia start
const explicit_loaded_modules = Dict{PkgId,Module}()
const loaded_modules_order = Vector{Module}()
const module_keys = IdDict{Module,PkgId}() # the reverse

Expand All @@ -2010,6 +2007,7 @@ root_module_key(m::Module) = @lock require_lock module_keys[m]
@constprop :none function register_root_module(m::Module)
# n.b. This is called from C after creating a new module in `Base.__toplevel__`,
# instead of adding them to the binding table there.
@info "Registering root module $m"
@lock require_lock begin
key = PkgId(m, String(nameof(m)))
if haskey(loaded_modules, key)
Expand All @@ -2024,6 +2022,7 @@ root_module_key(m::Module) = @lock require_lock module_keys[m]
end
push!(loaded_modules_order, m)
loaded_modules[key] = m
explicit_loaded_modules[key] = m
module_keys[m] = key
end
nothing
Expand Down

0 comments on commit a7c0985

Please sign in to comment.