diff --git a/Compiler/src/ssair/verify.jl b/Compiler/src/ssair/verify.jl index f9a9bb674a536..3aa1e00e3f2d3 100644 --- a/Compiler/src/ssair/verify.jl +++ b/Compiler/src/ssair/verify.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -irshow_was_loaded() = invokelatest(isdefined, Compiler.IRShow, :debuginfo_firstline) +irshow_was_loaded() = invokelatest(isdefinedglobal, Compiler.IRShow, :debuginfo_firstline) function maybe_show_ir(ir::IRCode) if irshow_was_loaded() # ensure we use I/O that does not yield, as this gets called during compilation diff --git a/base/docs/bindings.jl b/base/docs/bindings.jl index 5a0e8e01762e2..34aa87bd13076 100644 --- a/base/docs/bindings.jl +++ b/base/docs/bindings.jl @@ -16,8 +16,8 @@ end bindingexpr(x) = Expr(:call, Binding, splitexpr(x)...) -defined(b::Binding) = invokelatest(isdefined, b.mod, b.var) -resolve(b::Binding) = invokelatest(getfield, b.mod, b.var) +defined(b::Binding) = invokelatest(isdefinedglobal, b.mod, b.var) +resolve(b::Binding) = invokelatest(getglobal, b.mod, b.var) function splitexpr(x::Expr) isexpr(x, :macrocall) ? splitexpr(x.args[1]) : diff --git a/base/errorshow.jl b/base/errorshow.jl index 624461a31c641..d876f71520df6 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -339,8 +339,8 @@ function showerror(io::IO, ex::MethodError) # Check all modules (sorted for consistency) sorted_modules = sort!(collect(modules_to_check), by=nameof) for mod in sorted_modules - if isdefined(mod, name) - candidate = getfield(mod, name) + if isdefinedglobal(mod, name) + candidate = getglobal(mod, name) if candidate !== f && hasmethod(candidate, arg_types; world=ex.world) if mod === Base print(io, "\nYou may have intended to import ") diff --git a/base/show.jl b/base/show.jl index 73a3a0fcad66f..f89e72ff3ab53 100644 --- a/base/show.jl +++ b/base/show.jl @@ -632,8 +632,8 @@ function make_typealias(@nospecialize(x::Type)) x isa UnionAll && push!(xenv, x) for mod in mods for name in unsorted_names(mod) - if isdefined(mod, name) && !isdeprecated(mod, name) && isconst(mod, name) - alias = getfield(mod, name) + if isdefinedglobal(mod, name) && !isdeprecated(mod, name) && isconst(mod, name) + alias = getglobal(mod, name) if alias isa Type && !has_free_typevars(alias) && !print_without_params(alias) && x <: alias if alias isa UnionAll (ti, env) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), x, alias)::SimpleVector @@ -836,8 +836,8 @@ function make_typealiases(@nospecialize(x::Type)) x isa UnionAll && push!(xenv, x) for mod in mods for name in unsorted_names(mod) - if isdefined(mod, name) && !isdeprecated(mod, name) && isconst(mod, name) - alias = getfield(mod, name) + if isdefinedglobal(mod, name) && !isdeprecated(mod, name) && isconst(mod, name) + alias = getglobal(mod, name) if alias isa Type && !has_free_typevars(alias) && !print_without_params(alias) && !(alias <: Tuple) (ti, env) = ccall(:jl_type_intersection_with_env, Any, (Any, Any), x, alias)::SimpleVector ti === Union{} && continue diff --git a/src/gen_sysimg_symtab.jl b/src/gen_sysimg_symtab.jl index a91f2f994194c..110d83ba9083d 100644 --- a/src/gen_sysimg_symtab.jl +++ b/src/gen_sysimg_symtab.jl @@ -11,8 +11,8 @@ import Base.Iterators: take, drop function _eachmethod(f, m::Module, visited, vmt) push!(visited, m) for nm in names(m, all=true) - if isdefined(m, nm) - x = getfield(m, nm) + if isdefinedglobal(m, nm) + x = getglobal(m, nm) if isa(x, Module) && !in(x, visited) _eachmethod(f, x, visited, vmt) elseif isa(x, Type) diff --git a/stdlib/InteractiveUtils/src/InteractiveUtils.jl b/stdlib/InteractiveUtils/src/InteractiveUtils.jl index 0f69860f39d78..8499027fae6cc 100644 --- a/stdlib/InteractiveUtils/src/InteractiveUtils.jl +++ b/stdlib/InteractiveUtils/src/InteractiveUtils.jl @@ -53,7 +53,7 @@ function varinfo(m::Module=Base.active_module(), pattern::Regex=r""; all::Bool = if !isdefined(m2, v) || !occursin(pattern, string(v)) continue end - value = getfield(m2, v) + value = getglobal(m2, v) isbuiltin = value === Base || value === Base.active_module() || value === Core if recursive && !isbuiltin && isa(value, Module) && value !== m2 && nameof(value) === v && parentmodule(value) === m2 push!(workqueue, (value, "$prep$v.")) @@ -232,8 +232,8 @@ end function _methodswith(@nospecialize(t::Type), m::Module, supertypes::Bool) meths = Method[] for nm in names(m) - if isdefined(m, nm) - f = getfield(m, nm) + if isdefinedglobal(m, nm) + f = getglobal(m, nm) if isa(f, Base.Callable) methodswith(t, f, meths; supertypes = supertypes) end @@ -264,8 +264,8 @@ function _subtypes_in!(mods::Array, x::Type) m = pop!(mods) xt = xt::DataType for s in names(m, all = true) - if !isdeprecated(m, s) && isdefined(m, s) - t = getfield(m, s) + if !isdeprecated(m, s) && isdefinedglobal(m, s) + t = getglobal(m, s) dt = isa(t, UnionAll) ? unwrap_unionall(t) : t if isa(dt, DataType) if dt.name.name === s && dt.name.module == m && supertype(dt).name == xt.name diff --git a/test/core.jl b/test/core.jl index 4abe4f95a2e0b..997677cd69e39 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1206,8 +1206,8 @@ end # Module() constructor @test names(Module(:anonymous), all = true, imported = true) == [:anonymous] @test names(Module(:anonymous, false), all = true, imported = true) == [:anonymous] -@test invokelatest(getfield, Module(:anonymous, false, true), :Core) == Core -@test_throws UndefVarError invokelatest(getfield, Module(:anonymous, false, false), :Core) +@test invokelatest(getglobal, Module(:anonymous, false, true), :Core) == Core +@test_throws UndefVarError invokelatest(getglobal, Module(:anonymous, false, false), :Core) # exception from __init__() let didthrow = diff --git a/test/docs.jl b/test/docs.jl index 568cab48bd1e5..6c625735ecc7e 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -119,7 +119,7 @@ end # issue #38819 module NoDocStrings end -@test meta(NoDocStrings) === invokelatest(getfield, NoDocStrings, Base.Docs.META) +@test meta(NoDocStrings) === invokelatest(getglobal, NoDocStrings, Base.Docs.META) # General tests for docstrings. diff --git a/test/error.jl b/test/error.jl index f76a7809b08a9..0d8047aa92a44 100644 --- a/test/error.jl +++ b/test/error.jl @@ -109,8 +109,8 @@ end if mod ∉ visited push!(visited, mod) for name in names(mod, all=true) - isdefined(mod, name) || continue - value = getfield(mod, name) + isdefinedglobal(mod, name) || continue + value = getglobal(mod, name) if value isa Module value === Main && continue test_exceptions(value, visited) diff --git a/test/numbers.jl b/test/numbers.jl index 42eeeec4257c7..0553ab342f7a2 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2420,8 +2420,8 @@ end function allsubtypes!(m::Module, x::DataType, sts::Set) for s in names(m, all = true) - if isdefined(m, s) && !Base.isdeprecated(m, s) - t = getfield(m, s) + if isdefinedglobal(m, s) && !Base.isdeprecated(m, s) + t = getglobal(m, s) if isa(t, Type) && t <: x && t != Union{} push!(sts, t) elseif isa(t, Module) && t !== m && nameof(t) === s && parentmodule(t) === m diff --git a/test/precompile.jl b/test/precompile.jl index e95df0d50ae60..7cf9bdffadfc1 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -778,12 +778,12 @@ precompile_test_harness("code caching") do dir Base.compilecache(pkgid) @test Base.isprecompiled(pkgid) @eval using $Cache_module - M = invokelatest(getfield, @__MODULE__, Cache_module) + M = invokelatest(getglobal, @__MODULE__, Cache_module) Mid = rootid(M) invokelatest() do # Test that this cache file "owns" all the roots for name in (:f, :fpush, :callboth) - func = getfield(M, name) + func = getglobal(M, name) m = only(collect(methods(func))) @test all(i -> root_provenance(m, i) == Mid, 1:length(m.roots)) end @@ -1033,7 +1033,7 @@ precompile_test_harness("code caching") do dir Base.compilecache(Base.PkgId(string(pkg))) end @eval using $StaleA - MA = invokelatest(getfield, @__MODULE__, StaleA) + MA = invokelatest(getglobal, @__MODULE__, StaleA) Base.eval(MA, :(nbits(::UInt8) = 8)) Base.eval(MA, quote struct InvalidatedBinding @@ -1154,7 +1154,7 @@ precompile_test_harness("precompiletools") do dir Base.compilecache(pkgid) @test Base.isprecompiled(pkgid) @eval using $PrecompileToolsModule - M = invokelatest(getfield, @__MODULE__, PrecompileToolsModule) + M = invokelatest(getglobal, @__MODULE__, PrecompileToolsModule) invokelatest() do m = which(Tuple{typeof(findfirst), Base.Fix2{typeof(==), T}, Vector{T}} where T) success = 0 @@ -1281,7 +1281,7 @@ precompile_test_harness("invoke") do dir """) Base.compilecache(Base.PkgId(string(CallerModule))) @eval using $InvokeModule: $InvokeModule - MI = invokelatest(getfield, @__MODULE__, InvokeModule) + MI = invokelatest(getglobal, @__MODULE__, InvokeModule) @eval $MI.getlast(a::UnitRange) = a.stop @eval using $CallerModule invokelatest() do diff --git a/test/reflection.jl b/test/reflection.jl index 8cf2385ab8b18..29774c2bfa069 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -617,9 +617,9 @@ function module_depth(from::Module, to::Module) end function has_backslashes(mod::Module) for n in names(mod, all = true, imported = true) - isdefined(mod, n) || continue + isdefinedglobal(mod, n) || continue Base.isdeprecated(mod, n) && continue - f = getfield(mod, n) + f = getglobal(mod, n) if isa(f, Module) && module_depth(Main, f) <= module_depth(Main, mod) continue end