Skip to content

Conversation

@zixu-w
Copy link
Contributor

@zixu-w zixu-w commented Oct 21, 2025

  • Add SPI availability information to APIAvailability from attribute @_spi_available.
  • Correctly obtain effective availability for nested declarations without immediate availability attributes.

Resolves rdar://159702280

@zixu-w zixu-w requested a review from cyndyishida October 21, 2025 21:56
@zixu-w zixu-w requested a review from rjmccall as a code owner October 21, 2025 21:56
- Add SPI availability information to `APIAvailability` from attribute
  `@_spi_available`.
- Correctly obtain effective availability for nested declarations
  without immediate availability attributes.

Resolves rdar://159702280
@zixu-w zixu-w force-pushed the pr-159702280-apigen-availability branch from 887b239 to 278b4fb Compare October 21, 2025 23:13
@cyndyishida cyndyishida requested review from tshortli and xymus October 23, 2025 18:59
bool hasFallbackUnavailability = false, hasFallbackSPIAvailability = false;
auto platform = targetPlatform(module->getASTContext().LangOpts);
for (auto attr : decl->getSemanticAvailableAttrs()) {
const Decl *declForAvailability = decl->getInnermostDeclWithAvailability();
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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 { }

Copy link
Contributor

@cyndyishida cyndyishida left a 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.

@zixu-w
Copy link
Contributor Author

zixu-w commented Nov 3, 2025

@swift-ci please test

@zixu-w zixu-w merged commit 18a9d70 into swiftlang:main Nov 4, 2025
5 checks passed
elsakeirouz pushed a commit to elsakeirouz/swift that referenced this pull request Nov 6, 2025
- 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!
-->
elsakeirouz pushed a commit to elsakeirouz/swift that referenced this pull request Nov 6, 2025
- 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!
-->
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.

3 participants