-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[Swift 2.2] SE-0022 #1170
Merged
tkremenek
merged 12 commits into
swiftlang:swift-2.2-branch
from
tkremenek:Swift2.2-selector
Feb 2, 2016
Merged
[Swift 2.2] SE-0022 #1170
tkremenek
merged 12 commits into
swiftlang:swift-2.2-branch
from
tkremenek:Swift2.2-selector
Feb 2, 2016
Conversation
This file contains 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
…ncoding. As part of SE-0022, introduce an 'objc_selector' encoding for string literals that places the UTF-8 string literal into the appropriate segment for uniquing of Objective-C selector names.
Make sure to set the linkage correctly, treat the selector data as non-constant, note that it is externally-initialized, and add it to llvm.compiler.used rather than llvm.used.
This completes the core of the #selector feature, which can now be used to reference the selectors of @objc methods and initializers.
Introduce Fix-Its to aid migration from selectors spelled as string literals ("foo:bar:", which is deprecated), as well as from construction of Selector instances from string literals (Selector("foo:bar"), which is still acceptable but not recommended), to the #selector syntax. Jump through some hoops to disambiguate method references if there are overloads: fixits.swift:51:7: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead _ = "overloadedWithInt:" as Selector ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ()) In the cases where we cannot provide a Fix-It to a #selector expression, we wrap the string literal in a Selector(...) construction to suppress the deprecation warning. These are also easily searchable in the code base. This also means we're doing more validation of the string literals that go into Selector, i.e., that they are well-formed selectors and that we know about some method that is @objc and has that selector. We'll warn if either is untrue.
@swift-ci please test |
Pull-request initiated CI not yet available for swift-2.2-branch. |
tkremenek
added a commit
that referenced
this pull request
Feb 2, 2016
[Swift 2.2] pull in SE-0022 into swift-2.2-branch.
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.
Pull in support for SE-0022 into swift-2.2-branch.
From @DougGregor:
Description.
This proposal contains both a new feature (the #selector expression) and the deprecation of an existing feature (treating a string literal as a Selector). Our intent is to use 2.2 to start migrating existing clients over to the new syntax, which will become far more important with The Grand Renaming in Swift 3.
Risk
There is risk here, of course: I changed the way we emit Objective-C selector references a bit, and the Fix-It code for translating uses of string-literals-as-selectors is non-trivial and makes use of another new feature (SE-0021, compound names). That said, I’m not overly concerned about new problems being introduced by this code. I’d love to see better code completion for compound names, but haven’t figured out a good way to do it yet.