Commit Graph

16 Commits

Author SHA1 Message Date
Allan Shortlidge
463bf91f68 AST: Rename Swift runtime availability domain to StandaloneSwiftRuntime.
This name will distinguish the standalone Swift runtime availability domain
from the domain for the built-in Swift runtime on supported targets.
2025-10-21 21:55:25 -07:00
Allan Shortlidge
085f8ecca9 stdlib/SILGen: Emit SIL for Swift runtime availability queries.
When emitting SIL for `if #available(Swift ..., *)` queries, call the new
`_isSwiftRuntimeVersionAtLeast()` function in the stdlib to check the
condition. To support back deployment, the implementation of
`_isSwiftRuntimeVersionAtLeast()` is `@_alwaysEmitIntoClient` and performs its
comparison against the result of `_SwiftStdlibVersion.current`, which is
pre-existing ABI that the stdlib exposes for querying the Swift runtime
version.

Resolves rdar://162726037.
2025-10-15 22:42:53 -07:00
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
4e9a883824 AST: Rename SwiftLanguage availability domain kind to SwiftLanguageMode. 2025-10-08 15:46:34 -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
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
b4fb7c81c0 AST: Refactor AvailabilityQuery constructors.
Get rid of the boolean arguments for unavailability in AvailabilityQuery's
constructors and introduce a `asUnavailable()` modifier that can be used
instead in the contexts where unavailability is relevant.
2025-08-06 18:01:44 -07:00
Allan Shortlidge
aa199aaf81 Correct misspelling of "availability" in a few places. 2025-07-25 21:30:53 -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
4a76c04cf5 SILGen: Fix if #unavailable mis-compile for zippered libraries.
Inverted availability queries were mis-compiled for zippered libraries because
the code that emits calls to `isOSVersionAtLeastOrVariantVersionAtLeast()` was
not updated when the `if #unavailable` syntax was introduced (at that time
support for zippered libraries had not yet been upstreamed). The result of
these calls is now inverted when appropriate.

To make it easier to manage the growing complexity of supporting availability
queries, Sema now models the relevant information about an availability query
with the new `AvailabilityQuery` type. It encapsulates the domain for the
query, the result if it is known at compile time, and the version tuple
arguments to pass to a runtime invocation if applicable.

Resolves rdar://147929876.
2025-07-02 11:23:42 -07:00
Allan Shortlidge
303f7d8452 AST: Build scopes for if #available queries on custom availability domains.
Resolves rdar://138441298 and rdar://138441307.
2025-04-01 09:03:41 -07:00
Allan Shortlidge
e943c4bffd AST: Build statement condition availability scopes using AvailabilityContext.
Preparation for building availability scopes for `if #available` statements
that query non-platform availability domains.
2025-04-01 07:46:46 -07:00
Hamish Knight
738c70e8c8 [AST] Always walk folded SequenceExpr if available
Expand the special-cased ASTWalker behavior for folded SequenceExprs
such that we always walk the folded expression when available. This
ensures that we don't attempt to add the same node multiple times
when expanding ASTScopes during pre-checking.

rdar://147751795
2025-03-24 20:18:34 +00:00
Allan Shortlidge
151c9dee39 AST: Consolidate abstract/contrete syntax decl lookup functions. 2025-03-15 23:47:29 -07:00
Allan Shortlidge
02dcd5d8cf AST/Sema: Sink AvailabilityScopeBuilder from Sema to AST. 2025-03-15 23:47:29 -07:00