Skip to content

[ClangImporter] Import -_init...: selectors as initializers#89272

Open
airspeedswift wants to merge 1 commit into
swiftlang:mainfrom
airspeedswift:clangimporter-underscore-init-family
Open

[ClangImporter] Import -_init...: selectors as initializers#89272
airspeedswift wants to merge 1 commit into
swiftlang:mainfrom
airspeedswift:clangimporter-underscore-init-family

Conversation

@airspeedswift
Copy link
Copy Markdown
Member

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.

Addresses rdar://96631007

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.
@airspeedswift
Copy link
Copy Markdown
Member Author

@swift-ci please test

_ = UnderscoreInitTest(_other: 1)

// Explicit `swift_name(init(_otherSwiftName:))` is honored.
_ = UnderscoreInitTest(_otherSwiftName: 2)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

_ = UnderscoreInitTest()

// `omitNeedlessWords` doesn't strip the leading underscore.
_ = UnderscoreInitTest(_array: [])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow, what does this exercise that _ = UnderscoreInitTest(_other: 1) doesn't?

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