Skip to content

Commit

Permalink
Fix availability marker for Swift 5.9 compiler targeting host machine
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kateinoigakukun committed Feb 6, 2024
1 parent 5bca895 commit 88abb13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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

Expand All @@ -155,7 +160,7 @@ internal func swift_get_time(
_ nanoseconds: UnsafeMutablePointer<Int64>,
_ 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,
Expand Down
2 changes: 1 addition & 1 deletion Sources/JavaScriptEventLoop/JobQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 88abb13

Please sign in to comment.