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

Fix availability checking for stored properties and enum cases with associated values #36327

Merged
merged 3 commits into from
Mar 6, 2021

Conversation

slavapestov
Copy link
Contributor

The old behavior:

  • Stored properties could not have @available at all.
  • Enum elements with associated values could be @available without restriction.

When computing the in-memory layout of a type we require that all stored types are available at runtime, that is, not any newer than the intersection of the current deployment target and the availability context of their type.

This means that stored properties and enum elements with associated values must have the same availability checking behavior as each other, and also that both existing behaviors were wrong.

The new rule is that @available is only allowed on either kind of declaration if the OS version is not any newer than the enclosing availability context.

@slavapestov slavapestov requested a review from xymus March 5, 2021 22:39
@slavapestov
Copy link
Contributor Author

@xymus I suspect there are some similar edge cases with SPI that need to be straightened out.

This cannot be supported for the same reasons struct and class stored
properties with potential unavailability cannot be supported.

It is possible that some users relied on this, because it worked in
some cases where the type metadata for the potentially unavailable
type was not actually needed for anything (eg, if the type was @Frozen
and trivial, or a simple class reference). If this becomes an issue
we can downgrade this to a warning.

Note that just like the previous fix for stored properties, we do
still allow writing an '@available' attribute on the enum element if
the OS version is not any newer than the deployment target. This allows
annotating APIs with the OS version where they were introduced.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

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

This looks good!

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2021

Build failed
Swift Test Linux Platform
Git Sha - 511ada4

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

@AnthonyLatsis
Copy link
Collaborator

I believe the second commit message should say "as new as the enclosing availability context"?

@slavapestov slavapestov merged commit 9d5baaa into swiftlang:main Mar 6, 2021
varungandhi-apple added a commit to varungandhi-apple/swift that referenced this pull request Jul 7, 2021
In swiftlang#36327, trying to compile
library code where a struct has an unavailable stored property
or an enum with an unavailable case with associated values was made
into a hard error. Update the docs to reflect this limitation
for library authors shipping new versions of dylibs to older OSes.
@jerrydudu
Copy link

jerrydudu commented Jun 8, 2022

@slavapestov Why It Not work in Xcode14-beta now?

image

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.

5 participants