Skip to content

Fix objcImpl bug causing invalid @_hasStorage attributes in module interfaces #80360

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 3 commits into from
Mar 29, 2025

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Mar 28, 2025

Consider this code:

@objc @implementation extension MyObjCClass {
    public final var myProperty: Int {
        didSet { print("myProperty changed") }
    }
}

Because the var is public final, it needs to be printed into the module interface as part of an ordinary (non-objcImpl) extension. However, because the didSet observer is present, Swift would print a @_hasStorage attribute:

extension MyObjCClass {
    @_hasStorage public final var myProperty: Int {
        get
        set
    }
}

This is bad, of course, because stored properties are not allowed in ordinary extensions. But it's worse than that: because @_hasStorage is not particularly well validated, the compiler would not emit a diagnostic about this problem—it would simply crash. Often at a fairly arbitrary point if asserts were disabled.

This PR fixes this bug from basically all possible angles:

  • Diagnoses uses of @_hasStorage in invalid contexts.
  • Prevents emission of @_hasStorage for vars in module interfaces.
  • Ignores invalid @_hasStorage attributes in existing module interfaces.

Fixes rdar://144811653.

A bug in `@objc @implementation` is causing incorrect `@_hasStorage` attributes to be printed into module interfaces. As an initial step towards fixing this, diagnose bad `@_hasStorage` attributes and treat them as computed properties so that these malformed interfaces don’t cause compiler crashes.

Partially fixes rdar://144811653.
If an `@objc implementation extension` had a public stored property with an observer, Swift would print `@_hasStorage` on the extension. This is Not Good because in a module interface, an objcImpl extension appears to be an ordinary extension, and properties in ordinary extensions are not supposed to have storage.

Suppress printing this attribute in objcImpl extensions to avoid this problem.

Partially fixes rdar://144811653 by suppressing emission of bad attributes.
An objcImpl bug previously caused `@_hasStorage` to be emitted inside some extensions in module interfaces. An earlier commit in this PR created an error for this, but for backwards compatibility, it would actually be better to simply ignore the attribute in module interfaces. Modify TypeCheckStorage to emit a warning, not an error, in this situation.

Additionally, modify the module interface loader to show warnings when you verify a module interface, but not for other module interface uses (like compiling or importing one). The assumption here is that if you’re verifying a module interface, you’re either the author of the module that created it or you’re investigating a problem with it, and in either case you’d like to be told about minor defects in case they’re related.

Fixes rdar://144811653 thoroughly.
@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test Windows platform

@beccadax beccadax enabled auto-merge March 28, 2025 22:14
@beccadax beccadax merged commit 65dc578 into swiftlang:main Mar 29, 2025
5 checks passed
tshortli added a commit to tshortli/swift that referenced this pull request Mar 31, 2025
…king.

We're not ready to start emitting warnings when typechecking modules from
interface. It is causing performance regressions and spurious diagnostics to be
emitted.

Reverts a small part of swiftlang#80360.

Resolves rdar://148257136.
tshortli added a commit to tshortli/swift that referenced this pull request Mar 31, 2025
…cking.

We're not ready to start emitting warnings when typechecking modules from
interface. It is causing performance regressions and spurious diagnostics to be
emitted.

Reverts a small part of swiftlang#80360.

Resolves rdar://148257136.
tshortli added a commit to tshortli/swift that referenced this pull request Mar 31, 2025
…cking.

We're not ready to start emitting warnings when type-checking modules from
interface. It is causing performance regressions and spurious diagnostics to be
emitted.

Reverts a small part of swiftlang#80360.

Resolves rdar://148257136.
tshortli added a commit to tshortli/swift that referenced this pull request Mar 31, 2025
…cking.

We're not ready to start emitting warnings when type-checking modules from
interface. It is causing performance regressions and spurious diagnostics to be
emitted.

Reverts a small part of swiftlang#80360.

Resolves rdar://148257136.
tshortli added a commit to tshortli/swift that referenced this pull request Apr 1, 2025
…cking.

We're not ready to start emitting warnings when type-checking modules from
interface. It is causing performance regressions and spurious diagnostics to be
emitted.

Reverts a small part of swiftlang#80360.

Resolves rdar://148257136.
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