From cc92c30a292bad2750e4a43173749990e25aadf5 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Wed, 1 Nov 2023 09:46:57 -0400 Subject: [PATCH] Mark `SyntaxChildrenIndex` as `Sendable` Otherwise consumers of SwiftSyntax may encounter warnings when compiling with `-strict-concurrency=complete`. For example: ```swift extension DeclModifierListSyntax { var fileprivateModifierIndex: DeclModifierListSyntax.Index? { firstIndex(where: { $0.name.tokenKind == .keyword(.fileprivate) }) } var fileprivateModifier: DeclModifierSyntax? { fileprivateModifierIndex.flatMap { self[$0] } } func replacing(fileprivateModifierIndex: DeclModifierListSyntax.Index) -> DeclModifierListSyntax { let fileprivateModifier = self[fileprivateModifierIndex] return with( \.[fileprivateModifierIndex], fileprivateModifier.with( \.name, .keyword( .private, leadingTrivia: fileprivateModifier.leadingTrivia, trailingTrivia: fileprivateModifier.trailingTrivia ) ) ) } } ``` Produces the following warning: > cannot form key path that captures non-sendable type > 'DeclModifierListSyntax.Index' (aka 'SyntaxChildrenIndex') --- Sources/SwiftSyntax/SyntaxChildren.swift | 4 ++-- Sources/SwiftSyntax/SyntaxIdentifier.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftSyntax/SyntaxChildren.swift b/Sources/SwiftSyntax/SyntaxChildren.swift index ffe67a40bdf..893ccb56fe0 100644 --- a/Sources/SwiftSyntax/SyntaxChildren.swift +++ b/Sources/SwiftSyntax/SyntaxChildren.swift @@ -14,7 +14,7 @@ /// The data for an index in a syntax children collection that is not the end /// index. See ``SyntaxChildrenIndex`` for the representation of the end index. -struct SyntaxChildrenIndexData: Hashable, Comparable { +struct SyntaxChildrenIndexData: Hashable, Comparable, Sendable { /// The UTF-8 offset of the item at this index in the source file /// See `AbsoluteSyntaxPosition.offset` let offset: UInt32 @@ -50,7 +50,7 @@ struct SyntaxChildrenIndexData: Hashable, Comparable { } /// An index in a syntax children collection. -public struct SyntaxChildrenIndex: Hashable, Comparable, ExpressibleByNilLiteral { +public struct SyntaxChildrenIndex: Hashable, Comparable, ExpressibleByNilLiteral, Sendable { /// Construct the `endIndex` of a ``SyntaxChildren`` collection. public init(nilLiteral: ()) { self.data = nil diff --git a/Sources/SwiftSyntax/SyntaxIdentifier.swift b/Sources/SwiftSyntax/SyntaxIdentifier.swift index 6886c6bfe3f..8f3c297cf16 100644 --- a/Sources/SwiftSyntax/SyntaxIdentifier.swift +++ b/Sources/SwiftSyntax/SyntaxIdentifier.swift @@ -12,7 +12,7 @@ /// Represents a unique value for a node within its own tree. @_spi(RawSyntax) -public struct SyntaxIndexInTree: Comparable, Hashable { +public struct SyntaxIndexInTree: Comparable, Hashable, Sendable { let indexInTree: UInt32 static var zero: SyntaxIndexInTree = SyntaxIndexInTree(indexInTree: 0)