mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When computing linkage, the compiler would treat unavailable declarations as if
they were "always available" when they lack an `introduced:` version:
```
// Library
@available(macOS, unavailable)
public func foo() {
// …
}
// Client
import Library
@available(macOS, unavailable)
func bar() {
// Even though foo() and bar() are unavalable on macOS the compiler still
// strongly links foo().
foo()
}
```
This created an unnecessary dependency between libraries and their clients and
also can interfere with back deployment, since unavailable declarations may not
be present in a library on all OS versions. Developers could work around these
issues by conditionally compiling the code that references an unavailable
declaration, but they shouldn't have to given that unavailable code is meant to
be provably unreachable at runtime. Additionally, it could improve library code
size if we allowed the compiler to strip unavailable declarations from a binary
completely.
Resolves rdar://106673713
31 lines
795 B
Swift
31 lines
795 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
// RUN: %target-build-swift-dylib(%t/%target-library-name(Library)) -emit-module -emit-module-path %t/Library.swiftmodule -module-name Library -parse-as-library %t/Library.swift -swift-version 5 -enable-library-evolution
|
|
// RUN: %target-build-swift-dylib(%t/%target-library-name(ClientLibrary)) %t/ClientA.swift %t/ClientB.swift -I%t -L%t -swift-version 5 -lLibrary
|
|
|
|
//--- Library.swift
|
|
|
|
@available(*, unavailable)
|
|
public struct UnavailableStruct {}
|
|
|
|
//--- ClientA.swift
|
|
|
|
import Library
|
|
|
|
@inline(never)
|
|
func blackHole<T>(_ t: T) {}
|
|
|
|
@available(*, unavailable)
|
|
public func foo() {
|
|
blackHole(UnavailableStruct.self)
|
|
}
|
|
|
|
//--- ClientB.swift
|
|
|
|
import Library
|
|
|
|
@available(*, unavailable)
|
|
public func bar() {
|
|
blackHole(UnavailableStruct.self)
|
|
}
|