diff --git a/Package.swift b/Package.swift index e387f1453..0f4b1648b 100644 --- a/Package.swift +++ b/Package.swift @@ -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 @@ -164,7 +164,7 @@ let package = Package( "Testing", ], path: "Tests/_MemorySafeTestingTests", - swiftSettings: .packageSettings + .strictMemorySafety + swiftSettings: .packageSettings + [.strictMemorySafety()] ), .macro( @@ -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 @@ -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 { diff --git a/Sources/Testing/ExitTests/ExitTest.swift b/Sources/Testing/ExitTests/ExitTest.swift index b9ce39496..4cabda8b3 100644 --- a/Sources/Testing/ExitTests/ExitTest.swift +++ b/Sources/Testing/ExitTests/ExitTest.swift @@ -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( + @safe public static func __store( _ id: (UInt64, UInt64, UInt64, UInt64), _ body: @escaping @Sendable (repeat each T) async throws -> Void, into outValue: UnsafeMutableRawPointer, @@ -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( + @safe public static func __store( _ id: (UInt64, UInt64, UInt64, UInt64), _ body: T, into outValue: UnsafeMutableRawPointer, diff --git a/Sources/Testing/Expectations/Expectation+Macro.swift b/Sources/Testing/Expectations/Expectation+Macro.swift index 2f64aff3a..17127d058 100644 --- a/Sources/Testing/Expectations/Expectation+Macro.swift +++ b/Sources/Testing/Expectations/Expectation+Macro.swift @@ -131,7 +131,6 @@ public macro require( // MARK: - Matching errors by type -#if compiler(>=6.2) /// Check that an expression always throws an error of a given type. /// /// - Parameters: @@ -197,7 +196,6 @@ public macro expect( 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. /// @@ -263,7 +261,6 @@ public macro expect( 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. /// @@ -313,7 +310,6 @@ public macro require( 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. @@ -363,7 +359,6 @@ public macro require( 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. /// @@ -383,7 +378,6 @@ public macro require( 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. @@ -407,7 +401,6 @@ public macro require( // MARK: - Matching instances of equatable errors -#if compiler(>=6.2) /// Check that an expression always throws a specific error. /// /// - Parameters: @@ -449,7 +442,6 @@ public macro expect( 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. /// @@ -491,7 +483,6 @@ public macro expect( 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. /// @@ -537,7 +528,6 @@ public macro require( 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. @@ -585,7 +575,6 @@ public macro require( // MARK: - Arbitrary error matching -#if compiler(>=6.2) /// Check that an expression always throws an error matching some condition. /// /// - Parameters: @@ -649,7 +638,6 @@ public macro expect( 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. /// @@ -713,7 +701,6 @@ public macro expect( 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. /// @@ -784,7 +771,6 @@ public macro require( 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. diff --git a/Sources/Testing/Parameterization/TypeInfo.swift b/Sources/Testing/Parameterization/TypeInfo.swift index de377e6be..0ebda0a82 100644 --- a/Sources/Testing/Parameterization/TypeInfo.swift +++ b/Sources/Testing/Parameterization/TypeInfo.swift @@ -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 { diff --git a/Sources/Testing/Test+Discovery.swift b/Sources/Testing/Test+Discovery.swift index 87dafe7a4..d7d3b8ea7 100644 --- a/Sources/Testing/Test+Discovery.swift +++ b/Sources/Testing/Test+Discovery.swift @@ -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 diff --git a/Sources/TestingMacros/ConditionMacro.swift b/Sources/TestingMacros/ConditionMacro.swift index c4b1db7e3..6ba8ff124 100644 --- a/Sources/TestingMacros/ConditionMacro.swift +++ b/Sources/TestingMacros/ConditionMacro.swift @@ -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 } } """ diff --git a/Sources/TestingMacros/SuiteDeclarationMacro.swift b/Sources/TestingMacros/SuiteDeclarationMacro.swift index e44b0460a..4bee4c30f 100644 --- a/Sources/TestingMacros/SuiteDeclarationMacro.swift +++ b/Sources/TestingMacros/SuiteDeclarationMacro.swift @@ -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) } } """ diff --git a/Sources/TestingMacros/Support/EffectfulExpressionHandling.swift b/Sources/TestingMacros/Support/EffectfulExpressionHandling.swift index b093d1e77..28e0af56d 100644 --- a/Sources/TestingMacros/Support/EffectfulExpressionHandling.swift +++ b/Sources/TestingMacros/Support/EffectfulExpressionHandling.swift @@ -130,17 +130,6 @@ extension BidirectionalCollection { // 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. /// @@ -184,8 +173,7 @@ func applyEffectfulKeywords(_ effectfulKeywords: Set, 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 { diff --git a/Sources/TestingMacros/Support/TestContentGeneration.swift b/Sources/TestingMacros/Support/TestContentGeneration.swift index 2999478de..05214d1b8 100644 --- a/Sources/TestingMacros/Support/TestContentGeneration.swift +++ b/Sources/TestingMacros/Support/TestContentGeneration.swift @@ -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 ) diff --git a/Sources/TestingMacros/TestDeclarationMacro.swift b/Sources/TestingMacros/TestDeclarationMacro.swift index ef156edd6..b67bf3360 100644 --- a/Sources/TestingMacros/TestDeclarationMacro.swift +++ b/Sources/TestingMacros/TestDeclarationMacro.swift @@ -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) } } """ diff --git a/Tests/TestingTests/AttachmentTests.swift b/Tests/TestingTests/AttachmentTests.swift index b634c5007..7695dd634 100644 --- a/Tests/TestingTests/AttachmentTests.swift +++ b/Tests/TestingTests/AttachmentTests.swift @@ -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) } } diff --git a/Tests/TestingTests/MiscellaneousTests.swift b/Tests/TestingTests/MiscellaneousTests.swift index 6a65fb658..84d1ce493 100644 --- a/Tests/TestingTests/MiscellaneousTests.swift +++ b/Tests/TestingTests/MiscellaneousTests.swift @@ -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") @@ -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 { diff --git a/Tests/_MemorySafeTestingTests/MemorySafeTestDecls.swift b/Tests/_MemorySafeTestingTests/MemorySafeTestDecls.swift index 3eb19be5b..206c41488 100644 --- a/Tests/_MemorySafeTestingTests/MemorySafeTestDecls.swift +++ b/Tests/_MemorySafeTestingTests/MemorySafeTestDecls.swift @@ -8,8 +8,6 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // -#if compiler(>=6.2) - @testable import Testing #if !hasFeature(StrictMemorySafety) @@ -29,5 +27,3 @@ func exampleExitTest() async { await #expect(processExitsWith: .success) {} } #endif - -#endif