@@ -486,11 +486,36 @@ bool Decl::isAvailableAsSPI() const {
486486 return AvailabilityInference::isAvailableAsSPI (this );
487487}
488488
489+ const AvailableAttr *
490+ Decl::getActiveAvailableAttrForCurrentPlatform (bool ignoreAppExtensions) const {
491+ auto &ctx = getASTContext ();
492+ const AvailableAttr *bestAttr = nullptr ;
493+
494+ for (auto attr :
495+ getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
496+ if (!attr->hasPlatform () || !attr->isActivePlatform (ctx))
497+ continue ;
498+
499+ if (ignoreAppExtensions &&
500+ isApplicationExtensionPlatform (attr->getPlatform ()))
501+ continue ;
502+
503+ // We have an attribute that is active for the platform, but is it more
504+ // specific than our current best?
505+ if (!bestAttr || inheritsAvailabilityFromPlatform (
506+ attr->getPlatform (), bestAttr->getPlatform ())) {
507+ bestAttr = attr;
508+ }
509+ }
510+
511+ return bestAttr;
512+ }
513+
489514const AvailableAttr *Decl::getDeprecatedAttr () const {
490515 auto &ctx = getASTContext ();
491516 auto attrs = getAttrs ();
492517 const AvailableAttr *result = nullptr ;
493- const AvailableAttr *bestActive = attrs. findMostSpecificActivePlatform (ctx );
518+ const AvailableAttr *bestActive = getActiveAvailableAttrForCurrentPlatform ( );
494519
495520 for (auto attr :
496521 attrs.getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
@@ -531,7 +556,7 @@ const AvailableAttr *Decl::getSoftDeprecatedAttr() const {
531556 auto &ctx = getASTContext ();
532557 auto attrs = getAttrs ();
533558 const AvailableAttr *result = nullptr ;
534- const AvailableAttr *bestActive = attrs. findMostSpecificActivePlatform (ctx );
559+ const AvailableAttr *bestActive = getActiveAvailableAttrForCurrentPlatform ( );
535560
536561 for (auto attr :
537562 attrs.getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
@@ -608,10 +633,9 @@ bool Decl::isUnavailableInCurrentSwiftVersion() const {
608633static const AvailableAttr *
609634getDeclUnavailableAttr (const Decl *D, bool ignoreAppExtensions) {
610635 auto &ctx = D->getASTContext ();
611- auto attrs = D->getAttrs ();
612636 const AvailableAttr *result = nullptr ;
613637 const AvailableAttr *bestActive =
614- attrs. findMostSpecificActivePlatform (ctx, ignoreAppExtensions);
638+ D-> getActiveAvailableAttrForCurrentPlatform ( ignoreAppExtensions);
615639
616640 for (auto attr :
617641 D->getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
0 commit comments