From 5338635618df080f42374460fa25f56b5299cbc0 Mon Sep 17 00:00:00 2001 From: Michael Hatherly Date: Thu, 25 Feb 2016 10:57:35 +0200 Subject: [PATCH] Remove `at-init` from docsystem. Replaces macro init with a function instead. Appears to reduce the amount of code generated by `at-doc` which should help shorten bootstrapping time slightly. Also changes the name of the `ObjectIdDict` used to store docstrings to a gensym'd one to avoid naming clashes. `Docs.meta` has always been available to access this const without needing to know it's name so this shouldn't be a major breaking change. --- base/docs/Docs.jl | 32 ++++++++++++-------------------- base/docs/bootstrap.jl | 2 +- base/loading.jl | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 12ff28e9d882e..b9ebeae41b531 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -65,23 +65,16 @@ export doc # Basic API / Storage const modules = Module[] +const META = gensym(:meta) -const META′ = :__META__ +meta(m::Module = current_module()) = isdefined(m, META) ? getfield(m, META) : ObjectIdDict() -meta(mod) = mod.(META′) - -meta() = meta(current_module()) - -macro init() - META = esc(META′) - quote - if !isdefined($(Expr(:quote, META′))) - const $META = ObjectIdDict() - doc!($META, @doc_str $("Documentation metadata for `$(current_module())`.")) - push!(modules, current_module()) - nothing - end +function initmeta(m::Module = current_module()) + if !isdefined(m, META) + eval(m, :(const $META = $(ObjectIdDict()))) + push!(modules, m) end + nothing end "`doc!(obj, data)`: Associate the metadata `data` with `obj`." @@ -447,7 +440,6 @@ end function namedoc(meta, def, def′) quote - @init $(esc(def)) doc!($(esc(namify(def′))), $(mdify(meta))) nothing @@ -457,7 +449,6 @@ end function funcdoc(meta, def, def′) f = esc(namify(def′)) quote - @init $(esc(def)) doc!($f, $(esc(signature(def′))), $(mdify(meta)), $(esc(quot(def′)))) $f @@ -466,7 +457,6 @@ end function typedoc(meta, def, def′) quote - @init $(esc(def)) doc!($(esc(namify(def′))), $(mdify(meta)), $(field_meta(unblock(def′)))) nothing @@ -492,7 +482,6 @@ end function vardoc(meta, def, name) quote - @init $(esc(def)) doc!(@var($(esc(namify(name)))), $(mdify(meta))) end @@ -584,6 +573,9 @@ function docm(meta, ex, define = true) # otherwise calling `loaddocs` would redefine all documented functions and types. def = define ? x : nothing + # Initalise the module's docstring storage. + initmeta() + # Method / macro definitions and "call" syntax. # # function f(...) ... end @@ -629,7 +621,7 @@ function docm(meta, ex, define = true) # All other expressions are undocumentable and should be handled on a case-by-case basis # with `@__doc__`. Unbound string literals are also undocumentable since they cannot be - # retrieved from the `__META__` `ObjectIdDict` without a reference to the string. + # retrieved from the module's metadata `ObjectIdDict` without a reference to the string. docerror(ex) end @@ -666,7 +658,7 @@ Base.DocBootstrap.setexpand!(docm) # Names are resolved relative to the Base module, so inject the ones we need there. -eval(Base, :(import .Docs: @init, @var, doc!, doc, @doc_str)) +eval(Base, :(import .Docs: @var, doc!, doc, @doc_str)) Base.DocBootstrap.loaddocs() diff --git a/base/docs/bootstrap.jl b/base/docs/bootstrap.jl index 4295bb756ddfd..f6c8d2e522aa9 100644 --- a/base/docs/bootstrap.jl +++ b/base/docs/bootstrap.jl @@ -48,7 +48,7 @@ DocBootstrap """ loaddocs() -Move all docstrings from `DocBootstrap.docs` to their module's `__META__` dict. +Move all docstrings from `DocBootstrap.docs` to their module's metadata dict. """ function loaddocs() node = docs diff --git a/base/loading.jl b/base/loading.jl index b3b3faf05b6ce..8b522437c03cc 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -171,7 +171,7 @@ function _require_from_serialized(node::Int, mod::Symbol, path_to_try::ByteStrin if restored !== nothing for M in restored - if isdefined(M, :__META__) + if isdefined(M, Base.Docs.META) push!(Base.Docs.modules, M) end end