1818#include " swift/AST/ASTContext.h"
1919#include " swift/AST/Attr.h"
2020#include " swift/AST/AvailabilityConstraint.h"
21+ #include " swift/AST/AvailabilityDomain.h"
2122#include " swift/AST/Decl.h"
2223#include " swift/AST/PlatformKind.h"
2324#include " swift/AST/TypeCheckRequests.h"
@@ -432,22 +433,19 @@ bool AvailabilityInference::updateBeforePlatformForFallback(
432433
433434const AvailableAttr *
434435AvailabilityInference::attrForAnnotatedAvailableRange (const Decl *D) {
435- ASTContext &Ctx = D->getASTContext ();
436436 const AvailableAttr *bestAvailAttr = nullptr ;
437437
438438 D = abstractSyntaxDeclForAvailableAttribute (D);
439439
440- for (auto Attr : D->getAttrs ()) {
441- auto *AvailAttr = dyn_cast<AvailableAttr>(Attr);
442- if (AvailAttr == nullptr || !AvailAttr->Introduced .has_value () ||
443- !AvailAttr->isActivePlatform (Ctx) ||
444- AvailAttr->isLanguageVersionSpecific () ||
445- AvailAttr->isPackageDescriptionVersionSpecific ()) {
440+ for (auto semanticAttr :
441+ D->getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
442+ auto *attr = semanticAttr.getParsedAttr ();
443+
444+ if (!attr->hasPlatform () || !attr->Introduced .has_value ())
446445 continue ;
447- }
448446
449- if (isBetterThan (AvailAttr , bestAvailAttr))
450- bestAvailAttr = AvailAttr ;
447+ if (isBetterThan (attr , bestAvailAttr))
448+ bestAvailAttr = attr ;
451449 }
452450
453451 return bestAvailAttr;
@@ -468,12 +466,13 @@ bool Decl::isAvailableAsSPI() const {
468466
469467const AvailableAttr *
470468Decl::getActiveAvailableAttrForCurrentPlatform (bool ignoreAppExtensions) const {
471- auto &ctx = getASTContext ();
472469 const AvailableAttr *bestAttr = nullptr ;
473470
474- for (auto attr :
475- getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
476- if (!attr->hasPlatform () || !attr->isActivePlatform (ctx))
471+ for (auto semanticAttr :
472+ getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
473+ auto attr = semanticAttr.getParsedAttr ();
474+
475+ if (!attr->hasPlatform ())
477476 continue ;
478477
479478 if (ignoreAppExtensions &&
@@ -493,17 +492,14 @@ Decl::getActiveAvailableAttrForCurrentPlatform(bool ignoreAppExtensions) const {
493492
494493const AvailableAttr *Decl::getDeprecatedAttr () const {
495494 auto &ctx = getASTContext ();
496- auto attrs = getAttrs ();
497495 const AvailableAttr *result = nullptr ;
498496 const AvailableAttr *bestActive = getActiveAvailableAttrForCurrentPlatform ();
499497
500- for (auto attr :
501- attrs.getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
502- if (attr->hasPlatform () && (!bestActive || attr != bestActive))
503- continue ;
498+ for (auto semanticAttr :
499+ getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
500+ auto attr = semanticAttr.getParsedAttr ();
504501
505- if (!attr->isActivePlatform (ctx) && !attr->isLanguageVersionSpecific () &&
506- !attr->isPackageDescriptionVersionSpecific ())
502+ if (attr->hasPlatform () && (!bestActive || attr != bestActive))
507503 continue ;
508504
509505 // Unconditional deprecated.
@@ -534,17 +530,14 @@ const AvailableAttr *Decl::getDeprecatedAttr() const {
534530
535531const AvailableAttr *Decl::getSoftDeprecatedAttr () const {
536532 auto &ctx = getASTContext ();
537- auto attrs = getAttrs ();
538533 const AvailableAttr *result = nullptr ;
539534 const AvailableAttr *bestActive = getActiveAvailableAttrForCurrentPlatform ();
540535
541- for (auto attr :
542- attrs.getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
543- if (attr->hasPlatform () && (!bestActive || attr != bestActive))
544- continue ;
536+ for (auto semanticAttr :
537+ getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
538+ auto attr = semanticAttr.getParsedAttr ();
545539
546- if (!attr->isActivePlatform (ctx) && !attr->isLanguageVersionSpecific () &&
547- !attr->isPackageDescriptionVersionSpecific ())
540+ if (attr->hasPlatform () && (!bestActive || attr != bestActive))
548541 continue ;
549542
550543 std::optional<llvm::VersionTuple> deprecatedVersion = attr->Deprecated ;
@@ -560,19 +553,16 @@ const AvailableAttr *Decl::getSoftDeprecatedAttr() const {
560553}
561554
562555const AvailableAttr *Decl::getNoAsyncAttr () const {
563- auto &ctx = getASTContext ();
564556 const AvailableAttr *bestAttr = nullptr ;
565557
566- for (auto attr :
567- getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
558+ for (auto semanticAttr :
559+ getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
560+ auto attr = semanticAttr.getParsedAttr ();
568561
569562 if (attr->getPlatformAgnosticAvailability () !=
570563 PlatformAgnosticAvailabilityKind::NoAsync)
571564 continue ;
572565
573- if (attr->hasPlatform () && !attr->isActivePlatform (ctx))
574- continue ;
575-
576566 if (!bestAttr) {
577567 bestAttr = attr;
578568 continue ;
@@ -597,9 +587,12 @@ const AvailableAttr *Decl::getNoAsyncAttr() const {
597587
598588bool Decl::isUnavailableInCurrentSwiftVersion () const {
599589 llvm::VersionTuple vers = getASTContext ().LangOpts .EffectiveLanguageVersion ;
600- for (auto attr :
601- getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
602- if (attr->isLanguageVersionSpecific ()) {
590+ for (auto semanticAttr :
591+ getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
592+ auto attr = semanticAttr.getParsedAttr ();
593+ auto domain = semanticAttr.getDomain ();
594+
595+ if (domain.isSwiftLanguage ()) {
603596 if (attr->Introduced .has_value () && attr->Introduced .value () > vers)
604597 return true ;
605598 if (attr->Obsoleted .has_value () && attr->Obsoleted .value () <= vers)
@@ -617,18 +610,15 @@ getDeclUnavailableAttr(const Decl *D, bool ignoreAppExtensions) {
617610 const AvailableAttr *bestActive =
618611 D->getActiveAvailableAttrForCurrentPlatform (ignoreAppExtensions);
619612
620- for (auto attr :
621- D->getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
613+ for (auto semanticAttr :
614+ D->getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
615+ auto attr = semanticAttr.getParsedAttr ();
616+
622617 // If this is a platform-specific attribute and it isn't the most
623618 // specific attribute for the current platform, we're done.
624619 if (attr->hasPlatform () && (!bestActive || attr != bestActive))
625620 continue ;
626621
627- // If this attribute doesn't apply to the active platform, we're done.
628- if (!attr->isActivePlatform (ctx) && !attr->isLanguageVersionSpecific () &&
629- !attr->isPackageDescriptionVersionSpecific ())
630- continue ;
631-
632622 if (ignoreAppExtensions &&
633623 isApplicationExtensionPlatform (attr->getPlatform ()))
634624 continue ;
0 commit comments