Skip to content

Commit f0b5ed4

Browse files
authored
Merge pull request #601 from CodaFi/friday-the-thirteenth
Restore the Ability to Build with Xcode 13
2 parents bc04032 + e1b74e5 commit f0b5ed4

File tree

7 files changed

+32
-25
lines changed

7 files changed

+32
-25
lines changed

Sources/SwiftSyntax/BumpPtrAllocator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ extension UnsafeMutableRawPointer {
155155
/// - Parameter alignment: The alignment of the returned pointer, in bytes.
156156
/// Alignment must be a whole power of 2.
157157
/// - Returns: A pointer aligned to `alignment`.
158-
fileprivate func alignedUp(toMultipleOf alignment: Int) -> Self {
158+
@_spi(Testing)
159+
public func alignedUp(toMultipleOf alignment: Int) -> Self {
159160
let mask = UInt(alignment) &- 1
160161
assert(
161162
alignment > 0 && UInt(alignment) & mask == 0,

Sources/SwiftSyntax/TokenKind.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ extension TokenKind: Equatable {
143143
}
144144

145145
/// Plain token kind value, without an associated `String` value.
146-
public enum RawTokenKind {
146+
public enum RawTokenKind: Equatable, Hashable {
147147
case eof
148148
% for token in SYNTAX_TOKENS:
149149
case ${token.swift_kind()}

Sources/SwiftSyntax/gyb_generated/TokenKind.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ extension TokenKind: Equatable {
11221122
}
11231123

11241124
/// Plain token kind value, without an associated `String` value.
1125-
public enum RawTokenKind {
1125+
public enum RawTokenKind: Equatable, Hashable {
11261126
case eof
11271127
case associatedtypeKeyword
11281128
case classKeyword

Sources/_SwiftSyntaxTestSupport/Syntax+Assertions.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,24 @@ public func XCTAssertSameStructure(
4949

5050
/// Verifies that two trees are equivalent, ie. they have the same structure
5151
/// and optionally the same trivia if `includeTrivia` is set.
52-
public func XCTAssertSameStructure(
53-
_ actual: SyntaxProtocol,
54-
_ expected: SyntaxProtocol,
52+
public func XCTAssertSameStructure<ActualTree, ExpectedTree>(
53+
_ actual: ActualTree,
54+
_ expected: ExpectedTree,
5555
includeTrivia: Bool = false,
5656
file: StaticString = #filePath, line: UInt = #line
57-
) {
57+
)
58+
where ActualTree: SyntaxProtocol, ExpectedTree: SyntaxProtocol
59+
{
5860
let diff = actual.findFirstDifference(baseline: expected, includeTrivia: includeTrivia)
5961
XCTAssertNil(diff, diff!.debugDescription, file: file, line: line)
6062
}
6163

6264
/// See `SubtreeMatcher.assertSameStructure`.
63-
public func XCTAssertHasSubstructure(
65+
public func XCTAssertHasSubstructure<ExpectedTree: SyntaxProtocol>(
6466
_ markedText: String,
6567
parse: (String) throws -> Syntax,
6668
afterMarker: String? = nil,
67-
_ expected: SyntaxProtocol,
69+
_ expected: ExpectedTree,
6870
includeTrivia: Bool = false,
6971
file: StaticString = #filePath, line: UInt = #line
7072
) throws {
@@ -73,12 +75,14 @@ public func XCTAssertHasSubstructure(
7375
}
7476

7577
/// See `SubtreeMatcher.assertSameStructure`.
76-
public func XCTAssertHasSubstructure(
77-
_ actualTree: SyntaxProtocol,
78-
_ expected: SyntaxProtocol,
78+
public func XCTAssertHasSubstructure<ActualTree, ExpectedTree>(
79+
_ actualTree: ActualTree,
80+
_ expected: ExpectedTree,
7981
includeTrivia: Bool = false,
8082
file: StaticString = #filePath, line: UInt = #line
81-
) throws {
83+
) throws
84+
where ActualTree: SyntaxProtocol, ExpectedTree: SyntaxProtocol
85+
{
8286
let subtreeMatcher = SubtreeMatcher(Syntax(actualTree))
8387
try subtreeMatcher.assertSameStructure(Syntax(expected), file: file, line: line)
8488
}

Sources/_SwiftSyntaxTestSupport/SyntaxComparison.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ public struct TreeDifference {
2525
/// The `node` that's different to `baseline`, unless `reason` is
2626
/// `.missingNode`. In that case it's actually the parent that's missing a
2727
/// child node.
28-
public let node: SyntaxProtocol
28+
public let node: Syntax
2929
/// The corresponding `baseline` that does not match `node`, unless `reason`
3030
/// is `.additionalNode`. In that case it's what would be the parent (if the
3131
/// baseline node existed).
32-
public let baseline: SyntaxProtocol
32+
public let baseline: Syntax
3333
public let reason: DifferenceReason
3434

35-
public init(node: SyntaxProtocol, baseline: SyntaxProtocol, reason: DifferenceReason) {
36-
self.node = node
37-
self.baseline = baseline
35+
public init<Difference, Baseline>(node: Difference, baseline: Baseline, reason: DifferenceReason)
36+
where Difference: SyntaxProtocol, Baseline: SyntaxProtocol
37+
{
38+
self.node = Syntax(node)
39+
self.baseline = Syntax(baseline)
3840
self.reason = reason
3941
}
4042
}
@@ -89,7 +91,7 @@ extension TreeDifference: CustomDebugStringConvertible {
8991
public extension SyntaxProtocol {
9092
/// Compares the current tree against a `baseline`, returning the first
9193
/// difference it finds.
92-
func findFirstDifference(baseline: SyntaxProtocol, includeTrivia: Bool = false) -> TreeDifference? {
94+
func findFirstDifference<Tree: SyntaxProtocol>(baseline: Tree, includeTrivia: Bool = false) -> TreeDifference? {
9395
if let reason = isDifferent(baseline: baseline, includeTrivia: includeTrivia) {
9496
return TreeDifference(node: self, baseline: baseline, reason: reason)
9597
}
@@ -112,7 +114,7 @@ public extension SyntaxProtocol {
112114
return nil
113115
}
114116

115-
private func isDifferent(baseline: SyntaxProtocol, includeTrivia: Bool = false) -> DifferenceReason? {
117+
private func isDifferent<Tree: SyntaxProtocol>(baseline: Tree, includeTrivia: Bool = false) -> DifferenceReason? {
116118
if syntaxNodeType != baseline.syntaxNodeType {
117119
return .nodeType
118120
}

Tests/SwiftSyntaxParserTest/SyntaxComparisonTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public class SyntaxComparisonTests: XCTestCase {
160160
private func makeFunc(identifier: TokenSyntax, keyword: TokenSyntax = .funcKeyword(),
161161
body: CodeBlockSyntax? = nil, indent: Int = 0) -> FunctionDeclSyntax {
162162
let funcBody: CodeBlockSyntax
163-
if let body {
163+
if let body = body {
164164
funcBody = body
165165
} else {
166166
funcBody = makeBody()

Tests/SwiftSyntaxTest/VisitorTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class VisitorTests: XCTestCase {
1616
return .visitChildren
1717
}
1818

19-
static func check(_ tree: SyntaxProtocol, viewMode: SyntaxTreeViewMode) -> Bool {
19+
static func check<Tree: SyntaxProtocol>(_ tree: Tree, viewMode: SyntaxTreeViewMode) -> Bool {
2020
let visitor = MissingDeclChecker(viewMode: viewMode)
2121
visitor.walk(tree)
2222
return visitor.didSeeMissingDeclSyntax
@@ -56,7 +56,7 @@ public class VisitorTests: XCTestCase {
5656
return .visitChildren
5757
}
5858

59-
static func print(_ tree: SyntaxProtocol, viewMode: SyntaxTreeViewMode) -> String {
59+
static func print<Tree: SyntaxProtocol>(_ tree: Tree, viewMode: SyntaxTreeViewMode) -> String {
6060
let printer = TreePrinter(viewMode: viewMode)
6161
printer.walk(tree)
6262
return printer.out
@@ -83,7 +83,7 @@ public class VisitorTests: XCTestCase {
8383
}
8484

8585

86-
static func print(_ tree: SyntaxProtocol, viewMode: SyntaxTreeViewMode) -> String {
86+
static func print<Tree: SyntaxProtocol>(_ tree: Tree, viewMode: SyntaxTreeViewMode) -> String {
8787
let printer = TreePrinter(viewMode: viewMode)
8888
printer.walk(tree)
8989
return printer.out
@@ -108,7 +108,7 @@ public class VisitorTests: XCTestCase {
108108
}
109109

110110

111-
static func print(_ tree: SyntaxProtocol, viewMode: SyntaxTreeViewMode) -> String {
111+
static func print<Tree: SyntaxProtocol>(_ tree: Tree, viewMode: SyntaxTreeViewMode) -> String {
112112
let printer = TreePrinter(viewMode: viewMode)
113113
printer.walk(tree)
114114
return printer.out

0 commit comments

Comments
 (0)