@@ -486,11 +486,36 @@ bool Decl::isAvailableAsSPI() const {
486
486
return AvailabilityInference::isAvailableAsSPI (this );
487
487
}
488
488
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
+
489
514
const AvailableAttr *Decl::getDeprecatedAttr () const {
490
515
auto &ctx = getASTContext ();
491
516
auto attrs = getAttrs ();
492
517
const AvailableAttr *result = nullptr ;
493
- const AvailableAttr *bestActive = attrs. findMostSpecificActivePlatform (ctx );
518
+ const AvailableAttr *bestActive = getActiveAvailableAttrForCurrentPlatform ( );
494
519
495
520
for (auto attr :
496
521
attrs.getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
@@ -531,7 +556,7 @@ const AvailableAttr *Decl::getSoftDeprecatedAttr() const {
531
556
auto &ctx = getASTContext ();
532
557
auto attrs = getAttrs ();
533
558
const AvailableAttr *result = nullptr ;
534
- const AvailableAttr *bestActive = attrs. findMostSpecificActivePlatform (ctx );
559
+ const AvailableAttr *bestActive = getActiveAvailableAttrForCurrentPlatform ( );
535
560
536
561
for (auto attr :
537
562
attrs.getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
@@ -608,10 +633,9 @@ bool Decl::isUnavailableInCurrentSwiftVersion() const {
608
633
static const AvailableAttr *
609
634
getDeclUnavailableAttr (const Decl *D, bool ignoreAppExtensions) {
610
635
auto &ctx = D->getASTContext ();
611
- auto attrs = D->getAttrs ();
612
636
const AvailableAttr *result = nullptr ;
613
637
const AvailableAttr *bestActive =
614
- attrs. findMostSpecificActivePlatform (ctx, ignoreAppExtensions);
638
+ D-> getActiveAvailableAttrForCurrentPlatform ( ignoreAppExtensions);
615
639
616
640
for (auto attr :
617
641
D->getAttrs ().getAttributes <AvailableAttr, /* AllowInvalid=*/ false >()) {
0 commit comments