From bb9dfe8d8f1690660dde5e6cd6f7af70aa0c47eb Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 1 Oct 2024 10:07:23 -0300 Subject: [PATCH 1/3] fix: remove @_unsafeInheritExecutor attribute --- Sources/Helpers/SupabaseLogger.swift | 6 +++--- Sources/Helpers/TaskLocalHelpers.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Helpers/SupabaseLogger.swift b/Sources/Helpers/SupabaseLogger.swift index 1b0077f03..04a62faae 100644 --- a/Sources/Helpers/SupabaseLogger.swift +++ b/Sources/Helpers/SupabaseLogger.swift @@ -173,10 +173,10 @@ extension SupabaseLogger { @inlinable @discardableResult -@_unsafeInheritExecutor -package func trace( +package func trace( using logger: (any SupabaseLogger)?, - @_inheritActorContext _ operation: @Sendable () async throws -> R, + _ operation: () async throws -> R, + isolation _: isolated (any Actor)? = #isolation, fileID: StaticString = #fileID, function: StaticString = #function, line: UInt = #line diff --git a/Sources/Helpers/TaskLocalHelpers.swift b/Sources/Helpers/TaskLocalHelpers.swift index 820570890..8e99205af 100644 --- a/Sources/Helpers/TaskLocalHelpers.swift +++ b/Sources/Helpers/TaskLocalHelpers.swift @@ -8,12 +8,11 @@ import Foundation extension TaskLocal where Value == JSONObject { - @inlinable @discardableResult - @_unsafeInheritExecutor - package func withValue( + @inlinable package final func withValue( merging valueDuringOperation: Value, - @_inheritActorContext operation: @Sendable () async throws -> R, + operation: () async throws -> R, + isolation: isolated (any Actor)? = #isolation, file: String = #fileID, line: UInt = #line ) async rethrows -> R { @@ -21,6 +20,7 @@ extension TaskLocal where Value == JSONObject { return try await withValue( currentValue.merging(valueDuringOperation) { _, new in new }, operation: operation, + isolation: isolation, file: file, line: line ) From 17f08671035dc0c2430986803bf4f89ddc926e31 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 1 Oct 2024 10:12:34 -0300 Subject: [PATCH 2/3] keep #isolation to swift 6.0 only --- Sources/Helpers/SupabaseLogger.swift | 60 ++++++++++++++++++-------- Sources/Helpers/TaskLocalHelpers.swift | 56 ++++++++++++++++-------- 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/Sources/Helpers/SupabaseLogger.swift b/Sources/Helpers/SupabaseLogger.swift index 04a62faae..95b55f0b7 100644 --- a/Sources/Helpers/SupabaseLogger.swift +++ b/Sources/Helpers/SupabaseLogger.swift @@ -171,23 +171,45 @@ extension SupabaseLogger { } } -@inlinable -@discardableResult -package func trace( - using logger: (any SupabaseLogger)?, - _ operation: () async throws -> R, - isolation _: isolated (any Actor)? = #isolation, - fileID: StaticString = #fileID, - function: StaticString = #function, - line: UInt = #line -) async rethrows -> R { - logger?.debug("begin", fileID: fileID, function: function, line: line) - defer { logger?.debug("end", fileID: fileID, function: function, line: line) } - - do { - return try await operation() - } catch { - logger?.debug("error: \(error)", fileID: fileID, function: function, line: line) - throw error +#if compiler(>=6.0) + @inlinable + @discardableResult + package func trace( + using logger: (any SupabaseLogger)?, + _ operation: () async throws -> R, + isolation _: isolated (any Actor)? = #isolation, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) async rethrows -> R { + logger?.debug("begin", fileID: fileID, function: function, line: line) + defer { logger?.debug("end", fileID: fileID, function: function, line: line) } + + do { + return try await operation() + } catch { + logger?.debug("error: \(error)", fileID: fileID, function: function, line: line) + throw error + } } -} +#else + @inlinable + @discardableResult + package func trace( + using logger: (any SupabaseLogger)?, + _ operation: () async throws -> R, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) async rethrows -> R { + logger?.debug("begin", fileID: fileID, function: function, line: line) + defer { logger?.debug("end", fileID: fileID, function: function, line: line) } + + do { + return try await operation() + } catch { + logger?.debug("error: \(error)", fileID: fileID, function: function, line: line) + throw error + } + } +#endif diff --git a/Sources/Helpers/TaskLocalHelpers.swift b/Sources/Helpers/TaskLocalHelpers.swift index 8e99205af..e409a778d 100644 --- a/Sources/Helpers/TaskLocalHelpers.swift +++ b/Sources/Helpers/TaskLocalHelpers.swift @@ -7,22 +7,42 @@ import Foundation -extension TaskLocal where Value == JSONObject { - @discardableResult - @inlinable package final func withValue( - merging valueDuringOperation: Value, - operation: () async throws -> R, - isolation: isolated (any Actor)? = #isolation, - file: String = #fileID, - line: UInt = #line - ) async rethrows -> R { - let currentValue = wrappedValue - return try await withValue( - currentValue.merging(valueDuringOperation) { _, new in new }, - operation: operation, - isolation: isolation, - file: file, - line: line - ) +#if compiler(>=6.0) + extension TaskLocal where Value == JSONObject { + @discardableResult + @inlinable package final func withValue( + merging valueDuringOperation: Value, + operation: () async throws -> R, + isolation: isolated (any Actor)? = #isolation, + file: String = #fileID, + line: UInt = #line + ) async rethrows -> R { + let currentValue = wrappedValue + return try await withValue( + currentValue.merging(valueDuringOperation) { _, new in new }, + operation: operation, + isolation: isolation, + file: file, + line: line + ) + } } -} +#else + extension TaskLocal where Value == JSONObject { + @discardableResult + @inlinable package final func withValue( + merging valueDuringOperation: Value, + operation: () async throws -> R, + file: String = #fileID, + line: UInt = #line + ) async rethrows -> R { + let currentValue = wrappedValue + return try await withValue( + currentValue.merging(valueDuringOperation) { _, new in new }, + operation: operation, + file: file, + line: line + ) + } + } +#endif From 94d16dc61c6aeade0907f0a449dd541d72130c0a Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 1 Oct 2024 10:16:12 -0300 Subject: [PATCH 3/3] add @_unsafeInheritExecutor to swift < 6 --- Sources/Helpers/SupabaseLogger.swift | 1 + Sources/Helpers/TaskLocalHelpers.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/Helpers/SupabaseLogger.swift b/Sources/Helpers/SupabaseLogger.swift index 95b55f0b7..0352a334e 100644 --- a/Sources/Helpers/SupabaseLogger.swift +++ b/Sources/Helpers/SupabaseLogger.swift @@ -193,6 +193,7 @@ extension SupabaseLogger { } } #else + @_unsafeInheritExecutor @inlinable @discardableResult package func trace( diff --git a/Sources/Helpers/TaskLocalHelpers.swift b/Sources/Helpers/TaskLocalHelpers.swift index e409a778d..c2bc5592a 100644 --- a/Sources/Helpers/TaskLocalHelpers.swift +++ b/Sources/Helpers/TaskLocalHelpers.swift @@ -29,6 +29,7 @@ import Foundation } #else extension TaskLocal where Value == JSONObject { + @_unsafeInheritExecutor @discardableResult @inlinable package final func withValue( merging valueDuringOperation: Value,