Skip to content

Commit eab7a4a

Browse files
authored
fix: Swift 6 warnings related to @_unsafeInheritExecutor attribute (#549)
* fix: remove @_unsafeInheritExecutor attribute * keep #isolation to swift 6.0 only * add @_unsafeInheritExecutor to swift < 6
1 parent 8f61141 commit eab7a4a

File tree

2 files changed

+81
-37
lines changed

2 files changed

+81
-37
lines changed

Sources/Helpers/SupabaseLogger.swift

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,46 @@ extension SupabaseLogger {
171171
}
172172
}
173173

174-
@inlinable
175-
@discardableResult
176-
@_unsafeInheritExecutor
177-
package func trace<R>(
178-
using logger: (any SupabaseLogger)?,
179-
@_inheritActorContext _ operation: @Sendable () async throws -> R,
180-
fileID: StaticString = #fileID,
181-
function: StaticString = #function,
182-
line: UInt = #line
183-
) async rethrows -> R {
184-
logger?.debug("begin", fileID: fileID, function: function, line: line)
185-
defer { logger?.debug("end", fileID: fileID, function: function, line: line) }
186-
187-
do {
188-
return try await operation()
189-
} catch {
190-
logger?.debug("error: \(error)", fileID: fileID, function: function, line: line)
191-
throw error
174+
#if compiler(>=6.0)
175+
@inlinable
176+
@discardableResult
177+
package func trace<R: Sendable>(
178+
using logger: (any SupabaseLogger)?,
179+
_ operation: () async throws -> R,
180+
isolation _: isolated (any Actor)? = #isolation,
181+
fileID: StaticString = #fileID,
182+
function: StaticString = #function,
183+
line: UInt = #line
184+
) async rethrows -> R {
185+
logger?.debug("begin", fileID: fileID, function: function, line: line)
186+
defer { logger?.debug("end", fileID: fileID, function: function, line: line) }
187+
188+
do {
189+
return try await operation()
190+
} catch {
191+
logger?.debug("error: \(error)", fileID: fileID, function: function, line: line)
192+
throw error
193+
}
192194
}
193-
}
195+
#else
196+
@_unsafeInheritExecutor
197+
@inlinable
198+
@discardableResult
199+
package func trace<R: Sendable>(
200+
using logger: (any SupabaseLogger)?,
201+
_ operation: () async throws -> R,
202+
fileID: StaticString = #fileID,
203+
function: StaticString = #function,
204+
line: UInt = #line
205+
) async rethrows -> R {
206+
logger?.debug("begin", fileID: fileID, function: function, line: line)
207+
defer { logger?.debug("end", fileID: fileID, function: function, line: line) }
208+
209+
do {
210+
return try await operation()
211+
} catch {
212+
logger?.debug("error: \(error)", fileID: fileID, function: function, line: line)
213+
throw error
214+
}
215+
}
216+
#endif

Sources/Helpers/TaskLocalHelpers.swift

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,43 @@
77

88
import Foundation
99

10-
extension TaskLocal where Value == JSONObject {
11-
@inlinable
12-
@discardableResult
13-
@_unsafeInheritExecutor
14-
package func withValue<R>(
15-
merging valueDuringOperation: Value,
16-
@_inheritActorContext operation: @Sendable () async throws -> R,
17-
file: String = #fileID,
18-
line: UInt = #line
19-
) async rethrows -> R {
20-
let currentValue = wrappedValue
21-
return try await withValue(
22-
currentValue.merging(valueDuringOperation) { _, new in new },
23-
operation: operation,
24-
file: file,
25-
line: line
26-
)
10+
#if compiler(>=6.0)
11+
extension TaskLocal where Value == JSONObject {
12+
@discardableResult
13+
@inlinable package final func withValue<R>(
14+
merging valueDuringOperation: Value,
15+
operation: () async throws -> R,
16+
isolation: isolated (any Actor)? = #isolation,
17+
file: String = #fileID,
18+
line: UInt = #line
19+
) async rethrows -> R {
20+
let currentValue = wrappedValue
21+
return try await withValue(
22+
currentValue.merging(valueDuringOperation) { _, new in new },
23+
operation: operation,
24+
isolation: isolation,
25+
file: file,
26+
line: line
27+
)
28+
}
2729
}
28-
}
30+
#else
31+
extension TaskLocal where Value == JSONObject {
32+
@_unsafeInheritExecutor
33+
@discardableResult
34+
@inlinable package final func withValue<R>(
35+
merging valueDuringOperation: Value,
36+
operation: () async throws -> R,
37+
file: String = #fileID,
38+
line: UInt = #line
39+
) async rethrows -> R {
40+
let currentValue = wrappedValue
41+
return try await withValue(
42+
currentValue.merging(valueDuringOperation) { _, new in new },
43+
operation: operation,
44+
file: file,
45+
line: line
46+
)
47+
}
48+
}
49+
#endif

0 commit comments

Comments
 (0)