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

Avoid invalidating @_objcImplementation #76270

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Sep 5, 2024

In #69257, we modified ObjCReason to carry a pointer to the @implementation attribute for the MemberOfObjCImplementationExtension kind. This made it mark the @implementation attribute as invalid, suppressing diagnostics from the ObjCImplementationChecker.

However, invalidating the attribute also causes it to be skipped by serialization. That isn’t a problem if the diagnostics are errors, since we’ll never emit the serialized module, but #74135 softened these diagnostics to warnings for early adopters.

The upshot was that if Swift emitted one of these warnings when it compiled a library, clients of that library would see the objcImpl extension as a normal extension instead. This would cause various kinds of mischief: ambiguous name lookups because implementations weren’t being excluded, overrides failing because an implementation was public instead of open, asserts and crashes in SILGen and IRGen because stored properties were found in seemingly normal extensions, etc.

Fix this by setting a separate bit on ObjCImplementationAttr, rather than the invalid bit, and modifying the implementation checker to manually suppress many diagnostics when that bit is set.

Fixes rdar://134730183.

@beccadax
Copy link
Contributor Author

beccadax commented Sep 6, 2024

Revised the implementation—the original one would sometimes cause two diagnostics to be emitted on the same declaration. This wouldn't block a build that wasn't already being blocked, but it would make the developer experience worse.

In swiftlang#69257, we modified `ObjCReason` to carry a pointer to the @implementation attribute for the `MemberOfObjCImplementationExtension` kind. This made it mark the @implementation attribute as invalid, suppressing diagnostics from the ObjCImplementationChecker.

However, invalidating the attribute *also* causes it to be skipped by serialization. That isn’t a problem if the diagnostics are errors, since we’ll never emit the serialized module, but swiftlang#74135 softened these diagnostics to warnings for early adopters.

The upshot was that if Swift emitted one of these warnings when it compiled a library, clients of that library would see the objcImpl extension as a normal extension instead. This would cause various kinds of mischief: ambiguous name lookups because implementations weren’t being excluded, overrides failing because an implementation was `public` instead of `open`, asserts and crashes in SILGen and IRGen because stored properties were found in seemingly normal extensions, etc.

Fix this by setting a separate bit on ObjCImplementationAttr, rather than the invalid bit, and modifying the implementation checker to manually suppress many diagnostics when that bit is set.

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

beccadax commented Sep 6, 2024

@swift-ci please test

@beccadax beccadax changed the title [WIP] Avoid invalidating @_objcImplementation Avoid invalidating @_objcImplementation Sep 6, 2024
@beccadax beccadax marked this pull request as ready for review September 6, 2024 00:58
// expected-warning@-1 {{method cannot be in an @objc @implementation extension of a class (without final or @nonobjc) because the type of the parameter cannot be represented in Objective-C}}

// CHECK-DAG: @objc func goodMethod()
@objc public func goodMethod() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, but it would be nice if this test also demonstrated end-to-end that a client can also deserialize and use the emitted module here, since that's where the failure manifested IIUC.

@beccadax beccadax merged commit 4dae9ee into swiftlang:main Sep 11, 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