Skip to content

Commit

Permalink
use a fixed world for code loading (#49525)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Jun 9, 2023
1 parent feaea22 commit 59bf9e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ function __init__()
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), PROFILE_PRINT_COND[].handle)
errormonitor(Threads.@spawn(profile_printing_listener()))
end
_require_world_age[] = get_world_counter()
# Prevent spawned Julia process from getting stuck waiting on Tracy to connect.
delete!(ENV, "JULIA_WAIT_FOR_TRACY")
nothing
Expand Down
18 changes: 18 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ end
# require always works in Main scope and loads files from node 1
const toplevel_load = Ref(true)

const _require_world_age = Ref{UInt}(typemax(UInt))

"""
require(into::Module, module::Symbol)
Expand All @@ -1675,6 +1677,14 @@ For more details regarding code loading, see the manual sections on [modules](@r
[parallel computing](@ref code-availability).
"""
function require(into::Module, mod::Symbol)
if _require_world_age[] != typemax(UInt)
Base.invoke_in_world(_require_world_age[], __require, into, mod)
else
@invokelatest __require(into, mod)
end
end

function __require(into::Module, mod::Symbol)
@lock require_lock begin
LOADING_CACHE[] = LoadingCache()
try
Expand Down Expand Up @@ -1724,6 +1734,14 @@ require(uuidkey::PkgId) = @lock require_lock _require_prelocked(uuidkey)
const REPL_PKGID = PkgId(UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL")

function _require_prelocked(uuidkey::PkgId, env=nothing)
if _require_world_age[] != typemax(UInt)
Base.invoke_in_world(_require_world_age[], __require_prelocked, uuidkey, env)
else
@invokelatest __require_prelocked(uuidkey, env)
end
end

function __require_prelocked(uuidkey::PkgId, env=nothing)
assert_havelock(require_lock)
if !root_module_exists(uuidkey)
newm = _require(uuidkey, env)
Expand Down

0 comments on commit 59bf9e8

Please sign in to comment.