Skip to content

Commit 239de6c

Browse files
authored
Merge pull request #1701 from ahoppen/ahoppen/doc-improvements
Improve doc comments based on review comments
2 parents 4c0ad1b + b5c7d97 commit 239de6c

File tree

10 files changed

+40
-45
lines changed

10 files changed

+40
-45
lines changed

Sources/SwiftParserDiagnostics/LexerDiagnosticMessages.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ public extension SwiftSyntax.TokenDiagnostic {
204204
}
205205
let replacedText =
206206
text
207-
.replacingFirstOccurence(of: "", with: #"""#)
208-
.replacingLastOccurence(of: "", with: #"""#)
207+
.replacingFirstOccurrence(of: "", with: #"""#)
208+
.replacingLastOccurrence(of: "", with: #"""#)
209209

210210
let fixedToken = token.with(\.tokenKind, TokenKind.fromRaw(kind: rawKind, text: replacedText))
211211
return [

Sources/SwiftParserDiagnostics/Utils.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
extension String {
1414
/// Returns this string with the first letter uppercased.
1515
///
16-
/// If thes string does not start with a letter, no change is made to it.
16+
/// If the string does not start with a letter, no change is made to it.
1717
func withFirstLetterUppercased() -> String {
1818
if let firstLetter = self.first {
1919
return firstLetter.uppercased() + self.dropFirst()
@@ -22,20 +22,20 @@ extension String {
2222
}
2323
}
2424

25-
/// Replace the first occurance of `character` with `replacement`.
25+
/// Replace the first occurrence of `character` with `replacement`.
2626
///
2727
/// If `character` does not occur in this string, no change is made.
28-
func replacingFirstOccurence(of character: Character, with replacement: Character) -> String {
28+
func replacingFirstOccurrence(of character: Character, with replacement: Character) -> String {
2929
guard let match = self.firstIndex(of: character) else {
3030
return self
3131
}
3232
return self[startIndex..<match] + String(replacement) + self[index(after: match)...]
3333
}
3434

35-
/// Replace the last occurance of `character` with `replacement`.
35+
/// Replace the last occurrence of `character` with `replacement`.
3636
///
3737
/// If `character` does not occur in this string, no change is made.
38-
func replacingLastOccurence(of character: Character, with replacement: Character) -> String {
38+
func replacingLastOccurrence(of character: Character, with replacement: Character) -> String {
3939
guard let match = self.lastIndex(of: character) else {
4040
return self
4141
}

Sources/SwiftSyntax/BumpPtrAllocator.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A `BumpPtrAllocator` that allocates `slabSize` at a time.
13+
/// A ``BumpPtrAllocator`` that allocates `slabSize` at a time.
1414
/// Once all memory in a slab has been used, it allocates a new slab and no
1515
/// memory allocations are necessary until that slab is completely filled up.
1616
@_spi(RawSyntax) @_spi(Testing)
@@ -37,9 +37,7 @@ public class BumpPtrAllocator {
3737
private var customSizeSlabs: [Slab]
3838
private var _totalBytesAllocated: Int
3939

40-
/// Construct a new ``BumpPtrAllocator`` that allocates `slabSize` at a time.
41-
/// Once all memory in a slab has been used, it allocates a new slab and no
42-
/// memory allocations are necessary until that slab is completely filled up.
40+
/// Construct a new ``BumpPtrAllocator``.
4341
public init(slabSize: Int) {
4442
self.slabSize = slabSize
4543
slabs = []

Sources/SwiftSyntax/SourceLocation.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,22 @@ public struct SourceLocation: Hashable, Codable, CustomDebugStringConvertible {
5555
}
5656
}
5757

58-
/// Represents a start and end location in a Swift file.
58+
/// Represents a half-open range in a Swift file.
5959
public struct SourceRange: Hashable, Codable, CustomDebugStringConvertible {
6060

61-
/// The beginning location in the source range.
61+
/// The beginning location of the source range.
6262
///
6363
/// This location is included in the range
6464
public let start: SourceLocation
6565

66-
/// The beginning location in the source range.
66+
/// The end location of the source range.
6767
///
68-
/// This location is no longer part of the range
68+
/// The location of the character after the end of the range,
69+
/// ie. this location is not included in the range.
6970
public let end: SourceLocation
7071

71-
/// A description describing this range for debugging purposes, don't rely on it.
72+
/// A description describing this range for debugging purposes, don't rely on
73+
/// it being stable
7274
public var debugDescription: String {
7375
return "(\(start.debugDescription),\(end.debugDescription))"
7476
}

Sources/SwiftSyntax/Syntax.swift

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
5959

6060
/// Needed for the conformance to ``SyntaxProtocol``.
6161
///
62-
/// Kind of non-sensical on `Syntax` since this just returns `self`.
62+
/// Needed for the conformance to ``SyntaxProtocol``. Just returns `self`.
6363
public var _syntaxNode: Syntax {
6464
return self
6565
}
@@ -73,12 +73,12 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
7373
self.init(.forRoot(raw))
7474
}
7575

76-
/// Create a `Syntax` node from a specialized syntax node.
76+
/// Create a ``Syntax`` node from a specialized syntax node.
7777
public init(_ syntax: some SyntaxProtocol) {
7878
self = syntax._syntaxNode
7979
}
8080

81-
/// Creates a new `Syntax` node from any concrete node that conforms to `SyntaxProtocol`.
81+
/// Creates a new `Syntax` node from any node that conforms to ``SyntaxProtocol``.
8282
public init(fromProtocol syntax: SyntaxProtocol) {
8383
self = syntax._syntaxNode
8484
}
@@ -111,14 +111,7 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
111111
/// Returns `true` if `rhs` and `lhs` have the same ID.
112112
///
113113
/// Note `lhs` and `rhs` might have the same contents even if their IDs are
114-
/// different. For example two different `FunctionDeclSyntax` nodes in the
115-
/// might have the exact same contents but if they occur at a different
116-
/// location in the source file, they have different IDs.
117-
///
118-
/// Also note that the ID of a syntax node changes when it is anchored in a
119-
/// different syntax tree. Modifying any node in the syntax tree a node is
120-
/// contained in generates a copy of that tree and thus changes the IDs of all
121-
/// nodes in the tree, not just the modified node's children.
114+
/// different. See documentation on ``SyntaxIdentifier``.
122115
public static func == (lhs: Syntax, rhs: Syntax) -> Bool {
123116
return lhs.data.nodeId == rhs.data.nodeId
124117
}
@@ -244,11 +237,11 @@ extension SyntaxProtocol {
244237
return raw.kind
245238
}
246239

247-
/// The dynamic metatype of this node. You almost always want to prefer this
248-
/// over `type(of: self)` because if `self` is a `DeclSyntax` representing a
249-
/// `FunctionDeclSyntax`, `type(of: self)` will return `DeclSyntax`, while
240+
/// The dynamic metatype of the concrete node. You almost always want to prefer this
241+
/// over `type(of: self)` because if `self` is a ``DeclSyntax`` representing a
242+
/// ``FunctionDeclSyntax``, `type(of: self)` will return `DeclSyntax`, while
250243
/// `syntaxNodeType` looks at the dynamic kind of this node and returns
251-
/// `FunctionDeclSyntax`.
244+
/// ``FunctionDeclSyntax``.
252245
public var syntaxNodeType: SyntaxProtocol.Type {
253246
return self.raw.kind.syntaxNodeType
254247
}
@@ -780,7 +773,7 @@ public struct ReversedTokenSequence: Sequence {
780773
}
781774

782775
/// Returns the next element in a ``ReversedTokenSequence``, i.e. the one
783-
/// that occured before the current token in source order.
776+
/// that occurred before the current token in source order.
784777
public mutating func next() -> TokenSyntax? {
785778
guard let token = self.nextToken else { return nil }
786779
self.nextToken = token.previousToken(viewMode: viewMode)

Sources/SwiftSyntax/SyntaxArena.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
/// chunk of memory at a time, which it can then use to store syntax nodes in.
2222
/// This way, only a single memory allocation needs to be performed for multiple
2323
/// syntax nodes and since memory allocations have a non-trivial cost, this
24-
/// signficiantly speeds up parsing.
24+
/// significantly speeds up parsing.
2525
///
2626
/// As a consequence, syntax nodes cannot be freed individually but the memory
2727
/// will get freed once the owning ``SyntaxArena`` gets freed. Thus, it needs to
28-
/// be manually ensured that the ``SyntaxArena`` is not deallocated before any
28+
/// be manually ensured that the ``SyntaxArena`` is not deallocated while any
2929
/// of its nodes are being accessed. The ``SyntaxData`` type ensures this as
30-
/// follows: Each node retains its parent ``SyntaxData``, thus keeping it alive.
31-
/// The tree’s root keeps the ``SyntaxArena`` it is contained in alive. And if
32-
/// any children of this tree are allocated within a different ``SyntaxArena``,
33-
/// the root arena keeps those arenas alive via the `childRefs` property.
30+
/// follows:
31+
/// - The root node has a strong reference to its ``SyntaxArena``
32+
/// - Each node retains its parent ``SyntaxData``, thus keeping it alive.
33+
/// - If any node is allocated within a different ``SyntaxArena``, that arena
34+
/// is added to the root's `childRefs` property and thus kept a live as long
35+
/// as the parent tree is alive.
3436
///
35-
/// As an added benefit of the ``SyntaxArena``, `RawSyntax` nodes don’t need to
37+
/// As an added benefit of the ``SyntaxArena``, ``RawSyntax`` nodes don’t need to
3638
/// be reference-counted, further improving the performance of ``SwiftSyntax``
3739
/// when worked with at that level.
3840
public class SyntaxArena {

Sources/SwiftSyntax/SyntaxData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public struct SyntaxIndexInTree: Comparable, Hashable {
9393
}
9494
}
9595

96-
/// Provides a stable and unique identity for `Syntax` nodes.
96+
/// Provides a stable and unique identity for ``Syntax`` nodes.
9797
///
9898
/// Note that two nodes might have the same contents even if their IDs are
99-
/// different. For example two different `FunctionDeclSyntax` nodes in the
99+
/// different. For example two different ``FunctionDeclSyntax`` nodes in the
100100
/// might have the exact same contents but if they occur at a different
101101
/// location in the source file, they have different IDs.
102102
///

Sources/SwiftSyntax/SyntaxText.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ extension SyntaxText: CustomStringConvertible {
222222

223223
extension SyntaxText: CustomDebugStringConvertible {
224224
/// The string value of this text, which may be lossy if the text contains
225-
/// invalid Unicode.
225+
/// invalid Unicode. Don’t rely on this value being stable.
226226
public var debugDescription: String { description.debugDescription }
227227
}
228228

Sources/SwiftSyntax/TokenDiagnostic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public struct TokenDiagnostic: Hashable {
116116
/// Since the offset within the token is represented by 16 bits only,
117117
/// diagnostics that are more than 2^16 bytes from the token's start cannot
118118
/// be represented. In that case, emit a `tokenDiagnosticOffsetOverflow`
119-
/// diagnostic at the token’s start. 2^16 are quite a lot of characters for
119+
/// diagnostic at the token’s start. 2^16 is quite a lot of characters for
120120
/// a single token (even when we include comments as trivia), so we don’t
121-
/// expect to hit this case in the vast majority.
121+
/// expect to hit this case most of the time.
122122
public init(_ kind: Kind, byteOffset: Int) {
123123
precondition(byteOffset >= 0)
124124
// `type(of: self.byteOffset).max` gets optimized to a constant

Sources/SwiftSyntax/TokenSyntax.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
152152
}
153153

154154
extension TokenSyntax: CustomReflectable {
155-
/// A custom mirror that shows the token properties in a better for, making
155+
/// A custom mirror that shows the token properties in a simpler form, making
156156
/// the debug output of the token easier to read.
157157
public var customMirror: Mirror {
158158
return Mirror(

0 commit comments

Comments
 (0)