@@ -294,20 +294,18 @@ AvailabilityInference::parentDeclForInferredAvailability(const Decl *D) {
294
294
// / Returns true if the introduced version in \p newAttr should be used instead
295
295
// / of the introduced version in \p prevAttr when both are attached to the same
296
296
// / 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) {
301
299
// If there is no prevAttr, newAttr of course wins.
302
300
if (!prevAttr)
303
301
return true ;
304
302
305
303
// 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 ();
308
306
309
307
// If the new attribute's platform inherits from the old one, it wins.
310
- return inheritsAvailabilityFromPlatform (newAttr-> getPlatform (),
308
+ return inheritsAvailabilityFromPlatform (newAttr. getPlatform (),
311
309
prevAttr->getPlatform ());
312
310
}
313
311
@@ -433,22 +431,19 @@ bool AvailabilityInference::updateBeforePlatformForFallback(
433
431
434
432
const AvailableAttr *
435
433
AvailabilityInference::attrForAnnotatedAvailableRange (const Decl *D) {
436
- const AvailableAttr * bestAvailAttr = nullptr ;
434
+ std::optional<SemanticAvailableAttr> bestAvailAttr;
437
435
438
436
D = abstractSyntaxDeclForAvailableAttribute (D);
439
437
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 ())
445
440
continue ;
446
441
447
442
if (isBetterThan (attr, bestAvailAttr))
448
- bestAvailAttr = attr;
443
+ bestAvailAttr. emplace ( attr) ;
449
444
}
450
445
451
- return bestAvailAttr;
446
+ return bestAvailAttr ? bestAvailAttr-> getParsedAttr () : nullptr ;
452
447
}
453
448
454
449
std::optional<AvailabilityRange>
@@ -779,25 +774,24 @@ bool Decl::requiresUnavailableDeclABICompatibilityStubs() const {
779
774
780
775
AvailabilityRange AvailabilityInference::annotatedAvailableRangeForAttr (
781
776
const Decl *D, const SpecializeAttr *attr, ASTContext &ctx) {
782
-
783
- const AvailableAttr *bestAvailAttr = nullptr ;
777
+ std::optional<SemanticAvailableAttr> bestAvailAttr;
784
778
785
779
for (auto *availAttr : attr->getAvailableAttrs ()) {
786
780
auto semanticAttr = D->getSemanticAvailableAttr (availAttr);
787
781
if (!semanticAttr)
788
782
continue ;
789
783
790
- if (!availAttr-> Introduced . has_value () || !semanticAttr->isActive (ctx) ||
784
+ if (!semanticAttr-> getIntroduced () || !semanticAttr->isActive (ctx) ||
791
785
!semanticAttr->isPlatformSpecific ()) {
792
786
continue ;
793
787
}
794
788
795
- if (isBetterThan (availAttr , bestAvailAttr))
796
- bestAvailAttr = availAttr ;
789
+ if (isBetterThan (*semanticAttr , bestAvailAttr))
790
+ bestAvailAttr. emplace (*semanticAttr) ;
797
791
}
798
792
799
793
if (bestAvailAttr)
800
- return availableRange (bestAvailAttr, ctx);
794
+ return availableRange (bestAvailAttr-> getParsedAttr () , ctx);
801
795
802
796
return AvailabilityRange::alwaysAvailable ();
803
797
}
0 commit comments