Skip to content

Add Sendable annotations to swift-syntax (again) #2446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let experimentalFeaturesFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
"""
extension Parser {
@_spi(ExperimentalLanguageFeatures)
public struct ExperimentalFeatures: OptionSet {
public struct ExperimentalFeatures: OptionSet, Sendable {
public let rawValue: UInt
public init(rawValue: UInt) {
self.rawValue = rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let layoutNodesParsableFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
defer { withExtendedLifetime(parser) {} }
let node = parser.\(parserFunction)()
let raw = RawSyntax(parser.parseRemainder(into: node))
return Syntax(raw: raw, rawNodeArena: raw.arena).cast(Self.self)
return Syntax(raw: raw, rawNodeArena: parser.arena).cast(Self.self)
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let lookupTable = ArrayExprSyntax(leftSquare: .leftSquareToken(trailingTrivia: .
let keywordFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! EnumDeclSyntax(
"""
public enum Keyword: UInt8, Hashable
public enum Keyword: UInt8, Hashable, Sendable
"""
) {
for keyword in Keyword.allCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let syntaxEnumFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! EnumDeclSyntax(
"""
/// Enum to exhaustively switch over all different syntax nodes.
public enum SyntaxEnum
public enum SyntaxEnum: Sendable
"""
) {
DeclSyntax("case token(TokenSyntax)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let syntaxKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! EnumDeclSyntax(
"""
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
public enum SyntaxKind
public enum SyntaxKind: Sendable
"""
) {
DeclSyntax("case token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
}

return withExtendedLifetime(rewritten) {
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arena, allocationArena: SyntaxArena())
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, allocationArena: SyntaxArena())
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let tokenKindFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! EnumDeclSyntax(
"""
/// Enumerates the kinds of tokens in the Swift language.
public enum TokenKind: Hashable
public enum TokenKind: Hashable, Sendable
"""
) {
for tokenSpec in Token.allCases.map(\.spec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let triviaPiecesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
///
/// In general, you should deal with the actual Trivia collection instead
/// of individual pieces whenever possible.
public enum TriviaPiece
public enum TriviaPiece: Sendable
"""
) {
for trivia in TRIVIAS {
Expand Down Expand Up @@ -176,7 +176,7 @@ let triviaPiecesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
/// In contrast to ``TriviaPiece``, a ``RawTriviaPiece`` does not own the source
/// text of the trivia.
@_spi(RawSyntax)
public enum RawTriviaPiece: Equatable
public enum RawTriviaPiece: Equatable, Sendable
"""
) {
for trivia in TRIVIAS {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDiagnostics/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import SwiftSyntax

public struct Diagnostic: CustomDebugStringConvertible {
public struct Diagnostic: CustomDebugStringConvertible, Sendable {
/// The message that should be displayed to the user
public let diagMessage: DiagnosticMessage

Expand Down Expand Up @@ -74,7 +74,7 @@ public struct Diagnostic: CustomDebugStringConvertible {
}
}

public struct DiagnosticsError: Error {
public struct DiagnosticsError: Error, Sendable {
public var diagnostics: [Diagnostic]

/// The diagnostics must contain at least one with severity == `.error`.
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftDiagnostics/FixIt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftSyntax
/// Types conforming to this protocol represent Fix-It messages that can be
/// shown to the client.
/// The messages should describe the change that the Fix-It will perform
public protocol FixItMessage {
public protocol FixItMessage: Sendable {
/// The Fix-It message that should be displayed in the client.
var message: String { get }

Expand All @@ -24,8 +24,8 @@ public protocol FixItMessage {
}

/// A Fix-It that can be applied to resolve a diagnostic.
public struct FixIt {
public enum Change {
public struct FixIt: Sendable {
public enum Change: Sendable {
/// Replace `oldNode` by `newNode`.
case replace(oldNode: Syntax, newNode: Syntax)
/// Replace the leading trivia on the given token
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDiagnostics/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum DiagnosticSeverity: Sendable {

/// Types conforming to this protocol represent diagnostic messages that can be
/// shown to the client.
public protocol DiagnosticMessage {
public protocol DiagnosticMessage: Sendable {
/// The diagnostic message that should be displayed in the client.
var message: String { get }

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDiagnostics/Note.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftSyntax
/// Types conforming to this protocol represent note messages that can be
/// shown to the client.
/// The messages should describe what the note is pointing at.
public protocol NoteMessage {
public protocol NoteMessage: Sendable {
/// The message that should be displayed in the client.
var message: String { get }

Expand All @@ -31,7 +31,7 @@ extension NoteMessage {
}

/// A note that points to another node that's relevant for a Diagnostic.
public struct Note: CustomDebugStringConvertible {
public struct Note: CustomDebugStringConvertible, Sendable {
/// The node whose location the node is pointing.
public let node: Syntax

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftIDEUtils/SyntaxClassification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@_spi(RawSyntax) import SwiftSyntax

public enum SyntaxClassification {
public enum SyntaxClassification: Sendable {
/// An attribute starting with an `@`.
case attribute
/// A block comment starting with `/**` and ending with `*/.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftIDEUtils/SyntaxClassifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fileprivate struct TokenKindAndText {
}

/// Represents a source range that is associated with a syntax classification.
public struct SyntaxClassifiedRange: Equatable {
public struct SyntaxClassifiedRange: Equatable, Sendable {
public var kind: SyntaxClassification
public var range: ByteSourceRange

Expand Down Expand Up @@ -264,7 +264,7 @@ private struct ClassificationVisitor {
}

/// Provides a sequence of ``SyntaxClassifiedRange``s for a syntax node.
public struct SyntaxClassifications: Sequence {
public struct SyntaxClassifications: Sequence, Sendable {
public typealias Iterator = Array<SyntaxClassifiedRange>.Iterator

var classifications: [SyntaxClassifiedRange]
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftOperators/Operator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftSyntax
public typealias OperatorName = String

/// Describes the kind of an operator.
public enum OperatorKind: String {
public enum OperatorKind: String, Sendable {
/// Infix operator such as the + in a + b.
case infix

Expand All @@ -31,7 +31,7 @@ public enum OperatorKind: String {
}

/// Describes an operator.
public struct Operator {
public struct Operator: Sendable {
public let kind: OperatorKind
public let name: OperatorName
public let precedenceGroup: PrecedenceGroupName?
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftOperators/OperatorError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import SwiftSyntax

/// Describes errors that can occur when working with user-defined operators.
public enum OperatorError: Error {
public enum OperatorError: Error, Sendable {
/// Error produced when a given precedence group already exists in the
/// precedence graph.
case groupAlreadyExists(existing: PrecedenceGroup, new: PrecedenceGroup)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftOperators/OperatorTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SwiftSyntax
/// semantic representation, validating the correctness of those declarations,
/// and "folding" sequence expression syntax into a structured expression
/// syntax tree.
public struct OperatorTable {
public struct OperatorTable: Sendable {
var precedenceGraph: PrecedenceGraph = .init()
var infixOperators: [OperatorName: Operator] = [:]
var prefixOperators: [OperatorName: Operator] = [:]
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftOperators/PrecedenceGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SwiftSyntax

/// Describes the relative precedence of two groups.
enum Precedence {
enum Precedence: Sendable {
case unrelated
case higherThan
case lowerThan
Expand All @@ -35,7 +35,7 @@ enum Precedence {

/// A graph formed from a set of precedence groups, which can be used to
/// determine the relative precedence of two precedence groups.
struct PrecedenceGraph {
struct PrecedenceGraph: Sendable {
/// The known set of precedence groups, found by name.
var precedenceGroups: [PrecedenceGroupName: PrecedenceGroup] = [:]

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftOperators/PrecedenceGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwiftSyntax
public typealias PrecedenceGroupName = String

/// The associativity of a precedence group.
public enum Associativity: String {
public enum Associativity: String, Sendable {
/// The precedence group is nonassociative, meaning that one must
/// parenthesize when there are multiple operators in a sequence, e.g.,
/// if ^ was nonassociative, a ^ b ^ c would need to be disambiguated as
Expand All @@ -38,9 +38,9 @@ public enum Associativity: String {

/// Describes the relationship of a precedence group to another precedence
/// group.
public struct PrecedenceRelation {
public struct PrecedenceRelation: Sendable {
/// Describes the kind of a precedence relation.
public enum Kind {
public enum Kind: Sendable {
case higherThan
case lowerThan

Expand Down Expand Up @@ -93,7 +93,7 @@ public struct PrecedenceRelation {
/// precedence, e.g.,
///
/// infix operator *: MultiplicationPrecedence
public struct PrecedenceGroup {
public struct PrecedenceGroup: Sendable {
/// The name of the group, which must be unique.
public var name: PrecedenceGroupName

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/CollectionNodes+Parsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fileprivate extension SyntaxCollection {
} else {
// First unwrap: We know that children.last exists because children is not empty
// Second unwrap: This is a collection and collections never have optional children. Thus the last child can’t be nil.
let lastWithRemainder = parser.parseRemainder(into: layoutView.children.last!!)
let lastWithRemainder = parser.parseRemainder(into: layoutView.children[layoutView.children.count - 1]!)
let raw = layoutView.replacingChild(at: layoutView.children.count - 1, with: lastWithRemainder, arena: parser.arena)
return Syntax(raw: raw, rawNodeArena: parser.arena).cast(Self.self)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/IncrementalParseTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fileprivate struct SyntaxCursor {
/// The raw `edits` of this struct are guaranteed to
/// 1. not be overlapping.
/// 2. be in increasing source offset order.
public struct ConcurrentEdits {
public struct ConcurrentEdits: Sendable {
enum ConcurrentEditsError: Error, CustomStringConvertible {
case editsNotConcurrent

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/ParseSourceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extension Parser {
///
/// This contains the parsed syntax tree and additional information on how far the parser looked ahead to parse each node.
/// This information is required to perform an incremental parse of the tree after applying edits to it.
public struct IncrementalParseResult {
public struct IncrementalParseResult: Sendable {
/// The syntax tree from parsing source
public let tree: SourceFileSyntax
/// The lookahead ranges for syntax nodes describe
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ class LookaheadTrackerOwner {
}

/// Record the lookahead ranges for syntax nodes.
public struct LookaheadRanges {
public struct LookaheadRanges: Sendable {
/// For each node that is recorded for re-use, the number of UTF-8 bytes that the parser looked ahead to parse the node, measured from the start of the node’s leading trivia.
///
/// This information can be used to determine whether a node can be reused in incremental parse. A node can only be re-used if no byte in its looked range has changed.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/generated/ExperimentalFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

extension Parser {
@_spi(ExperimentalLanguageFeatures)
public struct ExperimentalFeatures: OptionSet {
public struct ExperimentalFeatures: OptionSet, Sendable {
public let rawValue: UInt

public init(rawValue: UInt) {
Expand Down
Loading