Skip to content

Commit 99b670f

Browse files
committed
[Syntax] Mark the parameter of casting initializers '__shared'
Initializer parameters are "+1" in caller site, but these casting initializers only uses the ._syntaxNode and don't store the parameter itself.
1 parent 70e3741 commit 99b670f

File tree

14 files changed

+282
-282
lines changed

14 files changed

+282
-282
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
183183
DeclSyntax(
184184
"""
185185
/// Create a \(raw: node.kind.doccLink) node from a specialized syntax node.
186-
public init(_ syntax: some \(node.kind.protocolType)) {
186+
public init(_ syntax: __shared some \(node.kind.protocolType)) {
187187
// We know this cast is going to succeed. Go through init(_: SyntaxData)
188188
// to do a sanity check and verify the kind matches in debug builds and get
189189
// maximum performance in release builds.
@@ -195,7 +195,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
195195
DeclSyntax(
196196
"""
197197
/// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node.
198-
public init?(_ syntax: (some \(node.kind.protocolType))?) {
198+
public init?(_ syntax: __shared (some \(node.kind.protocolType))?) {
199199
guard let syntax = syntax else { return nil }
200200
self.init(syntax)
201201
}
@@ -204,7 +204,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
204204

205205
DeclSyntax(
206206
"""
207-
public init(fromProtocol syntax: \(node.kind.protocolType)) {
207+
public init(fromProtocol syntax: __shared \(node.kind.protocolType)) {
208208
// We know this cast is going to succeed. Go through init(_: SyntaxData)
209209
// to do a sanity check and verify the kind matches in debug builds and get
210210
// maximum performance in release builds.
@@ -216,14 +216,14 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
216216
DeclSyntax(
217217
"""
218218
/// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node.
219-
public init?(fromProtocol syntax: \(node.kind.protocolType)?) {
219+
public init?(fromProtocol syntax: __shared \(node.kind.protocolType)?) {
220220
guard let syntax = syntax else { return nil }
221221
self.init(fromProtocol: syntax)
222222
}
223223
"""
224224
)
225225

226-
try InitializerDeclSyntax("public init?(_ node: some SyntaxProtocol)") {
226+
try InitializerDeclSyntax("public init?(_ node: __shared some SyntaxProtocol)") {
227227
try SwitchExprSyntax("switch node.raw.kind") {
228228
SwitchCaseListSyntax {
229229
SwitchCaseSyntax(

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
4747

4848
DeclSyntax(
4949
"""
50-
public init?(_ node: some SyntaxProtocol) {
50+
public init?(_ node: __shared some SyntaxProtocol) {
5151
guard node.raw.kind == .\(node.varOrCaseName) else { return nil }
5252
self._syntaxNode = node._syntaxNode
5353
}
@@ -256,7 +256,7 @@ private func generateSyntaxChildChoices(for child: Child) throws -> EnumDeclSynt
256256
}
257257
}
258258

259-
try! InitializerDeclSyntax("public init?(_ node: some SyntaxProtocol)") {
259+
try! InitializerDeclSyntax("public init?(_ node: __shared some SyntaxProtocol)") {
260260
for choice in choices {
261261
StmtSyntax(
262262
"""

Sources/SwiftSyntax/SyntaxChildren.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ struct RawSyntaxChildren: BidirectionalCollection, Sendable {
274274
}
275275
}
276276

277-
init(_ base: Syntax) {
277+
init(_ base: __shared Syntax) {
278278
self.init(base.absoluteRaw)
279279
}
280280
}

Sources/SwiftSyntax/SyntaxProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public protocol SyntaxProtocol: CustomStringConvertible,
2424

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

2929
/// The statically allowed structure of the syntax node.
3030
static var structure: SyntaxNodeStructure { get }

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -183,37 +183,37 @@ public struct DeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
183183
public let _syntaxNode: Syntax
184184

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

193193
/// Create a ``DeclSyntax`` node from a specialized optional syntax node.
194-
public init?(_ syntax: (some DeclSyntaxProtocol)?) {
194+
public init?(_ syntax: __shared (some DeclSyntaxProtocol)?) {
195195
guard let syntax = syntax else {
196196
return nil
197197
}
198198
self.init(syntax)
199199
}
200200

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

208208
/// Create a ``DeclSyntax`` node from a specialized optional syntax node.
209-
public init?(fromProtocol syntax: DeclSyntaxProtocol?) {
209+
public init?(fromProtocol syntax: __shared DeclSyntaxProtocol?) {
210210
guard let syntax = syntax else {
211211
return nil
212212
}
213213
self.init(fromProtocol: syntax)
214214
}
215215

216-
public init?(_ node: some SyntaxProtocol) {
216+
public init?(_ node: __shared some SyntaxProtocol) {
217217
switch node.raw.kind {
218218
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:
219219
self._syntaxNode = node._syntaxNode
@@ -510,37 +510,37 @@ public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
510510
public let _syntaxNode: Syntax
511511

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

520520
/// Create a ``ExprSyntax`` node from a specialized optional syntax node.
521-
public init?(_ syntax: (some ExprSyntaxProtocol)?) {
521+
public init?(_ syntax: __shared (some ExprSyntaxProtocol)?) {
522522
guard let syntax = syntax else {
523523
return nil
524524
}
525525
self.init(syntax)
526526
}
527527

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

535535
/// Create a ``ExprSyntax`` node from a specialized optional syntax node.
536-
public init?(fromProtocol syntax: ExprSyntaxProtocol?) {
536+
public init?(fromProtocol syntax: __shared ExprSyntaxProtocol?) {
537537
guard let syntax = syntax else {
538538
return nil
539539
}
540540
self.init(fromProtocol: syntax)
541541
}
542542

543-
public init?(_ node: some SyntaxProtocol) {
543+
public init?(_ node: __shared some SyntaxProtocol) {
544544
switch node.raw.kind {
545545
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:
546546
self._syntaxNode = node._syntaxNode
@@ -823,37 +823,37 @@ public struct PatternSyntax: PatternSyntaxProtocol, SyntaxHashable {
823823
public let _syntaxNode: Syntax
824824

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

833833
/// Create a ``PatternSyntax`` node from a specialized optional syntax node.
834-
public init?(_ syntax: (some PatternSyntaxProtocol)?) {
834+
public init?(_ syntax: __shared (some PatternSyntaxProtocol)?) {
835835
guard let syntax = syntax else {
836836
return nil
837837
}
838838
self.init(syntax)
839839
}
840840

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

848848
/// Create a ``PatternSyntax`` node from a specialized optional syntax node.
849-
public init?(fromProtocol syntax: PatternSyntaxProtocol?) {
849+
public init?(fromProtocol syntax: __shared PatternSyntaxProtocol?) {
850850
guard let syntax = syntax else {
851851
return nil
852852
}
853853
self.init(fromProtocol: syntax)
854854
}
855855

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

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

11091109
/// Create a ``StmtSyntax`` node from a specialized optional syntax node.
1110-
public init?(_ syntax: (some StmtSyntaxProtocol)?) {
1110+
public init?(_ syntax: __shared (some StmtSyntaxProtocol)?) {
11111111
guard let syntax = syntax else {
11121112
return nil
11131113
}
11141114
self.init(syntax)
11151115
}
11161116

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

11241124
/// Create a ``StmtSyntax`` node from a specialized optional syntax node.
1125-
public init?(fromProtocol syntax: StmtSyntaxProtocol?) {
1125+
public init?(fromProtocol syntax: __shared StmtSyntaxProtocol?) {
11261126
guard let syntax = syntax else {
11271127
return nil
11281128
}
11291129
self.init(fromProtocol: syntax)
11301130
}
11311131

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

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

13971397
/// Create a ``TypeSyntax`` node from a specialized optional syntax node.
1398-
public init?(_ syntax: (some TypeSyntaxProtocol)?) {
1398+
public init?(_ syntax: __shared (some TypeSyntaxProtocol)?) {
13991399
guard let syntax = syntax else {
14001400
return nil
14011401
}
14021402
self.init(syntax)
14031403
}
14041404

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

14121412
/// Create a ``TypeSyntax`` node from a specialized optional syntax node.
1413-
public init?(fromProtocol syntax: TypeSyntaxProtocol?) {
1413+
public init?(fromProtocol syntax: __shared TypeSyntaxProtocol?) {
14141414
guard let syntax = syntax else {
14151415
return nil
14161416
}
14171417
self.init(fromProtocol: syntax)
14181418
}
14191419

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

0 commit comments

Comments
 (0)