From f8fad2f95ad67b45f6340c0960e2396094d67e07 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Tue, 3 Nov 2026 13:15:54 +0000 Subject: [PATCH] Fix builds using Swift 5 language mode with newer compilers (#497) ### Motivation: We're using `#if swift(...)` in some places, which breaks builds using Swift 5 language mode with Swift 6.3+ compilers. ### Modifications: - Check `compiler(<6.4)` instead of `swift(<6.4)`. - Use `@_lifetime(self: copy self)` on the setter, which 6.2, 6.3, and 6.4 all accept. ### Result: Build succeeds when compiled with `-Xswiftc -swift-version -Xswiftc 5` on 6.2, 6.3, and 6.4. --- Sources/Crypto/Util/Backports.swift | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Sources/Crypto/Util/Backports.swift b/Sources/Crypto/Util/Backports.swift index 878ca8fb..c14b4917 100644 --- a/Sources/Crypto/Util/Backports.swift +++ b/Sources/Crypto/Util/Backports.swift @@ -18,29 +18,20 @@ import FoundationEssentials import Foundation #endif -#if swift(<6.4) +#if compiler(<6.4) @available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.0, *) extension ContiguousBytes { func withBytes(_ body: (RawSpan) throws -> R) rethrows -> R { try withUnsafeBytes { try body(RawSpan(_unsafeBytes: $0)) } } } -#endif -#if swift(<6.4) @available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.0, *) extension MutableRawSpan { - #if swift(>=6.3) subscript(_ byteOffset: Int) -> UInt8 { get { unsafeLoad(fromByteOffset: byteOffset, as: UInt8.self) } + @_lifetime(self: copy self) set { storeBytes(of: newValue, toByteOffset: byteOffset, as: UInt8.self) } } - #elseif swift(<6.3) - subscript(_ byteOffset: Int) -> UInt8 { - get { unsafeLoad(fromByteOffset: byteOffset, as: UInt8.self) } - @_lifetime(&self) - set { storeBytes(of: newValue, toByteOffset: byteOffset, as: UInt8.self) } - } - #endif } #endif