Skip to content
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

Fix docstring search by signatures revisited #54324

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,26 @@ function initmeta(m::Module)
nothing
end

struct TypeParams{T<:Tuple} end

function signature!(tv::Vector{Any}, expr::Expr)
is_macrocall = isexpr(expr, :macrocall)
if is_macrocall || isexpr(expr, :call)
sig = :(Union{Tuple{}})
first_arg = is_macrocall ? 3 : 2 # skip function arguments
if isexpr(expr.args[1], :curly)
push!((sig.args[end]::Expr).args, :($TypeParams{Tuple{$((expr.args[1]::Expr).args[2:end]...)}}))
if isempty(tv)
append!(tv, mapany(tvar, (expr.args[1]::Expr).args[2:end]))
end
end
for arg in expr.args[first_arg:end]
isexpr(arg, :parameters) && continue
if isexpr(arg, :kw) # optional arg
push!(sig.args, :(Tuple{$((sig.args[end]::Expr).args[2:end]...)}))
end
push!((sig.args[end]::Expr).args, argtype(arg))
end
if isexpr(expr.args[1], :curly) && isempty(tv)
append!(tv, mapany(tvar, (expr.args[1]::Expr).args[2:end]))
end
for i = length(tv):-1:1
push!(sig.args, :(Tuple{$((tv[i]::Expr).args[1])}))
end
for i = length(tv):-1:1
sig = Expr(:where, sig, tv[i])
end
Expand Down
12 changes: 4 additions & 8 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3294,18 +3294,14 @@ Tuple

"""
NamedTuple{names}(args::Tuple)

Construct a named tuple with the given `names` (a tuple of Symbols) from a tuple of values.
"""
NamedTuple{names}(args::Tuple)

"""
NamedTuple{names,T}(args::Tuple)

Construct a named tuple with the given `names` (a tuple of Symbols) and field types `T`
In the first form, construct a named tuple with the given `names` (a tuple of Symbols) from a tuple of values.
In the second form, construct a named tuple with the given `names` (a tuple of Symbols) and field types `T`
(a `Tuple` type) from a tuple of values.
"""
NamedTuple{names,T}(args::Tuple)
NamedTuple{names}(args::Tuple)
# NamedTuple{names,T}(args::Tuple) # redundant because of the same signature

"""
NamedTuple{names}(nt::NamedTuple)
Expand Down
18 changes: 9 additions & 9 deletions doc/src/base/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Base.AbstractVector
Base.AbstractMatrix
Base.AbstractVecOrMat
Core.Array
Core.Array(::UndefInitializer, ::Any)
Core.Array(::Nothing, ::Any)
Core.Array(::Missing, ::Any)
Core.Array{T,N}(::UndefInitializer, ::Any)
Core.Array{T,N}(::Nothing, ::Any)
Core.Array{T,N}(::Missing, ::Any)
Core.UndefInitializer
Core.undef
Base.Vector
Base.Vector(::UndefInitializer, ::Any)
Base.Vector(::Nothing, ::Any)
Base.Vector(::Missing, ::Any)
Base.Vector{T}(::UndefInitializer, ::Any)
Base.Vector{T}(::Nothing, ::Any)
Base.Vector{T}(::Missing, ::Any)
Base.Matrix
Base.Matrix(::UndefInitializer, ::Any, ::Any)
Base.Matrix(::Nothing, ::Any, ::Any)
Base.Matrix(::Missing, ::Any, ::Any)
Base.Matrix{T}(::UndefInitializer, ::Any, ::Any)
Base.Matrix{T}(::Nothing, ::Any, ::Any)
Base.Matrix{T}(::Missing, ::Any, ::Any)
Base.VecOrMat
Core.DenseArray
Base.DenseVector
Expand Down
4 changes: 2 additions & 2 deletions doc/src/base/c.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Base.unsafe_store!
Base.unsafe_modify!
Base.unsafe_replace!
Base.unsafe_swap!
Base.unsafe_copyto!{T}(::Ptr{T}, ::Ptr{T}, ::Any)
Base.unsafe_copyto!(::Ptr{T}, ::Ptr{T}, ::Any) where T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem reasonable/good/bugfixes, but I'm worried how breaking they might be to docsystem building across the ecosystem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nanosoldier, but that only runs testsuites which often do not include building docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Base.unsafe_copyto!(::Array, ::Any, ::Array, ::Any, ::Any)
Base.copyto!
Base.pointer
Base.unsafe_wrap{T,N}(::Union{Type{Array},Type{Array{T}},Type{Array{T,N}}}, ::Ptr{T}, ::NTuple{N,Int})
Base.unsafe_wrap(::Union{Type{Array},Type{Array{T}},Type{Array{T,N}}}, ::Ptr{T}, ::NTuple{N,Int}) where {T,N}
Base.pointer_from_objref
Base.unsafe_pointer_to_objref
Base.disable_sigint
Expand Down
2 changes: 1 addition & 1 deletion doc/src/base/parallel.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Base.Lockable
```@docs
Base.AbstractChannel
Base.Channel
Base.Channel(::Function)
Base.Channel{T}(::Function)
Base.put!(::Channel, ::Any)
Base.take!(::Channel)
Base.isfull(::Channel)
Expand Down
4 changes: 2 additions & 2 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ Base.collect(::Type{EmptyType{T}}) where {T} = "borked"
end

let fd = meta(I12515)[@var(Base.collect)]
@test fd.order[1] == (Union{Tuple{Type{I12515.EmptyType{T}}}, Tuple{T}} where T)
@test fd.order[1] == (Tuple{Type{I12515.EmptyType{T}}} where T)
end

# PR #12593
Expand Down Expand Up @@ -1403,7 +1403,7 @@ end

end

@test docstrings_equal(
@test_broken docstrings_equal(
@doc(I21016.Struct),
doc"""
String 1
Expand Down