Skip to content

Commit 5cdf916

Browse files
authored
Merge pull request #163 from allevato/swift-5.2-branch
Update to Swift 5.2 release.
2 parents b99433d + eb8a233 commit 5cdf916

File tree

5 files changed

+98
-95
lines changed

5 files changed

+98
-95
lines changed

Package.resolved

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"package": "SwiftSyntax",
1515
"repositoryURL": "https://github.com/apple/swift-syntax",
1616
"state": {
17-
"branch": "swift-DEVELOPMENT-SNAPSHOT-2020-01-29-a",
18-
"revision": "16f6af54d9ad3cfcb35cd557288783dded1107fd",
19-
"version": null
17+
"branch": null,
18+
"revision": "0688b9cfc4c3dd234e4f55f1f056b2affc849873",
19+
"version": "0.50200.0"
2020
}
2121
},
2222
{

Package.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ let package = Package(
2121
.library(name: "SwiftFormatConfiguration", targets: ["SwiftFormatConfiguration"]),
2222
],
2323
dependencies: [
24-
.package(
25-
url: "https://github.com/apple/swift-syntax",
26-
.revision("swift-DEVELOPMENT-SNAPSHOT-2020-01-29-a")
27-
),
24+
.package(url: "https://github.com/apple/swift-syntax", from: "0.50200.0"),
2825
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.0.1"),
2926
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.0.4")),
3027
],

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ is also expressed in the `SwiftSyntax` dependency in
2525

2626
| Xcode Release | Swift Version | `swift-format` Branch |
2727
|:-------------:|:---------------------------------------:|:----------------------|
28+
|| swift-5.2-RELEASE | `master` |
29+
| Xcode 11.4 | Swift 5.2 | `swift-5.2-branch` |
2830
| Xcode 11.0 | Swift 5.1 | `swift-5.1-branch` |
29-
|| swift-DEVELOPMENT-SNAPSHOT-2020-01-29-a | `master` |
3031

31-
For example, if you are using Xcode 11.0 (Swift 5.1), you can check out and
32+
For example, if you are using Xcode 11.4 (Swift 5.2), you can check out and
3233
build `swift-format` using the following commands:
3334

3435
```
35-
git clone -b swift-5.1-branch https://github.com/apple/swift-format.git
36+
git clone -b swift-5.2-branch https://github.com/apple/swift-format.git
3637
cd swift-format
3738
swift build
3839
```

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

+17-14
Original file line numberDiff line numberDiff line change
@@ -2036,22 +2036,25 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
20362036
return .visitChildren
20372037
}
20382038

2039-
override func visit(_ node: DerivativeRegistrationAttributeArgumentsSyntax)
2040-
-> SyntaxVisitorContinueKind
2041-
{
2042-
// This node encapsulates the entire list of arguments in a `@derivative(...)` or
2043-
// `@transpose(...)` attribute.
2044-
before(node.ofLabel, tokens: .open)
2045-
after(node.colon, tokens: .break(.continue, newlines: .elective(ignoresDiscretionary: true)))
2046-
after(node.comma, tokens: .close)
2039+
// `DerivativeRegistrationAttributeArguments` was added after the Swift 5.2 release was cut.
2040+
#if HAS_DERIVATIVE_REGISTRATION_ATTRIBUTE
2041+
override func visit(_ node: DerivativeRegistrationAttributeArgumentsSyntax)
2042+
-> SyntaxVisitorContinueKind
2043+
{
2044+
// This node encapsulates the entire list of arguments in a `@derivative(...)` or
2045+
// `@transpose(...)` attribute.
2046+
before(node.ofLabel, tokens: .open)
2047+
after(node.colon, tokens: .break(.continue, newlines: .elective(ignoresDiscretionary: true)))
2048+
after(node.comma, tokens: .close)
2049+
2050+
if let diffParams = node.diffParams {
2051+
before(diffParams.firstToken, tokens: .break(.same), .open)
2052+
after(diffParams.lastToken, tokens: .close)
2053+
}
20472054

2048-
if let diffParams = node.diffParams {
2049-
before(diffParams.firstToken, tokens: .break(.same), .open)
2050-
after(diffParams.lastToken, tokens: .close)
2055+
return .visitChildren
20512056
}
2052-
2053-
return .visitChildren
2054-
}
2057+
#endif
20552058

20562059
override func visit(_ node: DifferentiationParamsClauseSyntax) -> SyntaxVisitorContinueKind {
20572060
// This node encapsulates the `wrt:` label and value/variable in a `@differentiable`,

Tests/SwiftFormatPrettyPrintTests/DifferentiationAttributeTests.swift

+73-71
Original file line numberDiff line numberDiff line change
@@ -43,75 +43,77 @@ final class DifferentiationAttributeTests: PrettyPrintTestCase {
4343
assertPrettyPrintEqual(input: input, expected: expected, linelength: 43)
4444
}
4545

46-
func testDerivative() {
47-
let input =
48-
"""
49-
@derivative(of: foo, wrt: x)
50-
func deriv<T>(_ x: T) {}
51-
52-
@derivative(of: foobar, wrt: x)
53-
func deriv<T>(_ x: T) {}
54-
55-
@derivative(of: foobarbaz, wrt: theVariableNamedX)
56-
func deriv<T>(_ theVariableNamedX: T) {}
57-
"""
58-
59-
let expected =
60-
"""
61-
@derivative(of: foo, wrt: x)
62-
func deriv<T>(_ x: T) {}
63-
64-
@derivative(
65-
of: foobar, wrt: x
66-
)
67-
func deriv<T>(_ x: T) {}
68-
69-
@derivative(
70-
of: foobarbaz,
71-
wrt: theVariableNamedX
72-
)
73-
func deriv<T>(
74-
_ theVariableNamedX: T
75-
) {}
76-
77-
"""
78-
79-
assertPrettyPrintEqual(input: input, expected: expected, linelength: 28)
80-
}
81-
82-
func testTranspose() {
83-
let input =
84-
"""
85-
@transpose(of: foo, wrt: 0)
86-
func trans<T>(_ v: T) {}
87-
88-
@transpose(of: foobar, wrt: 0)
89-
func trans<T>(_ v: T) {}
90-
91-
@transpose(of: someReallyLongName, wrt: 0)
92-
func trans<T>(_ theVariableNamedV: T) {}
93-
"""
94-
95-
let expected =
96-
"""
97-
@transpose(of: foo, wrt: 0)
98-
func trans<T>(_ v: T) {}
99-
100-
@transpose(
101-
of: foobar, wrt: 0
102-
)
103-
func trans<T>(_ v: T) {}
104-
105-
@transpose(
106-
of: someReallyLongName,
107-
wrt: 0
108-
)
109-
func trans<T>(
110-
_ theVariableNamedV: T
111-
) {}
112-
113-
"""
114-
115-
assertPrettyPrintEqual(input: input, expected: expected, linelength: 27)
116-
}
46+
#if HAS_DERIVATIVE_REGISTRATION_ATTRIBUTE
47+
func testDerivative() {
48+
let input =
49+
"""
50+
@derivative(of: foo, wrt: x)
51+
func deriv<T>(_ x: T) {}
52+
53+
@derivative(of: foobar, wrt: x)
54+
func deriv<T>(_ x: T) {}
55+
56+
@derivative(of: foobarbaz, wrt: theVariableNamedX)
57+
func deriv<T>(_ theVariableNamedX: T) {}
58+
"""
59+
60+
let expected =
61+
"""
62+
@derivative(of: foo, wrt: x)
63+
func deriv<T>(_ x: T) {}
64+
65+
@derivative(
66+
of: foobar, wrt: x
67+
)
68+
func deriv<T>(_ x: T) {}
69+
70+
@derivative(
71+
of: foobarbaz,
72+
wrt: theVariableNamedX
73+
)
74+
func deriv<T>(
75+
_ theVariableNamedX: T
76+
) {}
77+
78+
"""
79+
80+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 28)
81+
}
82+
83+
func testTranspose() {
84+
let input =
85+
"""
86+
@transpose(of: foo, wrt: 0)
87+
func trans<T>(_ v: T) {}
88+
89+
@transpose(of: foobar, wrt: 0)
90+
func trans<T>(_ v: T) {}
91+
92+
@transpose(of: someReallyLongName, wrt: 0)
93+
func trans<T>(_ theVariableNamedV: T) {}
94+
"""
95+
96+
let expected =
97+
"""
98+
@transpose(of: foo, wrt: 0)
99+
func trans<T>(_ v: T) {}
100+
101+
@transpose(
102+
of: foobar, wrt: 0
103+
)
104+
func trans<T>(_ v: T) {}
105+
106+
@transpose(
107+
of: someReallyLongName,
108+
wrt: 0
109+
)
110+
func trans<T>(
111+
_ theVariableNamedV: T
112+
) {}
113+
114+
"""
115+
116+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 27)
117+
}
118+
#endif
117119
}

0 commit comments

Comments
 (0)