Skip to content

Commit 19d05f3

Browse files
committed
update piracies code to support v1.12 changes
Reflects current status of JuliaLang/julia#58131 PR.
1 parent 07be761 commit 19d05f3

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

src/piracies.jl

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,39 @@ function all_methods(mods::Module...; skip_deprecated::Bool = true)
1010
meths = Method[]
1111
mods = collect(mods)::Vector{Module}
1212

13-
function examine(mt::Core.MethodTable)
14-
examine(Base.MethodList(mt))
15-
end
16-
function examine(ml::Base.MethodList)
17-
for m in ml
18-
is_in_mods(m.module, true, mods) || continue
19-
push!(meths, m)
20-
end
13+
function examine_def(m::Method)
14+
is_in_mods(m.module, true, mods) && push!(meths, m)
15+
nothing
2116
end
2217

23-
work = Base.loaded_modules_array()
24-
filter!(mod -> mod === parentmodule(mod), work) # some items in loaded_modules_array are not top modules (really just Base)
25-
while !isempty(work)
26-
mod = pop!(work)
27-
for name in names(mod; all = true)
28-
(skip_deprecated && Base.isdeprecated(mod, name)) && continue
29-
isdefined(mod, name) || continue
30-
f = Base.unwrap_unionall(getfield(mod, name))
31-
if isa(f, Module) && f !== mod && parentmodule(f) === mod && nameof(f) === name
32-
push!(work, f)
33-
elseif isa(f, DataType) &&
34-
isdefined(f.name, :mt) &&
35-
parentmodule(f) === mod &&
36-
nameof(f) === name &&
37-
f.name.mt !== Symbol.name.mt &&
38-
f.name.mt !== DataType.name.mt
39-
examine(f.name.mt)
18+
examine(mt::Core.MethodTable) = Base.visit(examine_def, mt.defs)
19+
20+
if VERSION >= v"1.12-" && isdefined(Core, :GlobalMethods)
21+
examine(Core.GlobalMethods)
22+
else
23+
work = Base.loaded_modules_array()
24+
filter!(mod -> mod === parentmodule(mod), work) # some items in loaded_modules_array are not top modules (really just Base)
25+
while !isempty(work)
26+
mod = pop!(work)
27+
for name in names(mod; all = true)
28+
(skip_deprecated && Base.isdeprecated(mod, name)) && continue
29+
isdefined(mod, name) || continue
30+
f = Base.unwrap_unionall(getfield(mod, name))
31+
if isa(f, Module) && f !== mod && parentmodule(f) === mod && nameof(f) === name
32+
push!(work, f)
33+
elseif isa(f, DataType) &&
34+
isdefined(f.name, :mt) &&
35+
parentmodule(f) === mod &&
36+
nameof(f) === name &&
37+
f.name.mt !== Symbol.name.mt &&
38+
f.name.mt !== DataType.name.mt
39+
examine(f.name.mt)
40+
end
4041
end
4142
end
43+
examine(Symbol.name.mt)
44+
examine(DataType.name.mt)
4245
end
43-
examine(Symbol.name.mt)
44-
examine(DataType.name.mt)
4546
return meths
4647
end
4748

0 commit comments

Comments
 (0)