Swift iOS 13 在 Xcode 13.2 中宣布并发 - 他们是如何实现的?
Swift Concurrency announced for iOS 13 in Xcode 13.2 - how did they achieve this?
Xcode 13.2 Beta release notes 承诺 Swift 并发支持 iOS 13.
You can now use Swift Concurrency in applications that deploy to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes async/await, actors, global actors, structured concurrency, and the task APIs. (70738378)
然而,早在 2021 年夏季,当它首次出现在 WWDC 上时,很难限制 运行 仅在 iOS 15+ 上。
我的问题是:发生了什么变化?他们是如何实现向后兼容性的?它 运行 是否与 iOS 15 中 运行 的方式截然不同?
向后部署并发到旧的 OS 版本将并发运行时库与您的应用程序捆绑在一起,并提供此功能所需的支持,就像 Swift 在之前对标准库所做的那样Swift 5 中的 ABI 稳定性,当 Swift 可以与 OS 一起发布时。
这捆绑了 Concurrency portions of the standard library (stable link) along with some additional support and stubs for functionality (stable link) 的部分内容。
当部署到足够新的 OS 版本以包含这些运行时功能作为 OS 的一部分时,不需要此捆绑。
由于 iOS 15+(以及相关的 OS 版本)上的功能被声明需要内核更改(对于新的协作线程模型),而这些更改本身无法向后移植,因此某些功能包括基于现有功能的垫片,这些 存在于那些 OSes 上,但其性能可能略有不同,或者效率较低。
您可以在 Doug Gregor's PR for backporting concurrency — in a few places, checks for SWIFT_CONCURRENCY_BACK_DEPLOYMENT
change the implementation where some assumptions no longer hold, or functionality isn't present. For example, the GlobalExecutor
can't make assumptions about dispatch_get_global_queue
being cooperative (because that threading model doesn't exist on older OSes), so when backporting, it has to create its own queue for use as the global cooperative queue. @objc
-based actors also need to have their superclass swizzled 的几个地方看到这一点,这不需要在非反向部署的运行时发生。 (符号也必须在某些地方注入到 backdeploy 库中,并且必须删除某些行为,但这有点不那么有趣。)
总的来说,没有关于反向部署和非反向部署之间 确切 差异的全面文档(没有阅读所有代码),但可以安全地假设有效 反向部署库的行为将是相同的,尽管可能会以性能为代价。
Xcode 13.2 Beta release notes 承诺 Swift 并发支持 iOS 13.
You can now use Swift Concurrency in applications that deploy to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 or newer. This support includes async/await, actors, global actors, structured concurrency, and the task APIs. (70738378)
然而,早在 2021 年夏季,当它首次出现在 WWDC 上时,很难限制 运行 仅在 iOS 15+ 上。
我的问题是:发生了什么变化?他们是如何实现向后兼容性的?它 运行 是否与 iOS 15 中 运行 的方式截然不同?
向后部署并发到旧的 OS 版本将并发运行时库与您的应用程序捆绑在一起,并提供此功能所需的支持,就像 Swift 在之前对标准库所做的那样Swift 5 中的 ABI 稳定性,当 Swift 可以与 OS 一起发布时。
这捆绑了 Concurrency portions of the standard library (stable link) along with some additional support and stubs for functionality (stable link) 的部分内容。
当部署到足够新的 OS 版本以包含这些运行时功能作为 OS 的一部分时,不需要此捆绑。
由于 iOS 15+(以及相关的 OS 版本)上的功能被声明需要内核更改(对于新的协作线程模型),而这些更改本身无法向后移植,因此某些功能包括基于现有功能的垫片,这些 存在于那些 OSes 上,但其性能可能略有不同,或者效率较低。
您可以在 Doug Gregor's PR for backporting concurrency — in a few places, checks for SWIFT_CONCURRENCY_BACK_DEPLOYMENT
change the implementation where some assumptions no longer hold, or functionality isn't present. For example, the GlobalExecutor
can't make assumptions about dispatch_get_global_queue
being cooperative (because that threading model doesn't exist on older OSes), so when backporting, it has to create its own queue for use as the global cooperative queue. @objc
-based actors also need to have their superclass swizzled 的几个地方看到这一点,这不需要在非反向部署的运行时发生。 (符号也必须在某些地方注入到 backdeploy 库中,并且必须删除某些行为,但这有点不那么有趣。)
总的来说,没有关于反向部署和非反向部署之间 确切 差异的全面文档(没有阅读所有代码),但可以安全地假设有效 反向部署库的行为将是相同的,尽管可能会以性能为代价。