Skip to content

Commit ad0712f

Browse files
authored
various minor changes to the documentation (#50879)
A small contribution to an improved documentation. I've bundled a few tiny, unrelated changes together instead of submitting many PRs. Let me know if you prefer it differently or if you want any other change. Some comments: `llvmcall`: The file `test/llvmcall.jl` was mentioned. I've added a link to GitHub. However, it works only for tagged version. Improvements welcome. `@sync`: I would like to add links to `Distributed.@spawnat` and `Distributed.@distributed`, but I don't know how to do it from one package (Base) to another. I once asked about it on [Discourse](https://discourse.julialang.org/t/documentation-how-to-add-cross-references-to-functions-in-other-modules/88504), but didn't get an answer. `hasfastin`: now mentioned in the documentation
1 parent 15b590b commit ad0712f

File tree

14 files changed

+52
-16
lines changed

14 files changed

+52
-16
lines changed

base/abstractset.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,17 @@ function issubset(a, b)
338338
end
339339

340340
"""
341-
hasfastin(T)
341+
Base.hasfastin(T)
342342
343343
Determine whether the computation `x ∈ collection` where `collection::T` can be considered
344344
as a "fast" operation (typically constant or logarithmic complexity).
345345
The definition `hasfastin(x) = hasfastin(typeof(x))` is provided for convenience so that instances
346346
can be passed instead of types.
347347
However the form that accepts a type argument should be defined for new types.
348+
349+
The default for `hasfastin(T)` is `true` for subtypes of
350+
[`AbstractSet`](@ref), [`AbstractDict`](@ref) and [`AbstractRange`](@ref)
351+
and `false` otherwise.
348352
"""
349353
hasfastin(::Type) = false
350354
hasfastin(::Union{Type{<:AbstractSet},Type{<:AbstractDict},Type{<:AbstractRange}}) = true

base/docs/basedocs.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,11 @@ a tuple of types. All types, as well as the LLVM code, should be specified as li
13151315
not as variables or expressions (it may be necessary to use `@eval` to generate these
13161316
literals).
13171317
1318-
See `test/llvmcall.jl` for usage examples.
1318+
[Opaque pointers](https://llvm.org/docs/OpaquePointers.html) (written as `ptr`) are not allowed in the LLVM code.
1319+
1320+
See
1321+
[`test/llvmcall.jl`](https://github.com/JuliaLang/julia/blob/v$VERSION/test/llvmcall.jl)
1322+
for usage examples.
13191323
"""
13201324
Core.Intrinsics.llvmcall
13211325

base/essentials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ end
346346
pairs(::Type{NamedTuple}) = Pairs{Symbol, V, NTuple{N, Symbol}, NamedTuple{names, T}} where {V, N, names, T<:NTuple{N, Any}}
347347

348348
"""
349-
Iterators.Pairs(values, keys) <: AbstractDict{eltype(keys), eltype(values)}
349+
Base.Pairs(values, keys) <: AbstractDict{eltype(keys), eltype(values)}
350350
351351
Transforms an indexable container into a Dictionary-view of the same data.
352352
Modifying the key-space of the underlying data may invalidate this object.

base/experimental.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ end
8686
"""
8787
Experimental.@sync
8888
89-
Wait until all lexically-enclosed uses of `@async`, `@spawn`, `@spawnat` and `@distributed`
89+
Wait until all lexically-enclosed uses of [`@async`](@ref), [`@spawn`](@ref Threads.@spawn),
90+
`Distributed.@spawnat` and `Distributed.@distributed`
9091
are complete, or at least one of them has errored. The first exception is immediately
9192
rethrown. It is the responsibility of the user to cancel any still-running operations
9293
during error handling.

base/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ The `:terminates_globally` settings asserts that this method will eventually ter
581581
582582
!!! note
583583
The compiler will consider this a strong indication that the method will
584-
terminate relatively *quickly* and may (if otherwise legal), call this
584+
terminate relatively *quickly* and may (if otherwise legal) call this
585585
method at compile time. I.e. it is a bad idea to annotate this setting
586586
on a method that *technically*, but not *practically*, terminates.
587587

base/lock.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Creates a re-entrant lock for synchronizing [`Task`](@ref)s. The same task can
1010
acquire the lock as many times as required (this is what the "Reentrant" part
1111
of the name means). Each [`lock`](@ref) must be matched with an [`unlock`](@ref).
1212
13-
Calling 'lock' will also inhibit running of finalizers on that thread until the
14-
corresponding 'unlock'. Use of the standard lock pattern illustrated below
13+
Calling `lock` will also inhibit running of finalizers on that thread until the
14+
corresponding `unlock`. Use of the standard lock pattern illustrated below
1515
should naturally be supported, but beware of inverting the try/lock order or
1616
missing the try block entirely (e.g. attempting to return with the lock still
1717
held):

base/reflection.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ ismutable(@nospecialize(x)) = (@_total_meta; typeof(x).name.flags & 0x2 == 0x2)
521521
522522
Determine whether type `T` was declared as a mutable type
523523
(i.e. using `mutable struct` keyword).
524+
If `T` is not a type, then return `false`.
524525
525526
!!! compat "Julia 1.7"
526527
This function requires at least Julia 1.7.
@@ -539,6 +540,7 @@ ismutabletypename(tn::Core.TypeName) = tn.flags & 0x2 == 0x2
539540
540541
Determine whether type `T` was declared as a struct type
541542
(i.e. using the `struct` or `mutable struct` keyword).
543+
If `T` is not a type, then return `false`.
542544
"""
543545
function isstructtype(@nospecialize t)
544546
@_total_meta
@@ -553,6 +555,7 @@ end
553555
554556
Determine whether type `T` was declared as a primitive type
555557
(i.e. using the `primitive type` syntax).
558+
If `T` is not a type, then return `false`.
556559
"""
557560
function isprimitivetype(@nospecialize t)
558561
@_total_meta
@@ -573,6 +576,7 @@ Typical examples are numeric types such as [`UInt8`](@ref),
573576
This category of types is significant since they are valid as type parameters,
574577
may not track [`isdefined`](@ref) / [`isassigned`](@ref) status,
575578
and have a defined layout that is compatible with C.
579+
If `T` is not a type, then return `false`.
576580
577581
See also [`isbits`](@ref), [`isprimitivetype`](@ref), [`ismutable`](@ref).
578582
@@ -622,18 +626,20 @@ _objectid(@nospecialize(x)) = ccall(:jl_object_id, UInt, (Any,), x)
622626
Determine whether type `T` is a tuple "leaf type",
623627
meaning it could appear as a type signature in dispatch
624628
and has no subtypes (or supertypes) which could appear in a call.
629+
If `T` is not a type, then return `false`.
625630
"""
626631
isdispatchtuple(@nospecialize(t)) = (@_total_meta; isa(t, DataType) && (t.flags & 0x0004) == 0x0004)
627632

628633
datatype_ismutationfree(dt::DataType) = (@_total_meta; (dt.flags & 0x0100) == 0x0100)
629634

630635
"""
631-
ismutationfree(T)
636+
Base.ismutationfree(T)
632637
633638
Determine whether type `T` is mutation free in the sense that no mutable memory
634639
is reachable from this type (either in the type itself) or through any fields.
635640
Note that the type itself need not be immutable. For example, an empty mutable
636641
type is `ismutabletype`, but also `ismutationfree`.
642+
If `T` is not a type, then return `false`.
637643
"""
638644
function ismutationfree(@nospecialize(t))
639645
t = unwrap_unionall(t)
@@ -649,10 +655,11 @@ end
649655
datatype_isidentityfree(dt::DataType) = (@_total_meta; (dt.flags & 0x0200) == 0x0200)
650656

651657
"""
652-
isidentityfree(T)
658+
Base.isidentityfree(T)
653659
654660
Determine whether type `T` is identity free in the sense that this type or any
655661
reachable through its fields has non-content-based identity.
662+
If `T` is not a type, then return `false`.
656663
"""
657664
function isidentityfree(@nospecialize(t))
658665
t = unwrap_unionall(t)
@@ -684,6 +691,8 @@ isType(@nospecialize t) = isa(t, DataType) && t.name === _TYPE_NAME
684691
685692
Determine whether type `T` is a concrete type, meaning it could have direct instances
686693
(values `x` such that `typeof(x) === T`).
694+
Note that this is not the negation of `isabstracttype(T)`.
695+
If `T` is not a type, then return `false`.
687696
688697
See also: [`isbits`](@ref), [`isabstracttype`](@ref), [`issingletontype`](@ref).
689698
@@ -715,6 +724,8 @@ isconcretetype(@nospecialize(t)) = (@_total_meta; isa(t, DataType) && (t.flags &
715724
716725
Determine whether type `T` was declared as an abstract type
717726
(i.e. using the `abstract type` syntax).
727+
Note that this is not the negation of `isconcretetype(T)`.
728+
If `T` is not a type, then return `false`.
718729
719730
# Examples
720731
```jldoctest
@@ -737,6 +748,7 @@ end
737748
738749
Determine whether type `T` has exactly one possible instance; for example, a
739750
struct type with no fields.
751+
If `T` is not a type, then return `false`.
740752
"""
741753
issingletontype(@nospecialize(t)) = (@_total_meta; isa(t, DataType) && isdefined(t, :instance))
742754

base/strings/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ types may choose different "imaginary" character sizes as makes sense for their
2929
implementations (e.g. substrings may pass index arithmetic through to the
3030
underlying string they provide a view into). Relaxed indexing functions include
3131
those intended for index arithmetic: `thisind`, `nextind` and `prevind`. This
32-
model allows index arithmetic to work with out-of- bounds indices as
32+
model allows index arithmetic to work with out-of-bounds indices as
3333
intermediate values so long as one never uses them to retrieve a character,
3434
which often helps avoid needing to code around edge cases.
3535

base/task.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ const sync_varname = gensym(:sync)
457457
"""
458458
@sync
459459
460-
Wait until all lexically-enclosed uses of [`@async`](@ref), [`@spawn`](@ref Threads.@spawn), `@spawnat` and `@distributed`
460+
Wait until all lexically-enclosed uses of [`@async`](@ref), [`@spawn`](@ref Threads.@spawn),
461+
`Distributed.@spawnat` and `Distributed.@distributed`
461462
are complete. All exceptions thrown by enclosed async operations are collected and thrown as
462463
a [`CompositeException`](@ref).
463464

doc/src/base/collections.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Fully implemented by:
8989
```@docs
9090
Base.in
9191
Base.:∉
92+
Base.hasfastin
9293
Base.eltype
9394
Base.indexin
9495
Base.unique

doc/src/manual/functions.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ julia> function (x)
297297
#3 (generic function with 1 method)
298298
```
299299

300-
This creates a function taking one argument `x` and returning the value of the polynomial `x^2 +
300+
Each statement creates a function taking one argument `x` and returning the value of the polynomial `x^2 +
301301
2x - 1` at that value. Notice that the result is a generic function, but with a compiler-generated
302302
name based on consecutive numbering.
303303

@@ -327,6 +327,9 @@ julia> map(x -> x^2 + 2x - 1, [1, 3, -1])
327327
```
328328

329329
An anonymous function accepting multiple arguments can be written using the syntax `(x,y,z)->2x+y-z`.
330+
Argument-type declarations for anonymous functions work as for named functions, for example `x::Integer->2x`.
331+
The return type of an anonymous function cannot be specified.
332+
330333
A zero-argument anonymous function is written as `()->3`. The idea of a function with no arguments
331334
may seem strange, but is useful for "delaying" a computation. In this usage, a block of code is
332335
wrapped in a zero-argument function, which is later invoked by calling it as `f`.
@@ -981,7 +984,7 @@ can create performance challenges as discussed in [performance tips](@ref man-pe
981984
Functions in Julia can be combined by composing or piping (chaining) them together.
982985

983986
Function composition is when you combine functions together and apply the resulting composition to arguments.
984-
You use the function composition operator (``) to compose the functions, so `(f ∘ g)(args...)` is the same as `f(g(args...))`.
987+
You use the function composition operator (``) to compose the functions, so `(f ∘ g)(args...; kw...)` is the same as `f(g(args...; kw...))`.
985988

986989
You can type the composition operator at the REPL and suitably-configured editors using `\circ<tab>`.
987990

doc/src/manual/multi-threading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ threads in Julia:
439439
multiple threads where at least one thread modifies the collection
440440
(common examples include `push!` on arrays, or inserting
441441
items into a `Dict`).
442-
* The schedule used by `@spawn` is nondeterministic and should not be relied on.
442+
* The schedule used by [`@spawn`](@ref Threads.@spawn) is nondeterministic and should not be relied on.
443443
* Compute-bound, non-memory-allocating tasks can prevent garbage collection from
444444
running in other threads that are allocating memory. In these cases it may
445445
be necessary to insert a manual call to `GC.safepoint()` to allow GC to run.

doc/src/manual/style-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Instead of:
9696

9797
```julia
9898
function double(a::AbstractArray{<:Number})
99-
for i = firstindex(a):lastindex(a)
99+
for i in eachindex(a)
100100
a[i] *= 2
101101
end
102102
return a
@@ -107,7 +107,7 @@ use:
107107

108108
```julia
109109
function double!(a::AbstractArray{<:Number})
110-
for i = firstindex(a):lastindex(a)
110+
for i in eachindex(a)
111111
a[i] *= 2
112112
end
113113
return a

doc/src/manual/types.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,16 @@ type -- either [`Int32`](@ref) or [`Int64`](@ref).
13381338
reflects the size of a native pointer on that machine, the floating point register sizes
13391339
are specified by the IEEE-754 standard.)
13401340

1341+
Type aliases may be parametrized:
1342+
1343+
```jldoctest
1344+
julia> const Family{T} = Set{T}
1345+
Set
1346+
1347+
julia> Family{Char} === Set{Char}
1348+
true
1349+
```
1350+
13411351
## Operations on Types
13421352

13431353
Since types in Julia are themselves objects, ordinary functions can operate on them. Some functions

0 commit comments

Comments
 (0)