[ClangImporter] Import -_init...: selectors as initializers#89272
Open
airspeedswift wants to merge 1 commit into
Open
[ClangImporter] Import -_init...: selectors as initializers#89272airspeedswift wants to merge 1 commit into
-_init...: selectors as initializers#89272airspeedswift wants to merge 1 commit into
Conversation
Methods whose ObjC selector starts with `_init` (the SPI underscore convention) are classified by Clang as the init family but were being imported as Swift methods because `isInitMethod` required the selector's first word to be exactly `init`. Likewise, `objc_method_family(init)` and `swift_name(init(...))` annotations were silently ignored on such selectors. Accept `_init` as a valid first word and strip the matching prefix when computing the first argument label. The leading underscore is preserved on the resulting label (e.g. `-_initWithFoo:` imports as `init(_foo:)`) so the SPI marker stays visible at the use site.
Member
Author
|
@swift-ci please test |
hnrklssn
reviewed
May 20, 2026
| _ = UnderscoreInitTest(_other: 1) | ||
|
|
||
| // Explicit `swift_name(init(_otherSwiftName:))` is honored. | ||
| _ = UnderscoreInitTest(_otherSwiftName: 2) |
Member
There was a problem hiding this comment.
Isn't this the same signature as it would've had without swift_name? How can we tell that this is due to the swift_name and not due to the implicit name path?
hnrklssn
reviewed
May 20, 2026
| _ = UnderscoreInitTest() | ||
|
|
||
| // `omitNeedlessWords` doesn't strip the leading underscore. | ||
| _ = UnderscoreInitTest(_array: []) |
Member
There was a problem hiding this comment.
I don't follow, what does this exercise that _ = UnderscoreInitTest(_other: 1) doesn't?
This file contains hidden or 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
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.
Methods whose ObjC selector starts with
_init(the SPI underscore convention) are classified by Clang as the init family but were being imported as Swift methods becauseisInitMethodrequired the selector's first word to be exactlyinit. Likewise,objc_method_family(init)andswift_name(init(...))annotations were silently ignored on such selectors.Accept
_initas a valid first word and strip the matching prefix when computing the first argument label. The leading underscore is preserved on the resulting label (e.g.-_initWithFoo:imports asinit(_foo:)) so the SPI marker stays visible at the use site.Addresses rdar://96631007