@@ -573,49 +573,14 @@ bool Decl::isUnavailableInCurrentSwiftVersion() const {
573
573
return false ;
574
574
}
575
575
576
- std::optional<SemanticAvailableAttr> getDeclUnavailableAttr (const Decl *D) {
577
- auto &ctx = D->getASTContext ();
578
- std::optional<SemanticAvailableAttr> result;
579
- auto bestActive = D->getActiveAvailableAttrForCurrentPlatform ();
580
-
581
- for (auto attr : D->getSemanticAvailableAttrs (/* includingInactive=*/ false )) {
582
- // If this is a platform-specific attribute and it isn't the most
583
- // specific attribute for the current platform, we're done.
584
- if (attr.isPlatformSpecific () && (!bestActive || attr != bestActive))
585
- continue ;
586
-
587
- // Unconditional unavailable.
588
- if (attr.isUnconditionallyUnavailable ())
589
- return attr;
590
-
591
- switch (attr.getVersionAvailability (ctx)) {
592
- case AvailableVersionComparison::Available:
593
- case AvailableVersionComparison::PotentiallyUnavailable:
594
- break ;
595
-
596
- case AvailableVersionComparison::Obsoleted:
597
- case AvailableVersionComparison::Unavailable:
598
- result.emplace (attr);
599
- break ;
600
- }
601
- }
602
- return result;
603
- }
604
-
605
576
std::optional<SemanticAvailableAttr> Decl::getUnavailableAttr () const {
606
- if ( auto attr = getDeclUnavailableAttr ( this ))
607
- return attr ;
577
+ auto context = AvailabilityContext::forDeploymentTarget ( getASTContext ());
578
+ auto constraints = swift::getAvailabilityConstraintsForDecl ( this , context) ;
608
579
609
- // If D is an extension member, check if the extension is unavailable.
610
- //
611
- // Skip decls imported from Clang, they could be associated to the wrong
612
- // extension and inherit undesired unavailability. The ClangImporter
613
- // associates Objective-C protocol members to the first category where the
614
- // protocol is directly or indirectly adopted, no matter its availability
615
- // and the availability of other categories. rdar://problem/53956555
616
- if (!getClangNode ())
617
- if (auto ext = dyn_cast<ExtensionDecl>(getDeclContext ()))
618
- return ext->getUnavailableAttr ();
580
+ for (auto const &constraint : constraints) {
581
+ if (constraint.isUnavailable ())
582
+ return constraint.getAttr ();
583
+ }
619
584
620
585
return std::nullopt;
621
586
}
0 commit comments