-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.5] [SIL] Fixed return index for call-as-async (BOOL, Error, Value) case. #38863
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
nate-chandler
merged 3 commits into
swiftlang:release/5.5
from
nate-chandler:cherrypick/rdar81625544/release/5.5
Aug 17, 2021
Merged
[5.5] [SIL] Fixed return index for call-as-async (BOOL, Error, Value) case. #38863
nate-chandler
merged 3 commits into
swiftlang:release/5.5
from
nate-chandler:cherrypick/rdar81625544/release/5.5
Aug 17, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci please test |
@swift-ci please nominate |
Build failed |
009c874
to
8898fcd
Compare
Needed to be based on top of #38862 . |
@swift-ci please test |
tbkka
approved these changes
Aug 17, 2021
Previously, the function emitCBridgedToNativeValue handled three situations around optionals: - Bridged?, Native? - Bridged, Native? - Bridged, Native Here, handling for the fourth case - Bridged?, Native is added. To enable this, the number of Optional wrappings that the bridged type has that the native type does not is passed in to the function. Then, in the portions of the function where actual transformations are done, the values are unwrapped an appropriate number of times. Mostly that means force unwrapping N times before doing the transformation. In the case of types that conform to _ObjectiveCBridgeable, however, it means force unwrapping the value N-1 times after doing the transformation because _ObjectiveCBridgeable._unconditionallyBridgeFromObjectiveC performs one layer of unwrapping itself. rdar://81590807
The underlying problem was fixed by the change for rdar://81590807 . Add tests for the specific case that was originally reported. rdar://80704382
When converting an ObjC method type which is being called as async to a Swift function type, some of the values passed to the ObjC method's completion handler are converted to return values of the Swift function. The flag and error parameters, however, if present, are ignored. When abstracting the result type for the Swift method, the formal type of the corresponding parameter in the ObjC method's completion handler is used. Digging out that parameter entails indexing into the parameters of the completion handler. Previously, the indexing logic relied on the error appearing before the flag if both appeared before the value of interest. Here, the indexing is tweaked to check both special indices for each possible index until the first that matches neither is found. rdar://81625544
8898fcd
to
57fd46d
Compare
@swift-ci please test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
5.5 Summary: Fix compiler crash during call-as-async of ObjC method whose completion handler looks like
(BOOL, NSError *, Value)
.Explanation: When converting an ObjC method type which is being called as async to a Swift function type, some of the values passed to the ObjC method's completion handler are converted to return values of the Swift function. The flag and error parameters, however, if present, are ignored.
When abstracting the result type for the Swift method, the formal type of the corresponding parameter in the ObjC method's completion handler is used. Digging out that parameter entails indexing into the parameters of the completion handler. Previously, the indexing logic relied on the error appearing before the flag if both appeared before the value of interest. Here, the indexing is tweaked to check both special indices for each possible index until the first that matches neither is found.
Issue: rdar://81625544
Original PR: #38825
Testing: New regression tests, Swift CI
Reviewed by: Joe Groff
Risk: Low.
Scope: Limited to Swift import of ObjC methods as async functions.