Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change moves the construction of docstring registration calls into lowering
instead of doing so in a macro. The original intent was just to fix #58630,
but some refactoring is necessary to do this in a good way.
Not all of the following is implemented yet. Feedback on the design is welcome!
Current design
Docstrings are stored in a module-scoped IdDict mapping Base.Docs.Binding to
Base.Docs.MultiDoc, which either contains a single docstring, or a map from
method signature to docstring.
Docstrings are parsed to
@doc str x
calls (this macro is also public andused).
@doc
defers toCore.atdoc!
, which figures out if it's one of themany things we can document, tries to guess the signature of any methods if
x
is a function, and returns a quoted call to
Docs.doc!
, which registers thedocstring.
A few things make our current design complex:
trying to figure out what we're documenting purely by Expr. We need to dig
through struct contents and call expressions to find field docstrings and
signatures.
@doc
is sometimes responsible for evaluating the expression it's given, andsometimes not.
Complicating matters further are a few "doc-only" special cases where adding a
docstring changes the semantics of the following expression
This change
Structures and the information we store (other than including signatures'
first arguments in keys) are both unchanged.
Change two-arg
@doc
to produceExpr(:doc, ...)
instead of callingCore.atdoc
New
Expr(:doc, str, x, linenode)
form. Generally, this lowersx
as usual followed by a call like
and returns the value of
x
if we're not in a doc-only case. Pending parserchanges, this lets us prevent docstrings from changing what an expression
returns (modulo doc-only cases).
Unlike
Core.atdoc
, the newCore.setdoc
gets the answers from lowering, andcan query the runtime about the object to document. The "signature" key we
use for method
x
is now exactlyx.sig
.Misc
@doc x
("get docs forx") and
@doc str x
(set docstringstr
forx
) code paths, which arepretty disjoint.
@doc "foo" -> bar
syntax, which appears to be an undocumented specialsyntax. I'll put it back if people use it.
@doc
used to take all arguments and pass them toatdoc!
, so had at leastone secret undocumented argument
define
. Remove this option.Potential issues
expressions where there's nothing to lower. In its current form, this PR
breaks these.
to replace it.
don't mind being the one to add this to JuliaLowering too).
Todo
"str" x
asExpr(:doc, ...)
instead of a call to@doc
(JuliaSyntaxalready does this internally before Expr-converting it)
Expr(:doc)
; so far I'vetried to stay faithful to existing behaviour.
https://github.com/mlechu/julia/blob/docsystem-wrangling/src/julia-syntax.scm#L2604-L2617
(::T)(x) = x
T
@doc
should ideally return the same thing (Base.Docs.Binding) asbefore, probably by just calling one-arg
@doc
@__doc__
and quoted macro calls (should be easy)