Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Compiler/src/ssair/verify.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/docs/bindings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]) :
Expand Down
4 changes: 2 additions & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
Expand Down
8 changes: 4 additions & 4 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/gen_sysimg_symtab.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions test/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down