Skip to content

Commit 6bc5110

Browse files
authored
Merge pull request swiftlang#166 from ahoppen/changelog
Add a change log describing the changes since the Swift 5.1 release
2 parents c5be148 + 9e74ef0 commit 6bc5110

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

Changelog.md

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Changelog
2+
3+
Note: This is in reverse chronological order, so newer entries are added to the top.
4+
5+
## Swift 5.2
6+
7+
- Property `uniqueIdentifier` removed from syntax nodes and `SyntaxNode` ([#164](https://github.com/apple/swift-syntax/pull/164))
8+
9+
Use the newly added property `id` or the conformance to `Identifiable` instead.
10+
11+
- Syntax nodes and `SyntaxNode` conform to `Identifiable` ([#164](https://github.com/apple/swift-syntax/pull/164))
12+
13+
`Identifiable` conformance has been added to all syntax nodes and the `SyntaxNode` type using `SyntaxIdentifier` as the identifier.
14+
15+
- The `walk` method on syntax nodes has been removed. ([#158](https://github.com/apple/swift-syntax/pull/158))
16+
17+
Instead, use the `walk` method on the `SyntaxVisitor`.
18+
19+
```swift
20+
// Before
21+
tree.walk(&visitor)
22+
23+
// Now
24+
visitor.walk(tree)
25+
```
26+
27+
- `SyntaxVisitor` and `SyntaxAnyVisitor` are a `class` and no longer a `protocol`. ([#158](https://github.com/apple/swift-syntax/pull/158))
28+
29+
For performance reasons the `SyntaxVisitor` and `SyntaxAnyVisitor` were migrated from being a protocol to being a class.
30+
31+
Any structs conforming to the above protocols need to become classes. Implementing methods need to be marked `override` and, if necessary, any `mutating` keywords need to be removed.
32+
33+
```swift
34+
// Before
35+
struct Visitor: SyntaxVisitor {
36+
mutating func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
37+
/* ... */
38+
}
39+
}
40+
41+
// Now
42+
class Visitor: SyntaxVisitor {
43+
override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
44+
/* ... */
45+
}
46+
}
47+
```
48+
49+
- A new type `SyntaxEnum` has been introduced ([#155](https://github.com/apple/swift-syntax/pull/155))
50+
51+
The new type `SyntaxEnum` allow exhaustive switching over all syntax types. It can be constructed by calling `asSyntaxEnum` on `Syntax`.
52+
53+
```swift
54+
let node: Syntax
55+
56+
switch node.asSyntaxEnum {
57+
case .identifierExpr(let identifierExprSyntax):
58+
/* ... */
59+
}
60+
```
61+
62+
63+
### Modelling syntax nodes as structs
64+
65+
For increased performance, the modelling of the syntax node hierarchy has been switched from being `protocol`-based to being `struct`-based. This includes the following changes:
66+
67+
- The protocols `ExprSyntax`, `DeclSyntax`, `Syntax` etc. have been removed. ([#155](https://github.com/apple/swift-syntax/pull/155))
68+
69+
For passing values of these types around, use the new type erasers `ExprSyntax`, `DeclSyntax`, `Syntax` etc. instead. To add computed properties or functions to all expression nodes, write an extension on `ExprSyntaxProtocol`. To add methods to all syntax nodes, extend `SyntaxProtcol`.
70+
71+
**Pass type eraser**
72+
73+
```swift
74+
func foo(_ expr: ExprSyntax) {}
75+
```
76+
77+
stays the same. `ExprSyntax` is now a struct and not a protocol. See below on how to create an `ExprSyntax`.
78+
79+
**Extening a type**
80+
81+
```swift
82+
// Before
83+
extension ExprSyntax {
84+
func evaluateAsIntegerExpr() -> Int { /* ... */ }
85+
}
86+
87+
// Now
88+
extension ExprSyntaxProtocol {
89+
func evaluateAsIntegerExpr() -> Int { /* ... */ }
90+
}
91+
```
92+
93+
94+
- Checking a node's type can no longer be performed using the `is` operator. Use the `is(_: SyntaxProtocol)` method on any type eraser instead. ([#155](https://github.com/apple/swift-syntax/pull/155))
95+
96+
```swift
97+
// Before
98+
exprSyntax is IdentifierExprSyntax
99+
100+
// Now
101+
exprSyntax.is(IdentifierExprSyntax.self)
102+
```
103+
104+
105+
- Downcasting can no longer be performed using the `as` operator. For downcasting use the `as(_: SyntaxProtocol)` method on any type eraser. ([#155](https://github.com/apple/swift-syntax/pull/155))
106+
107+
```swift
108+
// Before
109+
exprSyntax as? IdentifierExprSyntax
110+
111+
// Now
112+
exprSyntax.as(IdentifierExprSyntax.self)
113+
```
114+
115+
- Upcasting needs to be performed explicitly. Use the designated initializers for this. ([#155](https://github.com/apple/swift-syntax/pull/155))
116+
117+
```swift
118+
// Before
119+
func foo() -> ExprSyntax {
120+
/* ... */
121+
return identiferExprSyntax
122+
}
123+
124+
// Now
125+
func foo() -> ExprSyntax {
126+
/* ... */
127+
return ExprSyntax(identiferExprSyntax)
128+
}
129+
```

0 commit comments

Comments
 (0)