@@ -21,6 +21,8 @@ Base.getindex(m::ModuleStore, k) = m.vals[k]
2121Base. setindex!(m:: ModuleStore , v, k) = (m. vals[k] = v)
2222Base. haskey(m:: ModuleStore , k) = haskey(m. vals, k)
2323
24+ Base. show(io:: IO , ms:: ModuleStore ) = print(io, " ModuleStore($(ms. name) ) with $(length(ms. vals)) entries" )
25+
2426const EnvStore = Dict{Symbol,ModuleStore}
2527
2628struct Package
@@ -41,6 +43,14 @@ struct MethodStore
4143 rt:: Any
4244end
4345
46+ function Base. show(io:: IO , ms:: MethodStore )
47+ print(io, ms. mod, " ." , ms. name, " (" )
48+ for (a,b) in ms. sig
49+ print(io, a, " ::" , b)
50+ end
51+ print(io, " ) at " , ms. file, " :" , ms. line, )
52+ end
53+
4454struct DataTypeStore <: SymStore
4555 name:: FakeTypeName
4656 super:: FakeTypeName
@@ -77,6 +87,10 @@ function DataTypeStore(@nospecialize(t), symbol, parent_mod, exported)
7787 DataTypeStore(FakeTypeName(ur_t), FakeTypeName(ur_t. super), parameters, types, isconcretetype(ur_t) && fieldcount(ur_t) > 0 ? collect(fieldnames(ur_t)) : Symbol[], MethodStore[], _doc(Base. Docs. Binding(parent_mod, symbol)), exported)
7888end
7989
90+ function Base. show(io:: IO , dts:: DataTypeStore )
91+ print(io, dts. name, " <: " , dts. super, " with $(length(dts. methods)) methods" )
92+ end
93+
8094struct FunctionStore <: SymStore
8195 name:: VarRef
8296 methods:: Vector{MethodStore}
@@ -93,6 +107,10 @@ function FunctionStore(@nospecialize(f), symbol, parent_mod, exported)
93107 end
94108end
95109
110+ function Base. show(io:: IO , fs:: FunctionStore )
111+ print(io, fs. name, " with $(length(fs. methods)) methods" )
112+ end
113+
96114struct GenericStore <: SymStore
97115 name:: VarRef
98116 typ:: Any
@@ -246,7 +264,9 @@ function cache_methods(@nospecialize(f), name, env, get_return_type)
246264 elseif ! (modstore[name] isa DataTypeStore || modstore[name] isa FunctionStore)
247265 modstore[name] = FunctionStore(VarRef(mvr, name), MethodStore[m[2 ]], " " , func_vr, false )
248266 else
249- push!(modstore[name]. methods, m[2 ])
267+ if ! (m[2 ] in modstore[name]. methods)
268+ push!(modstore[name]. methods, m[2 ])
269+ end
250270 end
251271 end
252272 return ms
273293function apply_to_everything(f, m = nothing , visited = Base. IdSet{Module}())
274294 if m isa Module
275295 push!(visited, m)
276- for s in unsorted_names(m, all = true , imported = true )
296+ for s in unsorted_names(m, all = true , imported = true , usings = true )
277297 (! isdefined(m, s) || s == nameof(m)) && continue
278298 x = getfield(m, s)
279299 f(x)
@@ -294,7 +314,7 @@ function oneverything(f, m = nothing, visited = Base.IdSet{Module}())
294314 if m isa Module
295315 push!(visited, m)
296316 state = nothing
297- for s in unsorted_names(m, all = true , imported = true )
317+ for s in unsorted_names(m, all = true , imported = true , usings = true )
298318 ! isdefined(m, s) && continue
299319 x = getfield(m, s)
300320 state = f(m, s, x, state)
@@ -363,7 +383,7 @@ istoplevelmodule(m) = parentmodule(m) === m || parentmodule(m) === Main
363383function getmoduletree(m:: Module , amn, visited = Base. IdSet{Module}())
364384 push!(visited, m)
365385 cache = ModuleStore(m)
366- for s in unsorted_names(m, all = true , imported = true )
386+ for s in unsorted_names(m, all = true , imported = true , usings = true )
367387 ! isdefined(m, s) && continue
368388 x = getfield(m, s)
369389 if x isa Module
401421all_names(m) = all_names(m, x -> isdefined(m, x))
402422function all_names(m, pred, symbols = Set(Symbol[]), seen = Set(Module[]))
403423 push!(seen, m)
404- ns = unsorted_names(m; all = true , imported = false )
424+ ns = unsorted_names(m; all = true , imported = false , usings = false )
405425 for n in ns
406426 isdefined(m, n) || continue
407427 Base. isdeprecated(m, n) && continue
@@ -416,6 +436,11 @@ function all_names(m, pred, symbols = Set(Symbol[]), seen = Set(Module[]))
416436 symbols
417437end
418438
439+ # On 1.12, names() includes bindings from Core in Base even not requested,
440+ # so we filter those out below. This could also be a version check, but doing it
441+ # this way should be more robust
442+ const CORE_BASE_NAMES_CONFUSION = :Bool in names(Base)
443+
419444function symbols(env:: EnvStore , m:: Union{Module,Nothing} = nothing , allnames:: Base.IdSet{Symbol} = getallns(), visited = Base. IdSet{Module}(); get_return_type = false )
420445 if m isa Module
421446 cache = _lookup(VarRef(m), env, true )
@@ -425,8 +450,13 @@ function symbols(env::EnvStore, m::Union{Module,Nothing} = nothing, allnames::Ba
425450 for s in ns
426451 ! isdefined(m, s) && continue
427452 x = getfield(m, s)
453+
454+ if CORE_BASE_NAMES_CONFUSION && m === Base && isdefined(Core, s) && getfield(Core, s) === x
455+ continue
456+ end
457+
428458 if Base. unwrap_unionall(x) isa DataType # Unions aren't handled here.
429- if parentmodule((x) ) === m
459+ if parentmodule(x ) === m
430460 cache[s] = DataTypeStore(x, s, m, s in getnames(m))
431461 cache_methods(x, s, env, get_return_type)
432462 elseif nameof(x) != = s
0 commit comments