Skip to content

WIP: Docstring refactoring #58747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/Base_compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ include("exports.jl")

# core docsystem
include("docs/core.jl")
Core.atdoc!(CoreDocs.docm)
Core._set_setdoc!(CoreDocs.boot_setdoc)

eval(x) = Core.eval(Base, x)
eval(m::Module, x) = Core.eval(m, x)
Expand Down
28 changes: 11 additions & 17 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -759,26 +759,21 @@ using Core: CodeInfo, MethodInstance, CodeInstance, GotoNode, GotoIfNot, ReturnN
end # module IR

# docsystem basics
macro doc(x...)
docex = atdoc(__source__, __module__, x...)
isa(docex, Expr) && docex.head === :escape && return docex
return Expr(:escape, Expr(:var"hygienic-scope", docex, typeof(atdoc).name.module, __source__))
macro doc(x) # retrieve doc for x
return docm_get(__source__, __module__, x)
end
macro __doc__(x)
return Expr(:escape, Expr(:block, Expr(:meta, :doc), x))
macro doc(str, x, define=true) # set doc for x
# define === false && return Expr(:error, "@doc with define=false not supported")
return Expr(:escape, Expr(:doc, str, x, __source__))
end

isbasicdoc(@nospecialize x) = (isa(x, Expr) && x.head === :.) || isa(x, Union{QuoteNode, Symbol})
firstarg(arg1, args...) = arg1
iscallexpr(ex::Expr) = (isa(ex, Expr) && ex.head === :where) ? iscallexpr(firstarg(ex.args...)) : (isa(ex, Expr) && ex.head === :call)
iscallexpr(ex) = false
function ignoredoc(source, mod, str, expr)
(isbasicdoc(expr) || iscallexpr(expr)) && return Expr(:escape, nothing)
Expr(:escape, expr)
macro __doc__(x) # annotate x as documentation target
return Expr(:escape, Expr(:block, Expr(:meta, :doc), x))
end

global atdoc = ignoredoc
atdoc!(λ) = global atdoc = λ
global docm_get = (x...) -> nothing
global setdoc = (x...) -> nothing
_set_docm_get!(λ) = global docm_get = λ
_set_setdoc!(λ) = global setdoc = λ

# macros for big integer syntax
macro int128_str end
Expand All @@ -788,7 +783,6 @@ macro big_str end
# macro for command syntax
macro cmd end


# simple stand-alone print definitions for debugging
abstract type IO end
struct CoreSTDOUT <: IO end
Expand Down
Loading