Skip to content

Commit 040a6ce

Browse files
authored
Backports for Julia 1.11.3 (#56652)
Backported PRs: - [x] #56595 <!-- fix precompile(::MethodInstance) ccall signature --> - [x] #56234 <!-- Revert "Extensions: make loading of extensions independent of what packages are in the sysimage (#52841) -->
2 parents 229f027 + 73a6d8e commit 040a6ce

File tree

6 files changed

+25
-58
lines changed

6 files changed

+25
-58
lines changed

base/Base.jl

-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ function __init__()
602602
init_load_path()
603603
init_active_project()
604604
append!(empty!(_sysimage_modules), keys(loaded_modules))
605-
empty!(explicit_loaded_modules)
606605
empty!(loaded_precompiles) # If we load a packageimage when building the image this might not be empty
607606
for (mod, key) in module_keys
608607
push!(get!(Vector{Module}, loaded_precompiles, key), mod)

base/loading.jl

+24-27
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,14 @@ function explicit_manifest_deps_get(project_file::String, where::PkgId, name::St
934934
entry = entry::Dict{String, Any}
935935
uuid = get(entry, "uuid", nothing)::Union{String, Nothing}
936936
uuid === nothing && continue
937+
# deps is either a list of names (deps = ["DepA", "DepB"]) or
938+
# a table of entries (deps = {"DepA" = "6ea...", "DepB" = "55d..."}
939+
deps = get(entry, "deps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
937940
if UUID(uuid) === where.uuid
938941
found_where = true
939-
# deps is either a list of names (deps = ["DepA", "DepB"]) or
940-
# a table of entries (deps = {"DepA" = "6ea...", "DepB" = "55d..."}
941-
deps = get(entry, "deps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
942942
if deps isa Vector{String}
943943
found_name = name in deps
944-
break
944+
found_name && @goto done
945945
elseif deps isa Dict{String, Any}
946946
deps = deps::Dict{String, Any}
947947
for (dep, uuid) in deps
@@ -960,30 +960,33 @@ function explicit_manifest_deps_get(project_file::String, where::PkgId, name::St
960960
return PkgId(UUID(uuid), name)
961961
end
962962
exts = extensions[where.name]::Union{String, Vector{String}}
963+
weakdeps = get(entry, "weakdeps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
963964
if (exts isa String && name == exts) || (exts isa Vector{String} && name in exts)
964-
weakdeps = get(entry, "weakdeps", nothing)::Union{Vector{String}, Dict{String, Any}, Nothing}
965-
if weakdeps !== nothing
966-
if weakdeps isa Vector{String}
967-
found_name = name in weakdeps
968-
break
969-
elseif weakdeps isa Dict{String, Any}
970-
weakdeps = weakdeps::Dict{String, Any}
971-
for (dep, uuid) in weakdeps
972-
uuid::String
973-
if dep === name
974-
return PkgId(UUID(uuid), name)
965+
for deps′ in [weakdeps, deps]
966+
if deps′ !== nothing
967+
if deps′ isa Vector{String}
968+
found_name = name in deps′
969+
found_name && @goto done
970+
elseif deps′ isa Dict{String, Any}
971+
deps′ = deps′::Dict{String, Any}
972+
for (dep, uuid) in deps′
973+
uuid::String
974+
if dep === name
975+
return PkgId(UUID(uuid), name)
976+
end
977+
end
975978
end
976979
end
977980
end
978981
end
979-
end
980982
# `name` is not an ext, do standard lookup as if this was the parent
981983
return identify_package(PkgId(UUID(uuid), dep_name), name)
982984
end
983985
end
984986
end
985987
end
986988
end
989+
@label done
987990
found_where || return nothing
988991
found_name || return PkgId(name)
989992
# Only reach here if deps was not a dict which mean we have a unique name for the dep
@@ -1518,7 +1521,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
15181521
uuid_trigger = UUID(totaldeps[trigger]::String)
15191522
trigger_id = PkgId(uuid_trigger, trigger)
15201523
push!(trigger_ids, trigger_id)
1521-
if !haskey(explicit_loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
1524+
if !haskey(Base.loaded_modules, trigger_id) || haskey(package_locks, trigger_id)
15221525
trigger1 = get!(Vector{ExtensionId}, EXT_DORMITORY, trigger_id)
15231526
push!(trigger1, gid)
15241527
else
@@ -2392,9 +2395,8 @@ function __require_prelocked(uuidkey::PkgId, env=nothing)
23922395
insert_extension_triggers(uuidkey)
23932396
# After successfully loading, notify downstream consumers
23942397
run_package_callbacks(uuidkey)
2395-
elseif !haskey(explicit_loaded_modules, uuidkey)
2396-
explicit_loaded_modules[uuidkey] = m
2397-
run_package_callbacks(uuidkey)
2398+
else
2399+
newm = root_module(uuidkey)
23982400
end
23992401
return m
24002402
end
@@ -2407,7 +2409,6 @@ end
24072409
PkgOrigin() = PkgOrigin(nothing, nothing, nothing)
24082410
const pkgorigins = Dict{PkgId,PkgOrigin}()
24092411

2410-
const explicit_loaded_modules = Dict{PkgId,Module}() # Emptied on Julia start
24112412
const loaded_modules = Dict{PkgId,Module}() # available to be explicitly loaded
24122413
const loaded_precompiles = Dict{PkgId,Vector{Module}}() # extended (complete) list of modules, available to be loaded
24132414
const loaded_modules_order = Vector{Module}()
@@ -2448,7 +2449,6 @@ end
24482449
end
24492450
maybe_loaded_precompile(key, module_build_id(m)) === nothing && push!(loaded_modules_order, m)
24502451
loaded_modules[key] = m
2451-
explicit_loaded_modules[key] = m
24522452
module_keys[m] = key
24532453
end
24542454
nothing
@@ -2480,9 +2480,6 @@ loaded_modules_array() = @lock require_lock copy(loaded_modules_order)
24802480
# after unreference_module, a subsequent require call will try to load a new copy of it, if stale
24812481
# reload(m) = (unreference_module(m); require(m))
24822482
function unreference_module(key::PkgId)
2483-
if haskey(explicit_loaded_modules, key)
2484-
m = pop!(explicit_loaded_modules, key)
2485-
end
24862483
if haskey(loaded_modules, key)
24872484
m = pop!(loaded_modules, key)
24882485
# need to ensure all modules are GC rooted; will still be referenced
@@ -3046,7 +3043,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
30463043
# build up the list of modules that we want the precompile process to preserve
30473044
if keep_loaded_modules
30483045
concrete_deps = copy(_concrete_dependencies)
3049-
for (pkgreq, modreq) in loaded_modules # TODO: convert all relevant staleness heuristics to use explicit_loaded_modules instead
3046+
for (pkgreq, modreq) in loaded_modules
30503047
if !(pkgreq === Main || pkgreq === Core || pkgreq === Base)
30513048
push!(concrete_deps, pkgreq => module_build_id(modreq))
30523049
end
@@ -4027,7 +4024,7 @@ end
40274024

40284025
# Variants that work for `invoke`d calls for which the signature may not be sufficient
40294026
precompile(mi::Core.MethodInstance, world::UInt=get_world_counter()) =
4030-
(ccall(:jl_compile_method_instance, Cvoid, (Any, Any, UInt), mi, C_NULL, world); return true)
4027+
(ccall(:jl_compile_method_instance, Cvoid, (Any, Ptr{Cvoid}, UInt), mi, C_NULL, world); return true)
40314028

40324029
"""
40334030
precompile(f, argtypes::Tuple{Vararg{Any}}, m::Method)

test/loading.jl

-19
Original file line numberDiff line numberDiff line change
@@ -1118,25 +1118,6 @@ end
11181118
run(cmd_proj_ext)
11191119
end
11201120

1121-
# Sysimage extensions
1122-
# The test below requires that LinearAlgebra is in the sysimage and that it has not been loaded yet.
1123-
# if it gets moved out, this test will need to be updated.
1124-
# We run this test in a new process so we are not vulnerable to a previous test having loaded LinearAlgebra
1125-
sysimg_ext_test_code = """
1126-
uuid_key = Base.PkgId(Base.UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e"), "LinearAlgebra")
1127-
Base.in_sysimage(uuid_key) || error("LinearAlgebra not in sysimage")
1128-
haskey(Base.explicit_loaded_modules, uuid_key) && error("LinearAlgebra already loaded")
1129-
using HasExtensions
1130-
Base.get_extension(HasExtensions, :LinearAlgebraExt) === nothing || error("unexpectedly got an extension")
1131-
using LinearAlgebra
1132-
haskey(Base.explicit_loaded_modules, uuid_key) || error("LinearAlgebra not loaded")
1133-
Base.get_extension(HasExtensions, :LinearAlgebraExt) isa Module || error("expected extension to load")
1134-
"""
1135-
cmd = `$(Base.julia_cmd()) --startup-file=no -e $sysimg_ext_test_code`
1136-
cmd = addenv(cmd, "JULIA_LOAD_PATH" => join([proj, "@stdlib"], sep))
1137-
run(cmd)
1138-
1139-
11401121
# Extensions in implicit environments
11411122
old_load_path = copy(LOAD_PATH)
11421123
try

test/project/Extensions/HasDepWithExtensions.jl/Manifest.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ deps = ["ExtDep3"]
2525
path = "../HasExtensions.jl"
2626
uuid = "4d3288b3-3afc-4bb6-85f3-489fffe514c8"
2727
version = "0.1.0"
28+
weakdeps = ["ExtDep", "ExtDep2"]
2829

2930
[deps.HasExtensions.extensions]
3031
Extension = "ExtDep"
3132
ExtensionDep = "ExtDep3"
3233
ExtensionFolder = ["ExtDep", "ExtDep2"]
33-
LinearAlgebraExt = "LinearAlgebra"
34-
35-
[deps.HasExtensions.weakdeps]
36-
ExtDep = "fa069be4-f60b-4d4c-8b95-f8008775090c"
37-
ExtDep2 = "55982ee5-2ad5-4c40-8cfe-5e9e1b01500d"
38-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3934

4035
[[deps.SomeOtherPackage]]
4136
path = "../SomeOtherPackage"

test/project/Extensions/HasExtensions.jl/Project.toml

-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ ExtDep3 = "a5541f1e-a556-4fdc-af15-097880d743a1"
88
[weakdeps]
99
ExtDep = "fa069be4-f60b-4d4c-8b95-f8008775090c"
1010
ExtDep2 = "55982ee5-2ad5-4c40-8cfe-5e9e1b01500d"
11-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1211

1312
[extensions]
1413
Extension = "ExtDep"
1514
ExtensionDep = "ExtDep3"
1615
ExtensionFolder = ["ExtDep", "ExtDep2"]
17-
LinearAlgebraExt = "LinearAlgebra"

test/project/Extensions/HasExtensions.jl/ext/LinearAlgebraExt.jl

-3
This file was deleted.

0 commit comments

Comments
 (0)