AST: Refactor SemanticDeclAvailabilityRequest.

Generalize the implementation of `SemanticDeclAvailabilityRequest` in
preparation for adding a new case to `SemanticDeclAvailability`. Use the
centralized availability constraint query instead of implementing a bespoke
algorithm for gathering constraints. Simplify `SemanticDeclAvailability` by
removing a case that is no longer relevant.

Part of rdar://138441307.
This commit is contained in:
Allan Shortlidge
2025-03-15 11:31:26 -07:00
parent 398b0deaa5
commit 2309793b70
6 changed files with 152 additions and 89 deletions

View File

@@ -170,6 +170,10 @@ enum class AvailabilityConstraintFlag : uint8_t {
/// referencing the extension. When this flag is specified, though, only the
/// attributes directly attached to the declaration are considered.
SkipEnclosingExtension = 1 << 0,
/// Include constraints for all domains, regardless of whether they are active
/// or relevant to type checking.
IncludeAllDomains = 1 << 1,
};
using AvailabilityConstraintFlags = OptionSet<AvailabilityConstraintFlag>;

View File

@@ -4128,21 +4128,31 @@ public:
void cacheResult(ValueDecl *value) const;
};
/// Describes the runtime availability of a declaration, which is a
/// classification of whether a decl can be used at runtime (as opposed to
/// compile time).
///
/// The elements of this enumeration must be ordered from most available to
/// least available.
enum class SemanticDeclAvailability : uint8_t {
/// The decl is potentially available in some contexts and/or under certain
/// deployment conditions.
/// The decl is potentially available at runtime. If it is unavailable at
/// compile time in the current module, it may still be considered available
/// at compile time by other modules with different settings. For example, a
/// decl that is obsolete in Swift 5 is still available to other modules that
/// are compiled for an earlier language mode.
PotentiallyAvailable,
/// The decl is always unavailable in the current compilation context.
/// However, it may still be used at runtime by other modules with different
/// settings. For example a decl that is obsolete in Swift 5 is still
/// available to other modules compiled for an earlier language mode.
ConditionallyUnavailable,
/// The decl is universally unavailable. For example, when compiling for macOS
/// a decl with `@available(macOS, unavailable)` can never be used (except in
/// contexts that are also completely unavailable on macOS).
CompletelyUnavailable,
/// The decl is always unavailable at compile time in the current module and
/// all other modules, but it is still required to be present at load time to
/// maintain ABI compatibility. For example, when compiling for macOS a decl
/// with an `@available(macOS, unavailable)` attribute can never be invoked,
/// except in contexts that are also completely unavailable on macOS. This
/// means the declaration is unreachable by execution at runtime, but the
/// decl's symbols may still have been strongly linked by other binaries built
/// by older versions of the compiler which may have emitted unavailable code
/// with strong references. To preserve ABI stability, the decl must still be
/// emitted.
AlwaysUnavailableABICompatible,
};
class SemanticDeclAvailabilityRequest