@@ -1995,8 +1995,12 @@ debug_loading_deadlocks::Bool = true # Enable a slightly more expensive, but mor
1995
1995
function start_loading (modkey:: PkgId )
1996
1996
# handle recursive calls to require
1997
1997
assert_havelock (require_lock)
1998
- loading = get (package_locks, modkey, nothing )
1999
- if loading != = nothing
1998
+ while true
1999
+ loading = get (package_locks, modkey, nothing )
2000
+ if loading === nothing
2001
+ package_locks[modkey] = current_task () => Threads. Condition (require_lock)
2002
+ return nothing
2003
+ end
2000
2004
# load already in progress for this module on the task
2001
2005
task, cond = loading
2002
2006
deps = String[modkey. name]
@@ -2035,10 +2039,9 @@ function start_loading(modkey::PkgId)
2035
2039
end
2036
2040
throw (ConcurrencyViolationError (msg))
2037
2041
end
2038
- return wait (cond)
2042
+ loading = wait (cond)
2043
+ loading isa Module && return loading
2039
2044
end
2040
- package_locks[modkey] = current_task () => Threads. Condition (require_lock)
2041
- return
2042
2045
end
2043
2046
2044
2047
function end_loading (modkey:: PkgId , @nospecialize loaded)
@@ -2417,9 +2420,9 @@ function _require(pkg::PkgId, env=nothing)
2417
2420
# attempt to load the module file via the precompile cache locations
2418
2421
if JLOptions (). use_compiled_modules != 0
2419
2422
@label load_from_cache
2420
- m = _require_search_from_serialized (pkg, path, UInt128 (0 ), true ; reasons)
2421
- if m isa Module
2422
- return m
2423
+ loaded = _require_search_from_serialized (pkg, path, UInt128 (0 ), true ; reasons)
2424
+ if loaded isa Module
2425
+ return loaded
2423
2426
end
2424
2427
end
2425
2428
@@ -2455,14 +2458,14 @@ function _require(pkg::PkgId, env=nothing)
2455
2458
@goto load_from_cache
2456
2459
end
2457
2460
# spawn off a new incremental pre-compile task for recursive `require` calls
2458
- cachefile_or_module = maybe_cachefile_lock (pkg, path) do
2461
+ loaded = maybe_cachefile_lock (pkg, path) do
2459
2462
# double-check now that we have lock
2460
2463
m = _require_search_from_serialized (pkg, path, UInt128 (0 ), true )
2461
2464
m isa Module && return m
2462
- compilecache (pkg, path; reasons)
2465
+ return compilecache (pkg, path; reasons)
2463
2466
end
2464
- cachefile_or_module isa Module && return cachefile_or_module :: Module
2465
- cachefile = cachefile_or_module
2467
+ loaded isa Module && return loaded
2468
+ cachefile = loaded
2466
2469
if isnothing (cachefile) # maybe_cachefile_lock returns nothing if it had to wait for another process
2467
2470
@goto load_from_cache # the new cachefile will have the newest mtime so will come first in the search
2468
2471
elseif isa (cachefile, Exception)
@@ -2475,11 +2478,11 @@ function _require(pkg::PkgId, env=nothing)
2475
2478
# fall-through to loading the file locally if not incremental
2476
2479
else
2477
2480
cachefile, ocachefile = cachefile:: Tuple{String, Union{Nothing, String}}
2478
- m = _tryrequire_from_serialized (pkg, cachefile, ocachefile)
2479
- if ! isa (m , Module)
2481
+ loaded = _tryrequire_from_serialized (pkg, cachefile, ocachefile)
2482
+ if ! isa (loaded , Module)
2480
2483
@warn " The call to compilecache failed to create a usable precompiled cache file for $(repr (" text/plain" , pkg)) " exception= m
2481
2484
else
2482
- return m
2485
+ return loaded
2483
2486
end
2484
2487
end
2485
2488
if JLOptions (). incremental != 0
0 commit comments