Skip to content

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Sep 11, 2025

Allow referencing an @_spi_available decl in extensions to @_spi_available types. This is a narrow fix as it should really be handled as part of the context check but that check is currently too permissive.

Fow now let's narrowly allow legal code. And then we should look at revisiting the SPI availability logic, separate it from normal SPI and treat more like availability.

Adding a test comparing the behavior of @_spi with @_spi_available to document the current implementation.

rdar://159292698

@xymus
Copy link
Contributor Author

xymus commented Sep 11, 2025

@swift-ci Please smoke test

// is currently too permissive. It allows SPI use in SPI available which
// can break swiftinterfaces. The SPI availability logic likely need to be
// separated from normal SPI and treated more like availability.
auto ext = dyn_cast_or_null<ExtensionDecl>(where.getDeclContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't handle a case like this:

@_spi_available(...)
public struct Outer {
  public struct Inner {
  
  }
}

extension Outer.Inner {
  // ...
}

It's probably not worth addressing now, though. We should aim to support that with a more holistic fix though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, we'd need to properly propagate the @_spi_available-ness across contexts. That will need a wider fix as the current mechanism for it is mixed in with the normal SPI and probably shouldn't be.

@xymus
Copy link
Contributor Author

xymus commented Sep 11, 2025

@swift-ci Please smoke test Windows

Allow referencing an `@_spi_available` decl in extensions to
`@_spi_available` types. This is a narrow fix as it should really be
handled as part of the context check but that check is currently too
permissive.

Fow now let's narrowly allow legal code. And then we should look at
revisiting the SPI availability logic, separate it from normal SPI and
treat more like availability.

Adding a test comparing the behavior of `@_spi` with `@_spi_available`
to document the current implementation.

rdar://159292698
@xymus
Copy link
Contributor Author

xymus commented Sep 11, 2025

@swift-ci Please smoke test

@xymus xymus merged commit b00a561 into swiftlang:main Sep 12, 2025
3 checks passed
@xymus xymus deleted the spi-avail-in-ext branch September 12, 2025 16:09
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