Skip to content

Commit 97a0cdf

Browse files
committed
Remove overhead of existentials
1 parent 52b02a0 commit 97a0cdf

27 files changed

+535
-447
lines changed

Sources/SwiftSyntax/RawSyntax.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,8 @@ final class RawSyntax: ManagedBuffer<RawSyntaxBase, RawSyntaxDataElement> {
11641164
/// is returned.
11651165
/// - Parameter newLayout: The children of the new node you're creating.
11661166
func replacingLayout(_ newLayout: [RawSyntax?]) -> RawSyntax {
1167+
// FIXME: We should make sure that the new layout is valid for this node
1168+
// type.
11671169
if isToken { return self }
11681170
return .createAndCalcLength(kind: kind, layout: newLayout, presence: presence)
11691171
}

Sources/SwiftSyntax/SourceLocation.swift

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,14 @@ public final class SourceLocationConverter {
227227
}
228228
}
229229

230-
extension _SyntaxBase {
231-
func startLocation(
230+
extension Syntax {
231+
/// The starting location, in the provided file, of this Syntax node.
232+
/// - Parameters:
233+
/// - converter: The `SourceLocationConverter` that was previously
234+
/// initialized using the root tree of this node.
235+
/// - afterLeadingTrivia: Whether to skip leading trivia when getting
236+
/// the node's location. Defaults to `true`.
237+
public func startLocation(
232238
converter: SourceLocationConverter,
233239
afterLeadingTrivia: Bool = true
234240
) -> SourceLocation {
@@ -238,7 +244,13 @@ extension _SyntaxBase {
238244
return converter.location(for: pos)
239245
}
240246

241-
func endLocation(
247+
/// The ending location, in the provided file, of this Syntax node.
248+
/// - Parameters:
249+
/// - converter: The `SourceLocationConverter` that was previously
250+
/// initialized using the root tree of this node.
251+
/// - afterTrailingTrivia: Whether to skip trailing trivia when getting
252+
/// the node's location. Defaults to `false`.
253+
public func endLocation(
242254
converter: SourceLocationConverter,
243255
afterTrailingTrivia: Bool = false
244256
) -> SourceLocation {
@@ -251,7 +263,15 @@ extension _SyntaxBase {
251263
return converter.location(for: pos)
252264
}
253265

254-
func sourceRange(
266+
/// The source range, in the provided file, of this Syntax node.
267+
/// - Parameters:
268+
/// - converter: The `SourceLocationConverter` that was previously
269+
/// initialized using the root tree of this node.
270+
/// - afterLeadingTrivia: Whether to skip leading trivia when getting
271+
/// the node's start location. Defaults to `true`.
272+
/// - afterTrailingTrivia: Whether to skip trailing trivia when getting
273+
/// the node's end location. Defaults to `false`.
274+
public func sourceRange(
255275
converter: SourceLocationConverter,
256276
afterLeadingTrivia: Bool = true,
257277
afterTrailingTrivia: Bool = false
@@ -262,19 +282,19 @@ extension _SyntaxBase {
262282
}
263283
}
264284

265-
extension Syntax {
285+
public extension _SpecializedSyntaxMixin {
266286
/// The starting location, in the provided file, of this Syntax node.
267287
/// - Parameters:
268288
/// - converter: The `SourceLocationConverter` that was previously
269289
/// initialized using the root tree of this node.
270290
/// - afterLeadingTrivia: Whether to skip leading trivia when getting
271291
/// the node's location. Defaults to `true`.
272-
public func startLocation(
292+
func startLocation(
273293
converter: SourceLocationConverter,
274294
afterLeadingTrivia: Bool = true
275295
) -> SourceLocation {
276-
return base.startLocation(converter: converter,
277-
afterLeadingTrivia: afterLeadingTrivia)
296+
return self.asSyntax.startLocation(converter: converter,
297+
afterLeadingTrivia: afterLeadingTrivia)
278298
}
279299

280300
/// The ending location, in the provided file, of this Syntax node.
@@ -283,12 +303,12 @@ extension Syntax {
283303
/// initialized using the root tree of this node.
284304
/// - afterTrailingTrivia: Whether to skip trailing trivia when getting
285305
/// the node's location. Defaults to `false`.
286-
public func endLocation(
306+
func endLocation(
287307
converter: SourceLocationConverter,
288308
afterTrailingTrivia: Bool = false
289309
) -> SourceLocation {
290-
return base.endLocation(converter: converter,
291-
afterTrailingTrivia: afterTrailingTrivia)
310+
return self.asSyntax.endLocation(converter: converter,
311+
afterTrailingTrivia: afterTrailingTrivia)
292312
}
293313

294314
/// The source range, in the provided file, of this Syntax node.
@@ -299,14 +319,14 @@ extension Syntax {
299319
/// the node's start location. Defaults to `true`.
300320
/// - afterTrailingTrivia: Whether to skip trailing trivia when getting
301321
/// the node's end location. Defaults to `false`.
302-
public func sourceRange(
322+
func sourceRange(
303323
converter: SourceLocationConverter,
304324
afterLeadingTrivia: Bool = true,
305325
afterTrailingTrivia: Bool = false
306326
) -> SourceRange {
307-
return base.sourceRange(converter: converter,
308-
afterLeadingTrivia: afterLeadingTrivia,
309-
afterTrailingTrivia: afterTrailingTrivia)
327+
return self.asSyntax.sourceRange(converter: converter,
328+
afterLeadingTrivia: afterLeadingTrivia,
329+
afterTrailingTrivia: afterTrailingTrivia)
310330
}
311331
}
312332

0 commit comments

Comments
 (0)