Skip to content

[5.9] Introduce -unavailable-decl-optimization #64810

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

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Mar 31, 2023

Cherry pick of #64644 and #64808

Introduce the -unavailable-decl-optimization frontend flag which can be used to reduce the size of a compiled binary by removing machine code related to declarations that are marked unavailable with an @available attribute. Unavailable code is meant to be provably unreachable at runtime for a specific execution context and therefore including machine code for these declarations is wasteful.

In this iteration, the flag supports two modes:

  • none: Does not remove any code related to unavailable declarations. This is the default.
  • complete: Avoids generating any machine code for unavailable declarations. This will be the most aggressive optimization available.

The plan is to expand the available modes in the future with at least one more option, stub, which will cause unavailable functions to be emitted as stubs containing just fatalError(). This option will be needed by owners of resilient libraries to preserve ABI compatibility since existing clients may link against the symbols for unavailable declarations, even if they never execute them.

Resolves rdar://106674022 and rdar://107425181

@tshortli tshortli force-pushed the unavailable-decl-optimization-5.9 branch from c7c0fde to 5e1fcbc Compare March 31, 2023 16:41
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli
Copy link
Contributor Author

@swift-ci please test Windows

@tshortli tshortli requested a review from nkcsgexi March 31, 2023 18:56
Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new mode is behind a flag.

@tshortli tshortli marked this pull request as ready for review March 31, 2023 20:57
@tshortli tshortli requested a review from a team as a code owner March 31, 2023 20:57
@tshortli tshortli merged commit 6a0851e into swiftlang:release/5.9 Mar 31, 2023
@tshortli tshortli deleted the unavailable-decl-optimization-5.9 branch March 31, 2023 21:49
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants