Skip to content

IRGen: Weakly link symbols for unavailable declarations #64429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Mar 16, 2023

This is a second attempt of #64353.

When computing linkage, the compiler would treat unavailable declarations as if they were "always available" if they also 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, in the future it could improve library code size if we allowed the compiler to strip unavailable declarations from a binary completely.

Resolves rdar://106673713

@tshortli tshortli force-pushed the weak-link-unavailable-symbols-redux branch 8 times, most recently from 36e1010 to ed1308d Compare March 23, 2023 06:39
@tshortli
Copy link
Contributor Author

@swift-ci Please Build Toolchain Windows Platform

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
@tshortli tshortli force-pushed the weak-link-unavailable-symbols-redux branch from ed1308d to adda1f5 Compare March 23, 2023 15:57
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli
Copy link
Contributor Author

@swift-ci please smoke test macOS

@tshortli tshortli marked this pull request as ready for review March 23, 2023 22:14
@tshortli tshortli merged commit 21109a3 into swiftlang:main Mar 23, 2023
@tshortli tshortli deleted the weak-link-unavailable-symbols-redux branch March 23, 2023 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant