Skip to content

Mimic old objcImpl behavior for early adopters #76462

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 4 commits into from
Sep 26, 2024

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Sep 13, 2024

Before the update to support the new syntax, the decl checker treated private and fileprivate members of objcImpl extensions as non-@objc by default. But SE-0436 specified that private and fileprivate members should be implicitly @objc unless opted out, so when support for the final syntax was added, this behavior was changed retroactively.

Unfortunately, we’ve found that some early adopters depended on the old behavior. Restore some logic deleted by #73309 for early adopter syntax only, with a warning telling the developer to put final or @nonobjc on the declaration if they want to preserve the behavior after updating it.

Also tweaks the ObjCImplementationChecker to ensure this logic will actually be run in time for it to suppress the “upgrade to @objc @implementation” warning, and corrects a couple of regressions arising from that change.

Edit: I've added additional commits to correct other issues with this part of the code in #73309:

  • Temporarily restores the behavior of an @objc @_objcImplementation extension with a warning telling the developer to correct their code
  • Permanently fixes a regression where a static or final member which overrode a superclass method or witnessed a protocol requirement would not be inferred as @objc.

Fixes rdar://135747897 and rdar://136113393.

Cherry-picking note: This relies on changes in the final version of #76270.

Before the update to support the new syntax, the decl checker treated private and fileprivate members of objcImpl extensions as non-@objc by default. But SE-0436 specified that private and fileprivate members should be implicitly @objc unless opted out, so when support for the final syntax was added, this behavior was changed retroactively.

Unfortunately, we’ve found that some early adopters depended on the old behavior. Restore some logic deleted by swiftlang#73309 for early adopter syntax *only*, with a warning telling the developer to put `final` or `@nonobjc` on the declaration if they want to preserve the behavior after updating it.

Also tweaks the ObjCImplementationChecker to ensure this logic will actually be run in time for it to suppress the “upgrade to @objc @implementation” warning, and corrects a couple of regressions arising from that change.

Fixes rdar://135747897.
@beccadax
Copy link
Contributor Author

@swift-ci please test

A previous change made it so that an objcImpl extension could declare a `final` or `static` member which overrode an `@objc` superclass method, or witnessed an `@objc` protocol requirement, without itself being `@objc`. Prevent that from happening by allowing processing of `final` members to continue to later codepaths, rather than returning early.

Fixes rdar://136113393.
Automatically detect when shouldMarkAsObjC() will behave differently based on the objcImpl early adopter flag and diagnose it. This works in either direction, although there isn’t anything yet that will emit diag:: objc_implementation_will_become_nonobjc.

NFC except for some minor changes to the wording of notes.
The combination `@objc @_objcImplementation extension` used to be treated like a normal `@objc extension`. Restore that behavior for early adopters.
@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax beccadax enabled auto-merge September 25, 2024 17:52
@beccadax beccadax merged commit f558d01 into swiftlang:main Sep 26, 2024
5 checks passed
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