@@ -294,20 +294,18 @@ AvailabilityInference::parentDeclForInferredAvailability(const Decl *D) {
294294// / Returns true if the introduced version in \p newAttr should be used instead
295295// / of the introduced version in \p prevAttr when both are attached to the same
296296// / declaration and refer to the active platform.
297- static bool isBetterThan (const AvailableAttr *newAttr,
298- const AvailableAttr *prevAttr) {
299- assert (newAttr);
300-
297+ static bool isBetterThan (const SemanticAvailableAttr &newAttr,
298+ const std::optional<SemanticAvailableAttr> &prevAttr) {
301299 // If there is no prevAttr, newAttr of course wins.
302300 if (!prevAttr)
303301 return true ;
304302
305303 // If they belong to the same platform, the one that introduces later wins.
306- if (prevAttr->getPlatform () == newAttr-> getPlatform ())
307- return prevAttr->Introduced .value () < newAttr-> Introduced .value ();
304+ if (prevAttr->getPlatform () == newAttr. getPlatform ())
305+ return prevAttr->getIntroduced () .value () < newAttr. getIntroduced () .value ();
308306
309307 // If the new attribute's platform inherits from the old one, it wins.
310- return inheritsAvailabilityFromPlatform (newAttr-> getPlatform (),
308+ return inheritsAvailabilityFromPlatform (newAttr. getPlatform (),
311309 prevAttr->getPlatform ());
312310}
313311
@@ -433,22 +431,19 @@ bool AvailabilityInference::updateBeforePlatformForFallback(
433431
434432const AvailableAttr *
435433AvailabilityInference::attrForAnnotatedAvailableRange (const Decl *D) {
436- const AvailableAttr * bestAvailAttr = nullptr ;
434+ std::optional<SemanticAvailableAttr> bestAvailAttr;
437435
438436 D = abstractSyntaxDeclForAvailableAttribute (D);
439437
440- for (auto semanticAttr :
441- D->getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
442- auto *attr = semanticAttr.getParsedAttr ();
443-
444- if (!attr->hasPlatform () || !attr->Introduced .has_value ())
438+ for (auto attr : D->getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
439+ if (!attr.isPlatformSpecific () || !attr.getIntroduced ())
445440 continue ;
446441
447442 if (isBetterThan (attr, bestAvailAttr))
448- bestAvailAttr = attr;
443+ bestAvailAttr. emplace ( attr) ;
449444 }
450445
451- return bestAvailAttr;
446+ return bestAvailAttr ? bestAvailAttr-> getParsedAttr () : nullptr ;
452447}
453448
454449std::optional<AvailabilityRange>
@@ -779,25 +774,24 @@ bool Decl::requiresUnavailableDeclABICompatibilityStubs() const {
779774
780775AvailabilityRange AvailabilityInference::annotatedAvailableRangeForAttr (
781776 const Decl *D, const SpecializeAttr *attr, ASTContext &ctx) {
782-
783- const AvailableAttr *bestAvailAttr = nullptr ;
777+ std::optional<SemanticAvailableAttr> bestAvailAttr;
784778
785779 for (auto *availAttr : attr->getAvailableAttrs ()) {
786780 auto semanticAttr = D->getSemanticAvailableAttr (availAttr);
787781 if (!semanticAttr)
788782 continue ;
789783
790- if (!availAttr-> Introduced . has_value () || !semanticAttr->isActive (ctx) ||
784+ if (!semanticAttr-> getIntroduced () || !semanticAttr->isActive (ctx) ||
791785 !semanticAttr->isPlatformSpecific ()) {
792786 continue ;
793787 }
794788
795- if (isBetterThan (availAttr , bestAvailAttr))
796- bestAvailAttr = availAttr ;
789+ if (isBetterThan (*semanticAttr , bestAvailAttr))
790+ bestAvailAttr. emplace (*semanticAttr) ;
797791 }
798792
799793 if (bestAvailAttr)
800- return availableRange (bestAvailAttr, ctx);
794+ return availableRange (bestAvailAttr-> getParsedAttr () , ctx);
801795
802796 return AvailabilityRange::alwaysAvailable ();
803797}
0 commit comments