Skip to content

Introduce -unavailable-decl-optimization #64644

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 4 commits into from
Mar 28, 2023

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Mar 27, 2023

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

Avoid SIL lowering for declarations marked unavailable when
`-unavailable-decl-optimiation=complete` is specified.

Part of rdar://106674022
This ensures SIL lowering will avoid generating code for unavailable global
vars when `-unavailable-decl-optimization=complete` is specfied.

Part of rdar://106674022
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli marked this pull request as ready for review March 27, 2023 22:23
@tshortli tshortli requested review from nkcsgexi and xymus March 27, 2023 22:24
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.

This is exciting!

@tshortli tshortli merged commit 9a1a2c3 into swiftlang:main Mar 28, 2023
@tshortli tshortli deleted the strip-unavailable-code branch March 28, 2023 16:10
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.

2 participants