@@ -423,8 +423,7 @@ AvailabilityInference::annotatedAvailableRange(const Decl *D, ASTContext &Ctx) {
423
423
}
424
424
425
425
bool Decl::isAvailableAsSPI () const {
426
- return AvailabilityInference::availableRange (this , getASTContext ())
427
- .isAvailableAsSPI ();
426
+ return AvailabilityInference::isAvailableAsSPI (this , getASTContext ());
428
427
}
429
428
430
429
std::optional<AvailableAttrDeclPair>
@@ -550,13 +549,10 @@ AvailabilityInference::annotatedAvailableRangeForAttr(const SpecializeAttr* attr
550
549
return AvailabilityContext::alwaysAvailable ();
551
550
}
552
551
553
- AvailabilityContext AvailabilityInference::availableRange (const Decl *D,
554
- ASTContext &Ctx) {
555
- std::optional<AvailabilityContext> AnnotatedRange =
556
- annotatedAvailableRange (D, Ctx);
557
- if (AnnotatedRange.has_value ()) {
558
- return AnnotatedRange.value ();
559
- }
552
+ static const AvailableAttr *attrForAvailableRange (const Decl *D,
553
+ ASTContext &Ctx) {
554
+ if (auto attr = AvailabilityInference::attrForAnnotatedAvailableRange (D, Ctx))
555
+ return attr;
560
556
561
557
// Unlike other declarations, extensions can be used without referring to them
562
558
// by name (they don't have one) in the source. For this reason, when checking
@@ -568,16 +564,30 @@ AvailabilityContext AvailabilityInference::availableRange(const Decl *D,
568
564
569
565
DeclContext *DC = D->getDeclContext ();
570
566
if (auto *ED = dyn_cast<ExtensionDecl>(DC)) {
571
- AnnotatedRange = annotatedAvailableRange (ED, Ctx);
572
- if (AnnotatedRange.has_value ()) {
573
- return AnnotatedRange.value ();
574
- }
567
+ if (auto attr =
568
+ AvailabilityInference::attrForAnnotatedAvailableRange (ED, Ctx))
569
+ return attr;
575
570
}
576
571
572
+ return nullptr ;
573
+ }
574
+
575
+ AvailabilityContext AvailabilityInference::availableRange (const Decl *D,
576
+ ASTContext &Ctx) {
577
+ if (auto attr = attrForAvailableRange (D, Ctx))
578
+ return availableRange (attr, Ctx);
579
+
577
580
// Treat unannotated declarations as always available.
578
581
return AvailabilityContext::alwaysAvailable ();
579
582
}
580
583
584
+ bool AvailabilityInference::isAvailableAsSPI (const Decl *D, ASTContext &Ctx) {
585
+ if (auto attr = attrForAvailableRange (D, Ctx))
586
+ return attr->IsSPI ;
587
+
588
+ return false ;
589
+ }
590
+
581
591
AvailabilityContext
582
592
AvailabilityInference::availableRange (const AvailableAttr *attr,
583
593
ASTContext &Ctx) {
@@ -590,8 +600,7 @@ AvailabilityInference::availableRange(const AvailableAttr *attr,
590
600
attr, Ctx, Platform, RemappedIntroducedVersion))
591
601
IntroducedVersion = RemappedIntroducedVersion;
592
602
593
- return AvailabilityContext{VersionRange::allGTE (IntroducedVersion),
594
- attr->IsSPI };
603
+ return AvailabilityContext{VersionRange::allGTE (IntroducedVersion)};
595
604
}
596
605
597
606
namespace {
0 commit comments