Skip to content

Commit b122bc7

Browse files
committed
Merge pull request #12835 from JuliaLang/jcb/docfixes
let's release this thing !
2 parents 5cc32bb + 5b8cb58 commit b122bc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2563
-10796
lines changed

base/array.jl

+10
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ convert{T,n,S}(::Type{Array{T,n}}, x::Array{S,n}) = copy!(similar(x,T), x)
241241

242242
promote_rule{T,n,S}(::Type{Array{T,n}}, ::Type{Array{S,n}}) = Array{promote_type(T,S),n}
243243

244+
"""
245+
collect(element_type, collection)
246+
247+
Return an array of type `Array{element_type,1}` of all items in a collection.
248+
"""
244249
function collect{T}(::Type{T}, itr)
245250
if applicable(length, itr)
246251
# when length() isn't defined this branch might pollute the
@@ -259,6 +264,11 @@ function collect{T}(::Type{T}, itr)
259264
return a
260265
end
261266

267+
"""
268+
collect(collection)
269+
270+
Return an array of all items in a collection. For associative collections, returns (key, value) tuples.
271+
"""
262272
collect(itr) = collect(eltype(itr), itr)
263273

264274
## Iteration ##

base/docs/Docs.jl

+46-42
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ end
104104

105105
function signature(expr::Expr)
106106
if isexpr(expr, :call)
107-
sig = :(Tuple{})
107+
sig = :(Union{Tuple{}})
108108
for arg in expr.args[2:end]
109109
isexpr(arg, :parameters) && continue
110-
push!(sig.args, argtype(arg))
110+
if isa(arg,Expr) && arg.head === :kw # optional arg
111+
push!(sig.args, :(Tuple{$(sig.args[end].args...)}))
112+
end
113+
push!(sig.args[end].args, argtype(arg))
111114
end
112115
Expr(:let, Expr(:block, sig), typevars(expr)...)
113116
else
@@ -133,50 +136,58 @@ tvar(s::Symbol) = :($(s) = TypeVar($(quot(s)), Any, true))
133136

134137
type FuncDoc
135138
main
136-
order::Vector{Method}
139+
order::Vector{Type}
137140
meta::ObjectIdDict
138141
source::ObjectIdDict
139142
end
140143

141144
FuncDoc() = FuncDoc(nothing, [], ObjectIdDict(), ObjectIdDict())
142145

146+
# handles the :(function foo end) form
143147
function doc!(f::Function, data)
144-
fd = get!(meta(), f, FuncDoc())
145-
fd.main = data
148+
doc!(f, Union{}, data, nothing)
146149
end
147150

148-
function doc!(f::Function, m::Method, data, source)
151+
type_morespecific(a::Type, b::Type) =
152+
(ccall(:jl_type_morespecific, Int32, (Any,Any), a, b) > 0)
153+
154+
# handles the :(function foo(x...); ...; end) form
155+
function doc!(f::Function, sig::ANY, data, source)
149156
fd = get!(meta(), f, FuncDoc())
150157
isa(fd, FuncDoc) || error("Can't document a method when the function already has metadata")
151-
!haskey(fd.meta, m) && push!(fd.order, m)
152-
fd.meta[m] = data
153-
fd.source[m] = source
158+
haskey(fd.meta, sig) || push!(fd.order, sig)
159+
sort!(fd.order, lt=type_morespecific)
160+
fd.meta[sig] = data
161+
fd.source[sig] = source
154162
end
155163

156-
function doc(f::Function)
157-
docs = []
164+
doc(f::Function) = doc(f, Tuple)
165+
166+
function doc(f::Function, sig::Type)
167+
isgeneric(f) && isempty(methods(f,sig)) && return nothing
158168
for mod in modules
159-
if haskey(meta(mod), f)
169+
if (haskey(meta(mod),f) && isa(meta(mod)[f],FuncDoc))
160170
fd = meta(mod)[f]
161-
length(docs) == 0 && fd.main !== nothing && push!(docs, fd.main)
162-
if isa(fd, FuncDoc)
163-
for m in fd.order
164-
push!(docs, fd.meta[m])
171+
results = []
172+
for msig in fd.order
173+
# try to find specific matching method signatures
174+
if sig <: msig
175+
push!(results, (msig,fd.meta[msig]))
165176
end
166-
elseif length(docs) == 0
167-
return fd
177+
end
178+
# if all method signatures are Union{} ( ⊥ ), concat all docstrings
179+
if isempty(results)
180+
return catdoc([fd.meta[msig] for msig in reverse(fd.order)]...)
181+
else
182+
sort!(results, lt=(a,b)->type_morespecific(first(a),first(b)))
183+
return catdoc([last(r) for r in results]...)
168184
end
169185
end
170186
end
171-
return catdoc(docs...)
187+
return nothing
172188
end
189+
doc(f::Function,args::Any...) = doc(f, Tuple{args...})
173190

174-
function doc(f::Function, m::Method)
175-
for mod in modules
176-
haskey(meta(mod), f) && isa(meta(mod)[f], FuncDoc) && haskey(meta(mod)[f].meta, m) &&
177-
return meta(mod)[f].meta[m]
178-
end
179-
end
180191

181192
"""
182193
`catdoc(xs...)`: Combine the documentation metadata `xs` into a single meta object.
@@ -209,7 +220,7 @@ end
209220
type TypeDoc
210221
main
211222
fields::Dict{Symbol, Any}
212-
order::Vector{Method}
223+
order::Vector{Type}
213224
meta::ObjectIdDict
214225
end
215226

@@ -221,11 +232,11 @@ function doc!(t::DataType, data, fields)
221232
td.fields = fields
222233
end
223234

224-
function doc!(f::DataType, m::Method, data, source)
235+
function doc!(f::DataType, sig::ANY, data, source)
225236
td = get!(meta(), f, TypeDoc())
226237
isa(td, TypeDoc) || error("Can't document a method when the type already has metadata")
227-
!haskey(td.meta, m) && push!(td.order, m)
228-
td.meta[m] = data
238+
!haskey(td.meta, sig) && push!(td.order, sig)
239+
td.meta[sig] = data
229240
end
230241

231242
function doc(f::DataType)
@@ -251,19 +262,17 @@ isfield(x) = isexpr(x, :.) &&
251262
isexpr(x.args[2], QuoteNode, :quote)
252263

253264
function fielddoc(T, k)
254-
for mod in modules
255-
if haskey(meta(mod), T) && isa(meta(mod)[T], TypeDoc) && haskey(meta(mod)[T].fields, k)
256-
return meta(mod)[T].fields[k]
257-
end
265+
for mod in modules
266+
if haskey(meta(mod), T) && isa(meta(mod)[T], TypeDoc) && haskey(meta(mod)[T].fields, k)
267+
return meta(mod)[T].fields[k]
268+
end
258269
end
259270
Text(sprint(io -> (print(io, "$T has fields: ");
260271
print_joined(io, fieldnames(T), ", ", " and "))))
261272
end
262273

263274
# Generic Callables
264275

265-
doc(f, ::Method) = doc(f)
266-
267276
# Modules
268277

269278
function doc(m::Module)
@@ -318,11 +327,10 @@ end
318327

319328
function funcdoc(meta, def, def′)
320329
f = esc(namify(def′))
321-
m = :(methods($f, $(esc(signature(def′))))[end])
322330
quote
323331
@init
324332
$(esc(def))
325-
doc!($f, $m, $(mdify(meta)), $(esc(quot(def′))))
333+
doc!($f, $(esc(signature(def′))), $(mdify(meta)), $(esc(quot(def′))))
326334
$f
327335
end
328336
end
@@ -400,11 +408,7 @@ end
400408

401409
function findmethod(ex)
402410
f = esc(namify(ex.args[1]))
403-
if any(x -> isexpr(x, :(::)), ex.args)
404-
:(doc($f, methods($f, $(esc(signature(ex))))[1]))
405-
else
406-
:(doc($f, @which($(esc(ex)))))
407-
end
411+
:(doc($f, $(esc(signature(ex)))))
408412
end
409413

410414
# Swap out the bootstrap macro with the real one

base/docs/basedocs.jl

+17-6
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,20 @@ keywords[symbol(";")] = doc"""
218218
interfaces.
219219
"""
220220

221+
keywords[:(&&)] = doc"""
222+
x && y
223+
224+
Short-circuiting boolean AND
225+
"""
226+
227+
keywords[:(||)] = doc"""
228+
x || y
229+
230+
Short-circuiting boolean OR
231+
"""
232+
221233
keywords[:ccall] = doc"""
222-
ccall((symbol, library) or function_pointer, ReturnType,
223-
(ArgumentType1, ...),
224-
ArgumentValue1, ...)
234+
ccall((symbol, library) or function_pointer, ReturnType, (ArgumentType1, ...), ArgumentValue1, ...)
225235
226236
Call function in C-exported shared library, specified by
227237
`(function name, library)` tuple, where each component is a string
@@ -297,6 +307,7 @@ keywords[:immutable] = doc"""
297307
# :@time
298308

299309
doc"""
310+
@r_str -> Regex
300311
Construct a regex, such as `r"^[a-z]*$"`. The regex also accepts
301312
one or more flags, listed after the ending quote, to change its
302313
behaviour:
@@ -327,7 +338,7 @@ For example, this regex has all three flags enabled:
327338
if Base.USE_GPL_LIBS
328339

329340
@doc doc"""
330-
fft(A[, dims])
341+
fft(A [, dims])
331342
332343
Performs a multidimensional FFT of the array `A`. The optional
333344
`dims` argument specifies an iterable subset of dimensions (e.g.
@@ -355,7 +366,7 @@ processors.
355366
end # USE_GPL_LIBS
356367

357368
"""
358-
include("file.jl")
369+
include(path::AbstractString)
359370
360371
Evaluate the contents of a source file in the current context.
361372
During including, a task-local include path is set to the directory
@@ -366,7 +377,7 @@ function is typically used to load source interactively, or to
366377
combine files in packages that are broken into multiple source
367378
files.
368379
"""
369-
include_from_node1
380+
include_from_node1(::AbstractString)
370381

371382
"""
372383
0 (zero; BrE: `/ˈzɪərəʊ/` or AmE: `/ˈziːroʊ/`) is both a number and the numerical digit used to represent that number in numerals. It fulfills a central role in mathematics as the additive identity of the integers, real numbers, and many other algebraic structures. As a digit, 0 is used as a placeholder in place value systems. Names for the number 0 in English include zero, nought or (US) naught (`/ˈnɔːt/`), nil, or — in contexts where at least one adjacent digit distinguishes it from the letter "O" — oh or o (`/ˈoʊ/`). Informal or slang terms for zero include zilch and zip. Ought and aught (/ˈɔːt/), as well as cipher, have also been used historically.

0 commit comments

Comments
 (0)