Skip to content

Add @implementation and feature flags for objcImpl #72596

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 8 commits into from
Mar 29, 2024

Conversation

beccadax
Copy link
Contributor

This PR makes a series of intertwined changes to @_objcImplementation:

  • Adds @implementation, the public syntax I intend to propose
    • @_objcImplementation will continue to be supported for the time being; the old syntax will warn instead of error for checker diagnostics
  • Adds ObjCImplementation experimental feature to gate access to @implementation extensions
    • When the feature is enabled, using @_objcImplementation will cause a deprecation warning
  • Adds CImplementation experimental feature to gate access to @implementation @_cdecl and @_objcImplementation @_cdecl
    • There are very few adopters for objcImpl with cdecl yet, so I'm hoping I can get away with this retroactive change

To aid in reviewing, I'm delaying some very mechanical follow-up work until another PR:

  • Renaming ObjCImplementationAttr to ImplementationAttr
  • Updating comments, method names, etc. in the compiler source code
  • Changing most tests from using @_objcImplementation to using @implementation

This PR will need a matching swift-syntax PR.

Fixes rdar://110728033.

@beccadax
Copy link
Contributor Author

With swiftlang/swift-syntax#2570

@swift-ci please test

@beccadax
Copy link
Contributor Author

With swiftlang/swift-syntax#2570

@swift-ci please test

Copy link
Contributor

@tshortli tshortli left a comment

Choose a reason for hiding this comment

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

LGTM! I left one suggestion for diagnostic wording.

They will eventually have slightly different deprecation status and error behavior, but not yet.

Fixes rdar://110728033.
They will have slightly different enablement and diagnostic behavior in a future commit.
• ObjCImplementation controls @implementation on extensions
• CImplementation controls @implementation and @_objcImplementation on cdecl functions

Why the difference between them? Because `@_objcImplementation extension` has already been adopted pretty widely, while `@_objcImplementation @_cdecl` is very new.
…only when the ObjCImplementation experimental language feature is enabled. (`@implementation extension` is the preferred form.)
Adopting @implementation turns all of the warnings into errors.
Helps allow test/decl/ext/cdecl_implementation.swift to run on non-ObjC platforms.
@beccadax beccadax force-pushed the objcimpl-real-name branch from 3f18cea to 0505c38 Compare March 27, 2024 23:05
@beccadax
Copy link
Contributor Author

With swiftlang/swift-syntax#2570

@swift-ci please test

@beccadax beccadax requested a review from tshortli March 28, 2024 00:14

// YES-DAG: cdecl_implementation_features.swift:[[@LINE+4]]:{{[0-9]+}}: warning: global function 'CImplFunc1' of type '(Double) -> ()' does not match type '(Int32) -> Void' declared by the header; this will become an error after adopting '@implementation'
// NO-DAG: cdecl_implementation_features.swift:[[@LINE+3]]:{{[0-9]+}}: error: '_objcImplementation' attribute is only valid when experimental feature CImplementation is enabled
// YES-NOT: cdecl_implementation_features.swift:[[@LINE+2]]:{{[0-9]+}}: warning: warning-only '@_objcImplementation' spelling is deprecated; use '@implementation' instead
Copy link
Contributor

Choose a reason for hiding this comment

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

This CHECK line looks like it might be out of date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just noticed that myself. Good catch!

• Simpler wording
• Now emitted only if there are no other @objcImpl diagnostics (so @implementation would not emit any new errors)
@beccadax beccadax force-pushed the objcimpl-real-name branch from 0505c38 to 858b557 Compare March 28, 2024 00:47
@beccadax
Copy link
Contributor Author

With swiftlang/swift-syntax#2570

@swift-ci please test

@beccadax
Copy link
Contributor Author

I will shortly be pushing changes that make the matching swift-syntax PR unnecessary.

Rather than adding custom parsing to SwiftSyntax, we can parse this as a custom attribute and convert it to a built-in one in ASTGen. Test that this works correctly (and fix a bug where it wasn’t).
@beccadax
Copy link
Contributor Author

@swift-ci please test

@nkcsgexi
Copy link
Contributor

🎉

@beccadax
Copy link
Contributor Author

@swift-ci please test

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.

3 participants