Commit Graph

252 Commits

Author SHA1 Message Date
Allan Shortlidge
b9e1cbd3ac AST: Enable -unavailable-decl-optimization on visionOS.
Using availability domains, reimplement the algorithm that determines whether a
declaration is unavailable at runtime. The new algorithm takes ABI compatible
platforms into account, ensuring that declarations that are available on iOS do
not get treated as unreachable at runtime when compiling for visionOS.

Resolves rdar://116742214.
2025-02-09 11:19:08 -08:00
Allan Shortlidge
cedb4d98de AST: Move AvailabilityConstraint implementation to a separate file. 2025-02-08 22:47:01 -08:00
Allan Shortlidge
aed1a013e4 Sema: Loosen more available than enclosing extension diagnostic.
When diagnosing a declaration that is more available than its context, to
preserve source compatibility we need to downgrade the diagnostic to a warning
when the outermost declaration is an extension. This logic regressed with
https://github.com/swiftlang/swift/pull/77950 and my earlier attempt to fix
this (https://github.com/swiftlang/swift/pull/78832) misidentified what had
regressed.

Really resolves rdar://143423070.
2025-02-03 14:07:27 -08:00
Allan Shortlidge
f9799aeba9 AST: Introduce a Custom availability domain kind. 2025-01-31 17:31:07 -08:00
Allan Shortlidge
4b773a45ca AST: Move AvailabilityDomain ordering to Availabilty.cpp.
Availability attribute inferrence is currently the only thing that depends on
having a total ordering on AvailabilityDomains.
2025-01-31 17:31:07 -08:00
Allan Shortlidge
7b8cbd7109 AST: Store unresolved domain strings in AvailableAttr.
This is the first step towards resolving the AvailabilityDomain associated with
an AvailableAttr during type checking instead of parsing.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
a6eb7e494b AST: Fix weak linking for potentially unavailable accessors in extensions.
In https://github.com/swiftlang/swift/pull/78454 queries for the platform
availability of decl were consolidated into
`Decl::getAvailableAttrForPlatformIntroduction()`. In addition to checking the
attributes directly attached to the decl, this method also checks whether the
decl is a member directly contained inside of an extension and checks for
attributes attached to the extension as well. Previously, this logic was only
used for availability checking diagnostics, where special casing extension
members was a requirement. As a result of the consolidation, though, the logic
is now also shared by the query that determines whether to weakly link symbols
associated with a decl. That determination already had its own way of handling
members of extensions but it seemed like consolidating the logic would stil be
a net improvement that would reduce overall complexity.

Unfortunately, the existing approach to getting the availability of the
enclosing extension had a subtle bug for both AccessorDecl and OpaqueTypeDecl.
If an AvailableAttr was not directly attached to the immediate decl, then
`Decl::getAvailableAttrForPlatformIntroduction()` would check if the enclosing
decl context was an extension and look at its attributes as well. For
AccessorDecl and OpaqueTypeDecl, checking the enclosing decl context would
accidentally skip over the VarDecl and AbstractFunctionDecl that are formally
the parents of those decls for the purposes of attribute inheritance. As a
result, the availability of the enclosing property or function could be ignored
if the enclosing extension had explicit availability attributes.

The fix is to use `AvailabilityInference::parentDeclForInferredAvailability()`
instead of `getDeclContext()` when looking for the immediately enclosing
extension.

Resolves rdar://143139472.
2025-01-24 17:43:42 -08:00
John McCall
95dca81d24 Merge pull request #78729 from rjmccall/isolated-sending-results-compiler-fix
Assorted fixes for runtime metadata mangling and demangling
2025-01-23 21:33:50 -05:00
John McCall
5a72b785f2 NFC: use visionOS instead of xrOS in the Swift codebase. We can't do
much about the LLVM triple, but we can do our best on the Swift side.
2025-01-22 21:41:14 -05:00
Allan Shortlidge
dfc741e30a AST: Optimize storage of VersionTuples in AvailableAttr.
Representing introduced, deprecated, and obsoleted versions at rest as optional
version tuples is redundant, since the empty version tuple already represents
"version not present".

NFC.
2025-01-22 16:01:19 -08:00
Allan Shortlidge
2908520841 AST: Introduce SemanticAvailableAttrRequest.
This request will finish type checking an AvailableAttr by resolving its domain
and then enforcing any restrictions that the domain has on the attribute, like
disallowing version specifications.

This change just introduces the request and plumbs it through. NFC.
2025-01-22 16:01:19 -08:00
Allan Shortlidge
ba822d1e23 AST: Eliminate remaining direct access to AvailableAttr's fields.
Most of the compiler should use SemanticAvailableAttr instead. In contexts like
ASTDumper where a semantic attribute is unavailable use accessors on
AvailableAttr.

NFC.
2025-01-21 22:56:07 -08:00
Allan Shortlidge
6e1f0ae1c8 AST: Use PointerIntPair in AvailabilityConstraint.
Now that SemanticAvailableAttr is pointer-like, AvailabilityConstraint can be
pointer sized too.

NFC.
2025-01-20 18:24:04 -08:00
Allan Shortlidge
afc5dc98dd AST: Remove inline AvailabilityDomain from SemanticAvailableAttr.
Now that AvailableAttr has storage for its cached AvailabilityDomain, it's no
longer necessary to store an AvailabilityDomain inline in
SemanticAvailableAttr.

NFC.
2025-01-14 11:18:39 -08:00
Allan Shortlidge
51aaacceb7 AST: Remove AvailableAttr::getPlatformAgnosticAvailability(). 2025-01-10 19:18:42 -08:00
Allan Shortlidge
11abffb2f4 AST: Adopt new AvailableAttr constructor in attribute inference.
It was difficult to preserve the existing, buggy behavior of availability
attribute inference with respect to attributes specifying availability for
non-platform-specific domains. Instead, this change improves attribute merging
by tracking every domain independently, and only merging attributes from the
same domain.
2025-01-10 18:43:12 -08:00
Allan Shortlidge
9edd9eed9e AST: Finish adopting SemanticAvailableAttr in AvailabilityInference utilities. 2025-01-08 08:17:27 -08:00
Allan Shortlidge
a882ac6e65 AST: Make some ASTContext parameters const-correct. 2025-01-08 08:17:27 -08:00
Allan Shortlidge
05d342eb98 AST: Remove AvailableAttr::hasPlatform().
Use SemanticAvailableAttr::isPlatformSpecific() instead.
2025-01-08 08:17:27 -08:00
Allan Shortlidge
5058534805 AST: Remove AvailableAttr::prettyPlatformString(). 2025-01-08 08:17:27 -08:00
Allan Shortlidge
c2e8e3060e AST: Remove AvailableAttr::isActivePlatform(). 2025-01-08 08:17:26 -08:00
Allan Shortlidge
b4e2cff9f9 AST: Introduce SemanticAvailableAttr::isSPI(). 2025-01-08 08:17:26 -08:00
Allan Shortlidge
0421835b12 AST: Adopt SemanticAvailableAttr in availability attribute inference. 2025-01-07 07:31:13 -08:00
Allan Shortlidge
dcfe563294 AST: Remove AvailabilityInference::availableRangeAndAttr() 2025-01-07 07:31:13 -08:00
Allan Shortlidge
efa1afff11 AST: Introduce SemanticAvailableAttr::getIntroducedRange().
It replaces the overload of AvailabilityInference::availableRange() that takes
an AvailableAttr.
2025-01-07 07:31:12 -08:00
Allan Shortlidge
f1d0885458 AST: Adopt SemanticAvailableAttr in AvailabilityConstraint. 2025-01-07 07:31:12 -08:00
Allan Shortlidge
4ed62e3154 AST: Introduce Decl::getAvailableAttrForPlatformIntroduction().
It replaces `AvailabilityInference::attrForAnnotatedAvailableRange()`.
2025-01-07 07:31:12 -08:00
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Allan Shortlidge
00aae6ead5 AST: Return SemanticAvailableAttr from Decl::getUnavailableAttr(). 2024-12-19 17:22:51 -08:00
Allan Shortlidge
055a9ecd07 AST: Return a SemanticAvailableAttr from Decl::getDeprecatedAttr(). 2024-12-19 17:22:51 -08:00
Allan Shortlidge
2bc0427279 AST: Update isBetterThan() to take SemanticAvailableAttrs. 2024-12-19 17:22:51 -08:00
Allan Shortlidge
000c9da3ed AST: Return SemanticAvailableAttr from Decl::getActiveAvailableAttrForCurrentPlatform(). 2024-12-19 17:22:51 -08:00
Allan Shortlidge
2ca2237767 AST: Return a SemanticAvailableAttr from Decl::getNoAsyncAttr(). 2024-12-19 17:22:51 -08:00
Allan Shortlidge
0de339db1c AST: Introduce a SemanticAvailableAttr::isNoAsync() convenience. 2024-12-19 17:22:04 -08:00
Allan Shortlidge
111661e1d2 AST: Move several queries to SemanticAvailableAttr. 2024-12-19 08:40:01 -08:00
Allan Shortlidge
17dfbf5053 AST: Adopt SemanticAvailableAttr for SpecializeAttr. 2024-12-19 08:40:00 -08:00
Allan Shortlidge
f42ca1e758 AST: Introduce Decl::getSemanticAvailableAttr().
This convenience returns an optional `SemanticAvailableAttr` (since in the
future, lookup of the `AvailabilityDomain` can fail). It replaces
`Decl::getDomainForAvailableAttr()`, since most callers will need to form a
`SemanticAvailableAttr` with the resulting domain anyways.
2024-12-19 08:40:00 -08:00
Allan Shortlidge
0288eaa3b7 AST: Introduce Decl::getSemanticAvailableAttrs().
This new attribute iterator returned from the query makes it simpler to
implement algorithms that need access to both the `AvailableAttr *` and its
corresponding `AvailabilityDomain`. This is also work towards making it
possible to return an optional `AvailabilityDomain` from
`Decl::getDomainForAvailableAttr()`.
2024-12-19 08:40:00 -08:00
Allan Shortlidge
4da7f83f84 AST: Remove Decl::getSemanticAvailableRangeAttr().
This query's functionality was not useful enough to be exposed on `Decl` and
cached in the request evaluator. Instead, just share a local implementation of
it in `TypeCheckAttr.cpp`.
2024-12-05 15:47:24 -08:00
Allan Shortlidge
64f9d5b945 AST: Remove Decl::getSemanticUnavailableAttr().
Also remove the underlying `SemanticUnavailableAttrRequest`, which used memory
very inefficiently in order to cache a detailed answer to what was usually a
much simpler question.

The only remaining use of `Decl::getSemanticUnavailableAttr()` that actually
needed to locate the semantic attribute making a declaration unavailable was in
`TypeCheckAttr.cpp`. The implementation of the request could just be used
directly in that one location. The other remaining callers only needed to know
if the decl was unavailable or not, which there are simpler queries for.

 # Please enter the commit message for your changes. Lines starting
2024-12-02 23:00:43 -08:00
Allan Shortlidge
b2cc10cd94 AST: Introduce Decl::isSemanticallyUnavailable().
Adopt it in a few places as a replacement for `Decl::getSemanticUnavailableAttr()`.
2024-12-02 23:00:43 -08:00
Allan Shortlidge
0ff25ca7b0 AST: Implement Decl::isUnreachableAtRuntime() using a request. 2024-12-02 23:00:43 -08:00
Allan Shortlidge
71afa86b6c AST: Fix Decl::isUnreachableAtRuntime() for obsolete decls in unavailable decls. 2024-12-02 23:00:43 -08:00
Allan Shortlidge
d8c946d186 AST: Introduce Decl::getActiveAvailableAttrForCurrentPlatform(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
5cdcb5d116 AST: Introduce Decl::getNoAsyncAttr(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
5143382265 AST: Introduce Decl::isUnavailableInCurrentSwiftVersion(). 2024-12-02 07:35:58 -08:00
Allan Shortlidge
c5398e17d3 AST: Introduce Decl::getDeprecatedAttr().
It replaces `DeclAttr::getDeprecated()` as the designated way to query for the
attribute that makes a decl deprecated.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
3e50a90c45 AST: Introduce Decl::getUnavailableAttr().
It replaces `DeclAttr::getUnavailable()` and `AvailableAttr::isUnavailable()`
as the designated way to query for the attribute that makes a decl unavailable.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
1dc7aa5b7b AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
cd13d7d777 AST: Remove AvailableAttr::RenameDecl.
The renamed decl is now stored exclusively in the split request evaluator
storage, which is more efficient since most availability attributes do not
specify a renamed decl.
2024-11-29 10:35:02 -05:00