Skip to content

Continue adoption of SemanticAvailableAttr #78308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3189,13 +3189,44 @@ class SemanticAvailableAttr final {
const AvailableAttr *getParsedAttr() const { return attr; }
const AvailabilityDomain getDomain() const { return domain; }

std::optional<llvm::VersionTuple> getIntroduced() const {
return attr->Introduced;
}

std::optional<llvm::VersionTuple> getDeprecated() const {
return attr->Deprecated;
}

std::optional<llvm::VersionTuple> getObsoleted() const {
return attr->Obsoleted;
}

/// Returns the `message:` field of the attribute, or an empty string.
StringRef getMessage() const { return attr->Message; }

/// Returns the `rename:` field of the attribute, or an empty string.
StringRef getRename() const { return attr->Rename; }

/// Returns the platform kind that the attribute applies to, or
/// `PlatformKind::none` if the attribute is not platform specific.
bool isPlatformSpecific() const { return domain.isPlatform(); }
bool isPlatformSpecific() const { return getDomain().isPlatform(); }

/// Returns the platform kind that the attribute applies to, or
/// `PlatformKind::none` if the attribute is not platform specific.
PlatformKind getPlatformKind() const { return domain.getPlatformKind(); }
PlatformKind getPlatform() const { return getDomain().getPlatformKind(); }

/// Whether this is attribute indicates unavailability in all versions.
bool isUnconditionallyUnavailable() const {
return attr->isUnconditionallyUnavailable();
}

/// Whether this is attribute indicates deprecation in all versions.
bool isUnconditionallyDeprecated() const {
return attr->isUnconditionallyDeprecated();
}

/// Whether this is a `noasync` attribute.
bool isNoAsync() const { return attr->isNoAsync(); }

/// Whether this attribute has an introduced, deprecated, or obsoleted
/// version.
Expand All @@ -3205,14 +3236,17 @@ class SemanticAvailableAttr final {

/// Whether this is a language mode specific attribute.
bool isSwiftLanguageModeSpecific() const {
return domain.isSwiftLanguage() && isVersionSpecific();
return getDomain().isSwiftLanguage() && isVersionSpecific();
}

/// Whether this is a PackageDescription version specific attribute.
bool isPackageDescriptionVersionSpecific() const {
return domain.isPackageDescription() && isVersionSpecific();
return getDomain().isPackageDescription() && isVersionSpecific();
}

/// Whether this attribute was spelled `@_unavailableInEmbedded`.
bool isEmbeddedSpecific() const { return attr->isForEmbedded(); }

/// Returns the active version from the AST context corresponding to
/// the available kind. For example, this will return the effective language
/// version for swift version-specific availability kind, PackageDescription
Expand All @@ -3228,6 +3262,14 @@ class SemanticAvailableAttr final {
/// Returns true if this attribute is considered active in the current
/// compilation context.
bool isActive(ASTContext &ctx) const;

bool operator==(const SemanticAvailableAttr &other) const {
return other.attr == attr;
}

bool operator!=(const SemanticAvailableAttr &other) const {
return other.attr != attr;
}
};

/// An iterable range of `SemanticAvailableAttr`s.
Expand Down
14 changes: 7 additions & 7 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1411,24 +1411,24 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
/// Returns the active platform-specific `@available` attribute for this decl.
/// There may be multiple `@available` attributes that are relevant to the
/// current platform, but the returned one has the highest priority.
const AvailableAttr *getActiveAvailableAttrForCurrentPlatform(
std::optional<SemanticAvailableAttr> getActiveAvailableAttrForCurrentPlatform(
bool ignoreAppExtensions = false) const;

/// Returns true if the declaration is deprecated at the current deployment
/// target.
bool isDeprecated() const { return getDeprecatedAttr() != nullptr; }
bool isDeprecated() const { return getDeprecatedAttr().has_value(); }

/// Returns the first `@available` attribute that indicates that this decl
/// is deprecated on current deployment target, or `nullptr` otherwise.
const AvailableAttr *getDeprecatedAttr() const;
std::optional<SemanticAvailableAttr> getDeprecatedAttr() const;

/// Returns the first `@available` attribute that indicates that this decl
/// will be deprecated in the future, or `nullptr` otherwise.
const AvailableAttr *getSoftDeprecatedAttr() const;
std::optional<SemanticAvailableAttr> getSoftDeprecatedAttr() const;

/// Returns the first @available attribute that indicates this decl is
/// unavailable from asynchronous contexts, or `nullptr` otherwise.
const AvailableAttr *getNoAsyncAttr() const;
std::optional<SemanticAvailableAttr> getNoAsyncAttr() const;

/// Returns true if the decl has been marked unavailable in the Swift language
/// version that is currently active.
Expand All @@ -1443,12 +1443,12 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
///
/// Note that this query only considers the attributes that are attached
/// directly to this decl (or the extension it is declared in, if applicable).
bool isUnavailable() const { return getUnavailableAttr() != nullptr; }
bool isUnavailable() const { return getUnavailableAttr().has_value(); }

/// If the decl is always unavailable in the current compilation
/// context, returns the attribute attached to the decl (or its parent
/// extension) that makes it unavailable.
const AvailableAttr *
std::optional<SemanticAvailableAttr>
getUnavailableAttr(bool ignoreAppExtensions = false) const;

/// Returns true if the decl is effectively always unavailable in the current
Expand Down
Loading