Skip to content

Implement a syntactic peephole for reversing implicit bridging conversions #10987

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 5 commits into from
Jul 15, 2017

Conversation

rjmccall
Copy link
Contributor

No description provided.

rjmccall added 5 commits July 15, 2017 01:12
Previously, we sometimes built optional injections and evaluations
on the outside.  NFC, but it makes the bridging peephole a lot simpler.
a known-non-empty state to a known-empty state.
create a tuple of argument sources, and destructure such tuples
during argument emission.  NFC.
conversions that reverse an implicit conversion done to align
foreign declarations with their imported types.

For example, consider an Objective-C method that returns an NSString*:
  - (nonnull NSString*) foo;
This will be imported into Swift as a method returning a String:
  func foo() -> String
A call to this method will implicitly convert the result to String
behind the scenes.  If the user then casts the result back to NSString*,
that would normally be compiled as an additional conversion.  The
compiler cannot simply eliminate the conversion because that is not
necessarily semantically equivalent.

This peephole recognizes as-casts that immediately reverse a bridging
conversion as a special case and gives them special power to eliminate
both conversions.  For example, 'foo() as NSString' will simply return
the original return value.  In addition to call results, this also
applies to call arguments, property accesses, and subscript accesses.
@rjmccall
Copy link
Contributor Author

@swift-ci Please test and merge.

@swift-ci swift-ci merged commit 07f5b8d into swiftlang:master Jul 15, 2017
@rjmccall rjmccall deleted the bridging-peephole branch July 15, 2017 06:50
@dabrahams
Copy link
Contributor

dabrahams commented Jul 16, 2017

This appears to be the cause of source compatibility suite failures https://ci.swift.org/view/Source%20Compatibility/job/swift-master-source-compat-suite/802/

I will revert if local testing confirms it. See also rdar://33341584

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