Skip to content

Commit b8ca62c

Browse files
Updated to Swift 5.10 (#7)
1 parent 129695b commit b8ca62c

25 files changed

+590
-545
lines changed

.github/workflows/pr.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,55 @@ jobs:
1414
uses: actions/checkout@v4
1515
with:
1616
fetch-depth: '0'
17-
- name: Install swift
17+
- name: Install Swift (MacOS)
18+
if: matrix.os == 'macos-latest'
1819
uses: SwiftyLab/setup-swift@latest
1920
with:
20-
swift-version: "5.9"
21+
swift-version: '5.10'
22+
check-latest: true
23+
- name: Install Swift (Windows)
24+
if: matrix.os == 'windows-latest'
25+
uses: compnerd/gha-setup-swift@main
26+
with:
27+
branch: swift-5.10-release
28+
tag: 5.10-RELEASE
2129
- name: Run Linux Build
2230
if: matrix.os == 'ubuntu-20.04'
2331
run: |
2432
swift build
2533
mv ./.build/debug/SwiftAstGen SwiftAstGen-linux
34+
gzexe SwiftAstGen-linux
2635
./SwiftAstGen-linux -s
2736
- name: Run Mac Build
2837
if: matrix.os == 'macos-latest'
2938
run: |
3039
swift build
3140
mv ./.build/debug/SwiftAstGen SwiftAstGen-mac
41+
gzexe SwiftAstGen-mac
3242
./SwiftAstGen-mac -s
3343
- name: Run Windows Build
3444
if: matrix.os == 'windows-latest'
3545
run: |
3646
swift build
3747
mv .\.build\debug\SwiftAstGen.exe SwiftAstGen-win.exe
3848
.\SwiftAstGen-win.exe -s
49+
- name: Run UPX for Windows Build
50+
if: matrix.os == 'windows-latest'
51+
uses: crazy-max/ghaction-upx@v3
52+
with:
53+
version: latest
54+
files: |
55+
SwiftAstGen-win.exe
56+
args: -fq
3957
- name: Run Swift Tests
4058
run: swift test
4159
- name: Set up JDK
42-
uses: actions/setup-java@v3
60+
if: matrix.os != 'windows-latest'
61+
uses: actions/setup-java@v4
4362
with:
4463
distribution: 'temurin'
4564
java-version: '19'
4665
- name: Run Scala Tests
66+
if: matrix.os != 'windows-latest'
4767
run: sbt test
4868
working-directory: ./Tests/ScalaSwiftNodeSyntaxTests

.github/workflows/release.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
fetch-depth: '0'
24-
- name: Install swift
24+
- name: Install Swift (MacOS)
25+
if: matrix.os == 'macos-latest'
2526
uses: SwiftyLab/setup-swift@latest
2627
with:
27-
swift-version: "5.9"
28+
swift-version: '5.10'
29+
check-latest: true
30+
- name: Install Swift (Windows)
31+
if: matrix.os == 'windows-latest'
32+
uses: compnerd/gha-setup-swift@main
33+
with:
34+
branch: swift-5.10-release
35+
tag: 5.10-RELEASE
2836
- name: Run Linux Build
2937
if: matrix.os == 'ubuntu-20.04'
3038
run: |

Package.resolved

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 5.10
22

33
import PackageDescription
44

@@ -12,7 +12,7 @@ let package = Package(
1212
],
1313
dependencies: [
1414
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
15-
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
15+
.package(url: "https://github.com/apple/swift-syntax", from: "510.0.1"),
1616
],
1717
targets: [
1818
.target(
@@ -22,6 +22,9 @@ let package = Package(
2222
.product(name: "SwiftParser", package: "swift-syntax"),
2323
.product(name: "SwiftOperators", package: "swift-syntax"),
2424
"CodeGeneration",
25+
],
26+
swiftSettings: [
27+
.unsafeFlags(["-warnings-as-errors"])
2528
]
2629
),
2730
.target(

Sources/CodeGeneration/SyntaxSupport/AttributeNodes.swift

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ public let ATTRIBUTE_NODES: [Node] = [
180180
Child(
181181
name: "availabilityArguments",
182182
deprecatedName: "availabilityList",
183-
kind: .collection(
184-
kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument",
185-
deprecatedCollectionElementName: "Availability")
183+
kind: .collection(kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument", deprecatedCollectionElementName: "Availability")
186184
),
187185
Child(
188186
name: "semicolon",
@@ -238,9 +236,7 @@ public let ATTRIBUTE_NODES: [Node] = [
238236
Child(
239237
name: "platforms",
240238
deprecatedName: "versionList",
241-
kind: .collection(
242-
kind: .platformVersionItemList, collectionElementName: "Platform",
243-
deprecatedCollectionElementName: "Availability"),
239+
kind: .collection(kind: .platformVersionItemList, collectionElementName: "Platform", deprecatedCollectionElementName: "Availability"),
244240
documentation: "The list of OS versions in which the declaration became ABI stable."
245241
),
246242
]
@@ -361,8 +357,7 @@ public let ATTRIBUTE_NODES: [Node] = [
361357
kind: .differentiabilityArgument,
362358
base: .syntax,
363359
nameForDiagnostics: "differentiability argument",
364-
documentation:
365-
"A differentiability argument: either the \"self\" identifier, a function parameter name, or a function parameter index.",
360+
documentation: "A differentiability argument: either the \"self\" identifier, a function parameter name, or a function parameter index.",
366361
traits: [
367362
"WithTrailingComma"
368363
],
@@ -476,8 +471,7 @@ public let ATTRIBUTE_NODES: [Node] = [
476471
name: "genericWhereClause",
477472
deprecatedName: "whereClause",
478473
kind: .node(kind: .genericWhereClause),
479-
documentation:
480-
"A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
474+
documentation: "A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
481475
isOptional: true
482476
),
483477
]
@@ -563,8 +557,7 @@ public let ATTRIBUTE_NODES: [Node] = [
563557
kind: .effectsAttributeArgumentList,
564558
base: .syntaxCollection,
565559
nameForDiagnostics: "@_effects arguments",
566-
documentation:
567-
"The arguments of the '@_effects' attribute. These will be parsed during the SIL stage.",
560+
documentation: "The arguments of the '@_effects' attribute. These will be parsed during the SIL stage.",
568561
elementChoices: [.token]
569562
),
570563

@@ -595,8 +588,7 @@ public let ATTRIBUTE_NODES: [Node] = [
595588
kind: .implementsAttributeArguments,
596589
base: .syntax,
597590
nameForDiagnostics: "@_implements arguemnts",
598-
documentation:
599-
"The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`",
591+
documentation: "The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`",
600592
children: [
601593
Child(
602594
name: "type",
@@ -637,7 +629,6 @@ public let ATTRIBUTE_NODES: [Node] = [
637629
.keyword(.kind),
638630
.keyword(.spi),
639631
.keyword(.spiModule),
640-
.keyword(.available),
641632
]),
642633
nameForDiagnostics: "label",
643634
documentation: "The label of the argument"
@@ -708,8 +699,7 @@ public let ATTRIBUTE_NODES: [Node] = [
708699
Child(
709700
name: "ordinal",
710701
kind: .token(choices: [.token(.integerLiteral)]),
711-
documentation:
712-
"The ordinal corresponding to the 'some' keyword that introduced this opaque type."
702+
documentation: "The ordinal corresponding to the 'some' keyword that introduced this opaque type."
713703
),
714704
]
715705
),
@@ -748,18 +738,14 @@ public let ATTRIBUTE_NODES: [Node] = [
748738
base: .syntaxCollection,
749739
nameForDiagnostics: "argument to '@_specialize",
750740
documentation: "A collection of arguments for the `@_specialize` attribute",
751-
elementChoices: [
752-
.labeledSpecializeArgument, .specializeAvailabilityArgument,
753-
.specializeTargetFunctionArgument, .genericWhereClause,
754-
]
741+
elementChoices: [.labeledSpecializeArgument, .specializeAvailabilityArgument, .specializeTargetFunctionArgument, .genericWhereClause]
755742
),
756743

757744
Node(
758745
kind: .specializeTargetFunctionArgument,
759746
base: .syntax,
760747
nameForDiagnostics: "attribute argument",
761-
documentation:
762-
"A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`",
748+
documentation: "A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`",
763749
traits: [
764750
"WithTrailingComma"
765751
],

Sources/CodeGeneration/SyntaxSupport/AvailabilityNodes.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public let AVAILABILITY_NODES: [Node] = [
1515
kind: .availabilityArgument,
1616
base: .syntax,
1717
nameForDiagnostics: "availability argument",
18-
documentation:
19-
"A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.",
18+
documentation: "A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.",
2019
traits: ["WithTrailingComma"],
2120
children: [
2221
Child(
@@ -55,8 +54,7 @@ public let AVAILABILITY_NODES: [Node] = [
5554
kind: .availabilityLabeledArgument,
5655
base: .syntax,
5756
nameForDiagnostics: "availability argument",
58-
documentation:
59-
"An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
57+
documentation: "An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
6058
children: [
6159
Child(
6260
name: "label",
@@ -104,8 +102,7 @@ public let AVAILABILITY_NODES: [Node] = [
104102
kind: .platformVersion,
105103
base: .syntax,
106104
nameForDiagnostics: "version restriction",
107-
documentation:
108-
"An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
105+
documentation: "An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
109106
children: [
110107
Child(
111108
name: "platform",
@@ -160,8 +157,7 @@ public let AVAILABILITY_NODES: [Node] = [
160157
kind: .versionTuple,
161158
base: .syntax,
162159
nameForDiagnostics: "version tuple",
163-
documentation:
164-
"A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
160+
documentation: "A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
165161
children: [
166162
Child(
167163
name: "major",
@@ -171,8 +167,7 @@ public let AVAILABILITY_NODES: [Node] = [
171167
Child(
172168
name: "components",
173169
kind: .collection(kind: .versionComponentList, collectionElementName: "VersionComponent"),
174-
documentation:
175-
"Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`."
170+
documentation: "Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`."
176171
),
177172
]
178173
),

Sources/CodeGeneration/SyntaxSupport/Child.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public enum TokenChoice: Equatable {
2424
case .token: return false
2525
}
2626
}
27+
28+
public var varOrCaseName: TokenSyntax {
29+
switch self {
30+
case .keyword(let keyword):
31+
return keyword.spec.varOrCaseName
32+
case .token(let token):
33+
return token.spec.varOrCaseName
34+
}
35+
}
2736
}
2837

2938
public enum ChildKind {
@@ -32,14 +41,11 @@ public enum ChildKind {
3241
/// The child always contains a node that matches one of the `choices`.
3342
case nodeChoices(choices: [Child])
3443
/// The child is a collection of `kind`.
35-
case collection(
36-
kind: SyntaxNodeKind, collectionElementName: String, defaultsToEmpty: Bool = false,
37-
deprecatedCollectionElementName: String? = nil)
44+
case collection(kind: SyntaxNodeKind, collectionElementName: String, defaultsToEmpty: Bool = false, deprecatedCollectionElementName: String? = nil)
3845
/// The child is a token that matches one of the given `choices`.
3946
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
4047
/// overrides the default leading/trailing space behavior of the token.
41-
case token(
42-
choices: [TokenChoice], requiresLeadingSpace: Bool? = nil, requiresTrailingSpace: Bool? = nil)
48+
case token(choices: [TokenChoice], requiresLeadingSpace: Bool? = nil, requiresTrailingSpace: Bool? = nil)
4349

4450
public var isNodeChoices: Bool {
4551
if case .nodeChoices = self {
@@ -123,11 +129,11 @@ public class Child {
123129

124130
public var syntaxNodeKind: SyntaxNodeKind {
125131
switch kind {
126-
case .node(let kind):
132+
case .node(kind: let kind):
127133
return kind
128134
case .nodeChoices:
129135
return .syntax
130-
case .collection(let kind, _, _, _):
136+
case .collection(kind: let kind, _, _, _):
131137
return kind
132138
case .token:
133139
return .token
@@ -143,8 +149,7 @@ public class Child {
143149
///
144150
/// For any other kind of child nodes, accessing this property crashes.
145151
public var syntaxChoicesType: TypeSyntax {
146-
precondition(
147-
kind.isNodeChoices, "Cannot get `syntaxChoicesType` for node that doesn’t have nodeChoices")
152+
precondition(kind.isNodeChoices, "Cannot get `syntaxChoicesType` for node that doesn’t have nodeChoices")
148153
return "\(raw: name.withFirstCharacterUppercased)"
149154
}
150155

@@ -223,7 +228,7 @@ public class Child {
223228
return choices.isEmpty
224229
case .node(let kind):
225230
return kind.isBase
226-
case .collection(let kind, _, _, _):
231+
case .collection(kind: let kind, _, _, _):
227232
return kind.isBase
228233
case .token:
229234
return false
@@ -236,8 +241,7 @@ public class Child {
236241
/// an experimental language feature.
237242
public var apiAttributes: AttributeListSyntax {
238243
guard isExperimental else { return "" }
239-
return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(
240-
\.trailingTrivia, .newline)
244+
return AttributeListSyntax("@_spi(ExperimentalLanguageFeatures)").with(\.trailingTrivia, .newline)
241245
}
242246

243247
/// If a classification is passed, it specifies the color identifiers in
@@ -254,19 +258,15 @@ public class Child {
254258
documentation: String? = nil,
255259
isOptional: Bool = false
256260
) {
257-
precondition(
258-
name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase")
259-
precondition(
260-
deprecatedName?.first?.isLowercase ?? true,
261-
"The first letter of a child’s deprecatedName should be lowercase")
261+
precondition(name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase")
262+
precondition(deprecatedName?.first?.isLowercase ?? true, "The first letter of a child’s deprecatedName should be lowercase")
262263
self.name = name
263264
self.deprecatedName = deprecatedName
264265
self.kind = kind
265266
self.experimentalFeature = experimentalFeature
266267
self.nameForDiagnostics = nameForDiagnostics
267268
self.documentationSummary = SwiftSyntax.Trivia.docCommentTrivia(from: documentation)
268-
self.documentationAbstract = String(
269-
documentation?.split(whereSeparator: \.isNewline).first ?? "")
269+
self.documentationAbstract = String(documentation?.split(whereSeparator: \.isNewline).first ?? "")
270270
self.isOptional = isOptional
271271
}
272272
}

0 commit comments

Comments
 (0)