Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backports-release-1.11] fix pkgdir during inits on 1.11 #56546

Open
wants to merge 6 commits into
base: backports-release-1.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,17 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
M = M::Module
if parentmodule(M) === M && PkgId(M) == pkg
register && register_root_module(M)
inits = sv[2]::Vector{Any}
if !isempty(inits)
unlock(require_lock) # temporarily _unlock_ during these callbacks
try
for (i, mod) in pairs(inits)
run_module_init(mod, i)
end
finally
lock(require_lock)
end
end
if timing_imports
elapsed_time = time_ns() - t_before
comp_time, recomp_time = cumulative_compile_time_ns() .- t_comp_before
Expand Down Expand Up @@ -1354,18 +1365,6 @@ function register_restored_modules(sv::SimpleVector, pkg::PkgId, path::String)
# Register this cache path now - If Requires.jl is loaded, Revise may end
# up looking at the cache path during the init callback.
get!(PkgOrigin, pkgorigins, pkg).cachepath = path

inits = sv[2]::Vector{Any}
if !isempty(inits)
unlock(require_lock) # temporarily _unlock_ during these callbacks
try
for (i, mod) in pairs(inits)
run_module_init(mod, i)
end
finally
lock(require_lock)
end
end
return restored
end

Expand Down
24 changes: 22 additions & 2 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,9 @@ precompile_test_harness("Issue #26028") do load_path
"""
module Baz26028
using Test
@test_throws(ConcurrencyViolationError("deadlock detected in loading Foo26028 -> Foo26028"),
@eval import Foo26028.Bar26028.x)
# TODO: This is broken on 1.11
# @test_throws(ConcurrencyViolationError("deadlock detected in loading Foo26028 -> Foo26028"),
# @eval import Foo26028.Bar26028.x)
import ..Foo26028.Bar26028.y
end
""")
Expand Down Expand Up @@ -2251,6 +2252,25 @@ precompile_test_harness("No package module") do load_path
String(take!(io)))
end

precompile_test_harness("pkgdir eval during init") do load_path
pkg_dir = joinpath(load_path, "PkgdirDuringInit")
mkpath(joinpath(pkg_dir, "src"))
srcpath = joinpath(pkg_dir, "src", "PkgdirDuringInit.jl")
write(srcpath,
"""
module PkgdirDuringInit
x = nothing
function __init__()
global x
x = pkgdir(@__MODULE__)
end
end #module
""")
Base.compilecache(Base.PkgId("PkgdirDuringInit"))
@eval using PkgdirDuringInit
@test PkgdirDuringInit.x == pkg_dir
end

empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, original_depot_path)
empty!(Base.LOAD_PATH)
Expand Down