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