Explicit Module Builds, the new Swift Driver, and SwiftPM

Hi. I'm new to compiler stack. I'm interested in new swift-driver because I want to use this to scan files that been effectected by the modification of single source file. Which may boost the build time for compiler-related tools like Static Analysis, IR generation, and so on like even Bazel build system, without having to fully compile all the files in module.

After reading current swift-driver and swift/libSwiftScan, I found for ".swiftinterface" deps, we use the Parser::getTopLevelDecls() to analysis the import module syntax, but we still parse the other uninterested decls like typealias

For clang module we use clang-scan-deps, which use the custom tokenizer to token only "include/import #if #else #end" decls.

Is there any plan to perform faster analysis speed using the similar tech ?

1 Like

There are not specific plans, as far as I know; but, that sounds like it would be a great improvement.

Thanks for the great write up! I wanted to ask about the limitation of .swiftmodule files being tied to a specific compiler version (and to some degree .swiftinterface files, since they are only forwards compatible).

I believe this is the issue of "module stability" which Swift does not yet support, is that correct? It's been quite a pain point for my team as we distribute a compiled .xcframework containing Swift code to our customers and there have been a lot of issues caused by folks being on different versions of Xcode.

For example, when we started compiling the framework with Xcode 13, the framework stopped working with anyone using an older version of Xcode because our .swiftinterface file now contains import Concurrency which is unknown to those older versions, even though we're not using any language-level concurrency features. I could be wrong on the exact details but I think that's the gist of it.

Is there any way to work around this other than compiling multiple versions of the framework with different Xcode versions? Do these changes you've described get us any closer to module stability?

Any info or advice you can provide is much appreciated!

Swift has module stability, and has since Swift 5. For precompiled binaries you need to make sure to build for distribution, which ensures library evolution mode is on, along with other settings to maximize compatibility. Swift.org - Library Evolution in Swift With Xcode 13.2, there's also a back compatibility library for the Swift concurrency module which deploys back to the 2019 OS versions. It is buggy so back deployment may need to wait for Xcode 13.3, which fixes many of those issues. But if you aren't deploying any concurrency APIs building for distribution should be all you need. If it isn't you should report bugs.

2 Likes