Skip to content

[SILGen] Handled transforming Bridged? -> Swift. #38773

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 1 commit into from
Aug 10, 2021

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Aug 6, 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

@nate-chandler nate-chandler requested a review from jckarter August 6, 2021 00:43
@nate-chandler nate-chandler force-pushed the rdar81590807 branch 2 times, most recently from d01cec7 to ba7ddb0 Compare August 6, 2021 00:49
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@jckarter
Copy link
Contributor

jckarter commented Aug 9, 2021

Hm, does this defeat the special handling of null bridging for types like NSString, where we intentionally map nil to empty "" String in this case?

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler changed the title [SILGen] In gen'd handlers, open optionals first. [SILGen] Bridged more called-as-async args from ObjC. Aug 9, 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
@nate-chandler nate-chandler changed the title [SILGen] Bridged more called-as-async args from ObjC. [SILGen] Handled transforming Bridged? -> Swift. Aug 10, 2021
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler merged commit 86bd7c8 into swiftlang:main Aug 10, 2021
@nate-chandler nate-chandler deleted the rdar81590807 branch August 10, 2021 16:54
@nate-chandler
Copy link
Contributor Author

nate-chandler commented Aug 12, 2021

(For cross-referencing purposes, the behavior was changed in a force-push to preserve the behavior of incorrectly nil NSStrings; that behavior is tested at https://github.com/apple/swift/pull/38773/files#diff-154a8dcf6adb593e4e77f29be44041d0ccc9ef9546fd0ef6bdb56dcb51119d87R34 .)

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