Skip to content

Commit 7c6d4f7

Browse files
authored
Merge pull request #2234 from hamishknight/i-spi
2 parents fee7838 + 6af9a71 commit 7c6d4f7

File tree

13 files changed

+52
-10
lines changed

13 files changed

+52
-10
lines changed

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ public class Node {
9898
public func apiAttributes(forRaw: Bool = false) -> AttributeListSyntax {
9999
let attrList = AttributeListSyntax {
100100
if isExperimental {
101-
"@_spi(ExperimentalLanguageFeatures)"
101+
// SPI for enum cases currently requires Swift 5.8 to work correctly.
102+
let experimentalSPI: AttributeListSyntax = """
103+
#if compiler(>=5.8)
104+
@_spi(ExperimentalLanguageFeatures)
105+
#endif
106+
"""
107+
experimentalSPI.with(\.trailingTrivia, .newline)
102108
}
103109
if forRaw {
104110
"@_spi(RawSyntax)"
@@ -107,6 +113,16 @@ public class Node {
107113
return attrList.with(\.trailingTrivia, attrList.isEmpty ? [] : .newline)
108114
}
109115

116+
/// The documentation note to print for an experimental feature.
117+
public var experimentalDocNote: SwiftSyntax.Trivia {
118+
let comment = experimentalFeature.map {
119+
"""
120+
- Experiment: Requires experimental feature `\($0.token)`.
121+
"""
122+
}
123+
return SwiftSyntax.Trivia.docCommentTrivia(from: comment)
124+
}
125+
110126
/// Construct the specification for a layout syntax node.
111127
init(
112128
kind: SyntaxNodeKind,

CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ public let STMT_NODES: [Node] = [
587587
Node(
588588
kind: .thenStmt,
589589
base: .stmt,
590-
// FIXME: This should be marked experimental.
591-
experimentalFeature: nil,
590+
experimentalFeature: .thenStatements,
592591
nameForDiagnostics: "'then' statement",
593592
documentation: """
594593
A statement used to indicate the produced value from an if/switch

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
1919
for node in SYNTAX_NODES.compactMap(\.collectionNode) {
2020
let documentation = SwiftSyntax.Trivia(joining: [
2121
node.documentation,
22+
node.experimentalDocNote,
2223
node.grammar,
2324
node.containedIn,
2425
])

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
2727
"""
2828
// MARK: - \(node.kind.syntaxType)
2929
30-
\(SwiftSyntax.Trivia(joining: [node.documentation, node.grammar, node.containedIn]))
30+
\(SwiftSyntax.Trivia(joining: [node.documentation, node.experimentalDocNote, node.grammar, node.containedIn]))
3131
\(node.node.apiAttributes())\
3232
public struct \(node.kind.syntaxType): \(node.baseType.syntaxBaseName)Protocol, SyntaxHashable, \(node.base.leafProtocolType)
3333
"""

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
175175
- <doc:SwiftSyntax/LabeledStmtSyntax>
176176
- <doc:SwiftSyntax/RepeatStmtSyntax>
177177
- <doc:SwiftSyntax/ReturnStmtSyntax>
178-
- <doc:SwiftSyntax/ThenStmtSyntax>
179178
- <doc:SwiftSyntax/ThrowStmtSyntax>
180179
- <doc:SwiftSyntax/WhileStmtSyntax>
181180
- <doc:SwiftSyntax/YieldStmtSyntax>

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,10 +2000,16 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
20002000
visitAnyPost(node._syntaxNode)
20012001
}
20022002

2003+
#if compiler(>=5.8)
2004+
@_spi(ExperimentalLanguageFeatures)
2005+
#endif
20032006
override open func visit(_ node: ThenStmtSyntax) -> SyntaxVisitorContinueKind {
20042007
return visitAny(node._syntaxNode)
20052008
}
20062009

2010+
#if compiler(>=5.8)
2011+
@_spi(ExperimentalLanguageFeatures)
2012+
#endif
20072013
override open func visitPost(_ node: ThenStmtSyntax) {
20082014
visitAnyPost(node._syntaxNode)
20092015
}

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ public enum SyntaxEnum {
258258
case switchDefaultLabel(SwitchDefaultLabelSyntax)
259259
case switchExpr(SwitchExprSyntax)
260260
case ternaryExpr(TernaryExprSyntax)
261+
#if compiler(>=5.8)
262+
@_spi(ExperimentalLanguageFeatures)
263+
#endif
261264
case thenStmt(ThenStmtSyntax)
262265
case throwStmt(ThrowStmtSyntax)
263266
case tryExpr(TryExprSyntax)

Sources/SwiftSyntax/generated/SyntaxKind.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ public enum SyntaxKind: CaseIterable {
258258
case switchDefaultLabel
259259
case switchExpr
260260
case ternaryExpr
261+
#if compiler(>=5.8)
262+
@_spi(ExperimentalLanguageFeatures)
263+
#endif
261264
case thenStmt
262265
case throwStmt
263266
case tryExpr

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,9 @@ open class SyntaxRewriter {
17841784
/// Visit a ``ThenStmtSyntax``.
17851785
/// - Parameter node: the node that is being visited
17861786
/// - Returns: the rewritten node
1787+
#if compiler(>=5.8)
1788+
@_spi(ExperimentalLanguageFeatures)
1789+
#endif
17871790
open func visit(_ node: ThenStmtSyntax) -> StmtSyntax {
17881791
return StmtSyntax(visitChildren(node))
17891792
}

Sources/SwiftSyntax/generated/SyntaxTransform.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,11 +1235,6 @@ public protocol SyntaxTransformVisitor {
12351235
/// - Returns: the sum of whatever the child visitors return.
12361236
func visit(_ node: TernaryExprSyntax) -> ResultType
12371237

1238-
/// Visiting ``ThenStmtSyntax`` specifically.
1239-
/// - Parameter node: the node we are visiting.
1240-
/// - Returns: the sum of whatever the child visitors return.
1241-
func visit(_ node: ThenStmtSyntax) -> ResultType
1242-
12431238
/// Visiting ``ThrowStmtSyntax`` specifically.
12441239
/// - Parameter node: the node we are visiting.
12451240
/// - Returns: the sum of whatever the child visitors return.
@@ -3110,6 +3105,9 @@ extension SyntaxTransformVisitor {
31103105
/// Visiting ``ThenStmtSyntax`` specifically.
31113106
/// - Parameter node: the node we are visiting.
31123107
/// - Returns: nil by default.
3108+
#if compiler(>=5.8)
3109+
@_spi(ExperimentalLanguageFeatures)
3110+
#endif
31133111
public func visit(_ node: ThenStmtSyntax) -> ResultType {
31143112
visitAny(Syntax(node))
31153113
}

0 commit comments

Comments
 (0)