From 4f6914819421a39f572085bc64c643ebd2c16fd7 Mon Sep 17 00:00:00 2001 From: Leo Dion Date: Tue, 2 Jun 2026 09:11:18 -0400 Subject: [PATCH] Allow resilient builds: gate @inlinable on Lock under library evolution Under `-enable-library-evolution` (BUILD_LIBRARY_FOR_DISTRIBUTION=YES), Swift 6.3+ rejects: - `@inlinable` deinit on a non-`@_fixed_layout` class (LockStorage) - `@inlinable` initializers that directly initialize a stored `let` property of a non-`@frozen` struct (Lock, LockedValueBox) Gate those `@inlinable` attributes behind the OPENAPIURLSESSION_NONINLINABLE_LOCK compilation condition so consumers that build this package resiliently can opt out, while the default build is byte-for-byte unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../OpenAPIURLSession/BufferedStream/Lock.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/OpenAPIURLSession/BufferedStream/Lock.swift b/Sources/OpenAPIURLSession/BufferedStream/Lock.swift index 589a84c..8bd366e 100644 --- a/Sources/OpenAPIURLSession/BufferedStream/Lock.swift +++ b/Sources/OpenAPIURLSession/BufferedStream/Lock.swift @@ -186,7 +186,15 @@ final class LockStorage: ManagedBuffer { } } + // Under `-enable-library-evolution` (BUILD_LIBRARY_FOR_DISTRIBUTION=YES), + // Swift 6.3+ rejects an `@inlinable` deinit on a non-`@_fixed_layout` class: + // "deinitializer can only be '@inlinable' if the class is '@_fixed_layout'". + // Consumers that build this package resiliently can define + // OPENAPIURLSESSION_NONINLINABLE_LOCK to drop the attribute; the default + // build is unchanged. + #if !OPENAPIURLSESSION_NONINLINABLE_LOCK @inlinable + #endif deinit { self.withUnsafeMutablePointerToElements { lockPtr in LockOperations.destroy(lockPtr) @@ -231,7 +239,12 @@ struct Lock { internal let _storage: LockStorage /// Create a new lock. + // Under library evolution, an `@inlinable` init may not directly initialize + // the stored `_storage` property unless the type is `@frozen`. Consumers + // building resiliently can define OPENAPIURLSESSION_NONINLINABLE_LOCK. + #if !OPENAPIURLSESSION_NONINLINABLE_LOCK @inlinable + #endif init() { self._storage = .create(value: ()) } @@ -309,7 +322,11 @@ struct LockedValueBox { internal let _storage: LockStorage /// Initialize the `Value`. + // See note above: `@inlinable` init cannot initialize stored `_storage` + // directly under library evolution unless the type is `@frozen`. + #if !OPENAPIURLSESSION_NONINLINABLE_LOCK @inlinable + #endif init(_ value: Value) { self._storage = .create(value: value) }