From 88abb1357bee8d7461b41ec0641afa1107056db2 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 6 Feb 2024 19:02:53 +0900 Subject: [PATCH] Fix availability marker for Swift 5.9 compiler targeting host machine When building JavaScriptKit with Xcode, targeting host machine, the `func enqueue(_: ExecutorJob)` must be guarded by `@available` attribute explicitly. And due to the 5.9 compiler issue, it emit some migration warnings too consevatively. This commit suppress the warning by updating minimum available OS versions. Those versions should not be a problem when building for Wasm. --- .../JavaScriptEventLoop.swift | 17 +++++++++++------ Sources/JavaScriptEventLoop/JobQueue.swift | 2 +- .../JavaScriptEventLoopTestSupport.swift | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift index 7f7e6997..7f678306 100644 --- a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift +++ b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift @@ -34,7 +34,7 @@ import JavaScriptEventLoop JavaScriptEventLoop.installGlobalExecutor() ``` */ -@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { /// A function that queues a given closure as a microtask into JavaScript event loop. @@ -92,7 +92,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { typealias swift_task_enqueueGlobal_hook_Fn = @convention(thin) (UnownedJob, swift_task_enqueueGlobal_original) -> Void let swift_task_enqueueGlobal_hook_impl: swift_task_enqueueGlobal_hook_Fn = { job, original in - JavaScriptEventLoop.shared.enqueue(job) + JavaScriptEventLoop.shared.unsafeEnqueue(job) } swift_task_enqueueGlobal_hook = unsafeBitCast(swift_task_enqueueGlobal_hook_impl, to: UnsafeMutableRawPointer?.self) @@ -112,7 +112,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { typealias swift_task_enqueueMainExecutor_hook_Fn = @convention(thin) (UnownedJob, swift_task_enqueueMainExecutor_original) -> Void let swift_task_enqueueMainExecutor_hook_impl: swift_task_enqueueMainExecutor_hook_Fn = { job, original in - JavaScriptEventLoop.shared.enqueue(job) + JavaScriptEventLoop.shared.unsafeEnqueue(job) } swift_task_enqueueMainExecutor_hook = unsafeBitCast(swift_task_enqueueMainExecutor_hook_impl, to: UnsafeMutableRawPointer?.self) @@ -130,15 +130,20 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { }) } + private func unsafeEnqueue(_ job: UnownedJob) { + insertJobQueue(job: job) + } + #if compiler(>=5.9) + @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) public func enqueue(_ job: consuming ExecutorJob) { // NOTE: Converting a `ExecutorJob` to an ``UnownedJob`` and invoking // ``UnownedJob/runSynchronously(_:)` on it multiple times is undefined behavior. - insertJobQueue(job: UnownedJob(job)) + unsafeEnqueue(UnownedJob(job)) } #else public func enqueue(_ job: UnownedJob) { - insertJobQueue(job: job) + unsafeEnqueue(job) } #endif @@ -155,7 +160,7 @@ internal func swift_get_time( _ nanoseconds: UnsafeMutablePointer, _ clock: CInt) -@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) extension JavaScriptEventLoop { fileprivate func enqueue( _ job: UnownedJob, withDelay seconds: Int64, _ nanoseconds: Int64, diff --git a/Sources/JavaScriptEventLoop/JobQueue.swift b/Sources/JavaScriptEventLoop/JobQueue.swift index 6cc0cfc3..5ad71f0a 100644 --- a/Sources/JavaScriptEventLoop/JobQueue.swift +++ b/Sources/JavaScriptEventLoop/JobQueue.swift @@ -12,7 +12,7 @@ struct QueueState: Sendable { fileprivate var isSpinning: Bool = false } -@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) extension JavaScriptEventLoop { func insertJobQueue(job newJob: UnownedJob) { diff --git a/Sources/JavaScriptEventLoopTestSupport/JavaScriptEventLoopTestSupport.swift b/Sources/JavaScriptEventLoopTestSupport/JavaScriptEventLoopTestSupport.swift index 9922de94..64e6776d 100644 --- a/Sources/JavaScriptEventLoopTestSupport/JavaScriptEventLoopTestSupport.swift +++ b/Sources/JavaScriptEventLoopTestSupport/JavaScriptEventLoopTestSupport.swift @@ -22,7 +22,7 @@ import JavaScriptEventLoop #if compiler(>=5.5) -@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) +@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) @_cdecl("swift_javascriptkit_activate_js_executor_impl") func swift_javascriptkit_activate_js_executor_impl() { JavaScriptEventLoop.installGlobalExecutor()