Skip to content
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

[6.0] SILOptimizer: Allow inlining of transparent functions in @backDeployed thunks #76140

Merged

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Aug 29, 2024

  • Explanation: Adjusts an optimizer heuristic to allow inlining of @_transparent functions into @backDeployed thunks so that the codegen for the availability checks in @backDeployed works as expected when compiling for iOS.
  • Scope: Without this fix, unoptimized iOS apps that use newly @backDeployed functions from the _Concurrency library crash when the app runs on macOS, due to the availability condition being misevaluated as checking a macOS version instead of an iOS version.
  • Issue/Radar: rdar://134793410
  • Original PR: SILOptimizer: Allow inlining of transparent functions in @backDeployed thunks #76135
  • Risk: Medium. The optimization adjustment is extremely targeted so that it should only affect optimization and codegen for @backDeployed thunks, but any change of this nature carries some risk of unforeseen consequences.
  • Testing: New tests added to the compiler test suite.
  • Reviewer: @eeckstein @slavapestov @mikeash

In the standard library shipped in Apple's SDKs and OSes, the implementation of
`_stdlib_isOSVersionAtLeast()` has diverged in order to solve some tricky
issues related to supporting iOS applications running on macOS. It's now time
to bring that change upstream in order to unblock further changes that depend
on it.

Originally introduced to resolve rdar://83378814.
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.0 labels Aug 29, 2024
…d thunks.

In order for availability checks in iOS apps to be evaluated correctly when
running on macOS, the application binary must call a copy of
`_stdlib_isOSVersionAtLeast_AEIC()` that was emitted into the app, instead of
calling the `_stdlib_isOSVersionAtLeast()` function provided by the standard
library. This is because the call to the underlying compiler-rt function
`__isPlatformVersionAtLeast()` must be given the correct platform identifier
argument; if the call is not emitted into the client, then the macOS platform
identifier is used and the iOS version number will be mistakenly interpreted as
a macOS version number at runtime.

The `_stdlib_isOSVersionAtLeast()` function in the standard library is marked
`@_transparent` on iOS so that its call to `_stdlib_isOSVersionAtLeast_AEIC()`
is always inlined into the client. This works for the code generated by normal
`if #available` checks, but for the `@backDeployed` function thunks, the calls
to `_stdlib_isOSVersionAtLeast()` were not being inlined and that was causing
calls to `@backDeployed` functions to crash in iOS apps running on macOS since
their availability checks were being misevaluated.

The SIL optimizer has a heuristic which inhibits mandatory inlining in
functions that are classified as thunks, in order to save code size. This
heuristic needs to be relaxed in `@backDeployed` thunks, so that mandatory
inlining of `_stdlib_isOSVersionAtLeast()` can behave as expected. The change
should be safe since the only `@_transparent` function a `@backDeployed` thunk
is ever expected to call is `_stdlib_isOSVersionAtLeast()`.

Resolves rdar://134793410.
@tshortli tshortli force-pushed the backdeployed-ios-apps-on-macos-6.0 branch from 0612c93 to ba575e7 Compare August 29, 2024 15:45
@tshortli
Copy link
Contributor Author

@swift-ci please test

@tshortli tshortli marked this pull request as ready for review August 29, 2024 15:46
@tshortli tshortli requested a review from a team as a code owner August 29, 2024 15:46
@tshortli tshortli requested a review from hborla August 29, 2024 16:22
@tshortli tshortli enabled auto-merge August 29, 2024 17:29
@tshortli tshortli merged commit 2ef2a5f into swiftlang:release/6.0 Aug 29, 2024
5 checks passed
@tshortli tshortli deleted the backdeployed-ios-apps-on-macos-6.0 branch August 29, 2024 21:31
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 swift 6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants