Commit Graph

48 Commits

Author SHA1 Message Date
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
678b0934d6 AST: Request-ify getting the AvailabilityDomain from a ValueDecl.
Cache the result of turning a `ValueDecl` into an `AvailabilityDomain`. Use
split caching to make the common case of the decl not representing an
availability domain efficient.

NFC.
2025-08-15 16:15:36 -07:00
Allan Shortlidge
0bba9bbc26 AST: Make the decl associated with an AvailabilityDomain a ValueDecl.
A decl that represents an `AvailabilityDomain` should always be a `ValueDecl`.
2025-08-14 11:35:00 -07:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01: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
4a7e76775a AST: Add llvm::raw_ostream conveniences for availability constructs.
Make it easier to debug availability by printing to output streams like
`llvm::errs()`.

NFC.
2025-07-17 18:59:01 -07:00
Allan Shortlidge
3d722e1919 ClangImporter: Generate and call custom availability domain predicates.
When importing custom availability domains with dynamic predicates from Clang
modules, synthesize predicate functions for `if #available` queries and call
them when generating SIL.

Resolves rdar://138441312.
2025-07-10 08:15:01 -07:00
Anthony Latsis
dd78cd6dbe ASTBridging: Bridge swift::PlatformKind directly 2025-06-20 16:46:03 +01:00
Allan Shortlidge
e16c638fc3 AST: Warn for non-existent platform versions in @available attributes. 2025-06-10 22:11:05 -07:00
Allan Shortlidge
f4b4dc9889 AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS.
When compiling for visionOS, iOS availability attributes are remapped into the
visionOS availability domain automatically. While the version remapping was
being performed correctly, there was a regression that caused the platform name
to be printed incorrectly in many diagnostics. Whenever an iOS version is
remapped to a visionOS version, availability diagnostics will now present
those versions as visionOS versions instead of iOS versions.

Resolves rdar://146293165.
2025-06-02 17:55:38 -07:00
Allan Shortlidge
abac42b759 Serialization: Encode custom availability domains.
When serializing `@available` attributes, if the attribute applies to a custom
domain include enough information to deserialize the reference to that domain.

Resolves rdar://138441265.
2025-04-08 08:53:42 -07:00
Allan Shortlidge
56e5ca70ba AST: Introduce AvailabilityDomain::isActivePlatform(). 2025-04-01 07:46:46 -07:00
Allan Shortlidge
592b70f00f AST: Fix AvailabilityContext platform range for certain targets.
https://github.com/swiftlang/swift/pull/79807 caused a regression in which
`AvailabilityContext` stopped tracking the available version range for the
active platform domain for certain platforms. Fix this by reverting to checking
`AvailabilityDomain::isActive()` to determine when a given platform
`AvailabilityDomain` represents the target platform. The compiler's existing
mapping from target triple to platform domain is incomplete and it's not clear
to me whether fixing that could cause other regressions.

Resolves rdar://147413616.
2025-03-20 16:26:54 -07:00
Allan Shortlidge
5e0eb09fc0 AST: Skip codegen for decls that are unavailable in custom domains.
Regardless of the value specified for `-unavailable-decl-optimization`, decls
that are unavailable in custom availability domains should be treated as always
unreachable at runtime.

Part of rdar://138441307.
2025-03-17 22:46:07 -07:00
Allan Shortlidge
7ae3a86d9b AST: Introduce "root" availability domains.
A root availability domain is a direct descendant of the universal availability
domain.
2025-03-17 22:09:28 -07:00
Allan Shortlidge
542986032f AST: Unique CustomAvailabilityDomain instances.
Store `CustomAvailabilityDomain` instances in a folding set on `ASTContext`.
This instances of custom domains to be created without needing to cache them in
disparate locations.
2025-03-12 18:30:45 -07:00
Rintaro Ishizaki
d60f1986a8 [ASTGen] Adopt AvailabilityDomainOrIdentifier scheme
Aligning with libParse
2025-03-07 04:14:50 -08:00
Allan Shortlidge
0462cfda11 AST: Teach AvailabilityContext to represent version-less availability.
This enables potential unavailability diagnostics to be emitted for decls that
are only available in version-less domains.
2025-03-06 22:29:50 -08:00
Allan Shortlidge
3ea979f712 AST: Request-ify retrieval of SemanticAvailabilitySpec.
Introduced `SemanticAvailabilitySpecRequest` to retrieve the semantic spec for
an `AvailabilitySpec`. Add an `isInvalid` bit to `AvailabilitySpec` to track
whether the request failed. Unfortunately, there aren't any easily accessible
spare bits in the layout of `AvailabilitySpec` so it had to be a new field.
2025-03-04 17:46:18 -08:00
Allan Shortlidge
3b9ca2f397 AST: Consolidate availability version remapping.
Introduce `SemanticAvailableAttr` conveniences to compute the deprecated and
obsoleted ranges for an attribute and ensure they remap versions when needed.
2025-03-01 20:23:11 -08:00
Allan Shortlidge
b02d44352e AST: Introduce StableAvailabilityDomainComparator. 2025-02-28 19:09:33 -08:00
Allan Shortlidge
aaa0e0a7b3 AST/Parse: Parse custom availability domain specs in if #available(...).
Delay resolution of availability domain identifiers parsed in availability
specifications until type-checking. This allows custom domain specifications to
be written in `if #available` queries.
2025-02-27 23:07:55 -08:00
Allan Shortlidge
62c8e72f23 AST: Centralize AvailabilityDomain lookup.
Implement lookup of availability domains for identifiers on
`AvailabilityDomainOrIdentifier`. Add a bit to that type which represents
whether or not lookup has already been attempted. This allows both
`AvailableAttr` and `AvailabilitySpec` to share a common implementation of
domain lookup.
2025-02-25 22:00:31 -08:00
Allan Shortlidge
8ebf2aa7e6 AST: Add printing utilities for AvailabilityDomain and AvailabilitySpec. 2025-02-25 19:45:39 -08:00
Allan Shortlidge
c54825b4c3 AST: Use AvailabilityDomainOrIdentifier to store domains in AvailabilitySpec. 2025-02-25 09:02:47 -08:00
Allan Shortlidge
bd4b562a64 AST: Make AvailabilityDomainOrIdentifier pointer-like. 2025-02-23 10:53:06 -08:00
Allan Shortlidge
06030d66aa AST: Introduce AvailabilityDomainOrIdentifier.
It provides a common way to represent either a parsed domain identifier or the
resolved domain.

NFC.
2025-02-13 21:18:05 -08:00
Allan Shortlidge
16de339051 AST: Enable -unavailable-code-optimization for zippered libraries.
Correct the determination of whether a declaration is unreachable at runtime
when compiling a zippered library.

Resolves rdar://125930716.
2025-02-09 11:20:48 -08:00
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
fa44b9e0b4 AST: Introduce some AvailabilityDomain conveniences.
One to get the active domain for the compilation target and another to get the
ABI compatibility domain for a given domain. The ABI compatibility domain will
be needed for queries that compute whether an unavailable declaration is still
reachable at runtime.

NFC.
2025-02-09 09:39:33 -08:00
Rintaro Ishizaki
df2ada37df [ASTGen] Generate AvailableAttr
* Move `AvailabilitySpec` handling logic to AST, so they can be shared
  between libParse and ASTGen
* Requestify '-define-availability' arguments parsing and parse them
  with 'SwiftParser' according to the 'ParserASTGen' feature flag
* Implement 'AvailableAttr' generation in ASTGen
2025-02-04 23:40:01 -08:00
Allan Shortlidge
1e76f19be9 Sema: Reject version specs in @available attributes for custom domains. 2025-01-31 17:31:13 -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
36c6c7fc68 AST: Add a DeclContext to AvailabilityDomain::builtinDomainForString().
A context is needed to customize the behavior of lookup in downstream versions
of Swift.
2025-01-28 13:47:42 -08:00
Allan Shortlidge
a5d60ce35e AST/Sema: Resolve AvailabilityDomain in SemanticAvailableAttrRequest.
Look up the AvailabilityDomain given its name during type checking, instead of
parsing.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
fe138e014a AST: Track an unavailable domain instead of platform in AvailabilityContext.
Now that most of the compiler tracks availability in terms of
AvailabilityDomain, it's time to do so in AvailabilityContext as well. This
will ensure that the compiler accurately suppresses diagnostics about a decl
being unavailable in an arbitrary domain when the context of the use is already
unavailable in that domain.

With this change, most of the special-casing for the Embedded Swift availability
domain has been removed from the compiler, outside of parsing and interface
printing.
2025-01-22 06:40:11 -08:00
Allan Shortlidge
b8c4298a07 AST: Introduce AvailabilityDomain::contains().
This operation describes the partial ordering with which Availability domains
form a lattice.

As a temporary measure, a containment ordering needs to be specified for the
Swift language, Embedded, and Package Description domains. Without this
ordering, there won't be a way for AvailabilityContext to preserve the
invariant that the unavailable domain of a child context contains the
unavailable domain for the parent. However, once AvailabilityContext is
refactored to represent the status of multiple availability domains
simultaneously, the ordering of these domains relative to each other can be
relaxed.

NFC.
2025-01-22 06:40:10 -08:00
Allan Shortlidge
691f6fc646 AST: Model Embedded Swift availability with a domain.
Remove the bit on AvailableAttr that previously modeled this.

Resolves rdar://138802876.
2025-01-19 08:52:53 -08:00
Allan Shortlidge
a6c543ea79 AST: Implement DenseMapInfo for AvailabilityDomain.
Needed to use AvailabilityDomain as a key in an llvm::SmallDenseMap.

NFC.
2025-01-14 09:14:55 -08:00
Allan Shortlidge
06443b9669 AST: Refactor AvailabilityDomain to prepare for external definitions.
Represent an AvailabilityDomain as a pointer union where one member of the
union is inline storage for built-in domains with known requirements and the
other member of the union is a pointer to an externally allocated domain
definition.

NFC.
2025-01-13 22:11:22 -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
cfb4b8f99b Parse: Adopt new AvailableAttr constructor. 2025-01-10 18:43:12 -08:00
Allan Shortlidge
a882ac6e65 AST: Make some ASTContext parameters const-correct. 2025-01-08 08:17:27 -08:00
Allan Shortlidge
6ce7e3cc8a AST: Adopt SemanticAvailableAttr in attribute printing. 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
7cf5d4bca5 AST: Adopt AvailabilityDomain in unavailability diagnostics. 2024-12-08 17:29:04 -08:00
Allan Shortlidge
9b7764a298 AST: Introduce AvailabilityDomain. 2024-12-08 17:29:04 -08:00