# Does module stability offer backwards compatibility?

**URL:** <https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794>\
**Category:** Using Swift\
**Created:** [March 16, 2021, 9:44pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794 "2021-03-16T21:44:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scott/32/23832_2.png) [@Scott](https://forums.swift.org/u/Scott)\
**Post date:** [March 16, 2021, 9:44pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/1 "2021-03-16T21:44:29Z")

</div>

The examples I've seen of module stability always present a scenario where you compile a swift library with a version of Swift, and then the consumer of that library is free to use a _later_ version of the Swift compiler than what your library was compiled with. For example: You compile a framework with Xcode 11.7 (Swift 5.2.4) w/ ABI and module stability, and then give it to another developer who is using Xcode 12.4 (Swift 5.3.2) and they can use it because module stability provides compatibility with future swift compilers.

I'm interested in backwards compatibility of libraries built with module stability. If I build my library in Xcode 12.4 (Swift 5.3.2), can I guarantee that it will work in an app compiled with Xcode 11.7 (Swift 5.2.4)? Or will I, as the library author, always need to build with a \<= version of the Swift compiler than my consumers?

I can't seem to find documentation on this, but if there is any I'd appreciate a link to it.

Notes:

- The WWDC video "Binary Frameworks in Swift" ([Binary Frameworks in Swift - WWDC19 - Videos - Apple Developer](https://developer.apple.com/videos/play/wwdc2019/416)) uses kind-of vague language like

> Compatible across compiler versions

Which makes it seem like you could, but in the talk he says

> And since they behave like source code, then future versions of the Swift Compiler will be able to import module interfaces created with older versions

- Harlan seems to indicate that swift interface files are not necessarily backwards-compatible here: [Can't use framework compiled with Swift 5.2 in Swift 5.1.3 project - #9 by harlanhaskins](https://forums.swift.org/t/cant-use-framework-compiled-with-swift-5-2-in-swift-5-1-3-project/35248/9)

Because of these I think the answer is that there are no backwards-compatibility guarantees, but I wasn't completely sure.

---

<div class="post-metadata">

**Author:** ![jonprescott](https://avatars.discourse-cdn.com/v4/letter/j/e36b37/32.png) [@jonprescott](https://forums.swift.org/u/jonprescott)\
**Post date:** [March 16, 2021, 10:14pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/2 "2021-03-16T22:14:20Z")

</div>

There was a great deal of ABI and module stability on these forums, the upshot is that modules stability only marches forward, not back. You might want to do a search on module stability on these forums.

---

<div class="post-metadata">

**Author:** ![harlanhaskins](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/harlanhaskins/32/333_2.png) [@harlanhaskins](https://forums.swift.org/u/harlanhaskins)\
**Post date:** [March 16, 2021, 10:24pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/3 "2021-03-16T22:24:17Z")

</div>

There's no guarantee of backwards compatibility with older compilers – there may be new syntax features used in the `swiftinterface` that an older compiler doesn't understand. However, if none of those features are used or exposed in a library (e.g. if you don't use `actor`s once those land), there's a chance the interface file from a newer compiler might still work with the older one. But it's not supported.

---

<div class="post-metadata">

**Author:** ![Scott](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scott/32/23832_2.png) [@Scott](https://forums.swift.org/u/Scott)\
**Post date:** [March 16, 2021, 10:33pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/4 "2021-03-16T22:33:47Z")

</div>

Thank you both for your help!

---

<div class="post-metadata">

**Author:** ![harlanhaskins](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/harlanhaskins/32/333_2.png) [@harlanhaskins](https://forums.swift.org/u/harlanhaskins)\
**Post date:** [March 26, 2021, 4:16pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/5 "2021-03-26T16:16:06Z")

</div>

I forgot to mention this, there's a feature that's being worked on in the compiler that (while not _guaranteeing_ backwards compatibility) seeks to reduce the surface area for backwards compatibility issues.

New syntax _should_ introduce a new "compiler feature" flag, which causes the compiler to automatically surround code that uses that feature with:

```swift
#if $SpacefaringFunctions
func goToMoon() spacefaring {
}
#endif

```

Again, not to guarantee backwards compatibility, but to make it more likely that a given compiler update produces swift interfaces that can at least be partially used by slightly older clients.

---

<div class="post-metadata">

**Author:** ![sirghi](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sirghi/32/5056_2.png) [@sirghi](https://forums.swift.org/u/sirghi)\
**Post date:** [April 9, 2023, 9:11am UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/6 "2023-04-09T09:11:12Z")

</div>

Nice one. Would this be some internals in the swift compiler, or as we write swift code we can make use of this?

We have a case where the SDK was built with 5.7.2 and the app with 5.5. Error message below:

```swift
(the SDK is built with 'Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)', while this compiler is 'Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)'). Please select a toolchain which matches the SDK.

```

Is there a place where we can check which interface features have appeared in each version, to deduce how likely it is for backwards compatibility to break between 2 specific versions?

Btw, can you tell whether the above error is related to backwards compatibility? Because I have a vague feeling it implies that the SDK was not built for distribution, although we pass `BUILD_LIBRARY_FOR_DISTRUBUTION` to xcodebuild.

---

<div class="post-metadata">

**Author:** ![harlanhaskins](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/harlanhaskins/32/333_2.png) [@harlanhaskins](https://forums.swift.org/u/harlanhaskins)\
**Post date:** [April 9, 2023, 3:32pm UTC](https://forums.swift.org/t/does-module-stability-offer-backwards-compatibility/45794/7 "2023-04-09T15:32:30Z")

</div>

This backwards compatibility feature is not intended to support this configuration. Either you’ll need to recompile the SDK with the 5.5 compiler or update Xcode and recompile the app with a newer Swift.
