Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 6.1
// swift-tools-version: 6.2

//
// This source file is part of the Swift.org open source project
Expand Down Expand Up @@ -164,7 +164,7 @@ let package = Package(
"Testing",
],
path: "Tests/_MemorySafeTestingTests",
swiftSettings: .packageSettings + .strictMemorySafety
swiftSettings: .packageSettings + [.strictMemorySafety()]
),

.macro(
Expand Down Expand Up @@ -369,17 +369,6 @@ extension Array where Element == PackageDescription.SwiftSetting {
// proposal via Swift Evolution.
.enableExperimentalFeature("SymbolLinkageMarkers"),

// This setting is no longer needed when building with a 6.2 or later
// toolchain now that SE-0458 has been accepted and implemented, but it is
// needed in order to preserve support for building with 6.1 development
// snapshot toolchains. (Production 6.1 toolchains can build the testing
// library even without this setting since this experimental feature is
// _suppressible_.) This setting can be removed once the minimum supported
// toolchain for building the testing library is ≥ 6.2. It is not needed
// in the CMake settings since that is expected to build using a
// new-enough toolchain.
.enableExperimentalFeature("AllowUnsafeAttribute"),

.enableUpcomingFeature("InferIsolatedConformances"),

// When building as a package, the macro plugin always builds as an
Expand Down Expand Up @@ -436,18 +425,6 @@ extension Array where Element == PackageDescription.SwiftSetting {

return result
}

/// Settings necessary to enable Strict Memory Safety, introduced in
/// [SE-0458: Opt-in Strict Memory Safety Checking](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0458-strict-memory-safety.md#swiftpm-integration).
static var strictMemorySafety: Self {
#if compiler(>=6.2)
// FIXME: Adopt official `.strictMemorySafety()` condition once the minimum
// supported toolchain is 6.2.
[.unsafeFlags(["-strict-memory-safety"])]
#else
[]
#endif
}
}

extension Array where Element == PackageDescription.CXXSetting {
Expand Down
10 changes: 2 additions & 8 deletions Sources/Testing/ExitTests/ExitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ extension ExitTest {
///
/// - Warning: This function is used to implement the
/// `#expect(processExitsWith:)` macro. Do not use it directly.
#if compiler(>=6.2)
@safe
#endif
public static func __store<each T>(
@safe public static func __store<each T>(
_ id: (UInt64, UInt64, UInt64, UInt64),
_ body: @escaping @Sendable (repeat each T) async throws -> Void,
into outValue: UnsafeMutableRawPointer,
Expand Down Expand Up @@ -394,10 +391,7 @@ extension ExitTest {
///
/// - Warning: This function is used to implement the
/// `#expect(processExitsWith:)` macro. Do not use it directly.
#if compiler(>=6.2)
@safe
#endif
public static func __store<T>(
@safe public static func __store<T>(
_ id: (UInt64, UInt64, UInt64, UInt64),
_ body: T,
into outValue: UnsafeMutableRawPointer,
Expand Down
14 changes: 0 additions & 14 deletions Sources/Testing/Expectations/Expectation+Macro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public macro require<T>(

// MARK: - Matching errors by type

#if compiler(>=6.2)
/// Check that an expression always throws an error of a given type.
///
/// - Parameters:
Expand Down Expand Up @@ -197,7 +196,6 @@ public macro expect<E, R>(
sourceLocation: SourceLocation = #_sourceLocation,
performing expression: () throws -> R
) -> E? = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error
#endif

/// Check that an expression always throws an error of a given type.
///
Expand Down Expand Up @@ -263,7 +261,6 @@ public macro expect<E, R>(
performing expression: () async throws -> R
) -> E? = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error

#if compiler(>=6.2)
/// Check that an expression always throws an error of a given type, and throw
/// an error if it does not.
///
Expand Down Expand Up @@ -313,7 +310,6 @@ public macro require<E, R>(
sourceLocation: SourceLocation = #_sourceLocation,
performing expression: () throws -> R
) -> E = #externalMacro(module: "TestingMacros", type: "RequireThrowsMacro") where E: Error
#endif

/// Check that an expression always throws an error of a given type, and throw
/// an error if it does not.
Expand Down Expand Up @@ -363,7 +359,6 @@ public macro require<E, R>(
performing expression: () async throws -> R
) -> E = #externalMacro(module: "TestingMacros", type: "RequireThrowsMacro") where E: Error

#if compiler(>=6.2)
/// Check that an expression never throws an error, and throw an error if it
/// does.
///
Expand All @@ -383,7 +378,6 @@ public macro require<R>(
sourceLocation: SourceLocation = #_sourceLocation,
performing expression: () throws -> R
) = #externalMacro(module: "TestingMacros", type: "RequireThrowsNeverMacro")
#endif

/// Check that an expression never throws an error, and throw an error if it
/// does.
Expand All @@ -407,7 +401,6 @@ public macro require<R>(

// MARK: - Matching instances of equatable errors

#if compiler(>=6.2)
/// Check that an expression always throws a specific error.
///
/// - Parameters:
Expand Down Expand Up @@ -449,7 +442,6 @@ public macro expect<E, R>(
sourceLocation: SourceLocation = #_sourceLocation,
performing expression: () throws -> R
) -> E? = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error & Equatable
#endif

/// Check that an expression always throws a specific error.
///
Expand Down Expand Up @@ -491,7 +483,6 @@ public macro expect<E, R>(
performing expression: () async throws -> R
) -> E? = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error & Equatable

#if compiler(>=6.2)
/// Check that an expression always throws a specific error, and throw an error
/// if it does not.
///
Expand Down Expand Up @@ -537,7 +528,6 @@ public macro require<E, R>(
sourceLocation: SourceLocation = #_sourceLocation,
performing expression: () throws -> R
) -> E = #externalMacro(module: "TestingMacros", type: "RequireMacro") where E: Error & Equatable
#endif

/// Check that an expression always throws a specific error, and throw an error
/// if it does not.
Expand Down Expand Up @@ -585,7 +575,6 @@ public macro require<E, R>(

// MARK: - Arbitrary error matching

#if compiler(>=6.2)
/// Check that an expression always throws an error matching some condition.
///
/// - Parameters:
Expand Down Expand Up @@ -649,7 +638,6 @@ public macro expect<R>(
performing expression: () throws -> R,
throws errorMatcher: (any Error) throws -> Bool
) -> (any Error)? = #externalMacro(module: "TestingMacros", type: "ExpectMacro")
#endif

/// Check that an expression always throws an error matching some condition.
///
Expand Down Expand Up @@ -713,7 +701,6 @@ public macro expect<R>(
throws errorMatcher: (any Error) async throws -> Bool
) -> (any Error)? = #externalMacro(module: "TestingMacros", type: "ExpectMacro")

#if compiler(>=6.2)
/// Check that an expression always throws an error matching some condition, and
/// throw an error if it does not.
///
Expand Down Expand Up @@ -784,7 +771,6 @@ public macro require<R>(
performing expression: () throws -> R,
throws errorMatcher: (any Error) throws -> Bool
) -> any Error = #externalMacro(module: "TestingMacros", type: "RequireMacro")
#endif

/// Check that an expression always throws an error matching some condition, and
/// throw an error if it does not.
Expand Down
17 changes: 0 additions & 17 deletions Sources/Testing/Parameterization/TypeInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,23 +405,6 @@ extension TypeInfo: Hashable {
}
}

#if compiler(<6.2)
// MARK: - ObjectIdentifier support

extension ObjectIdentifier {
/// Initialize an instance of this type from a type reference.
///
/// - Parameters:
/// - type: The type to initialize this instance from.
///
/// - Bug: The standard library should support this conversion.
/// ([134276458](rdar://134276458), [134415960](rdar://134415960))
fileprivate init(_ type: any ~Copyable.Type) {
self.init(unsafeBitCast(type, to: Any.Type.self))
}
}
#endif

// MARK: - Codable

extension TypeInfo: Codable {
Expand Down
5 changes: 1 addition & 4 deletions Sources/Testing/Test+Discovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ extension Test {
///
/// - Warning: This function is used to implement the `@Test` macro. Do not
/// use it directly.
#if compiler(>=6.2)
@safe
#endif
public static func __store(
@safe public static func __store(
_ generator: @escaping @Sendable () async -> Test,
into outValue: UnsafeMutableRawPointer,
asTypeAt typeAddress: UnsafeRawPointer
Expand Down
3 changes: 1 addition & 2 deletions Sources/TestingMacros/ConditionMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,10 @@ extension ExitTestConditionMacro {
var recordDecl: DeclSyntax?
#if !SWT_NO_LEGACY_TEST_DISCOVERY
let legacyEnumName = context.makeUniqueName("__🟡$")
let unsafeKeyword: TokenSyntax? = isUnsafeKeywordSupported ? .keyword(.unsafe, trailingTrivia: .space) : nil
recordDecl = """
enum \(legacyEnumName): Testing.__TestContentRecordContainer {
nonisolated static var __testContentRecord: Testing.__TestContentRecord {
\(unsafeKeyword)\(enumName).testContentRecord
unsafe \(enumName).testContentRecord
}
}
"""
Expand Down
3 changes: 1 addition & 2 deletions Sources/TestingMacros/SuiteDeclarationMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
#if !SWT_NO_LEGACY_TEST_DISCOVERY
// Emit a type that contains a reference to the test content record.
let enumName = context.makeUniqueName("__🟡$")
let unsafeKeyword: TokenSyntax? = isUnsafeKeywordSupported ? .keyword(.unsafe, trailingTrivia: .space) : nil
result.append(
"""
@available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.")
enum \(enumName): Testing.__TestContentRecordContainer {
nonisolated static var __testContentRecord: Testing.__TestContentRecord {
\(unsafeKeyword)\(testContentRecordName)
unsafe \(testContentRecordName)
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ extension BidirectionalCollection<Syntax> {

// MARK: - Inserting effect keywords/thunks

/// Whether or not the `unsafe` expression keyword is supported.
var isUnsafeKeywordSupported: Bool {
// The 'unsafe' keyword was introduced in 6.2 as part of SE-0458. Older
// toolchains are not aware of it.
#if compiler(>=6.2)
true
#else
false
#endif
}

/// Make a function call expression to an effectful thunk function provided by
/// the testing library.
///
Expand Down Expand Up @@ -184,8 +173,7 @@ func applyEffectfulKeywords(_ effectfulKeywords: Set<Keyword>, to expr: some Exp

let needAwait = effectfulKeywords.contains(.await) && !expr.is(AwaitExprSyntax.self)
let needTry = effectfulKeywords.contains(.try) && !expr.is(TryExprSyntax.self)

let needUnsafe = isUnsafeKeywordSupported && effectfulKeywords.contains(.unsafe) && !expr.is(UnsafeExprSyntax.self)
let needUnsafe = effectfulKeywords.contains(.unsafe) && !expr.is(UnsafeExprSyntax.self)

// First, add thunk function calls.
if insertThunkCalls {
Expand Down
3 changes: 1 addition & 2 deletions Sources/TestingMacros/Support/TestContentGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ func makeTestContentRecordDecl(named name: TokenSyntax, in typeName: TypeSyntax?
IntegerLiteralExprSyntax(context, radix: .binary)
}

let unsafeKeyword: TokenSyntax? = isUnsafeKeywordSupported ? .keyword(.unsafe, trailingTrivia: .space) : nil
var result: DeclSyntax = """
@available(*, deprecated, message: "This property is an implementation detail of the testing library. Do not use it directly.")
private nonisolated \(staticKeyword(for: typeName)) let \(name): Testing.__TestContentRecord = (
\(kindExpr), \(kind.commentRepresentation)
0,
\(unsafeKeyword)\(accessorName),
unsafe \(accessorName),
\(contextExpr),
0
)
Expand Down
3 changes: 1 addition & 2 deletions Sources/TestingMacros/TestDeclarationMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,12 @@ public struct TestDeclarationMacro: PeerMacro, Sendable {
#if !SWT_NO_LEGACY_TEST_DISCOVERY
// Emit a type that contains a reference to the test content record.
let enumName = context.makeUniqueName(thunking: functionDecl, withPrefix: "__🟡$")
let unsafeKeyword: TokenSyntax? = isUnsafeKeywordSupported ? .keyword(.unsafe, trailingTrivia: .space) : nil
result.append(
"""
@available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.")
enum \(enumName): Testing.__TestContentRecordContainer {
nonisolated static var __testContentRecord: Testing.__TestContentRecord {
\(unsafeKeyword)\(testContentRecordName)
unsafe \(testContentRecordName)
}
}
"""
Expand Down
6 changes: 1 addition & 5 deletions Tests/TestingTests/AttachmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,12 @@ struct AttachmentTests {
}
valueAttached()

// BUG: We could use #expect(throws: Never.self) here, but the Swift 6.1
// compiler crashes trying to expand the macro (rdar://138997009)
do {
#expect(throws: Never.self) {
let filePath = try #require(attachment.fileSystemPath)
defer {
remove(filePath)
}
try compare(attachableValue, toContentsOfFileAtPath: filePath)
} catch {
Issue.record(error)
}
}

Expand Down
2 changes: 0 additions & 2 deletions Tests/TestingTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ struct MiscellaneousTests {
#expect(testType.displayName == "Named Sendable test type")
}

#if compiler(>=6.2) && hasFeature(RawIdentifiers)
@Test func `Test with raw identifier gets a display name`() throws {
let test = try #require(Test.current)
#expect(test.displayName == "Test with raw identifier gets a display name")
Expand All @@ -320,7 +319,6 @@ struct MiscellaneousTests {
func `Test with raw identifier and raw identifier parameter labels can compile`(`argument name` i: Int) {
#expect(i == 0)
}
#endif

@Test("Free functions are runnable")
func freeFunction() async throws {
Expand Down
4 changes: 0 additions & 4 deletions Tests/_MemorySafeTestingTests/MemorySafeTestDecls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

#if compiler(>=6.2)

@testable import Testing

#if !hasFeature(StrictMemorySafety)
Expand All @@ -29,5 +27,3 @@ func exampleExitTest() async {
await #expect(processExitsWith: .success) {}
}
#endif

#endif