Skip to content

Fix two objcImpl resyntaxing bugs #74135

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 2 commits into from
Jun 6, 2024

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Jun 5, 2024

#73309 introduced two minor bugs that were not previously detected:

  1. The newly-required (and sometimes implicitly added) @objc attribute was unnecessarily printed into module interfaces, where it could sometimes interfere with final or @nonobjc members of the extension. It should have been omitted.

  2. The type checker began diagnosing an error for members which were only final implicitly because something about their signature, such as their parameter types, made them ineligible for @objc. This behavior is correct but for early adopters, it needs to be softened to a warning.

Correct both of these issues.

Fixes rdar://129178360 and rdar://129247349.

beccadax added 2 commits June 4, 2024 17:47
objcImpl extensions with final public members need to be printed into module interfaces, but with the @implementation attribute suppressed. That worked fine…but when we switched to the new syntax, we should also have suppressed the @objc attribute, and we mistakenly did not. Correct this oversight.

Fixes rdar://129178360.
Before the change from @_objcImplementation to @objc @implementation, if a member was unrepresentable in ObjC, it would become implicitly `final`. After that change, this is now an error. We do want a diagnostic here, but we don’t want to break backwards compatibility for early adopters.

Soften the error to a warning when the old @objcImplementation syntax is used.

Fixes rdar://129247349.
@beccadax

This comment was marked as outdated.

1 similar comment
@beccadax
Copy link
Contributor Author

beccadax commented Jun 5, 2024

@swift-ci please test

@beccadax beccadax merged commit 91afad2 into swiftlang:main Jun 6, 2024
5 checks passed
beccadax added a commit to beccadax/swift that referenced this pull request Jul 8, 2024
beccadax added a commit to beccadax/swift that referenced this pull request Sep 6, 2024
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 added a commit to beccadax/swift that referenced this pull request Sep 6, 2024
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.
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.

1 participant