@@ -1280,17 +1280,21 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
1280
1280
sv = try
1281
1281
if ocachepath != = nothing
1282
1282
@debug " Loading object cache file $ocachepath for $(repr (" text/plain" , pkg)) "
1283
- ccall (:jl_restore_package_image_from_file , Ref{SimpleVector} , (Cstring, Any, Cint, Cstring, Cint),
1283
+ ccall (:jl_restore_package_image_from_file , Any , (Cstring, Any, Cint, Cstring, Cint),
1284
1284
ocachepath, depmods, #= completeinfo=# false , pkg. name, ignore_native)
1285
1285
else
1286
1286
@debug " Loading cache file $path for $(repr (" text/plain" , pkg)) "
1287
- ccall (:jl_restore_incremental , Ref{SimpleVector} , (Cstring, Any, Cint, Cstring),
1287
+ ccall (:jl_restore_incremental , Any , (Cstring, Any, Cint, Cstring),
1288
1288
path, depmods, #= completeinfo=# false , pkg. name)
1289
1289
end
1290
1290
finally
1291
1291
lock (require_lock)
1292
1292
end
1293
+ if isa (sv, Exception)
1294
+ return sv
1295
+ end
1293
1296
1297
+ sv = sv:: SimpleVector
1294
1298
edges = sv[3 ]:: Vector{Any}
1295
1299
ext_edges = sv[4 ]:: Union{Nothing,Vector{Any}}
1296
1300
extext_methods = sv[5 ]:: Vector{Any}
@@ -1438,7 +1442,6 @@ function run_module_init(mod::Module, i::Int=1)
1438
1442
end
1439
1443
1440
1444
function run_package_callbacks (modkey:: PkgId )
1441
- @assert modkey != precompilation_target
1442
1445
run_extension_callbacks (modkey)
1443
1446
assert_havelock (require_lock)
1444
1447
unlock (require_lock)
@@ -1568,7 +1571,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
1568
1571
uuid_trigger = UUID (totaldeps[trigger]:: String )
1569
1572
trigger_id = PkgId (uuid_trigger, trigger)
1570
1573
push! (trigger_ids, trigger_id)
1571
- if ! haskey (Base. loaded_modules, trigger_id) || haskey (package_locks, trigger_id) || (trigger_id == precompilation_target)
1574
+ if ! haskey (Base. loaded_modules, trigger_id) || haskey (package_locks, trigger_id)
1572
1575
trigger1 = get! (Vector{ExtensionId}, EXT_DORMITORY, trigger_id)
1573
1576
push! (trigger1, gid)
1574
1577
else
@@ -1581,7 +1584,6 @@ end
1581
1584
loading_extension:: Bool = false
1582
1585
loadable_extensions:: Union{Nothing,Vector{PkgId}} = nothing
1583
1586
precompiling_extension:: Bool = false
1584
- precompilation_target:: Union{Nothing,PkgId} = nothing
1585
1587
function run_extension_callbacks (extid:: ExtensionId )
1586
1588
assert_havelock (require_lock)
1587
1589
succeeded = try
@@ -2178,7 +2180,6 @@ function canstart_loading(modkey::PkgId, build_id::UInt128, stalecheck::Bool)
2178
2180
# load already in progress for this module on the task
2179
2181
task, cond = loading
2180
2182
deps = String[modkey. name]
2181
- pkgid = modkey
2182
2183
assert_havelock (cond. lock)
2183
2184
if debug_loading_deadlocks && current_task () != = task
2184
2185
waiters = Dict {Task,Pair{Task,PkgId}} () # invert to track waiting tasks => loading tasks
@@ -2198,18 +2199,26 @@ function canstart_loading(modkey::PkgId, build_id::UInt128, stalecheck::Bool)
2198
2199
end
2199
2200
end
2200
2201
if current_task () === task
2201
- others = String[modkey. name] # repeat this to emphasize the cycle here
2202
+ push! (deps, modkey. name) # repeat this to emphasize the cycle here
2203
+ others = Set {String} ()
2202
2204
for each in package_locks # list the rest of the packages being loaded too
2203
2205
if each[2 ][1 ] === task
2204
2206
other = each[1 ]. name
2205
- other == modkey. name || other == pkgid . name || push! (others, other)
2207
+ other == modkey. name || push! (others, other)
2206
2208
end
2207
2209
end
2210
+ # remove duplicates from others already in deps
2211
+ for dep in deps
2212
+ delete! (others, dep)
2213
+ end
2208
2214
msg = sprint (deps, others) do io, deps, others
2209
2215
print (io, " deadlock detected in loading " )
2210
- join (io, deps, " -> " )
2211
- print (io, " -> " )
2212
- join (io, others, " && " )
2216
+ join (io, deps, " using " )
2217
+ if ! isempty (others)
2218
+ print (io, " (while loading " )
2219
+ join (io, others, " and " )
2220
+ print (io, " )" )
2221
+ end
2213
2222
end
2214
2223
throw (ConcurrencyViolationError (msg))
2215
2224
end
@@ -2383,6 +2392,10 @@ function __require(into::Module, mod::Symbol)
2383
2392
error (" `using/import $mod ` outside of a Module detected. Importing a package outside of a module \
2384
2393
is not allowed during package precompilation." )
2385
2394
end
2395
+ topmod = moduleroot (into)
2396
+ if nameof (topmod) === mod
2397
+ return topmod
2398
+ end
2386
2399
@lock require_lock begin
2387
2400
LOADING_CACHE[] = LoadingCache ()
2388
2401
try
@@ -2491,10 +2504,7 @@ function _require_prelocked(uuidkey::PkgId, env=nothing)
2491
2504
try
2492
2505
toplevel_load[] = false
2493
2506
m = __require_prelocked (uuidkey, env)
2494
- if m === nothing
2495
- error (" package `$(uuidkey. name) ` did not define the expected \
2496
- module `$(uuidkey. name) `, check for typos in package module name" )
2497
- end
2507
+ m isa Module || check_package_module_loaded_error (uuidkey)
2498
2508
finally
2499
2509
toplevel_load[] = last
2500
2510
end_loading (uuidkey, m)
@@ -2984,6 +2994,9 @@ const newly_inferred = CodeInstance[]
2984
2994
function include_package_for_output (pkg:: PkgId , input:: String , depot_path:: Vector{String} , dl_load_path:: Vector{String} , load_path:: Vector{String} ,
2985
2995
concrete_deps:: typeof (_concrete_dependencies), source:: Union{Nothing,String} )
2986
2996
2997
+ @lock require_lock begin
2998
+ m = start_loading (pkg, UInt128 (0 ), false )
2999
+ @assert m === nothing
2987
3000
append! (empty! (Base. DEPOT_PATH ), depot_path)
2988
3001
append! (empty! (Base. DL_LOAD_PATH), dl_load_path)
2989
3002
append! (empty! (Base. LOAD_PATH ), load_path)
@@ -2992,6 +3005,8 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
2992
3005
Base. _track_dependencies[] = true
2993
3006
get! (Base. PkgOrigin, Base. pkgorigins, pkg). path = input
2994
3007
append! (empty! (Base. _concrete_dependencies), concrete_deps)
3008
+ end
3009
+
2995
3010
uuid_tuple = pkg. uuid === nothing ? (UInt64 (0 ), UInt64 (0 )) : convert (NTuple{2 , UInt64}, pkg. uuid)
2996
3011
2997
3012
ccall (:jl_set_module_uuid , Cvoid, (Any, NTuple{2 , UInt64}), Base. __toplevel__, uuid_tuple)
@@ -3010,21 +3025,22 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
3010
3025
ccall (:jl_set_newly_inferred , Cvoid, (Any,), nothing )
3011
3026
end
3012
3027
# check that the package defined the expected module so we can give a nice error message if not
3013
- Base. check_package_module_loaded (pkg)
3028
+ m = maybe_root_module (pkg)
3029
+ m isa Module || check_package_module_loaded_error (pkg)
3014
3030
3015
3031
# Re-populate the runtime's newly-inferred array, which will be included
3016
3032
# in the output. We removed it above to avoid including any code we may
3017
3033
# have compiled for error handling and validation.
3018
3034
ccall (:jl_set_newly_inferred , Cvoid, (Any,), newly_inferred)
3035
+ @lock require_lock end_loading (pkg, m)
3036
+ # insert_extension_triggers(pkg)
3037
+ # run_package_callbacks(pkg)
3019
3038
end
3020
3039
3021
- function check_package_module_loaded (pkg:: PkgId )
3022
- if ! haskey (Base. loaded_modules, pkg)
3023
- # match compilecache error type for non-125 errors
3024
- error (" $(repr (" text/plain" , pkg)) did not define the expected module `$(pkg. name) `, \
3025
- check for typos in package module name" )
3026
- end
3027
- return nothing
3040
+ function check_package_module_loaded_error (pkg)
3041
+ # match compilecache error type for non-125 errors
3042
+ error (" package `$(pkg. name) ` did not define the expected \
3043
+ module `$(pkg. name) `, check for typos in package module name" )
3028
3044
end
3029
3045
3030
3046
# protects against PkgId and UUID being imported and losing Base prefix
@@ -3100,7 +3116,6 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
3100
3116
Base.track_nested_precomp($(_pkg_str (vcat (Base. precompilation_stack, pkg))) )
3101
3117
Base.loadable_extensions = $(_pkg_str (loadable_exts))
3102
3118
Base.precompiling_extension = $(loading_extension)
3103
- Base.precompilation_target = $(_pkg_str (pkg))
3104
3119
Base.include_package_for_output($(_pkg_str (pkg)) , $(repr (abspath (input))) , $(repr (depot_path)) , $(repr (dl_load_path)) ,
3105
3120
$(repr (load_path)) , $(_pkg_str (concrete_deps)) , $(repr (source_path (nothing ))) )
3106
3121
""" )
0 commit comments