如何在非标准库 Swift 框架中为容器启用高级 SIL 优化?

How do I enable high level SIL optimizations for containers in a non-stdlib Swift framework?

阅读 High level SIL optimizations 后,我特别注意到以下内容(在 从标准库中克隆代码):

The Swift compiler can copy code from the standard library into the application. This allows the optimizer to inline calls from stdlib and improve the performance of code that uses common operators such as '++' or basic containers such as Array. However, importing code from the standard library can increase the binary size. Marking functions with @_semantics("stdlib_binary_only") will prevent the copying of the marked function from the standard library into the user program.

现在,这太棒了。但是,如果我正在编写自己的容器怎么办?

我目前正在编写一个(从哲学上)扩展标准库的框架,引入我认为缺少的一些数据结构;例如树和图。

但是,据我了解,这些容器(在我的框架之外)不会得到特殊的 cloning/inlining 待遇,即使它们被单调乏味地标记为相关 @effects@inline(__always)@_transparent 等属性。据我了解,这些优化 仅供标准库和朋友使用

优化(如果有的话)将仅应用于我的框架内的代码,而不是导入我的框架的模块。

这让我很为难。它实际上意味着,要利用这些高级优化的力量,我的所有代码必须在一个模块中。那根本不可能。

我有大约 800 个密集的 Swift 文件,跨越 9 个框架。仅编译时间就是一场噩梦;更不用说它会给 SourceKitService(和我,就此而言)造成多么严重的创伤。

如果可能的话,我该如何解决这个问题?

Cross-module-inlining 现在可用于 Swift 4.2 及更高版本!