Skip to content

[Syntax] Mark the parameter of casting initializers '__shared' #2728

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 1 commit into from
Jul 18, 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 @@ -183,7 +183,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
DeclSyntax(
"""
/// Create a \(raw: node.kind.doccLink) node from a specialized syntax node.
public init(_ syntax: some \(node.kind.protocolType)) {
public init(_ syntax: __shared some \(node.kind.protocolType)) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
Expand All @@ -195,7 +195,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
DeclSyntax(
"""
/// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node.
public init?(_ syntax: (some \(node.kind.protocolType))?) {
public init?(_ syntax: __shared (some \(node.kind.protocolType))?) {
guard let syntax = syntax else { return nil }
self.init(syntax)
}
Expand All @@ -204,7 +204,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

DeclSyntax(
"""
public init(fromProtocol syntax: \(node.kind.protocolType)) {
public init(fromProtocol syntax: __shared \(node.kind.protocolType)) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
Expand All @@ -216,14 +216,14 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
DeclSyntax(
"""
/// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node.
public init?(fromProtocol syntax: \(node.kind.protocolType)?) {
public init?(fromProtocol syntax: __shared \(node.kind.protocolType)?) {
guard let syntax = syntax else { return nil }
self.init(fromProtocol: syntax)
}
"""
)

try InitializerDeclSyntax("public init?(_ node: some SyntaxProtocol)") {
try InitializerDeclSyntax("public init?(_ node: __shared some SyntaxProtocol)") {
try SwitchExprSyntax("switch node.raw.kind") {
SwitchCaseListSyntax {
SwitchCaseSyntax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {

DeclSyntax(
"""
public init?(_ node: some SyntaxProtocol) {
public init?(_ node: __shared some SyntaxProtocol) {
guard node.raw.kind == .\(node.varOrCaseName) else { return nil }
self._syntaxNode = node._syntaxNode
}
Expand Down Expand Up @@ -256,7 +256,7 @@ private func generateSyntaxChildChoices(for child: Child) throws -> EnumDeclSynt
}
}

try! InitializerDeclSyntax("public init?(_ node: some SyntaxProtocol)") {
try! InitializerDeclSyntax("public init?(_ node: __shared some SyntaxProtocol)") {
for choice in choices {
StmtSyntax(
"""
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/SyntaxChildren.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ struct RawSyntaxChildren: BidirectionalCollection, Sendable {
}
}

init(_ base: Syntax) {
init(_ base: __shared Syntax) {
self.init(base.absoluteRaw)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/SyntaxProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public protocol SyntaxProtocol: CustomStringConvertible,

/// Converts the given specialized node to this type. Returns `nil` if the
/// conversion is not possible.
init?(_ node: some SyntaxProtocol)
init?(_ node: __shared some SyntaxProtocol)

/// The statically allowed structure of the syntax node.
static var structure: SyntaxNodeStructure { get }
Expand Down
50 changes: 25 additions & 25 deletions Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,37 +183,37 @@ public struct DeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
public let _syntaxNode: Syntax

/// Create a ``DeclSyntax`` node from a specialized syntax node.
public init(_ syntax: some DeclSyntaxProtocol) {
public init(_ syntax: __shared some DeclSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``DeclSyntax`` node from a specialized optional syntax node.
public init?(_ syntax: (some DeclSyntaxProtocol)?) {
public init?(_ syntax: __shared (some DeclSyntaxProtocol)?) {
guard let syntax = syntax else {
return nil
}
self.init(syntax)
}

public init(fromProtocol syntax: DeclSyntaxProtocol) {
public init(fromProtocol syntax: __shared DeclSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``DeclSyntax`` node from a specialized optional syntax node.
public init?(fromProtocol syntax: DeclSyntaxProtocol?) {
public init?(fromProtocol syntax: __shared DeclSyntaxProtocol?) {
guard let syntax = syntax else {
return nil
}
self.init(fromProtocol: syntax)
}

public init?(_ node: some SyntaxProtocol) {
public init?(_ node: __shared some SyntaxProtocol) {
switch node.raw.kind {
case .accessorDecl, .actorDecl, .associatedTypeDecl, .classDecl, .deinitializerDecl, .editorPlaceholderDecl, .enumCaseDecl, .enumDecl, .extensionDecl, .functionDecl, .ifConfigDecl, .importDecl, .initializerDecl, .macroDecl, .macroExpansionDecl, .missingDecl, .operatorDecl, .poundSourceLocation, .precedenceGroupDecl, .protocolDecl, .structDecl, .subscriptDecl, .typeAliasDecl, .variableDecl:
self._syntaxNode = node._syntaxNode
Expand Down Expand Up @@ -510,37 +510,37 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
public let _syntaxNode: Syntax

/// Create a ``ExprSyntax`` node from a specialized syntax node.
public init(_ syntax: some ExprSyntaxProtocol) {
public init(_ syntax: __shared some ExprSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``ExprSyntax`` node from a specialized optional syntax node.
public init?(_ syntax: (some ExprSyntaxProtocol)?) {
public init?(_ syntax: __shared (some ExprSyntaxProtocol)?) {
guard let syntax = syntax else {
return nil
}
self.init(syntax)
}

public init(fromProtocol syntax: ExprSyntaxProtocol) {
public init(fromProtocol syntax: __shared ExprSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``ExprSyntax`` node from a specialized optional syntax node.
public init?(fromProtocol syntax: ExprSyntaxProtocol?) {
public init?(fromProtocol syntax: __shared ExprSyntaxProtocol?) {
guard let syntax = syntax else {
return nil
}
self.init(fromProtocol: syntax)
}

public init?(_ node: some SyntaxProtocol) {
public init?(_ node: __shared some SyntaxProtocol) {
switch node.raw.kind {
case .arrayExpr, .arrowExpr, .asExpr, .assignmentExpr, .awaitExpr, .binaryOperatorExpr, .booleanLiteralExpr, .borrowExpr, ._canImportExpr, ._canImportVersionInfo, .closureExpr, .consumeExpr, .copyExpr, .declReferenceExpr, .dictionaryExpr, .discardAssignmentExpr, .doExpr, .editorPlaceholderExpr, .floatLiteralExpr, .forceUnwrapExpr, .functionCallExpr, .genericSpecializationExpr, .ifExpr, .inOutExpr, .infixOperatorExpr, .integerLiteralExpr, .isExpr, .keyPathExpr, .macroExpansionExpr, .memberAccessExpr, .missingExpr, .nilLiteralExpr, .optionalChainingExpr, .packElementExpr, .packExpansionExpr, .patternExpr, .postfixIfConfigExpr, .postfixOperatorExpr, .prefixOperatorExpr, .regexLiteralExpr, .sequenceExpr, .simpleStringLiteralExpr, .stringLiteralExpr, .subscriptCallExpr, .superExpr, .switchExpr, .ternaryExpr, .tryExpr, .tupleExpr, .typeExpr, .unresolvedAsExpr, .unresolvedIsExpr, .unresolvedTernaryExpr:
self._syntaxNode = node._syntaxNode
Expand Down Expand Up @@ -823,37 +823,37 @@ public struct PatternSyntax: PatternSyntaxProtocol, SyntaxHashable {
public let _syntaxNode: Syntax

/// Create a ``PatternSyntax`` node from a specialized syntax node.
public init(_ syntax: some PatternSyntaxProtocol) {
public init(_ syntax: __shared some PatternSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``PatternSyntax`` node from a specialized optional syntax node.
public init?(_ syntax: (some PatternSyntaxProtocol)?) {
public init?(_ syntax: __shared (some PatternSyntaxProtocol)?) {
guard let syntax = syntax else {
return nil
}
self.init(syntax)
}

public init(fromProtocol syntax: PatternSyntaxProtocol) {
public init(fromProtocol syntax: __shared PatternSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``PatternSyntax`` node from a specialized optional syntax node.
public init?(fromProtocol syntax: PatternSyntaxProtocol?) {
public init?(fromProtocol syntax: __shared PatternSyntaxProtocol?) {
guard let syntax = syntax else {
return nil
}
self.init(fromProtocol: syntax)
}

public init?(_ node: some SyntaxProtocol) {
public init?(_ node: __shared some SyntaxProtocol) {
switch node.raw.kind {
case .expressionPattern, .identifierPattern, .isTypePattern, .missingPattern, .tuplePattern, .valueBindingPattern, .wildcardPattern:
self._syntaxNode = node._syntaxNode
Expand Down Expand Up @@ -1099,37 +1099,37 @@ public struct StmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
public let _syntaxNode: Syntax

/// Create a ``StmtSyntax`` node from a specialized syntax node.
public init(_ syntax: some StmtSyntaxProtocol) {
public init(_ syntax: __shared some StmtSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``StmtSyntax`` node from a specialized optional syntax node.
public init?(_ syntax: (some StmtSyntaxProtocol)?) {
public init?(_ syntax: __shared (some StmtSyntaxProtocol)?) {
guard let syntax = syntax else {
return nil
}
self.init(syntax)
}

public init(fromProtocol syntax: StmtSyntaxProtocol) {
public init(fromProtocol syntax: __shared StmtSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``StmtSyntax`` node from a specialized optional syntax node.
public init?(fromProtocol syntax: StmtSyntaxProtocol?) {
public init?(fromProtocol syntax: __shared StmtSyntaxProtocol?) {
guard let syntax = syntax else {
return nil
}
self.init(fromProtocol: syntax)
}

public init?(_ node: some SyntaxProtocol) {
public init?(_ node: __shared some SyntaxProtocol) {
switch node.raw.kind {
case .breakStmt, .continueStmt, .deferStmt, .discardStmt, .doStmt, .expressionStmt, .fallThroughStmt, .forStmt, .guardStmt, .labeledStmt, .missingStmt, .repeatStmt, .returnStmt, .thenStmt, .throwStmt, .whileStmt, .yieldStmt:
self._syntaxNode = node._syntaxNode
Expand Down Expand Up @@ -1387,37 +1387,37 @@ public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
public let _syntaxNode: Syntax

/// Create a ``TypeSyntax`` node from a specialized syntax node.
public init(_ syntax: some TypeSyntaxProtocol) {
public init(_ syntax: __shared some TypeSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``TypeSyntax`` node from a specialized optional syntax node.
public init?(_ syntax: (some TypeSyntaxProtocol)?) {
public init?(_ syntax: __shared (some TypeSyntaxProtocol)?) {
guard let syntax = syntax else {
return nil
}
self.init(syntax)
}

public init(fromProtocol syntax: TypeSyntaxProtocol) {
public init(fromProtocol syntax: __shared TypeSyntaxProtocol) {
// We know this cast is going to succeed. Go through init(_: SyntaxData)
// to do a sanity check and verify the kind matches in debug builds and get
// maximum performance in release builds.
self = Syntax(syntax).cast(Self.self)
}

/// Create a ``TypeSyntax`` node from a specialized optional syntax node.
public init?(fromProtocol syntax: TypeSyntaxProtocol?) {
public init?(fromProtocol syntax: __shared TypeSyntaxProtocol?) {
guard let syntax = syntax else {
return nil
}
self.init(fromProtocol: syntax)
}

public init?(_ node: some SyntaxProtocol) {
public init?(_ node: __shared some SyntaxProtocol) {
switch node.raw.kind {
case .arrayType, .attributedType, .classRestrictionType, .compositionType, .dictionaryType, .functionType, .identifierType, .implicitlyUnwrappedOptionalType, .memberType, .metatypeType, .missingType, .namedOpaqueReturnType, .optionalType, .packElementType, .packExpansionType, .someOrAnyType, .suppressedType, .tupleType:
self._syntaxNode = node._syntaxNode
Expand Down
Loading