Skip to content
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

Updated to Swift 5.10 #7

Merged
merged 2 commits into from
Mar 15, 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
26 changes: 23 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,55 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Install swift
- name: Install Swift (MacOS)
if: matrix.os == 'macos-latest'
uses: SwiftyLab/setup-swift@latest
with:
swift-version: "5.9"
swift-version: '5.10'
check-latest: true
- name: Install Swift (Windows)
if: matrix.os == 'windows-latest'
uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.10-release
tag: 5.10-RELEASE
- name: Run Linux Build
if: matrix.os == 'ubuntu-20.04'
run: |
swift build
mv ./.build/debug/SwiftAstGen SwiftAstGen-linux
gzexe SwiftAstGen-linux
./SwiftAstGen-linux -s
- name: Run Mac Build
if: matrix.os == 'macos-latest'
run: |
swift build
mv ./.build/debug/SwiftAstGen SwiftAstGen-mac
gzexe SwiftAstGen-mac
./SwiftAstGen-mac -s
- name: Run Windows Build
if: matrix.os == 'windows-latest'
run: |
swift build
mv .\.build\debug\SwiftAstGen.exe SwiftAstGen-win.exe
.\SwiftAstGen-win.exe -s
- name: Run UPX for Windows Build
if: matrix.os == 'windows-latest'
uses: crazy-max/ghaction-upx@v3
with:
version: latest
files: |
SwiftAstGen-win.exe
args: -fq
- name: Run Swift Tests
run: swift test
- name: Set up JDK
uses: actions/setup-java@v3
if: matrix.os != 'windows-latest'
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '19'
- name: Run Scala Tests
if: matrix.os != 'windows-latest'
run: sbt test
working-directory: ./Tests/ScalaSwiftNodeSyntaxTests
12 changes: 10 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Install swift
- name: Install Swift (MacOS)
if: matrix.os == 'macos-latest'
uses: SwiftyLab/setup-swift@latest
with:
swift-version: "5.9"
swift-version: '5.10'
check-latest: true
- name: Install Swift (Windows)
if: matrix.os == 'windows-latest'
uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.10-release
tag: 5.10-RELEASE
- name: Run Linux Build
if: matrix.os == 'ubuntu-20.04'
run: |
Expand Down
7 changes: 4 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "f0bdad18f08b8438e54c541e12efce628281aa84df2fdc05c794ae30b579c24c",
"pins" : [
{
"identity" : "swift-argument-parser",
Expand All @@ -14,10 +15,10 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b",
"version" : "509.0.0"
"revision" : "fa8f95c2d536d6620cc2f504ebe8a6167c9fc2dd",
"version" : "510.0.1"
}
}
],
"version" : 2
"version" : 3
}
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 5.10

import PackageDescription

Expand All @@ -12,7 +12,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "510.0.1"),
],
targets: [
.target(
Expand All @@ -22,6 +22,9 @@ let package = Package(
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
"CodeGeneration",
],
swiftSettings: [
.unsafeFlags(["-warnings-as-errors"])
]
),
.target(
Expand Down
32 changes: 9 additions & 23 deletions Sources/CodeGeneration/SyntaxSupport/AttributeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "availabilityArguments",
deprecatedName: "availabilityList",
kind: .collection(
kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument",
deprecatedCollectionElementName: "Availability")
kind: .collection(kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument", deprecatedCollectionElementName: "Availability")
),
Child(
name: "semicolon",
Expand Down Expand Up @@ -238,9 +236,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "platforms",
deprecatedName: "versionList",
kind: .collection(
kind: .platformVersionItemList, collectionElementName: "Platform",
deprecatedCollectionElementName: "Availability"),
kind: .collection(kind: .platformVersionItemList, collectionElementName: "Platform", deprecatedCollectionElementName: "Availability"),
documentation: "The list of OS versions in which the declaration became ABI stable."
),
]
Expand Down Expand Up @@ -361,8 +357,7 @@ public let ATTRIBUTE_NODES: [Node] = [
kind: .differentiabilityArgument,
base: .syntax,
nameForDiagnostics: "differentiability argument",
documentation:
"A differentiability argument: either the \"self\" identifier, a function parameter name, or a function parameter index.",
documentation: "A differentiability argument: either the \"self\" identifier, a function parameter name, or a function parameter index.",
traits: [
"WithTrailingComma"
],
Expand Down Expand Up @@ -476,8 +471,7 @@ public let ATTRIBUTE_NODES: [Node] = [
name: "genericWhereClause",
deprecatedName: "whereClause",
kind: .node(kind: .genericWhereClause),
documentation:
"A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
documentation: "A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
isOptional: true
),
]
Expand Down Expand Up @@ -563,8 +557,7 @@ public let ATTRIBUTE_NODES: [Node] = [
kind: .effectsAttributeArgumentList,
base: .syntaxCollection,
nameForDiagnostics: "@_effects arguments",
documentation:
"The arguments of the '@_effects' attribute. These will be parsed during the SIL stage.",
documentation: "The arguments of the '@_effects' attribute. These will be parsed during the SIL stage.",
elementChoices: [.token]
),

Expand Down Expand Up @@ -595,8 +588,7 @@ public let ATTRIBUTE_NODES: [Node] = [
kind: .implementsAttributeArguments,
base: .syntax,
nameForDiagnostics: "@_implements arguemnts",
documentation:
"The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`",
documentation: "The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`",
children: [
Child(
name: "type",
Expand Down Expand Up @@ -637,7 +629,6 @@ public let ATTRIBUTE_NODES: [Node] = [
.keyword(.kind),
.keyword(.spi),
.keyword(.spiModule),
.keyword(.available),
]),
nameForDiagnostics: "label",
documentation: "The label of the argument"
Expand Down Expand Up @@ -708,8 +699,7 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "ordinal",
kind: .token(choices: [.token(.integerLiteral)]),
documentation:
"The ordinal corresponding to the 'some' keyword that introduced this opaque type."
documentation: "The ordinal corresponding to the 'some' keyword that introduced this opaque type."
),
]
),
Expand Down Expand Up @@ -748,18 +738,14 @@ public let ATTRIBUTE_NODES: [Node] = [
base: .syntaxCollection,
nameForDiagnostics: "argument to '@_specialize",
documentation: "A collection of arguments for the `@_specialize` attribute",
elementChoices: [
.labeledSpecializeArgument, .specializeAvailabilityArgument,
.specializeTargetFunctionArgument, .genericWhereClause,
]
elementChoices: [.labeledSpecializeArgument, .specializeAvailabilityArgument, .specializeTargetFunctionArgument, .genericWhereClause]
),

Node(
kind: .specializeTargetFunctionArgument,
base: .syntax,
nameForDiagnostics: "attribute argument",
documentation:
"A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`",
documentation: "A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`",
traits: [
"WithTrailingComma"
],
Expand Down
15 changes: 5 additions & 10 deletions Sources/CodeGeneration/SyntaxSupport/AvailabilityNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .availabilityArgument,
base: .syntax,
nameForDiagnostics: "availability argument",
documentation:
"A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.",
documentation: "A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.",
traits: ["WithTrailingComma"],
children: [
Child(
Expand Down Expand Up @@ -55,8 +54,7 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .availabilityLabeledArgument,
base: .syntax,
nameForDiagnostics: "availability argument",
documentation:
"An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
documentation: "An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
children: [
Child(
name: "label",
Expand Down Expand Up @@ -104,8 +102,7 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .platformVersion,
base: .syntax,
nameForDiagnostics: "version restriction",
documentation:
"An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
documentation: "An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
children: [
Child(
name: "platform",
Expand Down Expand Up @@ -160,8 +157,7 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .versionTuple,
base: .syntax,
nameForDiagnostics: "version tuple",
documentation:
"A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
documentation: "A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
children: [
Child(
name: "major",
Expand All @@ -171,8 +167,7 @@ public let AVAILABILITY_NODES: [Node] = [
Child(
name: "components",
kind: .collection(kind: .versionComponentList, collectionElementName: "VersionComponent"),
documentation:
"Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`."
documentation: "Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`."
),
]
),
Expand Down
38 changes: 19 additions & 19 deletions Sources/CodeGeneration/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public enum TokenChoice: Equatable {
case .token: return false
}
}

public var varOrCaseName: TokenSyntax {
switch self {
case .keyword(let keyword):
return keyword.spec.varOrCaseName
case .token(let token):
return token.spec.varOrCaseName
}
}
}

public enum ChildKind {
Expand All @@ -32,14 +41,11 @@ public enum ChildKind {
/// The child always contains a node that matches one of the `choices`.
case nodeChoices(choices: [Child])
/// The child is a collection of `kind`.
case collection(
kind: SyntaxNodeKind, collectionElementName: String, defaultsToEmpty: Bool = false,
deprecatedCollectionElementName: String? = nil)
case collection(kind: SyntaxNodeKind, collectionElementName: String, defaultsToEmpty: Bool = false, deprecatedCollectionElementName: String? = nil)
/// The child is a token that matches one of the given `choices`.
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
/// overrides the default leading/trailing space behavior of the token.
case token(
choices: [TokenChoice], requiresLeadingSpace: Bool? = nil, requiresTrailingSpace: Bool? = nil)
case token(choices: [TokenChoice], requiresLeadingSpace: Bool? = nil, requiresTrailingSpace: Bool? = nil)

public var isNodeChoices: Bool {
if case .nodeChoices = self {
Expand Down Expand Up @@ -123,11 +129,11 @@ public class Child {

public var syntaxNodeKind: SyntaxNodeKind {
switch kind {
case .node(let kind):
case .node(kind: let kind):
return kind
case .nodeChoices:
return .syntax
case .collection(let kind, _, _, _):
case .collection(kind: let kind, _, _, _):
return kind
case .token:
return .token
Expand All @@ -143,8 +149,7 @@ public class Child {
///
/// For any other kind of child nodes, accessing this property crashes.
public var syntaxChoicesType: TypeSyntax {
precondition(
kind.isNodeChoices, "Cannot get `syntaxChoicesType` for node that doesn’t have nodeChoices")
precondition(kind.isNodeChoices, "Cannot get `syntaxChoicesType` for node that doesn’t have nodeChoices")
return "\(raw: name.withFirstCharacterUppercased)"
}

Expand Down Expand Up @@ -223,7 +228,7 @@ public class Child {
return choices.isEmpty
case .node(let kind):
return kind.isBase
case .collection(let kind, _, _, _):
case .collection(kind: let kind, _, _, _):
return kind.isBase
case .token:
return false
Expand All @@ -236,8 +241,7 @@ public class Child {
/// an experimental language feature.
public var apiAttributes: AttributeListSyntax {
guard isExperimental else { return "" }
return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(
\.trailingTrivia, .newline)
return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .newline)
}

/// If a classification is passed, it specifies the color identifiers in
Expand All @@ -254,19 +258,15 @@ public class Child {
documentation: String? = nil,
isOptional: Bool = false
) {
precondition(
name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase")
precondition(
deprecatedName?.first?.isLowercase ?? true,
"The first letter of a child’s deprecatedName should be lowercase")
precondition(name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase")
precondition(deprecatedName?.first?.isLowercase ?? true, "The first letter of a child’s deprecatedName should be lowercase")
self.name = name
self.deprecatedName = deprecatedName
self.kind = kind
self.experimentalFeature = experimentalFeature
self.nameForDiagnostics = nameForDiagnostics
self.documentationSummary = SwiftSyntax.Trivia.docCommentTrivia(from: documentation)
self.documentationAbstract = String(
documentation?.split(whereSeparator: \.isNewline).first ?? "")
self.documentationAbstract = String(documentation?.split(whereSeparator: \.isNewline).first ?? "")
self.isOptional = isOptional
}
}
Loading
Loading