-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[APIGen] Handle SPI availability for nested decls #85048
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
Conversation
- Add SPI availability information to `APIAvailability` from attribute `@_spi_available`. - Correctly obtain effective availability for nested declarations without immediate availability attributes. Resolves rdar://159702280
887b239 to
278b4fb
Compare
| bool hasFallbackUnavailability = false, hasFallbackSPIAvailability = false; | ||
| auto platform = targetPlatform(module->getASTContext().LangOpts); | ||
| for (auto attr : decl->getSemanticAvailableAttrs()) { | ||
| const Decl *declForAvailability = decl->getInnermostDeclWithAvailability(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be fine for now, but FWIW getInnermostDeclWithAvailability() is probably not going to give you correct information for 100% of cases. For example:
@available(macOS 26, *)
public struct Outer {
@available(iOS 26, *)
public struct Inner {
public func f()
}
}
f() is implicitly introduced in macOS 26 but getInnermostDeclWithAvailability() is going to find Inner which only has an attribute for iOS. Correctly finding the attribute that is responsible for the platform availability of a decl on the current platform is a pretty tricky task to get right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a really good point. Forgot that we are also matching platforms here. But the current code doesn't correctly handle this case as well.
I think we'll have to traverse up until we hit an availability attribute with the matching platform, or the top level context right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, to be clear this seems like an improvement over the existing approach and would be fine to land as-is if you want to make incremental progress. To really make it as accurate as possible, you'll probably need to re-implement something like getSemanticAvailableRangeDeclAndAttr() here. The other (existing) problem with this code is that it doesn't handle the case where availability is inherited from an attribute for a different platform:
// Implicitly @available(visionOS 26, *) too
@available(iOS 26, *)
public struct Outer { }
cyndyishida
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also fine with this as is.
but please file a bug report so we don't forget about known bugs mentioned in
problem with this code is that it doesn't handle the case where availability is inherited from an attribute for a different platform:
// Implicitly @available(visionOS 26, *) too
@available(iOS 26, *)
public struct Outer { }
and
probably not going to give you correct information for 100% of cases. For example:
@available(macOS 26, *)
public struct Outer {
@available(iOS 26, *)
public struct Inner {
public func f()
}
}
f() is implicitly introduced in macOS 26 but getInnermostDeclWithAvailability() is going to find Inner which only has an attribute for iOS.
|
@swift-ci please test |
- Add SPI availability information to `APIAvailability` from attribute `@_spi_available`. - Correctly obtain effective availability for nested declarations without immediate availability attributes. Resolves rdar://159702280 <!-- If this pull request is targeting a release branch, please fill out the following form: https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1 Otherwise, replace this comment with a description of your changes and rationale. Provide links to external references/discussions if appropriate. If this pull request resolves any GitHub issues, link them like so: Resolves <link to issue>, resolves <link to another issue>. For more information about linking a pull request to an issue, see: https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue --> <!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci Thank you for your contribution to Swift! -->
- Add SPI availability information to `APIAvailability` from attribute `@_spi_available`. - Correctly obtain effective availability for nested declarations without immediate availability attributes. Resolves rdar://159702280 <!-- If this pull request is targeting a release branch, please fill out the following form: https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1 Otherwise, replace this comment with a description of your changes and rationale. Provide links to external references/discussions if appropriate. If this pull request resolves any GitHub issues, link them like so: Resolves <link to issue>, resolves <link to another issue>. For more information about linking a pull request to an issue, see: https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue --> <!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci Thank you for your contribution to Swift! -->
APIAvailabilityfrom attribute@_spi_available.Resolves rdar://159702280