Skip to content

Commit d280792

Browse files
Fix @time_imports extension recognition (#55718)
1 parent 7a645dd commit d280792

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

base/loading.jl

+30-11
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ const TIMING_IMPORTS = Threads.Atomic{Int}(0)
12031203
# these return either the array of modules loaded from the path / content given
12041204
# or an Exception that describes why it couldn't be loaded
12051205
# and it reconnects the Base.Docs.META
1206-
function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{Nothing, String}, depmods::Vector{Any}, ignore_native::Union{Nothing,Bool}=nothing)
1206+
function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{Nothing, String}, depmods::Vector{Any}, ignore_native::Union{Nothing,Bool}=nothing; register::Bool=true)
12071207
if isnothing(ignore_native)
12081208
if JLOptions().code_coverage == 0 && JLOptions().malloc_log == 0
12091209
ignore_native = false
@@ -1252,13 +1252,14 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
12521252
for M in restored
12531253
M = M::Module
12541254
if parentmodule(M) === M && PkgId(M) == pkg
1255+
register && register_root_module(M)
12551256
if timing_imports
12561257
elapsed = round((time_ns() - t_before) / 1e6, digits = 1)
12571258
comp_time, recomp_time = cumulative_compile_time_ns() .- t_comp_before
12581259
print(lpad(elapsed, 9), " ms ")
1259-
parentid = get(EXT_PRIMED, pkg, nothing)
1260-
if parentid !== nothing
1261-
print(parentid.name, "")
1260+
ext_parent = extension_parent_name(M)
1261+
if ext_parent !== nothing
1262+
print(ext_parent::String, "")
12621263
end
12631264
print(pkg.name)
12641265
if comp_time > 0
@@ -1280,6 +1281,27 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
12801281
end
12811282
end
12821283

1284+
# if M is an extension, return the string name of the parent. Otherwise return nothing
1285+
function extension_parent_name(M::Module)
1286+
rootmodule = moduleroot(M)
1287+
src_path = pathof(rootmodule)
1288+
src_path === nothing && return nothing
1289+
pkgdir_parts = splitpath(src_path)
1290+
ext_pos = findlast(==("ext"), pkgdir_parts)
1291+
if ext_pos !== nothing && ext_pos >= length(pkgdir_parts) - 2
1292+
parent_package_root = joinpath(pkgdir_parts[1:ext_pos-1]...)
1293+
parent_package_project_file = locate_project_file(parent_package_root)
1294+
if parent_package_project_file isa String
1295+
d = parsed_toml(parent_package_project_file)
1296+
name = get(d, "name", nothing)
1297+
if name !== nothing
1298+
return name
1299+
end
1300+
end
1301+
end
1302+
return nothing
1303+
end
1304+
12831305
function register_restored_modules(sv::SimpleVector, pkg::PkgId, path::String)
12841306
# This function is also used by PkgCacheInspector.jl
12851307
restored = sv[1]::Vector{Any}
@@ -1461,7 +1483,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}
14611483
triggers = triggers::Union{String, Vector{String}}
14621484
triggers isa String && (triggers = [triggers])
14631485
id = PkgId(uuid5(parent.uuid::UUID, ext), ext)
1464-
if id in keys(EXT_PRIMED) || haskey(Base.loaded_modules, id)
1486+
if haskey(EXT_PRIMED, id) || haskey(Base.loaded_modules, id)
14651487
continue # extension is already primed or loaded, don't add it again
14661488
end
14671489
EXT_PRIMED[id] = parent
@@ -1890,8 +1912,7 @@ function _tryrequire_from_serialized(pkg::PkgId, path::String, ocachepath::Union
18901912
depmods[i] = dep
18911913
end
18921914
# then load the file
1893-
loaded = _include_from_serialized(pkg, path, ocachepath, depmods, ignore_native)
1894-
loaded isa Module && register_root_module(loaded)
1915+
loaded = _include_from_serialized(pkg, path, ocachepath, depmods, ignore_native; register = true)
18951916
return loaded
18961917
end
18971918

@@ -1958,8 +1979,7 @@ end
19581979
if dep === nothing
19591980
try
19601981
set_pkgorigin_version_path(modkey, modpath)
1961-
dep = _include_from_serialized(modkey, modcachepath, modocachepath, modstaledeps)
1962-
dep isa Module && stalecheck && register_root_module(dep)
1982+
dep = _include_from_serialized(modkey, modcachepath, modocachepath, modstaledeps; register = stalecheck)
19631983
finally
19641984
end_loading(modkey, dep)
19651985
end
@@ -1975,9 +1995,8 @@ end
19751995
end
19761996
restored = get(loaded_precompiles, pkg => newbuild_id, nothing)
19771997
if !isa(restored, Module)
1978-
restored = _include_from_serialized(pkg, path_to_try, ocachefile, staledeps)
1998+
restored = _include_from_serialized(pkg, path_to_try, ocachefile, staledeps; register = stalecheck)
19791999
end
1980-
isa(restored, Module) && stalecheck && register_root_module(restored)
19812000
isa(restored, Module) && return restored
19822001
@debug "Deserialization checks failed while attempting to load cache from $path_to_try" exception=restored
19832002
@label check_next_path

0 commit comments

Comments
 (0)