From ff012aa05f03a28cebd0b436669668aa781bf311 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Wed, 17 May 2023 17:52:36 +0900 Subject: [PATCH] improve inferrability of loading.jl (#49812) --- base/loading.jl | 13 ++++++++----- base/reflection.jl | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index 9cc2f13752dfb..27de1df7f81b5 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -627,7 +627,7 @@ function manifest_deps_get(env::String, where::PkgId, name::String)::Union{Nothi exts = get(d, "extensions", nothing)::Union{Dict{String, Any}, Nothing} if exts !== nothing # Check if `where` is an extension of the project - if where.name in keys(exts) && where.uuid == uuid5(proj.uuid, where.name) + if where.name in keys(exts) && where.uuid == uuid5(proj.uuid::String, where.name) # Extensions can load weak deps... weakdeps = get(d, "weakdeps", nothing)::Union{Dict{String, Any}, Nothing} if weakdeps !== nothing @@ -1209,7 +1209,9 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi extensions = get(d_proj, "extensions", nothing)::Union{Nothing, Dict{String, Any}} extensions === nothing && return weakdeps === nothing && return - return _insert_extension_triggers(pkg, extensions, weakdeps) + if weakdeps isa Dict{String, Any} + return _insert_extension_triggers(pkg, extensions, weakdeps) + end end # Now look in manifest @@ -1231,7 +1233,7 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi return _insert_extension_triggers(pkg, extensions, weakdeps) end - d_weakdeps = Dict{String, String}() + d_weakdeps = Dict{String, Any}() for (dep_name, entries) in d dep_name in weakdeps || continue entries::Vector{Any} @@ -1251,8 +1253,9 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi return nothing end -function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, <:Any}, weakdeps::Dict{String, <:Any}) - for (ext::String, triggers::Union{String, Vector{String}}) in extensions +function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, Any}, weakdeps::Dict{String, Any}) + for (ext, triggers) in extensions + triggers = triggers::Union{String, Vector{String}} triggers isa String && (triggers = [triggers]) id = PkgId(uuid5(parent.uuid, ext), ext) if id in keys(EXT_PRIMED) || haskey(Base.loaded_modules, id) diff --git a/base/reflection.jl b/base/reflection.jl index 97f1ed14c6729..0ae644d5d41af 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -1248,7 +1248,8 @@ function may_invoke_generator(method::Method, @nospecialize(atype), sparams::Sim generator = method.generator isa(generator, Core.GeneratedFunctionStub) || return false gen_mthds = _methods_by_ftype(Tuple{typeof(generator.gen), Vararg{Any}}, 1, method.primary_world) - (gen_mthds isa Vector && length(gen_mthds) == 1) || return false + gen_mthds isa Vector || return false + length(gen_mthds) == 1 || return false generator_method = first(gen_mthds).method nsparams = length(sparams)