Skip to content

[SIL] Fixed return index for call-as-async (BOOL, Error, Value) case. #38825

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 10, 2021

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.

Based on #38785 .

rdar://81625544

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 nate-chandler requested a review from jckarter August 10, 2021 17:15
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 519a70103bc749911639d07f7ad4a0ca523cc0a1

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
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test windows 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.

2 participants