Skip to content

Require Swift 5.8 for SPI experimental feature syntax nodes #2234

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 4 commits into from
Sep 25, 2023
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
18 changes: 17 additions & 1 deletion CodeGeneration/Sources/SyntaxSupport/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ public class Node {
public func apiAttributes(forRaw: Bool = false) -> AttributeListSyntax {
let attrList = AttributeListSyntax {
if isExperimental {
"@_spi(ExperimentalLanguageFeatures)"
// SPI for enum cases currently requires Swift 5.8 to work correctly.
let experimentalSPI: AttributeListSyntax = """
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
"""
experimentalSPI.with(\.trailingTrivia, .newline)
}
if forRaw {
"@_spi(RawSyntax)"
Expand All @@ -107,6 +113,16 @@ public class Node {
return attrList.with(\.trailingTrivia, attrList.isEmpty ? [] : .newline)
}

/// The documentation note to print for an experimental feature.
public var experimentalDocNote: SwiftSyntax.Trivia {
let comment = experimentalFeature.map {
"""
- Experiment: Requires experimental feature `\($0.token)`.
"""
}
return SwiftSyntax.Trivia.docCommentTrivia(from: comment)
}

/// Construct the specification for a layout syntax node.
init(
kind: SyntaxNodeKind,
Expand Down
3 changes: 1 addition & 2 deletions CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@ public let STMT_NODES: [Node] = [
Node(
kind: .thenStmt,
base: .stmt,
// FIXME: This should be marked experimental.
experimentalFeature: nil,
experimentalFeature: .thenStatements,
nameForDiagnostics: "'then' statement",
documentation: """
A statement used to indicate the produced value from an if/switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
for node in SYNTAX_NODES.compactMap(\.collectionNode) {
let documentation = SwiftSyntax.Trivia(joining: [
node.documentation,
node.experimentalDocNote,
node.grammar,
node.containedIn,
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
"""
// MARK: - \(node.kind.syntaxType)

\(SwiftSyntax.Trivia(joining: [node.documentation, node.grammar, node.containedIn]))
\(SwiftSyntax.Trivia(joining: [node.documentation, node.experimentalDocNote, node.grammar, node.containedIn]))
\(node.node.apiAttributes())\
public struct \(node.kind.syntaxType): \(node.baseType.syntaxBaseName)Protocol, SyntaxHashable, \(node.base.leafProtocolType)
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ These articles are intended for developers wishing to contribute to SwiftSyntax
- <doc:SwiftSyntax/LabeledStmtSyntax>
- <doc:SwiftSyntax/RepeatStmtSyntax>
- <doc:SwiftSyntax/ReturnStmtSyntax>
- <doc:SwiftSyntax/ThenStmtSyntax>
- <doc:SwiftSyntax/ThrowStmtSyntax>
- <doc:SwiftSyntax/WhileStmtSyntax>
- <doc:SwiftSyntax/YieldStmtSyntax>
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2000,10 +2000,16 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
visitAnyPost(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visit(_ node: ThenStmtSyntax) -> SyntaxVisitorContinueKind {
return visitAny(node._syntaxNode)
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
override open func visitPost(_ node: ThenStmtSyntax) {
visitAnyPost(node._syntaxNode)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ public enum SyntaxEnum {
case switchDefaultLabel(SwitchDefaultLabelSyntax)
case switchExpr(SwitchExprSyntax)
case ternaryExpr(TernaryExprSyntax)
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case thenStmt(ThenStmtSyntax)
case throwStmt(ThrowStmtSyntax)
case tryExpr(TryExprSyntax)
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ public enum SyntaxKind: CaseIterable {
case switchDefaultLabel
case switchExpr
case ternaryExpr
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
case thenStmt
case throwStmt
case tryExpr
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,9 @@ open class SyntaxRewriter {
/// Visit a ``ThenStmtSyntax``.
/// - Parameter node: the node that is being visited
/// - Returns: the rewritten node
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
open func visit(_ node: ThenStmtSyntax) -> StmtSyntax {
return StmtSyntax(visitChildren(node))
}
Expand Down
8 changes: 3 additions & 5 deletions Sources/SwiftSyntax/generated/SyntaxTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,6 @@ public protocol SyntaxTransformVisitor {
/// - Returns: the sum of whatever the child visitors return.
func visit(_ node: TernaryExprSyntax) -> ResultType

/// Visiting ``ThenStmtSyntax`` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: the sum of whatever the child visitors return.
func visit(_ node: ThenStmtSyntax) -> ResultType

/// Visiting ``ThrowStmtSyntax`` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: the sum of whatever the child visitors return.
Expand Down Expand Up @@ -3110,6 +3105,9 @@ extension SyntaxTransformVisitor {
/// Visiting ``ThenStmtSyntax`` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: nil by default.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public func visit(_ node: ThenStmtSyntax) -> ResultType {
visitAny(Syntax(node))
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftSyntax/generated/SyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2953,12 +2953,18 @@ open class SyntaxVisitor {
/// Visiting ``ThenStmtSyntax`` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: how should we continue visiting.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
open func visit(_ node: ThenStmtSyntax) -> SyntaxVisitorContinueKind {
return .visitChildren
}

/// The function called after visiting ``ThenStmtSyntax`` and its descendants.
/// - node: the node we just finished visiting.
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
open func visitPost(_ node: ThenStmtSyntax) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public struct RawTernaryExprSyntax: RawExprSyntaxNodeProtocol {
}
}

#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
@_spi(RawSyntax)
public struct RawThenStmtSyntax: RawStmtSyntaxNodeProtocol {
@_spi(RawSyntax)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,15 @@ public struct TernaryExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSy
/// then <expr>
/// ```
///
/// - Experiment: Requires experimental feature `thenStatements`.
///
/// ### Children
///
/// - `thenKeyword`: `then`
/// - `expression`: ``ExprSyntax``
#if compiler(>=5.8)
@_spi(ExperimentalLanguageFeatures)
#endif
public struct ThenStmtSyntax: StmtSyntaxProtocol, SyntaxHashable, _LeafStmtSyntaxNodeProtocol {
public let _syntaxNode: Syntax

Expand Down