Skip to content

Commit 39ec125

Browse files
committed
[NFC] Rename 'arena:' argument labels
1 parent 327d640 commit 39ec125

18 files changed

+1906
-1886
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
"""

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/Raw/RawSyntax.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,14 +704,14 @@ extension RawSyntax {
704704
initializingLeadingTriviaWith: { buffer in
705705
guard var ptr = buffer.baseAddress else { return }
706706
for piece in leadingTrivia {
707-
ptr.initialize(to: .make(piece, arena: arena))
707+
ptr.initialize(to: .make(piece, rawAllocationArena: arena))
708708
ptr += 1
709709
}
710710
},
711711
initializingTrailingTriviaWith: { buffer in
712712
guard var ptr = buffer.baseAddress else { return }
713713
for piece in trailingTrivia {
714-
ptr.initialize(to: .make(piece, arena: arena))
714+
ptr.initialize(to: .make(piece, rawAllocationArena: arena))
715715
ptr += 1
716716
}
717717
}

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
@@ -526,7 +526,7 @@ extension SyntaxProtocol {
526526
return raw.formLeadingTrivia()
527527
}
528528
set {
529-
self = Syntax(self).withLeadingTrivia(newValue, arena: RawSyntaxArena()).cast(Self.self)
529+
self = Syntax(self).withLeadingTrivia(newValue, rawAllocationArena: RawSyntaxArena()).cast(Self.self)
530530
}
531531
}
532532

@@ -545,7 +545,7 @@ extension SyntaxProtocol {
545545
return raw.formTrailingTrivia()
546546
}
547547
set {
548-
self = Syntax(self).withTrailingTrivia(newValue, arena: RawSyntaxArena()).cast(Self.self)
548+
self = Syntax(self).withTrailingTrivia(newValue, rawAllocationArena: RawSyntaxArena()).cast(Self.self)
549549
}
550550
}
551551

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)