Commit Graph

33 Commits

Author SHA1 Message Date
Allan Shortlidge
1a86cd9c26 AST: Introduce a Swift runtime availability domain.
Add support for the `Swift` availability domain, which represents availability
with respect to the Swift runtime. Use of this domain is restricted by the
experimental feature `SwiftRuntimeAvailability`.
2025-10-08 17:31:57 -07:00
Allan Shortlidge
2d8465b043 AST: Introduce the SwiftLanguageMode availability domain spelling.
Require `-enable-experimental-feature SwiftRuntimeAvailability` to use this new
spelling.
2025-10-08 15:46:34 -07:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Allan Shortlidge
ee988c0da8 Sema: Infer key path immutability during expression availability checking.
Accessor availability diagnostics for key path expressions were first
introduced by https://github.com/swiftlang/swift/pull/83931. Those changes were
insufficient because sometimes key path expressions are generated in the AST
with more mutability than is needed by the context and so setter availability
could be diagnosed inappropriately. Key path expression binding was refined in
https://github.com/swiftlang/swift/pull/84491 to make this less likely to
occur. However, there are still some circumstances in which a mutable key path
is generated in the AST and then immediately coerced into an immutable key path
to satisfy the contextual type. This change infers the immutability of these key
path expressions by looking through surrounding conversion expressions.
2025-09-25 07:13:18 -07:00
Allan Shortlidge
0647da5416 AST: Introduce an "always enabled" custom availability domain kind.
An always enabled availability domain is implicitly available in all contexts,
so uses of declarations that are marked as `@available` in the domain are never
rejected. This is useful for an availability domain representing a feature flag
that has become permanently enabled.

Partially resolves rdar://157593409.
2025-09-11 14:39:05 -07:00
Allan Shortlidge
2d5824ef1a Sema: Diagnose key path setter availability.
Diagnose the availability of the specific accessors that are referenced
implicitly via a key path reference. This causes setter availability to be
diagnosed when passing a key path to a function that takes a `WritableKeyPath`.

Resolves rdar://157232221.
2025-08-27 07:58:35 -07:00
Allan Shortlidge
5e2dfdf4e6 Merge pull request #83714 from tshortli/allow-obsolete-in-swift-overrides 2025-08-14 07:16:50 -07:00
Allan Shortlidge
550d7bb754 Sema: Allow overrides to be unavailable in the current Swift language mode.
Fixes a regression from https://github.com/swiftlang/swift/pull/83354.

Resolves rdar://158262522
2025-08-13 17:57:05 -07:00
Allan Shortlidge
93902835d0 AST: Allow overloads to be disambiguated by obsoletion version.
Previously, whether a declaration is unavailable because it is obsolete was
determined based solely on the deployment target and not based on contextual
availability. Taking contextual availability into account makes availability
checking more internally consistent and allows library authors to evolve APIs
by obsoleting the previous declaration while introducing a new declaration in the
same version:

```
@available(macOS, obsoleted: 15)
func foo(_ x: Int) { }

@available(macOS, introduced: 15)
func foo(_ x: Int, y: Int = 0) { }

foo(42) // unambiguous, regardless of contextual version of macOS
```

This change primarily accepts more code that wasn't accepted previously, but it
could also be source breaking for some code that was previously allowed to use
obsoleted declarations in contexts that will always run on OS versions where
the declaration is obsolete. That code was clearly taking advantage of an
availabilty loophole, though, and in practice I don't expect it to be common.

Resolves rdar://144647964.
2025-08-13 11:26:07 -07:00
Allan Shortlidge
6e3361eb53 Tests: Add more obsoletion tests. 2025-08-13 11:25:33 -07:00
Allan Shortlidge
600e971b40 AST: Revert disambiguation of overloads by obsoletion version.
It caused a regression when building the CloudKit module from its interface in
the Xcode 26 SDKs.

This effectively reverts https://github.com/swiftlang/swift/pull/83384 (though
a few parts of that PR that did not cause any regressions have been kept).

Resolves rdar://157342004.
2025-08-11 21:50:40 -07:00
Allan Shortlidge
4d41db3b5d Sema: Rationalize availability checking in unavailable contexts.
Correct several behaviors of availability checking in unavailable contexts that
were inconsistent with the checking model:

- Avoid diagnosing unintroduced and obsolted declarations in contexts that are
  unavailable in the same domain.
- Diagnose unavailability normally in type signature contexts.
2025-08-08 07:57:44 -07:00
Allan Shortlidge
01cfa338d8 Merge pull request #83548 from tshortli/value-generics-availability
AST: Update Swift 6.2 runtime OS versions
2025-08-05 21:22:24 -07:00
Allan Shortlidge
cdebf2bea8 AST: Update 6.2 runtime OS versions.
Swift 6.2 is aligned with the version 26 of each of Apple's operating systems
and the runtime availability metadata should reflect this.
2025-08-05 13:37:38 -07:00
Hamish Knight
396a6a8fe6 Enable InlineArray type sugar
Promote it from an experimental feature.

rdar://155607927
2025-08-04 15:16:30 +01:00
Allan Shortlidge
bb89d339f0 AST: Allow overloads to be disambiguated by obsoletion version.
Previously, whether a declaration is unavailable because it is obsolete was
determined based solely on the deployment target and not based on contextual
availability. Taking contextual availability into account makes availability
checking more internally consistent and allows library authors to evolve APIs
by obsoleting the previous declaration while introducing a new declaration in the
same version:

```
@available(macOS, obsoleted: 15)
func foo(_ x: Int) { }

@available(macOS, introduced: 15)
func foo(_ x: Int, y: Int = 0) { }

foo(42) // unambiguous, regardless of contextual version of macOS
```

This change primarily accepts more code that wasn't accepted previously, but it
could also be source breaking for some code that was previously allowed to use
obsoleted declarations in contexts that will always run on OS versions where
the declaration is obsolete. That code was clearly taking advantage of an
availabilty loophole, though, and in practice I don't expect it to be common.

Resolves rdar://144647964.
2025-07-29 08:18:35 -07:00
Allan Shortlidge
67cc4c6ec3 Sema: Diagnose override availability for custom domains.
Resolves rdar://156159486.
2025-07-26 18:46:05 -07:00
Allan Shortlidge
60554b3de1 Sema: Fix rendering of accessor names in an availability diagnostic. 2025-07-26 15:36:46 -07:00
Allan Shortlidge
0fabfa3f99 Sema: Check custom domain availability during conformance checking.
Protocol requirement witnesses cannot only be available in a custom
availability domain if the requirement does not have the same availability
constraint.

Resolves rdar://156462516.
2025-07-25 21:30:53 -07:00
Allan Shortlidge
8cb20c3f4e AST: Fix a crash when handling duplicate available attrs. 2025-07-25 15:14:53 -07:00
Allan Shortlidge
5601e66a69 Sema: Generalize more-available-than-enclosing-decl diagnostics.
NFC.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
034c62cf01 AST: Generalize availability fix-its to support custom availability domains.
Resolves rdar://156118254.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
aeb5a46d9e AST: Emit warnings for redundant availability checks in custom domains. 2025-07-18 13:27:08 -07:00
Allan Shortlidge
a3fbe3d530 AST: Introduce queries on Decl for active @available attrs.
Use these queries to replace some duplicated code. Also, move the
`attr_inlinable_available.swift` test to the `Availability` sub-directory since
the test has more to do with availability checking than it has to do
specifically with the `@inlinable` attr.
2025-07-18 13:27:08 -07:00
Allan Shortlidge
59b136ccc4 Merge pull request #83054 from tshortli/unavailable-setters-require-read-only-key-paths
ConstraintSystem: Make key paths for properties with unavailable setters read-only
2025-07-16 21:31:41 -07:00
Allan Shortlidge
99380bf00f Sema: Sometimes allow universally unavailable declarations to be referenced.
In implicit contexts that are universally unavailable, allow writable key paths
to be formed to properties with setters that are also marked as universally
unavailable. This fixes a regression from the previous commit where the code
synthesized for `@Observable` properties in universally unavailable classes was
rejected by the availability checker.
2025-07-15 14:08:57 -07:00
Allan Shortlidge
4076fa6b2e ConstraintSystem: Make key paths for properties with unavailable setters read-only.
Previously, only conditional unavailability was considered, but setters that
are always unavailable must also make a keypath read-only.

Resolves rdar://155832511.
2025-07-15 10:33:44 -07:00
Allan Shortlidge
e03cf967c3 Sema: Diagnose invalid OS versions in if #available queries.
Part of rdar://155558161.
2025-07-14 16:03:52 -07:00
Allan Shortlidge
59d74fa1c7 Sema: Diagnose opaque types that depend on availability of a custom domain.
Serialization and IRGen don't yet support opaque return types that would depend
on querying availability of a custom domain so we need to reject this code to
avoid mis-compiling it.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
897a74f495 Tests: Move some availability tests into a new test/Availability directory.
Un-reverts 9c01ee2c1b.

Also, add myself as a reviewer for more availability related files.

NFC.
2025-06-23 15:57:34 -07:00
Allan Shortlidge
de1017fef4 Revert "Move some availability tests into a new test/Availability directory"
This reverts commit 9c01ee2c1b.
2025-06-08 22:22:41 -07:00
Slava Pestov
7c78224877 Add regression test for rdar://152700122 2025-06-06 17:10:42 -04:00
Slava Pestov
9c01ee2c1b Move some availability tests into a new test/Availability directory 2025-06-06 17:10:42 -04:00