Skip to content

[SILGen] Fixed handler formal arg type indexing. #38785

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 2 commits into from
Aug 10, 2021

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Aug 6, 2021

In the synthesized completion handler that is passed to ObjC methods that are called as async, the formal type of each argument is the corresponding parameter of the formal type of the block. The non-error, non-index arguments need to be prepared so that they can be used to fulfill the continuation; the lambda which does that preparation for each such argument takes the formal type of that argument. As such, the call to that lambda needs to pass the type of the corresponding parameter of the formal type of the block to that lambda. Doing so entails skipping over the error and flag parameters if they appear before some of the non-error, non-index arguments.

Previously, no parameters were skipped over. Consequently, when an error or flag argument preceded one of the non-error, non-index arguments, the wrong formal type was passed to the preparation lambda.

Here, that is fixed by passing the correct index. The to-be-used indices for the formal block parameters are the same as the to-be-used indices for the lowered block parameters minus one reflecting the fact that the lowered block always has an initial block_storage parameter as the first argument which the formal type never has.

Based on #38773 .

rdar://81617749

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler requested a review from jckarter August 6, 2021 18:39
@swift-ci
Copy link
Contributor

swift-ci commented Aug 6, 2021

Build failed
Swift Test Linux Platform
Git Sha - 0315413647115ca4980e339789bf19bbcf807c9c

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test linux platform

@swift-ci
Copy link
Contributor

swift-ci commented Aug 6, 2021

Build failed
Swift Test OS X Platform
Git Sha - 0315413647115ca4980e339789bf19bbcf807c9c

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test windows platform

@swift-ci
Copy link
Contributor

swift-ci commented Aug 6, 2021

Build failed
Swift Test OS X Platform
Git Sha - 5e352f81baba19a7a9888658aa74533baee4ca2e

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

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

Looks good, thanks Nate!

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
In the synthesized completion handler that is passed to ObjC methods
that are called as async, the formal type of each argument is the
corresponding parameter of the formal type of the block.  The non-error,
non-index arguments need to be prepared so that they can be used to
fulfill the continuation; the lambda which does that preparation for
each such argument takes the formal type of that argument.  As such, the
call to that lambda needs to pass the type of the corresponding
parameter of the formal type of the block to that lambda.  Doing so
entails skipping over the error and flag parameters if they appear
before some of the non-error, non-index arguments.

Previously, no parameters were skipped over.  Consequently, when an
error or flag argument preceded one of the non-error, non-index
arguments, the wrong formal type was passed to the preparation lambda.

Here, that is fixed by passing the correct index.  The to-be-used
indices for the formal block parameters are the same as the to-be-used
indices for the lowered block parameters minus one reflecting the fact
that the lowered block always has an initial block_storage parameter as
the first argument which the formal type never has.

rdar://81617749
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - cef64c9

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test macos platform

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.

3 participants