Skip to content

Commit 57cce71

Browse files
authored
Merge pull request #78308 from tshortli/adopt-semantic-available-attr
2 parents cd1ef24 + 00aae6e commit 57cce71

12 files changed

+219
-203
lines changed

include/swift/AST/Attr.h

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,13 +3189,44 @@ class SemanticAvailableAttr final {
31893189
const AvailableAttr *getParsedAttr() const { return attr; }
31903190
const AvailabilityDomain getDomain() const { return domain; }
31913191

3192+
std::optional<llvm::VersionTuple> getIntroduced() const {
3193+
return attr->Introduced;
3194+
}
3195+
3196+
std::optional<llvm::VersionTuple> getDeprecated() const {
3197+
return attr->Deprecated;
3198+
}
3199+
3200+
std::optional<llvm::VersionTuple> getObsoleted() const {
3201+
return attr->Obsoleted;
3202+
}
3203+
3204+
/// Returns the `message:` field of the attribute, or an empty string.
3205+
StringRef getMessage() const { return attr->Message; }
3206+
3207+
/// Returns the `rename:` field of the attribute, or an empty string.
3208+
StringRef getRename() const { return attr->Rename; }
3209+
31923210
/// Returns the platform kind that the attribute applies to, or
31933211
/// `PlatformKind::none` if the attribute is not platform specific.
3194-
bool isPlatformSpecific() const { return domain.isPlatform(); }
3212+
bool isPlatformSpecific() const { return getDomain().isPlatform(); }
31953213

31963214
/// Returns the platform kind that the attribute applies to, or
31973215
/// `PlatformKind::none` if the attribute is not platform specific.
3198-
PlatformKind getPlatformKind() const { return domain.getPlatformKind(); }
3216+
PlatformKind getPlatform() const { return getDomain().getPlatformKind(); }
3217+
3218+
/// Whether this is attribute indicates unavailability in all versions.
3219+
bool isUnconditionallyUnavailable() const {
3220+
return attr->isUnconditionallyUnavailable();
3221+
}
3222+
3223+
/// Whether this is attribute indicates deprecation in all versions.
3224+
bool isUnconditionallyDeprecated() const {
3225+
return attr->isUnconditionallyDeprecated();
3226+
}
3227+
3228+
/// Whether this is a `noasync` attribute.
3229+
bool isNoAsync() const { return attr->isNoAsync(); }
31993230

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

32063237
/// Whether this is a language mode specific attribute.
32073238
bool isSwiftLanguageModeSpecific() const {
3208-
return domain.isSwiftLanguage() && isVersionSpecific();
3239+
return getDomain().isSwiftLanguage() && isVersionSpecific();
32093240
}
32103241

32113242
/// Whether this is a PackageDescription version specific attribute.
32123243
bool isPackageDescriptionVersionSpecific() const {
3213-
return domain.isPackageDescription() && isVersionSpecific();
3244+
return getDomain().isPackageDescription() && isVersionSpecific();
32143245
}
32153246

3247+
/// Whether this attribute was spelled `@_unavailableInEmbedded`.
3248+
bool isEmbeddedSpecific() const { return attr->isForEmbedded(); }
3249+
32163250
/// Returns the active version from the AST context corresponding to
32173251
/// the available kind. For example, this will return the effective language
32183252
/// version for swift version-specific availability kind, PackageDescription
@@ -3228,6 +3262,14 @@ class SemanticAvailableAttr final {
32283262
/// Returns true if this attribute is considered active in the current
32293263
/// compilation context.
32303264
bool isActive(ASTContext &ctx) const;
3265+
3266+
bool operator==(const SemanticAvailableAttr &other) const {
3267+
return other.attr == attr;
3268+
}
3269+
3270+
bool operator!=(const SemanticAvailableAttr &other) const {
3271+
return other.attr != attr;
3272+
}
32313273
};
32323274

32333275
/// An iterable range of `SemanticAvailableAttr`s.

include/swift/AST/Decl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,24 +1411,24 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
14111411
/// Returns the active platform-specific `@available` attribute for this decl.
14121412
/// There may be multiple `@available` attributes that are relevant to the
14131413
/// current platform, but the returned one has the highest priority.
1414-
const AvailableAttr *getActiveAvailableAttrForCurrentPlatform(
1414+
std::optional<SemanticAvailableAttr> getActiveAvailableAttrForCurrentPlatform(
14151415
bool ignoreAppExtensions = false) const;
14161416

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

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

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

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

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

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

14541454
/// Returns true if the decl is effectively always unavailable in the current

0 commit comments

Comments
 (0)