Skip to content

Commit 8b8e963

Browse files
topolaritysjkelly
andcommitted
Avoid unnecessary Docs.META initializations
If the target module does not have a Docs.META dict (e.g. if `--strip-metadata` is used), `Docs.meta()` has the side effect of creating a new IdDict and initializing the Docs.META field of the target module. We need to avoid eval'ing into modules after they've been closed, so for methods that do not mutate the new IdDict we should avoid the init. Resolves #48390. Co-authored-by: Steve Kelly <kd2cca@gmail.com>
1 parent 94c4fb5 commit 8b8e963

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

base/docs/Docs.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ end
161161
function docstr(binding::Binding, typesig = Union{})
162162
@nospecialize typesig
163163
for m in modules
164-
dict = meta(m)
165-
if haskey(dict, binding)
166-
docs = dict[binding].docs
167-
if haskey(docs, typesig)
168-
return docs[typesig]
164+
if isdefined(m, META) && getfield(m, META) !== nothing
165+
dict = meta(m)
166+
if haskey(dict, binding)
167+
docs = dict[binding].docs
168+
if haskey(docs, typesig)
169+
return docs[typesig]
170+
end
169171
end
170172
end
171173
end

stdlib/REPL/src/docview.jl

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,14 @@ function doc(binding::Binding, sig::Type = Union{})
164164
results, groups = DocStr[], MultiDoc[]
165165
# Lookup `binding` and `sig` for matches in all modules of the docsystem.
166166
for mod in modules
167-
dict = meta(mod)
168-
if haskey(dict, binding)
169-
multidoc = dict[binding]
170-
push!(groups, multidoc)
171-
for msig in multidoc.order
172-
sig <: msig && push!(results, multidoc.docs[msig])
167+
if isdefined(mod, Docs.META) && getfield(mod, Docs.META) !== nothing
168+
dict = meta(mod)
169+
if haskey(dict, binding)
170+
multidoc = dict[binding]
171+
push!(groups, multidoc)
172+
for msig in multidoc.order
173+
sig <: msig && push!(results, multidoc.docs[msig])
174+
end
173175
end
174176
end
175177
end
@@ -565,14 +567,16 @@ Return documentation for a particular `field` of a type if it exists.
565567
"""
566568
function fielddoc(binding::Binding, field::Symbol)
567569
for mod in modules
568-
dict = meta(mod)
569-
if haskey(dict, binding)
570-
multidoc = dict[binding]
571-
if haskey(multidoc.docs, Union{})
572-
fields = multidoc.docs[Union{}].data[:fields]
573-
if haskey(fields, field)
574-
doc = fields[field]
575-
return isa(doc, Markdown.MD) ? doc : Markdown.parse(doc)
570+
if isdefined(mod, Docs.META) && getfield(mod, Docs.META) !== nothing
571+
dict = meta(mod)
572+
if haskey(dict, binding)
573+
multidoc = dict[binding]
574+
if haskey(multidoc.docs, Union{})
575+
fields = multidoc.docs[Union{}].data[:fields]
576+
if haskey(fields, field)
577+
doc = fields[field]
578+
return isa(doc, Markdown.MD) ? doc : Markdown.parse(doc)
579+
end
576580
end
577581
end
578582
end
@@ -834,8 +838,10 @@ function apropos(io::IO, needle::Regex)
834838
for mod in modules
835839
# Module doc might be in README.md instead of the META dict
836840
docsearch(doc(mod), needle) && println(io, mod)
837-
for (k, v) in meta(mod)
838-
docsearch(v, needle) && println(io, k)
841+
if isdefined(mod, Docs.META) && getfield(mod, Docs.META) !== nothing
842+
for (k, v) in meta(mod)
843+
docsearch(v, needle) && println(io, k)
844+
end
839845
end
840846
end
841847
end

0 commit comments

Comments
 (0)