Skip to content
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
merged 12 commits into from
Feb 2, 2016
Merged

[Swift 2.2] SE-0022 #1170

merged 12 commits into from
Feb 2, 2016

Conversation

tkremenek
Copy link
Member

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.

…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.
@DougGregor
Copy link
Member

@swift-ci please test

@tkremenek
Copy link
Member Author

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.
@tkremenek tkremenek merged commit fc23740 into swiftlang:swift-2.2-branch Feb 2, 2016
@tkremenek tkremenek deleted the Swift2.2-selector branch February 3, 2016 02:14
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