-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
SILOptimizer: Allow inlining of transparent functions in @backDeployed
thunks
#76135
SILOptimizer: Allow inlining of transparent functions in @backDeployed
thunks
#76135
Conversation
4197cef
to
f7816cf
Compare
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.
f7816cf
to
42a68fd
Compare
_stdlib_isOSVersionAtLeast_AEIC()
for availability checks@backDeployed
thunks
@swift-ci please test |
@swift-ci please test Windows |
@swift-ci benchmark |
Run the benchmarks to be on the safe side (I don't expect any changes) |
…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.
42a68fd
to
789b795
Compare
@swift-ci please test |
We lost the link to these benchmark results since I had to rerun the tests after fixing some broken ones. Here are the original results: https://ci.swift.org/job/swift-PR-macos-perf/1001/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
As promised in the FIXME, update the SIL printer and parser to handle the new thunk kind for `@backDeployed` thunks. Follow up to swiftlang#76135.
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 normalif #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.