简体   繁体   English

Swift Concurrency 在 Xcode 13.2 中为 iOS 13 宣布 - 他们是如何实现这一目标的?

[英]Swift Concurrency announced for iOS 13 in Xcode 13.2 - how did they achieve this?

Xcode 13.2 Beta release notes features a promise for Swift Concurrency support for iOS 13. Xcode 13.2 Beta 发行说明承诺为 iOS 13 提供 Swift 并发支持。

You can now use Swift Concurrency in applications that deploy to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 or newer.您现在可以在部署到 macOS 10.15、iOS 13、tvOS 13 和 watchOS 6 或更高版本的应用程序中使用 Swift Concurrency。 This support includes async/await, actors, global actors, structured concurrency, and the task APIs.这种支持包括异步/等待、参与者、全局参与者、结构化并发和任务 API。 (70738378) (70738378)

However, back in Summer 2021 when it first appeared at WWDC it was hard constrained to be run on iOS 15+ only.然而,早在 2021 年夏季,当它首次出现在 WWDC 时,它就很难被限制只能在 iOS 15+ 上运行。

My question is: what changed?我的问题是:发生了什么变化? How did they achieve backwards compatibility?他们是如何实现向后兼容的? Does it run in any way that is drastically different from the way it would run in iOS 15?它的运行方式是否与在 iOS 15 中的运行方式截然不同?

Back-deploying concurrency to older OS versions bundles a concurrency runtime library along with your app with the support required for this feature, much like Swift used to do with the standard library prior to ABI stability in Swift 5, when Swift could be shipped with the OS.将并发回部署到较旧的操作系统版本将并发运行时库与您的应用程序捆绑在一起,并提供此功能所需的支持,就像 Swift 在 Swift 5 中的 ABI 稳定之前使用标准库所做的那样,当时 Swift 可以随操作系统。

This bundles parts of the Concurrency portions of the standard library ( stable link ) along with some additional support and stubs for functionality ( stable link ).这捆绑了标准库的并发部分( 稳定链接)以及一些额外的支持和功能存根稳定链接)。

This bundling isn't necessary when deploying to OS versions new enough to contain these runtime features as part of the OS.当部署到足够新的操作系统版本以包含这些运行时功能作为操作系统的一部分时,这种捆绑不是必需的。


Since the feature on iOS 15+ (and associated OS releases) was stated to require kernel changes (for the new cooperative threading model) which themselves cannot be backported, the implementation of certain features includes shims based on existing functionality which does exist on those OSes, but which might perform a little bit differently, or less efficiently.由于 iOS 15+(和相关操作系统版本)上的功能被声明需要内核更改(对于新的协作线程模型),而这些内核本身无法向后移植,因此某些功能的实现包括基于这些操作系统上确实存在的现有功能的垫片,但其性能可能略有不同,或者效率较低。

You can see this in a few places in Doug Gregor's PR for backporting concurrency — in a few places, you can see checks for SWIFT_CONCURRENCY_BACK_DEPLOYMENT which change the implementation where some assumptions no longer hold, or functionality isn't present.您可以在Doug Gregor 的SWIFT_CONCURRENCY_BACK_DEPLOYMENT移植并发PR中的几个地方看到这一点——在一些地方,您可以看到检查SWIFT_CONCURRENCY_BACK_DEPLOYMENT ,这改变了某些假设不再成立或功能不存在的实现。 For example, the GlobalExecutor can't rely on getting a global Dispatch queue as its main shared queue when backporting, and has to create its own for use.例如, GlobalExecutor在向后移植时不能依赖于获取全局 Dispatch 队列作为其主要共享队列,而必须创建自己的供使用。 @objc -based actors also need to have their superclass swizzled , which doesn't need to happen on non-backdeployed runtimes.基于@objc的 actor还需要让他们的超类 swizzled ,这不需要在非后台部署的运行时发生。 (Symbols also have to be injected in some places into the backdeploy libs, and certain behaviors have to be stubbed out, but that's a bit less interesting.) (符号还必须在某些地方注入到后台部署库中,某些行为必须被剔除,但这有点不那么有趣。)

Overall, there isn't comprehensive documentation on the exact differences between backdeploying and not (short of reading all of the code), but it should be safe to assume that the effective behavior of the backdeployed lib will be the same, though potentially at the cost of performance.总的来说,没有关于后台部署和非后台部署之间的确切区别的全面文档(没有阅读所有代码),但可以安全地假设后台部署库的有效行为将是相同的,尽管可能在性能成本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM