@@ -1935,8 +1935,12 @@ debug_loading_deadlocks::Bool = true # Enable a slightly more expensive, but mor
19351935function start_loading (modkey:: PkgId )
19361936 # handle recursive calls to require
19371937 assert_havelock (require_lock)
1938- loading = get (package_locks, modkey, nothing )
1939- if loading != = nothing
1938+ while true
1939+ loading = get (package_locks, modkey, nothing )
1940+ if loading === nothing
1941+ package_locks[modkey] = current_task () => Threads. Condition (require_lock)
1942+ return nothing
1943+ end
19401944 # load already in progress for this module on the task
19411945 task, cond = loading
19421946 deps = String[modkey. name]
@@ -1975,10 +1979,9 @@ function start_loading(modkey::PkgId)
19751979 end
19761980 throw (ConcurrencyViolationError (msg))
19771981 end
1978- return wait (cond)
1982+ loading = wait (cond)
1983+ loading isa Module && return loading
19791984 end
1980- package_locks[modkey] = current_task () => Threads. Condition (require_lock)
1981- return
19821985end
19831986
19841987function end_loading (modkey:: PkgId , @nospecialize loaded)
@@ -2343,9 +2346,9 @@ function _require(pkg::PkgId, env=nothing)
23432346 # attempt to load the module file via the precompile cache locations
23442347 if JLOptions (). use_compiled_modules != 0
23452348 @label load_from_cache
2346- m = _require_search_from_serialized (pkg, path, UInt128 (0 ), true ; reasons)
2347- if m isa Module
2348- return m
2349+ loaded = _require_search_from_serialized (pkg, path, UInt128 (0 ), true ; reasons)
2350+ if loaded isa Module
2351+ return loaded
23492352 end
23502353 end
23512354
@@ -2381,31 +2384,30 @@ function _require(pkg::PkgId, env=nothing)
23812384 @goto load_from_cache
23822385 end
23832386 # spawn off a new incremental pre-compile task for recursive `require` calls
2384- cachefile_or_module = maybe_cachefile_lock (pkg, path) do
2385- # double-check now that we have lock
2387+ loaded = maybe_cachefile_lock (pkg, path) do
2388+ # double-check the search now that we have lock
23862389 m = _require_search_from_serialized (pkg, path, UInt128 (0 ), true )
23872390 m isa Module && return m
2388- compilecache (pkg, path; reasons)
2391+ return compilecache (pkg, path; reasons)
23892392 end
2390- cachefile_or_module isa Module && return cachefile_or_module:: Module
2391- cachefile = cachefile_or_module
2392- if isnothing (cachefile) # maybe_cachefile_lock returns nothing if it had to wait for another process
2393+ loaded isa Module && return loaded
2394+ if isnothing (loaded) # maybe_cachefile_lock returns nothing if it had to wait for another process
23932395 @goto load_from_cache # the new cachefile will have the newest mtime so will come first in the search
2394- elseif isa (cachefile , Exception)
2395- if precompilableerror (cachefile )
2396+ elseif isa (loaded , Exception)
2397+ if precompilableerror (loaded )
23962398 verbosity = isinteractive () ? CoreLogging. Info : CoreLogging. Debug
2397- @logmsg verbosity " Skipping precompilation due to precompilable error. Importing $(repr (" text/plain" , pkg)) ." exception= m
2399+ @logmsg verbosity " Skipping precompilation due to precompilable error. Importing $(repr (" text/plain" , pkg)) ." exception= loaded
23982400 else
2399- @warn " The call to compilecache failed to create a usable precompiled cache file for $(repr (" text/plain" , pkg)) " exception= m
2401+ @warn " The call to compilecache failed to create a usable precompiled cache file for $(repr (" text/plain" , pkg)) " exception= loaded
24002402 end
24012403 # fall-through to loading the file locally if not incremental
24022404 else
2403- cachefile, ocachefile = cachefile :: Tuple{String, Union{Nothing, String}}
2404- m = _tryrequire_from_serialized (pkg, cachefile, ocachefile)
2405- if ! isa (m , Module)
2406- @warn " The call to compilecache failed to create a usable precompiled cache file for $(repr (" text/plain" , pkg)) " exception= m
2405+ cachefile, ocachefile = loaded :: Tuple{String, Union{Nothing, String}}
2406+ loaded = _tryrequire_from_serialized (pkg, cachefile, ocachefile)
2407+ if ! isa (loaded , Module)
2408+ @warn " The call to compilecache failed to create a usable precompiled cache file for $(repr (" text/plain" , pkg)) " exception= loaded
24072409 else
2408- return m
2410+ return loaded
24092411 end
24102412 end
24112413 if JLOptions (). incremental != 0
0 commit comments