diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 0819383d79d70..ead5b076ce45a 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -10,12 +10,16 @@ export doc const modules = Module[] -meta() = current_module().META +const META′ = gensym("META") + +@eval meta(mod) = mod.$META′ + +meta() = meta(current_module()) macro init() - META = esc(:META) + META = esc(META′) quote - if !isdefined(:META) + if !isdefined($(Expr(:quote, META′))) const $META = ObjectIdDict() doc!($META, @doc_str $("Documentation metadata for `$(current_module())`.")) push!(modules, current_module()) @@ -30,7 +34,7 @@ end function doc(obj) for mod in modules - haskey(mod.META, obj) && return mod.META[obj] + haskey(meta(mod), obj) && return meta(mod)[obj] end end @@ -97,8 +101,8 @@ end function doc(f::Function) docs = [] for mod in modules - if haskey(mod.META, f) - fd = mod.META[f] + if haskey(meta(mod), f) + fd = meta(mod)[f] length(docs) == 0 && fd.main != nothing && push!(docs, fd.main) if isa(fd, FuncDoc) for m in fd.order @@ -114,8 +118,8 @@ end function doc(f::Function, m::Method) for mod in modules - haskey(mod.META, f) && isa(mod.META[f], FuncDoc) && haskey(mod.META[f].meta, m) && - return mod.META[f].meta[m] + haskey(meta(mod), f) && isa(meta(mod)[f], FuncDoc) && haskey(meta(mod)[f].meta, m) && + return meta(mod)[f].meta[m] end end @@ -168,8 +172,8 @@ end function doc(f::DataType) docs = [] for mod in modules - if haskey(mod.META, f) - fd = mod.META[f] + if haskey(meta(mod), f) + fd = meta(mod)[f] if isa(fd, TypeDoc) length(docs) == 0 && fd.main != nothing && push!(docs, fd.main) for m in fd.order @@ -189,8 +193,8 @@ isfield(x) = isexpr(x, :.) && function fielddoc(T, k) for mod in modules - if haskey(mod.META, T) && isa(mod.META[T], TypeDoc) && haskey(mod.META[T].fields, k) - return mod.META[T].fields[k] + if haskey(meta(mod), T) && isa(meta(mod)[T], TypeDoc) && haskey(meta(mod)[T].fields, k) + return meta(mod)[T].fields[k] end end Text(sprint(io -> (print(io, "$T has fields: "); diff --git a/test/docs.jl b/test/docs.jl index d0679067d7cd0..577c54c008cbd 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -142,10 +142,12 @@ const K = :K end -@test DocsTest.META[DocsTest] == doc"DocsTest" +import Base.Docs: meta + +@test meta(DocsTest)[DocsTest] == doc"DocsTest" let f = DocsTest.f - funcdoc = DocsTest.META[f] + funcdoc = meta(DocsTest)[f] order = [methods(f, sig)[1] for sig in [(Any,), (Any, Any)]] @test funcdoc.main == nothing @test funcdoc.order == order @@ -154,40 +156,40 @@ let f = DocsTest.f end let g = DocsTest.g - funcdoc = DocsTest.META[g] + funcdoc = meta(DocsTest)[g] @test funcdoc.main == doc"g" end let AT = DocsTest.AT - @test DocsTest.META[AT] == doc"AT" + @test meta(DocsTest)[AT] == doc"AT" end let BT = DocsTest.BT - @test DocsTest.META[BT] == doc"BT" + @test meta(DocsTest)[BT] == doc"BT" end let T = DocsTest.T - typedoc = DocsTest.META[T] + typedoc = meta(DocsTest)[T] @test typedoc.main == doc"T" @test typedoc.fields[:x] == doc"T.x" @test typedoc.fields[:y] == doc"T.y" end let IT = DocsTest.IT - typedoc = DocsTest.META[IT] + typedoc = meta(DocsTest)[IT] @test typedoc.main == doc"IT" @test typedoc.fields[:x] == doc"IT.x" @test typedoc.fields[:y] == doc"IT.y" end let TA = DocsTest.TA - @test DocsTest.META[TA] == doc"TA" + @test meta(DocsTest)[TA] == doc"TA" end let mac = getfield(DocsTest, symbol("@mac")) - funcdoc = DocsTest.META[mac] + funcdoc = meta(DocsTest)[mac] @test funcdoc.main == doc"@mac" end -@test DocsTest.META[:G] == doc"G" -@test DocsTest.META[:K] == doc"K" +@test meta(DocsTest)[:G] == doc"G" +@test meta(DocsTest)[:K] == doc"K"