From a318593c77b80978b9844910aff8474a206e7464 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 17 Oct 2023 09:41:05 -0700 Subject: [PATCH] Remove `SyntaxKind` conformance to `CaseIterable` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s no good reason to iterate over all cases in `SyntaxKind` and if `SyntaxKind` conforms to `CaseIterable`, we can’t mark members of it as deprecated (https://github.com/apple/swift-syntax/pull/2237/files#r1359917461) --- .../templates/swiftsyntax/SyntaxKindFile.swift | 2 +- Release Notes/511.md | 3 +++ Sources/SwiftSyntax/generated/SyntaxKind.swift | 2 +- .../Sources/swift-parser-cli/BasicFormat.swift | 11 +++++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift index 151950547ad..f65137ff215 100644 --- a/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift +++ b/CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxKindFile.swift @@ -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: CaseIterable + public enum SyntaxKind """ ) { DeclSyntax("case token") diff --git a/Release Notes/511.md b/Release Notes/511.md index ba375aa9d80..79a05671373 100644 --- a/Release Notes/511.md +++ b/Release Notes/511.md @@ -16,6 +16,9 @@ - Effect specifiers: - Description: The `unexpectedAfterThrowsSpecifier` node of the various effect specifiers has been removed. - Pull request: https://github.com/apple/swift-syntax/pull/2219 +- `SyntaxKind` removed conformance to `CaseIterable` + - Description: `SyntaxKind` no longer conforms to `CaseIterable` since there is no good use case to iterate over all syntax kinds. + - Pull request: https://github.com/apple/swift-syntax/pull/2292 ## Template diff --git a/Sources/SwiftSyntax/generated/SyntaxKind.swift b/Sources/SwiftSyntax/generated/SyntaxKind.swift index 016e8d142ee..92931b634f0 100644 --- a/Sources/SwiftSyntax/generated/SyntaxKind.swift +++ b/Sources/SwiftSyntax/generated/SyntaxKind.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// /// Enumerates the known kinds of Syntax represented in the Syntax tree. -public enum SyntaxKind: CaseIterable { +public enum SyntaxKind { case token case accessorBlock case accessorDeclList diff --git a/SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift b/SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift index 3ff12c6d301..0588e1843c1 100644 --- a/SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift +++ b/SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift @@ -47,8 +47,15 @@ struct BasicFormat: ParsableCommand, ParseCommand { var nodeType: String = "SourceFileSyntax" func run() throws { - let parsableMetatypes = SyntaxKind.allCases.compactMap { - $0.syntaxNodeType as? SyntaxParseable.Type + guard case .choices(let choices) = Syntax.structure else { + fatalError("Expected `Syntax.structure` to be the `choices` case") + } + + let parsableMetatypes = choices.compactMap { (choice) -> SyntaxParseable.Type? in + guard case .node(let nodeType) = choice else { + return nil + } + return nodeType as? SyntaxParseable.Type } let parsableMetatypesByName = Dictionary( parsableMetatypes.map {