Fix docstring search by signatures revisited #54324
These changes seem reasonable/good/bugfixes, but I'm worried how breaking they might be to docsystem building across the ecosystem.
Thanks for making this PR! I can't do a full review right now, but hopefully we can find someone who is willing to.
Is there a way to figure this out? From some JuliaCon talks for example I get the impression that it is possible to test many or all packages with a modified Julia version and see what happens. If the documentation of a package would require changes, then this would result in an error during precompilation or when building the docs.
There is nanosoldier, but that only runs testsuites which often do not include building docs.
In Base, most changes occur in docstrings (as opposed to separate documentation files), and a missing change gives an error during precompilation. So with nanosoldier we might still get an idea of how big the problem really is.
I would also have thought that this issue should be detected by Nanosoldier.
The only way to circumvent this possible incompatibility is if we decide to formally allow this syntax for functions. (But then, it should be documented somewhere.)
Then, it should also formally be defined show this syntax is interpreted. If we just say that in the documentation, fun{X}(args) is _exactly_ equivalent to fun(args) where {X}, then it is clear that everything in X is a type variable (with possible subtyping). Apart from the case in which fun is the name of a type/constructor, as then it could also be a concrete type (or some other bitstype). I previously thought that it is not easily possible for the macro-called function determining which is the case, but as I now think of it, I'm no longer so sure. For outer constructors, for sure when the macro is called, the type must already exist. And in order for the Julia compiler to accept fun{X} without X being in the where clause, X must also be well defined (in the context of the calling module, which is available to the macro). I don't know how it is when the docstring is attached to an inner constructor, though.
Then, in the specification of what fun{X}(args) means when fun is a constructor, should we allow mixing actual generic types (coming first?) with parametric types from the arguments (pretty clumsy IMHO)? Or just disallow this shorthand notation?
[I'm moving the discussion out of the code review because it has a wider scope]
In my opinion, we should not allow the syntax f{T}(x::T) for docstrings if f is a function (as opposed to a constructor). For constructors, I also find it bad syntax because it cannot distinguish between actual types and type parameters. If T is a parameter, then one should write f{T}(x::T) where T. However, the currently allowed syntax might be so widespread in the existing documentation that it might be better not to change it. After all, replacing a type parameter by an actual type should not happen often. I still think that it would be helpful to run nanosoldier (or whatever tool is appropriate) over a large collection of packages to see how much would break with disallowing this syntax.
I am also concerned about breakage in the ecosystem, on the other hand, there is a also real bug here that keep coming up again and again, and surely we must be able to deal with it somehow?
What are the possible failure modes here? I am a bit confused by the discussion here. Which of these can occur here:
1. The changes here could lead to makedocs invocations that previously worked now erroring out?
- I think we could live with that; package authors would be annoyed, but if we give a clear guidance about this change and how to deal with it in the release notes, and why it was necessary, it seems acceptable.
2. The changes here could lead to Julia code not (pre)compiling anymore?
- Similar conclusion as in 1, but we can at least get a rough idea about it via NanoSoldier
3. The changes here could lead to silent breakage, e.g. manuals suddenly don't include certain docstrings
- that's the annoying kind, it could even lead to projects making several release with broken documentation without realizing.
Any other relevant failure modes I am forgetting here?
In Base, most changes occur in docstrings (as opposed to separate documentation files), and a missing change gives an error during precompilation.
This line confuses me: looking at this PR, it's the other way around: most changes here are in the .md files, and one is in a docstring. What gives?
With this, PR, ?NamedTuple{names,T}, ?NamedTuple{names} and `?NamedTuple all give the same output, which includes four docstrings,
NamedTuple(itr)
NamedTuple{names}(nt::NamedTuple)
NamedTuple{names}(args::Tuple)
NamedTuple{names,T}(args::Tuple)
NamedTuple
Is that intended?
It has been a while, but here's what I think I remember:
@docs block) or you want to [...](@ref something(concrete)) a particular method, this might not always work out.
@docs block that used wrong syntax and links within docstrings. I don't think that this will lead to an error in precompilation: The markdown files are irrelevant for precompilation anyways, they are "external" documentation. And if you have links within docstrings, well, they are just strings until you actually want to generate some hypertext out of it. So the links may be broken in the documentation, which might give a warning or an error depending on your makedocs configuration, but it should not affect precompilation, same for markdown.
Union structure. Which should be pretty rare. Why would you ever care to programmatically get the docstring of a particular method? Probably only if you want to copy this docstring for another method (which is how I arrived at this bug, as far as I remember). And if you used the previous internal representation, I'm pretty sure that this was an implementation detail and therefore can change without notice. And REPL of course also uses the Docs system, since I have no idea how REPL internally does this, maybe it needs some adjustments.
So indeed, I also don't understand @matthias314's statement about the changes in docstrings in Base.
I have to admit that don't understand that comment myself anymore!
Regarding breakages: If I understand correctly, @projekter would also prefer to disallow type parameters that are not explicitly specified. I think it would be instructive to see how many packages would break if we did this. We could either take this temporarily out of this PR or by use my original PR and then run nanosoldier.
LilithHafner
projekter
This is an extension of #53824 (therefore also fixes #52669), where details on the issue can be found (and, related to this, a different area where the issue shows, namely when you try to include documentation for a particular method of a function, which is similarly impossible when type parameters are involved).
The fix proposed there had two drawbacks:
However, I completely agree with @matthias314's analysis that in this way, it is impossible to make the distinction between existing types and parametric types (which cannot be done well during macro deconstruction). This is also an issue in the code currently in Base; any type parameter will always be seen as parametric. For this reason, I'd rather see this whole behavior disappear; in the end, you cannot write Julia code like this. Removing the
if isemptywould prevent such a usage. A kind of middle ground would be to allow the current behavior, but only if the type is constrained (because this would not be possible for existing types).---
UPDATE: several more issues are fixed by this:
Fixes #29437
Fixes #41601