improved name resolution
Showing 1 of 1 files from the diff.
src/symbols.jl
changed.
@@ -135,7 +135,7 @@
Loading
135 | 135 | end |
|
136 | 136 | ||
137 | 137 | const _global_method_cache = IdDict{Any,Vector{Any}}() |
|
138 | - | function methodinfo(@nospecialize(f); types=Tuple, world=typemax(UInt)) |
|
138 | + | function methodinfo(@nospecialize(f); types = Tuple, world = typemax(UInt)) |
|
139 | 139 | key = (f, types, world) |
|
140 | 140 | cached = get(_global_method_cache, key, nothing) |
|
141 | 141 | if cached === nothing |
@@ -158,7 +158,7 @@
Loading
158 | 158 | world = typemax(UInt) |
|
159 | 159 | ms = Tuple{Module,MethodStore}[] |
|
160 | 160 | methods0 = try |
|
161 | - | methodinfo(f; types=types, world=world) |
|
161 | + | methodinfo(f; types = types, world = world) |
|
162 | 162 | catch err |
|
163 | 163 | return ms |
|
164 | 164 | end |
@@ -230,10 +230,10 @@
Loading
230 | 230 | end |
|
231 | 231 | end |
|
232 | 232 | ||
233 | - | function apply_to_everything(f, m=nothing, visited=Base.IdSet{Module}()) |
|
233 | + | function apply_to_everything(f, m = nothing, visited = Base.IdSet{Module}()) |
|
234 | 234 | if m isa Module |
|
235 | 235 | push!(visited, m) |
|
236 | - | for s in unsorted_names(m, all=true, imported=true) |
|
236 | + | for s in unsorted_names(m, all = true, imported = true) |
|
237 | 237 | (!isdefined(m, s) || s == nameof(m)) && continue |
|
238 | 238 | x = getfield(m, s) |
|
239 | 239 | f(x) |
@@ -250,11 +250,11 @@
Loading
250 | 250 | ||
251 | 251 | ||
252 | 252 | ||
253 | - | function oneverything(f, m=nothing, visited=Base.IdSet{Module}()) |
|
253 | + | function oneverything(f, m = nothing, visited = Base.IdSet{Module}()) |
|
254 | 254 | if m isa Module |
|
255 | 255 | push!(visited, m) |
|
256 | 256 | state = nothing |
|
257 | - | for s in unsorted_names(m, all=true) |
|
257 | + | for s in unsorted_names(m, all = true, imported = true) |
|
258 | 258 | !isdefined(m, s) && continue |
|
259 | 259 | x = getfield(m, s) |
|
260 | 260 | state = f(m, s, x, state) |
@@ -270,7 +270,7 @@
Loading
270 | 270 | end |
|
271 | 271 | ||
272 | 272 | const _global_symbol_cache_by_mod = IdDict{Module,Base.IdSet{Symbol}}() |
|
273 | - | function build_namecache(m, s, @nospecialize(x), state::Union{Base.IdSet{Symbol},Nothing}=nothing) |
|
273 | + | function build_namecache(m, s, @nospecialize(x), state::Union{Base.IdSet{Symbol},Nothing} = nothing) |
|
274 | 274 | if state === nothing |
|
275 | 275 | state = get(_global_symbol_cache_by_mod, m, nothing) |
|
276 | 276 | if state === nothing |
@@ -320,10 +320,10 @@
Loading
320 | 320 | usedby(outer, inner) = outer !== inner && isdefined(outer, nameof(inner)) && getproperty(outer, nameof(inner)) === inner && all(isdefined(outer, name) || !isdefined(inner, name) for name in unsorted_names(inner)) |
|
321 | 321 | istoplevelmodule(m) = parentmodule(m) === m || parentmodule(m) === Main |
|
322 | 322 | ||
323 | - | function getmoduletree(m::Module, amn, visited=Base.IdSet{Module}()) |
|
323 | + | function getmoduletree(m::Module, amn, visited = Base.IdSet{Module}()) |
|
324 | 324 | push!(visited, m) |
|
325 | 325 | cache = ModuleStore(m) |
|
326 | - | for s in unsorted_names(m, all=true, imported=true) |
|
326 | + | for s in unsorted_names(m, all = true, imported = true) |
|
327 | 327 | !isdefined(m, s) && continue |
|
328 | 328 | x = getfield(m, s) |
|
329 | 329 | if x isa Module |
@@ -352,18 +352,37 @@
Loading
352 | 352 | cache |
|
353 | 353 | end |
|
354 | 354 | ||
355 | - | function getenvtree(names=nothing) |
|
355 | + | function getenvtree(names = nothing) |
|
356 | 356 | amn = allmodulenames() |
|
357 | 357 | EnvStore(nameof(m) => getmoduletree(m, amn) for m in Base.loaded_modules_array() if names === nothing || nameof(m) in names) |
|
358 | 358 | end |
|
359 | 359 | ||
360 | - | function symbols(env::EnvStore, m::Union{Module,Nothing}=nothing, allnames::Base.IdSet{Symbol}=getallns(), visited=Base.IdSet{Module}()) |
|
360 | + | # faster and more correct split_module_names |
|
361 | + | all_names(m) = all_names(m, x -> isdefined(m, x)) |
|
362 | + | function all_names(m, pred, symbols = Set(Symbol[]), seen = Set(Module[])) |
|
363 | + | push!(seen, m) |
|
364 | + | ns = unsorted_names(m; all = true, imported = false) |
|
365 | + | for n in ns |
|
366 | + | isdefined(m, n) || continue |
|
367 | + | Base.isdeprecated(m, n) && continue |
|
368 | + | val = getfield(m, n) |
|
369 | + | if val isa Module && !(val in seen) |
|
370 | + | all_names(val, pred, symbols, seen) |
|
371 | + | end |
|
372 | + | if pred(n) |
|
373 | + | push!(symbols, n) |
|
374 | + | end |
|
375 | + | end |
|
376 | + | symbols |
|
377 | + | end |
|
378 | + | ||
379 | + | function symbols(env::EnvStore, m::Union{Module,Nothing} = nothing, allnames::Base.IdSet{Symbol} = getallns(), visited = Base.IdSet{Module}()) |
|
361 | 380 | if m isa Module |
|
362 | 381 | cache = _lookup(VarRef(m), env, true) |
|
363 | 382 | cache === nothing && return |
|
364 | 383 | push!(visited, m) |
|
365 | - | internalnames, othernames = split_module_names(m, allnames) |
|
366 | - | for s in internalnames |
|
384 | + | ns = all_names(m) |
|
385 | + | for s in ns |
|
367 | 386 | !isdefined(m, s) && continue |
|
368 | 387 | x = getfield(m, s) |
|
369 | 388 | if Base.unwrap_unionall(x) isa DataType # Unions aren't handled here. |
@@ -409,23 +428,6 @@
Loading
409 | 428 | cache[s] = GenericStore(VarRef(VarRef(m), s), FakeTypeName(typeof(x)), _doc(x), s in getnames(m)) |
|
410 | 429 | end |
|
411 | 430 | end |
|
412 | - | for s in othernames |
|
413 | - | x = getfield(m, s) |
|
414 | - | if x isa Function |
|
415 | - | if x isa Core.IntrinsicFunction |
|
416 | - | cache[s] = VarRef(VarRef(Core.Intrinsics), nameof(x)) |
|
417 | - | else |
|
418 | - | cache[s] = VarRef(VarRef(parentmodule(x)), nameof(x)) |
|
419 | - | end |
|
420 | - | elseif x isa DataType |
|
421 | - | cache[s] = VarRef(VarRef(parentmodule(x)), nameof(x)) |
|
422 | - | elseif x isa Module |
|
423 | - | cache[s] = VarRef(x) |
|
424 | - | else |
|
425 | - | # We'd like to have these as VarRef's but we don't know where they live. |
|
426 | - | cache[s] = GenericStore(VarRef(VarRef(m), s), FakeTypeName(typeof(x)), _doc(x), s in getnames(m)) |
|
427 | - | end |
|
428 | - | end |
|
429 | 431 | else |
|
430 | 432 | for m in Base.loaded_modules_array() |
|
431 | 433 | in(m, visited) || symbols(env, m, allnames, visited) |
@@ -452,7 +454,7 @@
Loading
452 | 454 | cache[:Base][Symbol("@.")] = cache[:Base][Symbol("@__dot__")] |
|
453 | 455 | cache[:Core][:Main] = GenericStore(VarRef(nothing, :Main), FakeTypeName(Module), _doc(Main), true) |
|
454 | 456 | # Add built-ins |
|
455 | - | builtins = Symbol[nameof(getfield(Core, n).instance) for n in unsorted_names(Core, all=true) if isdefined(Core, n) && getfield(Core, n) isa DataType && isdefined(getfield(Core, n), :instance) && getfield(Core, n).instance isa Core.Builtin] |
|
457 | + | builtins = Symbol[nameof(getfield(Core, n).instance) for n in unsorted_names(Core, all = true) if isdefined(Core, n) && getfield(Core, n) isa DataType && isdefined(getfield(Core, n), :instance) && getfield(Core, n).instance isa Core.Builtin] |
|
456 | 458 | cnames = unsorted_names(Core) |
|
457 | 459 | for f in builtins |
|
458 | 460 | if !haskey(cache[:Core], f) |
@@ -529,7 +531,7 @@
Loading
529 | 531 | end |
|
530 | 532 | ||
531 | 533 | ||
532 | - | function collect_extended_methods(depot::EnvStore, extendeds=Dict{VarRef,Vector{VarRef}}()) |
|
534 | + | function collect_extended_methods(depot::EnvStore, extendeds = Dict{VarRef,Vector{VarRef}}()) |
|
533 | 535 | for m in depot |
|
534 | 536 | collect_extended_methods(m[2], extendeds, m[2].name) |
|
535 | 537 | end |
@@ -578,4 +580,4 @@
Loading
578 | 580 | end |
|
579 | 581 | ||
580 | 582 | get_all_modules() = let allms = Base.IdSet{Module}(); apply_to_everything(x -> if x isa Module push!(allms, x) end); allms end |
|
581 | - | get_used_modules(M, allms=get_all_modules()) = [m for m in allms if usedby(M, m)] |
|
583 | + | get_used_modules(M, allms = get_all_modules()) = [m for m in allms if usedby(M, m)] |
Files | Coverage |
---|---|
src | 71.17% |
Project Totals (5 files) | 71.17% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.