Skip to content

Commit e930b41

Browse files
authored
Adopt swift-syntax-600. (#338)
This PR changes our swift-syntax dependency from swift-syntax-510 to swift-syntax-600. We rely on several upcoming Swift 6 features, including swift-syntax's `lexicalContext` property, in order to correctly build and run tests. This PR migrates us to the latest prerelease swift-syntax-600 package so that we can take advantage of said feature. swift-testing clients that have an explicit or inherited dependency on swift-syntax-510 or earlier may fail to build as a result of this change. As a reminder, swift-testing is an experimental package and we do not guarantee compatibility with older versions of the toolchain or related packages. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 3f388d0 commit e930b41

16 files changed

+11
-200
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let package = Package(
3333
],
3434

3535
dependencies: [
36-
.package(url: "https://github.com/apple/swift-syntax.git", from: Version(stringLiteral: Context.environment["SWT_SWIFT_SYNTAX_VERSION"] ?? "510.0.1")),
36+
.package(url: "https://github.com/apple/swift-syntax.git", from: Version(stringLiteral: Context.environment["SWT_SWIFT_SYNTAX_VERSION"] ?? "600.0.0-latest")),
3737
],
3838

3939
targets: [

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let package = Package(
3333
],
3434

3535
dependencies: [
36-
.package(url: "https://github.com/apple/swift-syntax.git", from: Version(stringLiteral: Context.environment["SWT_SWIFT_SYNTAX_VERSION"] ?? "510.0.1")),
36+
.package(url: "https://github.com/apple/swift-syntax.git", from: Version(stringLiteral: Context.environment["SWT_SWIFT_SYNTAX_VERSION"] ?? "600.0.0-latest")),
3737
],
3838

3939
targets: [

Sources/Testing/Test+Discovery.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ extension Test {
8989
/// - tests: A dictionary of tests to amend.
9090
///
9191
/// - Returns: The number of key-value pairs added to `tests`.
92-
///
93-
/// - Bug: This function is necessary because containing type information is
94-
/// not available during expansion of the `@Test` macro.
95-
/// ([105470382](rdar://105470382))
9692
@discardableResult private static func _synthesizeSuiteTypes(into tests: inout [ID: Self]) -> Int {
9793
let originalCount = tests.count
9894

Sources/Testing/Testing.docc/OrganizingTests.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ _not_ be annotated with the `@available` attribute:
147147
The compiler will emit an error when presented with a test suite that does not
148148
meet this requirement.
149149

150-
- Bug: Inherited availability is not always visible to the compiler during
151-
expansion of the ``Suite(_:_:)`` macro. A test function may crash when run on
152-
an unsupported system. ([110974351](rdar://110974351))
153-
154150
### Classes must be final
155151

156152
The testing library does not currently support inheritance between test suite

Sources/Testing/Traits/Tags/Tag+Macro.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,9 @@ extension Tag {
2727
// described static member.
2828
var fullyQualifiedMemberNameComponents = TypeInfo(describing: type).fullyQualifiedNameComponents
2929

30-
#if canImport(SwiftSyntax600)
3130
// Strip off the "Testing" and "Tag" components of the fully-qualified name
3231
// since they're redundant. Macro expansion will have already checked that
3332
// the type is nested inside `Tag`.
34-
#else
35-
// Ensure that the tag is nested somewhere inside Testing.Tag, then strip
36-
// off those elements of the fully-qualified type name. These preconditions
37-
// are necessary because we do not currently have access, during macro
38-
// expansion, to the lexical context in which a tag is declared.
39-
precondition(fullyQualifiedMemberNameComponents.count >= 2, "Tags must be specified as members of the Tag type or a nested type in Tag.")
40-
precondition(fullyQualifiedMemberNameComponents[0 ..< 2] == ["Testing", "Tag"], "Tags must be specified as members of the Tag type or a nested type in Tag.")
41-
#endif
4233
fullyQualifiedMemberNameComponents = Array(fullyQualifiedMemberNameComponents.dropFirst(2))
4334

4435
// Add the specified tag name to the fully-qualified name and reconstruct

Sources/TestingMacros/SuiteDeclarationMacro.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
5959
context.diagnose(diagnostics)
6060
}
6161

62-
#if canImport(SwiftSyntax600)
6362
// Check if the lexical context is appropriate for a suite or test.
6463
diagnostics += diagnoseIssuesWithLexicalContext(context.lexicalContext, containing: declaration, attribute: suiteAttribute)
65-
#endif
6664
diagnostics += diagnoseIssuesWithLexicalContext(declaration, containing: declaration, attribute: suiteAttribute)
6765

6866
// Suites inheriting from XCTestCase are not supported.

Sources/TestingMacros/Support/Additions/FunctionDeclSyntaxAdditions.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ extension FunctionDeclSyntax {
9696
colonToken = .colonToken()
9797
} else {
9898
let hasThrowsSpecifier: Bool
99-
#if canImport(SwiftSyntax600)
10099
hasThrowsSpecifier = signature.effectSpecifiers?.throwsClause != nil
101-
#else
102-
hasThrowsSpecifier = signature.effectSpecifiers?.throwsSpecifier != nil
103-
#endif
104100
if hasThrowsSpecifier {
105101
selector += "AndReturnError"
106102
colonToken = .colonToken()

Sources/TestingMacros/Support/Additions/MacroExpansionContextAdditions.swift

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ extension MacroExpansionContext {
2828
///
2929
/// If the lexical context includes functions, closures, or some other
3030
/// non-type scope, the value of this property is `nil`.
31-
///
32-
/// If swift-syntax-600 or newer is available, `node` is ignored. The argument
33-
/// will be removed once the testing library's swift-syntax dependency is
34-
/// updated to swift-syntax-600 or later.
35-
func typeOfLexicalContext(containing node: some WithAttributesSyntax) -> TypeSyntax? {
36-
#if canImport(SwiftSyntax600)
31+
var typeOfLexicalContext: TypeSyntax? {
3732
var typeNames = [String]()
3833
for lexicalContext in lexicalContext.reversed() {
3934
guard let decl = lexicalContext.asProtocol((any DeclGroupSyntax).self) else {
@@ -46,42 +41,6 @@ extension MacroExpansionContext {
4641
}
4742

4843
return "\(raw: typeNames.joined(separator: "."))"
49-
#else
50-
// Find the beginning of the first attribute on the declaration, including
51-
// those embedded in #if statements, to account for patterns like
52-
// `@MainActor @Test func` where there's a space ahead of @Test, but the
53-
// whole function is still at the top level.
54-
func firstAttribute(in attributes: AttributeListSyntax) -> AttributeSyntax? {
55-
attributes.lazy
56-
.compactMap { attribute in
57-
switch (attribute as AttributeListSyntax.Element?) {
58-
case let .ifConfigDecl(ifConfigDecl):
59-
ifConfigDecl.clauses.lazy
60-
.compactMap { clause in
61-
if case let .attributes(attributes) = clause.elements {
62-
return firstAttribute(in: attributes)
63-
}
64-
return nil
65-
}.first
66-
case let .attribute(attribute):
67-
attribute
68-
default:
69-
nil
70-
}
71-
}.first
72-
}
73-
let firstAttribute = firstAttribute(in: node.attributes)!
74-
75-
// HACK: If the test function appears to be indented, assume it is nested in
76-
// a type. Use `Self` as the presumptive name of the type.
77-
//
78-
// This hack works around rdar://105470382.
79-
if let lastLeadingTrivia = firstAttribute.leadingTrivia.pieces.last,
80-
lastLeadingTrivia.isWhitespace && !lastLeadingTrivia.isNewline {
81-
return TypeSyntax(IdentifierTypeSyntax(name: .keyword(.Self)))
82-
}
83-
return nil
84-
#endif
8544
}
8645
}
8746

Sources/TestingMacros/Support/DiagnosticMessage+Diagnosing.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ func diagnoseIssuesWithLexicalContext(
237237
return diagnostics
238238
}
239239

240-
#if canImport(SwiftSyntax600)
241240
/// Diagnose issues with the lexical context containing a declaration.
242241
///
243242
/// - Parameters:
@@ -256,7 +255,6 @@ func diagnoseIssuesWithLexicalContext(
256255
.map { diagnoseIssuesWithLexicalContext($0, containing: decl, attribute: attribute) }
257256
.reduce(into: [], +=)
258257
}
259-
#endif
260258

261259
/// Create a declaration that prevents compilation if it is generic.
262260
///
@@ -278,13 +276,12 @@ func makeGenericGuardDecl(
278276
guardingAgainst decl: some DeclSyntaxProtocol,
279277
in context: some MacroExpansionContext
280278
) -> DeclSyntax? {
281-
#if canImport(SwiftSyntax600)
282279
guard context.lexicalContext.lazy.map(\.kind).contains(.extensionDecl) else {
283280
// Don't bother emitting a member if the declaration is not in an extension
284281
// because we'll already be able to emit a better error.
285282
return nil
286283
}
287-
#endif
284+
288285
let genericGuardName = if let functionDecl = decl.as(FunctionDeclSyntax.self) {
289286
context.makeUniqueName(thunking: functionDecl)
290287
} else {

Sources/TestingMacros/Support/DiagnosticMessage.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,8 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
118118
result = ("subscript", "a")
119119
case .enumCaseDecl:
120120
result = ("enumeration case", "an")
121-
#if canImport(SwiftSyntax600)
122121
case .typeAliasDecl:
123122
result = ("typealias", "a")
124-
#else
125-
case .typealiasDecl:
126-
result = ("typealias", "a")
127-
#endif
128123
case .macroDecl:
129124
result = ("macro", "a")
130125
case .protocolDecl:
@@ -400,7 +395,6 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
400395
}
401396
}
402397

403-
#if canImport(SwiftSyntax600)
404398
/// Create a diagnostic message stating that the given attribute cannot be
405399
/// applied to the given declaration outside the scope of an extension to
406400
/// `Tag`.
@@ -417,7 +411,6 @@ struct DiagnosticMessage: SwiftDiagnostics.DiagnosticMessage {
417411
severity: .error
418412
)
419413
}
420-
#endif
421414

422415
/// Create a diagnostic message stating that the given attribute has no effect
423416
/// when applied to the given extension declaration.

0 commit comments

Comments
 (0)