Skip to content

Commit 1968b14

Browse files
committed
loading: add missing lock when calling toplevel create_expr_cache to create a module
Avoids a discrepency in behavior between direct loading and precompile
1 parent 822b6db commit 1968b14

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

base/loading.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,6 @@ function run_module_init(mod::Module, i::Int=1)
14381438
end
14391439

14401440
function run_package_callbacks(modkey::PkgId)
1441-
@assert modkey != precompilation_target
14421441
run_extension_callbacks(modkey)
14431442
assert_havelock(require_lock)
14441443
unlock(require_lock)
@@ -1568,7 +1567,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
15681567
uuid_trigger = UUID(totaldeps[trigger]::String)
15691568
trigger_id = PkgId(uuid_trigger, trigger)
15701569
push!(trigger_ids, trigger_id)
1571-
if !haskey(Base.loaded_modules, trigger_id) || haskey(package_locks, trigger_id) || (trigger_id == precompilation_target)
1570+
if !haskey(Base.loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
15721571
trigger1 = get!(Vector{ExtensionId}, EXT_DORMITORY, trigger_id)
15731572
push!(trigger1, gid)
15741573
else
@@ -1581,7 +1580,6 @@ end
15811580
loading_extension::Bool = false
15821581
loadable_extensions::Union{Nothing,Vector{PkgId}} = nothing
15831582
precompiling_extension::Bool = false
1584-
precompilation_target::Union{Nothing,PkgId} = nothing
15851583
function run_extension_callbacks(extid::ExtensionId)
15861584
assert_havelock(require_lock)
15871585
succeeded = try
@@ -2502,10 +2500,7 @@ function _require_prelocked(uuidkey::PkgId, env=nothing)
25022500
try
25032501
toplevel_load[] = false
25042502
m = __require_prelocked(uuidkey, env)
2505-
if m === nothing
2506-
error("package `$(uuidkey.name)` did not define the expected \
2507-
module `$(uuidkey.name)`, check for typos in package module name")
2508-
end
2503+
m isa Module || check_package_module_loaded_error(uuidkey)
25092504
finally
25102505
toplevel_load[] = last
25112506
end_loading(uuidkey, m)
@@ -2995,6 +2990,9 @@ const newly_inferred = CodeInstance[]
29952990
function include_package_for_output(pkg::PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String},
29962991
concrete_deps::typeof(_concrete_dependencies), source::Union{Nothing,String})
29972992

2993+
@lock require_lock begin
2994+
m = start_loading(pkg, UInt128(0), false)
2995+
@assert m === nothing
29982996
append!(empty!(Base.DEPOT_PATH), depot_path)
29992997
append!(empty!(Base.DL_LOAD_PATH), dl_load_path)
30002998
append!(empty!(Base.LOAD_PATH), load_path)
@@ -3003,6 +3001,8 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
30033001
Base._track_dependencies[] = true
30043002
get!(Base.PkgOrigin, Base.pkgorigins, pkg).path = input
30053003
append!(empty!(Base._concrete_dependencies), concrete_deps)
3004+
end
3005+
30063006
uuid_tuple = pkg.uuid === nothing ? (UInt64(0), UInt64(0)) : convert(NTuple{2, UInt64}, pkg.uuid)
30073007

30083008
ccall(:jl_set_module_uuid, Cvoid, (Any, NTuple{2, UInt64}), Base.__toplevel__, uuid_tuple)
@@ -3021,21 +3021,22 @@ function include_package_for_output(pkg::PkgId, input::String, depot_path::Vecto
30213021
ccall(:jl_set_newly_inferred, Cvoid, (Any,), nothing)
30223022
end
30233023
# check that the package defined the expected module so we can give a nice error message if not
3024-
Base.check_package_module_loaded(pkg)
3024+
m = maybe_root_module(pkg)
3025+
m isa Module || check_package_module_loaded_error(pkg)
30253026

30263027
# Re-populate the runtime's newly-inferred array, which will be included
30273028
# in the output. We removed it above to avoid including any code we may
30283029
# have compiled for error handling and validation.
30293030
ccall(:jl_set_newly_inferred, Cvoid, (Any,), newly_inferred)
3031+
@lock require_lock end_loading(pkg, m)
3032+
# insert_extension_triggers(pkg)
3033+
# run_package_callbacks(pkg)
30303034
end
30313035

3032-
function check_package_module_loaded(pkg::PkgId)
3033-
if !haskey(Base.loaded_modules, pkg)
3034-
# match compilecache error type for non-125 errors
3035-
error("$(repr("text/plain", pkg)) did not define the expected module `$(pkg.name)`, \
3036-
check for typos in package module name")
3037-
end
3038-
return nothing
3036+
function check_package_module_loaded_error(pkg)
3037+
# match compilecache error type for non-125 errors
3038+
error("package `$(pkg.name)` did not define the expected \
3039+
module `$(pkg.name)`, check for typos in package module name")
30393040
end
30403041

30413042
# protects against PkgId and UUID being imported and losing Base prefix
@@ -3111,7 +3112,6 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
31113112
Base.track_nested_precomp($(_pkg_str(vcat(Base.precompilation_stack, pkg))))
31123113
Base.loadable_extensions = $(_pkg_str(loadable_exts))
31133114
Base.precompiling_extension = $(loading_extension)
3114-
Base.precompilation_target = $(_pkg_str(pkg))
31153115
Base.include_package_for_output($(_pkg_str(pkg)), $(repr(abspath(input))), $(repr(depot_path)), $(repr(dl_load_path)),
31163116
$(repr(load_path)), $(_pkg_str(concrete_deps)), $(repr(source_path(nothing))))
31173117
""")

test/precompile.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ precompile_test_harness("No package module") do load_path
22302230
""")
22312231
@test_throws r"Failed to precompile NoModule" Base.compilecache(Base.identify_package("NoModule"), io, io)
22322232
@test occursin(
2233-
"NoModule [top-level] did not define the expected module `NoModule`, check for typos in package module name",
2233+
"package `NoModule` did not define the expected module `NoModule`, check for typos in package module name",
22342234
String(take!(io)))
22352235

22362236

@@ -2242,7 +2242,7 @@ precompile_test_harness("No package module") do load_path
22422242
""")
22432243
@test_throws r"Failed to precompile WrongModuleName" Base.compilecache(Base.identify_package("WrongModuleName"), io, io)
22442244
@test occursin(
2245-
"WrongModuleName [top-level] did not define the expected module `WrongModuleName`, check for typos in package module name",
2245+
"package `WrongModuleName` did not define the expected module `WrongModuleName`, check for typos in package module name",
22462246
String(take!(io)))
22472247

22482248

0 commit comments

Comments
 (0)