Skip to content

Commit d9882f0

Browse files
committed
[NFC] Rename 'arena:' argument labels
1 parent ca5b6d4 commit d9882f0

17 files changed

+1935
-1915
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
163163
AccessorDeclSyntax(
164164
"""
165165
set(value) {
166-
self = Syntax(self).replacingChild(at: \(raw: index), with: Syntax(value), arena: RawSyntaxArena()).cast(\(node.kind.syntaxType).self)
166+
self = Syntax(self).replacingChild(at: \(raw: index), with: Syntax(value), rawAllocationArena: RawSyntaxArena()).cast(\(node.kind.syntaxType).self)
167167
}
168168
"""
169169
)
@@ -200,7 +200,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
200200
from: [element.raw], arena: arena)
201201
}
202202
return Syntax(self)
203-
.replacingChild(at: \(raw: index), with: collection, rawNodeArena: arena, allocationArena: arena)
203+
.replacingChild(at: \(raw: index), with: collection, rawNodeArena: arena, rawAllocationArena: arena)
204204
.cast(\(node.kind.syntaxType).self)
205205
}
206206
"""

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxRewriterFile.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,30 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3333
DeclSyntax("public let viewMode: SyntaxTreeViewMode")
3434
DeclSyntax(
3535
"""
36-
/// The arena in which the parents of rewritten nodes should be allocated.
36+
/// The raw arena in which the parents of rewritten nodes should be allocated.
3737
///
3838
/// The `SyntaxRewriter` subclass is responsible for generating the rewritten nodes. To incorporate them into the
3939
/// tree, all of the rewritten node's parents also need to be re-created. This is the arena in which those
40-
/// intermediate nodes should be allocated.
41-
private let arena: RawSyntaxArena?
40+
/// intermediate raw nodes should be allocated.
41+
private let rawArena: RawSyntaxArena?
4242
"""
4343
)
4444

4545
DeclSyntax(
4646
"""
4747
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate) {
4848
self.viewMode = viewMode
49-
self.arena = nil
49+
self.rawArena = nil
5050
}
5151
"""
5252
)
5353

5454
DeclSyntax(
5555
"""
5656
@_spi(RawSyntax)
57-
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, arena: RawSyntaxArena? = nil) {
57+
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, rawAllocationArena: RawSyntaxArena? = nil) {
5858
self.viewMode = viewMode
59-
self.arena = arena
59+
self.rawArena = rawAllocationArena
6060
}
6161
"""
6262
)
@@ -71,7 +71,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
7171
}
7272
7373
return withExtendedLifetime(rewritten) {
74-
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, allocationArena: RawSyntaxArena())
74+
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, rawAllocationArena: RawSyntaxArena())
7575
}
7676
}
7777
"""
@@ -347,13 +347,13 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
347347
if newLayout.baseAddress != nil {
348348
// A child node was rewritten. Build the updated node.
349349
350-
let arena = self.arena ?? RawSyntaxArena()
351-
let newRaw = node.raw.layoutView!.replacingLayout(with: newLayout, arena: arena)
350+
let rawArena = self.rawArena ?? RawSyntaxArena()
351+
let newRaw = node.raw.layoutView!.replacingLayout(with: newLayout, arena: rawArena)
352352
newLayout.deinitialize()
353353
newLayout.deallocate()
354354
// 'withExtendedLifetime' to keep 'RawSyntaxArena's of them alive until here.
355355
return withExtendedLifetime(rewrittens) {
356-
Syntax(raw: newRaw, rawNodeArena: arena)
356+
Syntax(raw: newRaw, rawNodeArena: rawArena)
357357
}
358358
} else {
359359
// No child node was rewritten. So no need to change this node as well.

Sources/SwiftParser/Parser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ extension Parser {
831831

832832
/// Creates a replicate of `syntax` with all tokens marked as missing.
833833
func withAllTokensMarkedMissing<T: RawSyntaxNodeProtocol>(syntax: T) -> T {
834-
let tokenMissingMaker = TokenMissingMaker(arena: self.arena)
834+
let tokenMissingMaker = TokenMissingMaker(rawAllocationArena: self.arena)
835835
let allMissing = tokenMissingMaker.rewrite(
836836
Syntax(raw: RawSyntax(syntax), rawNodeArena: self.arena)
837837
).raw

Sources/SwiftSyntax/Syntax.swift

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,14 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
144144
/// - Parameters:
145145
/// - newRaw: The node that should replace `self`
146146
/// - rawNodeArena: The arena in which `newRaw` resides
147-
/// - allocationArena: The arena in which new nodes should be allocated
147+
/// - rawAllocationArena: The arena in which new nodes should be allocated
148148
/// - Returns: A syntax tree with all parents where this node has been
149149
/// replaced by `newRaw`
150-
func replacingSelf(_ newRaw: RawSyntax, rawNodeArena: RetainedRawSyntaxArena, allocationArena: RawSyntaxArena) -> Syntax {
150+
func replacingSelf(
151+
_ newRaw: RawSyntax,
152+
rawNodeArena: RetainedRawSyntaxArena,
153+
rawAllocationArena: RawSyntaxArena
154+
) -> Syntax {
151155
precondition(newRaw.arenaReference == rawNodeArena)
152156
// If we have a parent already, then ask our current parent to copy itself
153157
// recursively up to the root.
@@ -156,7 +160,7 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
156160
at: layoutIndexInParent,
157161
with: newRaw,
158162
rawNodeArena: rawNodeArena,
159-
allocationArena: allocationArena
163+
rawAllocationArena: rawAllocationArena
160164
)
161165
return newParent.child(at: layoutIndexInParent)!
162166
} else {
@@ -172,75 +176,91 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
172176
/// - index: The index pointing to where in the raw layout to place this
173177
/// child.
174178
/// - newChild: The raw syntax for the new child to replace.
175-
/// - newChildArena: The arena in which `newChild` resides.
176-
/// - arena: The arena in which the new node will be allocated.
179+
/// - rawNodeArena: The arena in which `newChild` resides.
180+
/// - rawAllocationArena: The arena in which the new node will be allocated.
177181
/// - Returns: The new root node created by this operation, and the new child
178182
/// syntax data.
179183
/// - SeeAlso: replacingSelf(_:)
180184
func replacingChild(
181185
at index: Int,
182186
with newChild: RawSyntax?,
183187
rawNodeArena: RetainedRawSyntaxArena?,
184-
allocationArena: RawSyntaxArena
188+
rawAllocationArena: RawSyntaxArena
185189
) -> Syntax {
186190
precondition(newChild == nil || (rawNodeArena != nil && newChild!.arenaReference == rawNodeArena!))
187191
// After newRaw has been allocated in `allocationArena`, `rawNodeArena` will
188192
// be a child arena of `allocationArena` and thus, `allocationArena` will
189193
// keep `newChild` alive.
190194
let newRaw = withExtendedLifetime(rawNodeArena) {
191-
raw.layoutView!.replacingChild(at: index, with: newChild, arena: allocationArena)
195+
raw.layoutView!.replacingChild(at: index, with: newChild, arena: rawAllocationArena)
192196
}
193-
return replacingSelf(newRaw, rawNodeArena: RetainedRawSyntaxArena(allocationArena), allocationArena: allocationArena)
197+
return replacingSelf(
198+
newRaw,
199+
rawNodeArena: RetainedRawSyntaxArena(rawAllocationArena),
200+
rawAllocationArena: rawAllocationArena
201+
)
194202
}
195203

196-
/// Same as `replacingChild(at:with:rawNodeArena:allocationArena:)` but takes a `__RawSyntaxArena` instead of a `RetainedRawSyntaxArena`.
204+
/// Same as `replacingChild(at:with:rawNodeArena:rawAllocationArena:)` but takes a `__RawSyntaxArena` instead of a `RetainedRawSyntaxArena`.
197205
func replacingChild(
198206
at index: Int,
199207
with newChild: RawSyntax?,
200208
rawNodeArena: RawSyntaxArena?,
201-
allocationArena: RawSyntaxArena
209+
rawAllocationArena: RawSyntaxArena
202210
) -> Syntax {
203211
return self.replacingChild(
204212
at: index,
205213
with: newChild,
206214
rawNodeArena: rawNodeArena.map(RetainedRawSyntaxArena.init),
207-
allocationArena: allocationArena
215+
rawAllocationArena: rawAllocationArena
208216
)
209217
}
210218

211-
/// Identical to `replacingChild(at: Int, with: RawSyntax?, arena: RawSyntaxArena)`
219+
/// Identical to `replacingChild(at: Int, with: RawSyntax?, rawAllocationArena: RawSyntaxArena)`
212220
/// that ensures that the arena of`newChild` doesn’t get de-allocated before
213221
/// `newChild` has been addded to the result.
214-
func replacingChild(at index: Int, with newChild: Syntax?, arena: RawSyntaxArena) -> Syntax {
222+
func replacingChild(at index: Int, with newChild: Syntax?, rawAllocationArena: RawSyntaxArena) -> Syntax {
215223
return withExtendedLifetime(newChild) {
216224
return replacingChild(
217225
at: index,
218226
with: newChild?.raw,
219227
rawNodeArena: newChild?.raw.arenaReference.retained,
220-
allocationArena: arena
228+
rawAllocationArena: rawAllocationArena
221229
)
222230
}
223231
}
224232

225-
func withLeadingTrivia(_ leadingTrivia: Trivia, arena: RawSyntaxArena) -> Syntax {
226-
if let raw = raw.withLeadingTrivia(leadingTrivia, arena: arena) {
227-
return replacingSelf(raw, rawNodeArena: RetainedRawSyntaxArena(arena), allocationArena: arena)
233+
func withLeadingTrivia(_ leadingTrivia: Trivia, rawAllocationArena: RawSyntaxArena) -> Syntax {
234+
if let raw = raw.withLeadingTrivia(leadingTrivia, arena: rawAllocationArena) {
235+
return replacingSelf(
236+
raw,
237+
rawNodeArena: RetainedRawSyntaxArena(rawAllocationArena),
238+
rawAllocationArena: rawAllocationArena
239+
)
228240
} else {
229241
return self
230242
}
231243
}
232244

233-
func withTrailingTrivia(_ trailingTrivia: Trivia, arena: RawSyntaxArena) -> Syntax {
234-
if let raw = raw.withTrailingTrivia(trailingTrivia, arena: arena) {
235-
return replacingSelf(raw, rawNodeArena: RetainedRawSyntaxArena(arena), allocationArena: arena)
245+
func withTrailingTrivia(_ trailingTrivia: Trivia, rawAllocationArena: RawSyntaxArena) -> Syntax {
246+
if let raw = raw.withTrailingTrivia(trailingTrivia, arena: rawAllocationArena) {
247+
return replacingSelf(
248+
raw,
249+
rawNodeArena: RetainedRawSyntaxArena(rawAllocationArena),
250+
rawAllocationArena: rawAllocationArena
251+
)
236252
} else {
237253
return self
238254
}
239255
}
240256

241-
func withPresence(_ presence: SourcePresence, arena: RawSyntaxArena) -> Syntax {
242-
if let raw = raw.tokenView?.withPresence(presence, arena: arena) {
243-
return replacingSelf(raw, rawNodeArena: RetainedRawSyntaxArena(arena), allocationArena: arena)
257+
func withPresence(_ presence: SourcePresence, rawAllocationArena: RawSyntaxArena) -> Syntax {
258+
if let raw = raw.tokenView?.withPresence(presence, arena: rawAllocationArena) {
259+
return replacingSelf(
260+
raw,
261+
rawNodeArena: RetainedRawSyntaxArena(rawAllocationArena),
262+
rawAllocationArena: rawAllocationArena
263+
)
244264
} else {
245265
return self
246266
}

Sources/SwiftSyntax/SyntaxCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extension SyntaxCollection {
7171
let arena = RawSyntaxArena()
7272
let newRaw = layoutView.replacingLayout(with: layout, arena: arena)
7373
return Syntax(self)
74-
.replacingSelf(newRaw, rawNodeArena: RetainedRawSyntaxArena(arena), allocationArena: arena)
74+
.replacingSelf(newRaw, rawNodeArena: RetainedRawSyntaxArena(arena), rawAllocationArena: arena)
7575
.cast(Self.self)
7676
}
7777

Sources/SwiftSyntax/SyntaxProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ extension SyntaxProtocol {
484484
return raw.formLeadingTrivia()
485485
}
486486
set {
487-
self = Syntax(self).withLeadingTrivia(newValue, arena: RawSyntaxArena()).cast(Self.self)
487+
self = Syntax(self).withLeadingTrivia(newValue, rawAllocationArena: RawSyntaxArena()).cast(Self.self)
488488
}
489489
}
490490

@@ -503,7 +503,7 @@ extension SyntaxProtocol {
503503
return raw.formTrailingTrivia()
504504
}
505505
set {
506-
self = Syntax(self).withTrailingTrivia(newValue, arena: RawSyntaxArena()).cast(Self.self)
506+
self = Syntax(self).withTrailingTrivia(newValue, rawAllocationArena: RawSyntaxArena()).cast(Self.self)
507507
}
508508
}
509509

Sources/SwiftSyntax/TokenSyntax.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
7171
return tokenView.presence
7272
}
7373
set {
74-
self = Syntax(self).withPresence(newValue, arena: RawSyntaxArena()).cast(TokenSyntax.self)
74+
self = Syntax(self).withPresence(newValue, rawAllocationArena: RawSyntaxArena()).cast(TokenSyntax.self)
7575
}
7676
}
7777

@@ -91,7 +91,7 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
9191
return tokenView.formLeadingTrivia()
9292
}
9393
set {
94-
self = Syntax(self).withLeadingTrivia(newValue, arena: RawSyntaxArena()).cast(TokenSyntax.self)
94+
self = Syntax(self).withLeadingTrivia(newValue, rawAllocationArena: RawSyntaxArena()).cast(TokenSyntax.self)
9595
}
9696
}
9797

@@ -101,7 +101,7 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
101101
return tokenView.formTrailingTrivia()
102102
}
103103
set {
104-
self = Syntax(self).withTrailingTrivia(newValue, arena: RawSyntaxArena()).cast(TokenSyntax.self)
104+
self = Syntax(self).withTrailingTrivia(newValue, rawAllocationArena: RawSyntaxArena()).cast(TokenSyntax.self)
105105
}
106106
}
107107

@@ -117,7 +117,7 @@ public struct TokenSyntax: SyntaxProtocol, SyntaxHashable {
117117
let arena = RawSyntaxArena()
118118
let newRaw = tokenView.withKind(newValue, arena: arena)
119119
self = Syntax(self)
120-
.replacingSelf(newRaw, rawNodeArena: RetainedRawSyntaxArena(arena), allocationArena: arena)
120+
.replacingSelf(newRaw, rawNodeArena: RetainedRawSyntaxArena(arena), rawAllocationArena: arena)
121121
.cast(TokenSyntax.self)
122122
}
123123
}

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
open class SyntaxRewriter {
2525
public let viewMode: SyntaxTreeViewMode
2626

27-
/// The arena in which the parents of rewritten nodes should be allocated.
27+
/// The raw arena in which the parents of rewritten nodes should be allocated.
2828
///
2929
/// The `SyntaxRewriter` subclass is responsible for generating the rewritten nodes. To incorporate them into the
3030
/// tree, all of the rewritten node's parents also need to be re-created. This is the arena in which those
31-
/// intermediate nodes should be allocated.
32-
private let arena: RawSyntaxArena?
31+
/// intermediate raw nodes should be allocated.
32+
private let rawArena: RawSyntaxArena?
3333

3434
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate) {
3535
self.viewMode = viewMode
36-
self.arena = nil
36+
self.rawArena = nil
3737
}
3838

3939
@_spi(RawSyntax)
40-
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, arena: RawSyntaxArena? = nil) {
40+
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, rawAllocationArena: RawSyntaxArena? = nil) {
4141
self.viewMode = viewMode
42-
self.arena = arena
42+
self.rawArena = rawAllocationArena
4343
}
4444

4545
/// Rewrite `node`, keeping its parent unless `detach` is `true`.
@@ -50,7 +50,7 @@ open class SyntaxRewriter {
5050
}
5151

5252
return withExtendedLifetime(rewritten) {
53-
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, allocationArena: RawSyntaxArena())
53+
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, rawAllocationArena: RawSyntaxArena())
5454
}
5555
}
5656

@@ -4812,13 +4812,13 @@ open class SyntaxRewriter {
48124812
if newLayout.baseAddress != nil {
48134813
// A child node was rewritten. Build the updated node.
48144814

4815-
let arena = self.arena ?? RawSyntaxArena()
4816-
let newRaw = node.raw.layoutView!.replacingLayout(with: newLayout, arena: arena)
4815+
let rawArena = self.rawArena ?? RawSyntaxArena()
4816+
let newRaw = node.raw.layoutView!.replacingLayout(with: newLayout, arena: rawArena)
48174817
newLayout.deinitialize()
48184818
newLayout.deallocate()
48194819
// 'withExtendedLifetime' to keep 'RawSyntaxArena's of them alive until here.
48204820
return withExtendedLifetime(rewrittens) {
4821-
Syntax(raw: newRaw, rawNodeArena: arena)
4821+
Syntax(raw: newRaw, rawNodeArena: rawArena)
48224822
}
48234823
} else {
48244824
// No child node was rewritten. So no need to change this node as well.

0 commit comments

Comments
 (0)